@bsol-oss/react-datatable5 12.0.0-beta.4 → 12.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +94 -76
- package/dist/index.js +815 -375
- package/dist/index.mjs +819 -378
- package/dist/types/components/DataTable/DataTable.d.ts +1 -1
- package/dist/types/components/DataTable/DataTableServer.d.ts +1 -1
- package/dist/types/components/DataTable/DefaultTable.d.ts +9 -12
- package/dist/types/components/DataTable/components/TextCell.d.ts +10 -0
- package/dist/types/components/DataTable/context/DataTableContext.d.ts +3 -2
- package/dist/types/components/DataTable/controls/DensityFeature.d.ts +23 -0
- package/dist/types/components/DataTable/controls/DensityToggleButton.d.ts +6 -0
- package/dist/types/components/DataTable/controls/EditSortingButton.d.ts +7 -0
- package/dist/types/components/DataTable/controls/FilterDialog.d.ts +5 -0
- package/dist/types/components/DataTable/controls/PageSizeControl.d.ts +4 -0
- package/dist/types/components/DataTable/controls/Pagination.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ReloadButton.d.ts +5 -0
- package/dist/types/components/DataTable/controls/ResetFilteringButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/ResetSelectionButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/ResetSortingButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/RowCountText.d.ts +1 -0
- package/dist/types/components/DataTable/controls/SelectAllRowsToggle.d.ts +8 -0
- package/dist/types/components/DataTable/controls/TableControls.d.ts +23 -0
- package/dist/types/components/DataTable/controls/TableFilterTags.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableFilters.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableSelector.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableSorter.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableViewer.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ViewDialog.d.ts +5 -0
- package/dist/types/components/DataTable/display/CardHeader.d.ts +13 -0
- package/dist/types/components/DataTable/display/DataDisplay.d.ts +6 -0
- package/dist/types/components/DataTable/display/EmptyState.d.ts +5 -0
- package/dist/types/components/DataTable/display/ErrorAlert.d.ts +4 -0
- package/dist/types/components/DataTable/display/RecordDisplay.d.ts +9 -0
- package/dist/types/components/DataTable/display/Table.d.ts +10 -0
- package/dist/types/components/DataTable/display/TableBody.d.ts +21 -0
- package/dist/types/components/DataTable/display/TableCardContainer.d.ts +7 -0
- package/dist/types/components/DataTable/display/TableCards.d.ts +11 -0
- package/dist/types/components/DataTable/display/TableComponent.d.ts +6 -0
- package/dist/types/components/DataTable/display/TableDataDisplay.d.ts +6 -0
- package/dist/types/components/DataTable/display/TableFooter.d.ts +5 -0
- package/dist/types/components/DataTable/display/TableHeader.d.ts +9 -0
- package/dist/types/components/DataTable/display/TableLoadingComponent.d.ts +5 -0
- package/dist/types/components/DataTable/display/TextCell.d.ts +10 -0
- package/dist/types/components/DataTable/useDataTable.d.ts +1 -1
- package/dist/types/components/Form/components/core/DefaultForm.d.ts +2 -1
- package/dist/types/components/Form/components/core/FormRoot.d.ts +2 -1
- package/dist/types/components/Form/components/fields/CustomInput.d.ts +8 -0
- package/dist/types/components/Form/components/fields/DatePicker.d.ts +2 -7
- package/dist/types/components/Form/components/fields/EnumPicker.d.ts +2 -1
- package/dist/types/components/Form/components/fields/FilePicker.d.ts +2 -5
- package/dist/types/components/Form/components/fields/StringInputField.d.ts +2 -5
- package/dist/types/components/Form/components/fields/TextAreaInput.d.ts +12 -0
- package/dist/types/components/Form/components/fields/TimePicker.d.ts +7 -0
- package/dist/types/components/Form/components/fields/types.d.ts +6 -0
- package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +17 -1
- package/dist/types/components/Form/components/viewers/CustomViewer.d.ts +8 -0
- package/dist/types/components/Form/components/viewers/TextAreaViewer.d.ts +12 -0
- package/dist/types/components/Form/components/viewers/TimeViewer.d.ts +7 -0
- package/dist/types/components/TimePicker/TimePicker.d.ts +20 -0
- package/dist/types/index.d.ts +32 -33
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, Flex,
|
|
2
|
+
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, Flex, Text, useDisclosure, DialogBackdrop, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Tag as Tag$1, Input, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, CheckboxCard as CheckboxCard$1, Image, EmptyState as EmptyState$2, VStack, Alert, Card, Tooltip as Tooltip$1, Group, InputElement, Icon, List, Table as Table$1, Checkbox as Checkbox$1, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, Accordion, Field as Field$1, Popover, NumberInput, Show, RadioCard, CheckboxGroup, Textarea, Center, Heading } from '@chakra-ui/react';
|
|
3
3
|
import { AiOutlineColumnWidth } from 'react-icons/ai';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { createContext, useContext, useState, useEffect, useRef } from 'react';
|
|
6
6
|
import { LuX, LuCheck, LuChevronRight, LuChevronDown } from 'react-icons/lu';
|
|
7
|
-
import {
|
|
7
|
+
import { MdOutlineSort, MdFilterAlt, MdSearch, MdClose, MdOutlineViewColumn, MdFilterListAlt, MdPushPin, MdCancel, MdClear, MdOutlineChecklist, MdDateRange } from 'react-icons/md';
|
|
8
8
|
import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
|
|
9
9
|
import { BiDownArrow, BiUpArrow, BiError } from 'react-icons/bi';
|
|
10
10
|
import { CgClose } from 'react-icons/cg';
|
|
11
11
|
import Dayzed from '@bsol-oss/dayzed-react19';
|
|
12
12
|
import { HiMiniEllipsisHorizontal, HiChevronLeft, HiChevronRight } from 'react-icons/hi2';
|
|
13
|
-
import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
|
|
13
|
+
import { IoMdEye, IoMdCheckbox, IoMdClock } from 'react-icons/io';
|
|
14
14
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
15
15
|
import { bind, bindAll } from 'bind-event-listener';
|
|
16
16
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
17
17
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
18
18
|
import rafSchd from 'raf-schd';
|
|
19
19
|
import invariant from 'tiny-invariant';
|
|
20
|
-
import { HiColorSwatch } from 'react-icons/hi';
|
|
20
|
+
import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
|
|
21
21
|
import { flexRender, makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, createColumnHelper } from '@tanstack/react-table';
|
|
22
22
|
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
23
23
|
import { BsExclamationCircleFill } from 'react-icons/bs';
|
|
@@ -29,6 +29,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
29
29
|
import axios from 'axios';
|
|
30
30
|
import { FormProvider, useFormContext, useForm as useForm$1 } from 'react-hook-form';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
import utc from 'dayjs/plugin/utc';
|
|
32
33
|
import { TiDeleteOutline } from 'react-icons/ti';
|
|
33
34
|
|
|
34
35
|
const DataTableContext = createContext({
|
|
@@ -37,6 +38,39 @@ const DataTableContext = createContext({
|
|
|
37
38
|
setGlobalFilter: () => { },
|
|
38
39
|
type: "client",
|
|
39
40
|
translate: {},
|
|
41
|
+
data: [],
|
|
42
|
+
columns: [],
|
|
43
|
+
columnOrder: [],
|
|
44
|
+
columnFilters: [],
|
|
45
|
+
density: "sm",
|
|
46
|
+
sorting: [],
|
|
47
|
+
setPagination: function () {
|
|
48
|
+
throw new Error("Function not implemented.");
|
|
49
|
+
},
|
|
50
|
+
setSorting: function () {
|
|
51
|
+
throw new Error("Function not implemented.");
|
|
52
|
+
},
|
|
53
|
+
setColumnFilters: function () {
|
|
54
|
+
throw new Error("Function not implemented.");
|
|
55
|
+
},
|
|
56
|
+
setRowSelection: function () {
|
|
57
|
+
throw new Error("Function not implemented.");
|
|
58
|
+
},
|
|
59
|
+
setColumnOrder: function () {
|
|
60
|
+
throw new Error("Function not implemented.");
|
|
61
|
+
},
|
|
62
|
+
setDensity: function () {
|
|
63
|
+
throw new Error("Function not implemented.");
|
|
64
|
+
},
|
|
65
|
+
setColumnVisibility: function () {
|
|
66
|
+
throw new Error("Function not implemented.");
|
|
67
|
+
},
|
|
68
|
+
pagination: {
|
|
69
|
+
pageIndex: 0,
|
|
70
|
+
pageSize: 10,
|
|
71
|
+
},
|
|
72
|
+
rowSelection: {},
|
|
73
|
+
columnVisibility: {},
|
|
40
74
|
});
|
|
41
75
|
|
|
42
76
|
const useDataTableContext = () => {
|
|
@@ -78,63 +112,6 @@ Dialog.Description;
|
|
|
78
112
|
const DialogTrigger = Dialog.Trigger;
|
|
79
113
|
Dialog.ActionTrigger;
|
|
80
114
|
|
|
81
|
-
const ColumnOrderChanger = ({ columns }) => {
|
|
82
|
-
const [order, setOrder] = useState([]);
|
|
83
|
-
const [originalOrder, setOriginalOrder] = useState([]);
|
|
84
|
-
const { table } = useDataTableContext();
|
|
85
|
-
const handleChangeOrder = (startIndex, endIndex) => {
|
|
86
|
-
const newOrder = Array.from(order);
|
|
87
|
-
const [removed] = newOrder.splice(startIndex, 1);
|
|
88
|
-
newOrder.splice(endIndex, 0, removed);
|
|
89
|
-
setOrder(newOrder);
|
|
90
|
-
};
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
setOrder(columns);
|
|
93
|
-
}, [columns]);
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (originalOrder.length > 0) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (columns.length <= 0) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
setOriginalOrder(columns);
|
|
102
|
-
}, [columns]);
|
|
103
|
-
return (jsxs(Flex, { gap: 2, flexFlow: "column", children: [jsx(Flex, { gap: 2, flexFlow: "column", children: order.map((columnId, index) => (jsxs(Flex, { gap: 2, alignItems: "center", justifyContent: "space-between", children: [jsx(IconButton, { onClick: () => {
|
|
104
|
-
const prevIndex = index - 1;
|
|
105
|
-
if (prevIndex >= 0) {
|
|
106
|
-
handleChangeOrder(index, prevIndex);
|
|
107
|
-
}
|
|
108
|
-
}, disabled: index === 0, "aria-label": "", children: jsx(MdArrowUpward, {}) }), table
|
|
109
|
-
.getAllFlatColumns()
|
|
110
|
-
.filter((column) => {
|
|
111
|
-
return column.id === columnId;
|
|
112
|
-
})
|
|
113
|
-
.map((column) => {
|
|
114
|
-
const displayName = column.columnDef.meta === undefined
|
|
115
|
-
? column.id
|
|
116
|
-
: column.columnDef.meta.displayName;
|
|
117
|
-
return jsx("span", { children: displayName }, column.id);
|
|
118
|
-
}), jsx(IconButton, { onClick: () => {
|
|
119
|
-
const nextIndex = index + 1;
|
|
120
|
-
if (nextIndex < order.length) {
|
|
121
|
-
handleChangeOrder(index, nextIndex);
|
|
122
|
-
}
|
|
123
|
-
}, disabled: index === order.length - 1, "aria-label": "", children: jsx(MdArrowDownward, {}) })] }, columnId))) }), jsxs(Flex, { gap: "0.25rem", children: [jsx(Button$1, { onClick: () => {
|
|
124
|
-
table.setColumnOrder(order);
|
|
125
|
-
}, children: "Apply" }), jsx(Button$1, { onClick: () => {
|
|
126
|
-
table.setColumnOrder(originalOrder);
|
|
127
|
-
}, children: "Reset" })] })] }));
|
|
128
|
-
};
|
|
129
|
-
const TableOrderer = () => {
|
|
130
|
-
const { table } = useDataTableContext();
|
|
131
|
-
return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const EditOrderButton = ({ text, icon = jsx(MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
135
|
-
return (jsx(Fragment, { children: jsxs(DialogRoot, { size: "cover", children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", children: [icon, " ", text] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsxs(DialogHeader, { children: [jsx(DialogTitle, {}), title] }), jsx(DialogBody, { children: jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: jsx(TableOrderer, {}) }) }), jsx(DialogFooter, {})] })] }) }));
|
|
136
|
-
};
|
|
137
|
-
|
|
138
115
|
const TableSorter = () => {
|
|
139
116
|
const { table } = useDataTableContext();
|
|
140
117
|
return (jsx(Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsx(Fragment, { children: headerGroup.headers.map((header) => {
|
|
@@ -440,7 +417,7 @@ const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
|
440
417
|
const FilterDialog = ({ icon = jsx(MdFilterAlt, {}), }) => {
|
|
441
418
|
const filterModal = useDisclosure();
|
|
442
419
|
const { translate } = useDataTableContext();
|
|
443
|
-
return (jsxs(DialogRoot, { size: ["full", "full", "md", "md"], open: filterModal.open, children: [jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: filterModal.onOpen, children: [icon, " ", translate.t("
|
|
420
|
+
return (jsxs(DialogRoot, { size: ["full", "full", "md", "md"], open: filterModal.open, children: [jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: filterModal.onOpen, children: [icon, " ", translate.t("filter_dialog.button_text")] }) }), jsxs(DialogContent, { children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: translate.t("filter_dialog.title") }) }), jsx(DialogBody, { display: "flex", flexFlow: "column", children: jsx(TableFilter, {}) }), jsxs(DialogFooter, { children: [jsx(ResetFilteringButton, { text: translate.t("filter_dialog.reset") }), jsx(Button$1, { onClick: filterModal.onClose, variant: "subtle", children: translate.t("filter_dialog.close") })] }), jsx(DialogCloseTrigger, { onClick: filterModal.onClose })] })] }));
|
|
444
421
|
};
|
|
445
422
|
|
|
446
423
|
const MenuContent = React.forwardRef(function MenuContent(props, ref) {
|
|
@@ -2478,8 +2455,8 @@ CheckboxCard$1.Indicator;
|
|
|
2478
2455
|
function ColumnCard({ columnId }) {
|
|
2479
2456
|
const ref = useRef(null);
|
|
2480
2457
|
const [dragging, setDragging] = useState(false); // NEW
|
|
2481
|
-
const { table } = useDataTableContext();
|
|
2482
|
-
const displayName = columnId;
|
|
2458
|
+
const { table, translate } = useDataTableContext();
|
|
2459
|
+
const displayName = translate.t(columnId);
|
|
2483
2460
|
const column = table.getColumn(columnId);
|
|
2484
2461
|
invariant(column);
|
|
2485
2462
|
useEffect(() => {
|
|
@@ -2494,13 +2471,16 @@ function ColumnCard({ columnId }) {
|
|
|
2494
2471
|
onDrop: () => setDragging(false), // NEW
|
|
2495
2472
|
});
|
|
2496
2473
|
}, [columnId, table]);
|
|
2497
|
-
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor:
|
|
2474
|
+
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor: "grab", children: jsx(FaGripLinesVertical, { color: "colorPalette.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2498
2475
|
}
|
|
2499
2476
|
function CardContainer({ location, children }) {
|
|
2500
2477
|
const ref = useRef(null);
|
|
2501
2478
|
const [isDraggedOver, setIsDraggedOver] = useState(false);
|
|
2502
2479
|
useEffect(() => {
|
|
2503
2480
|
const el = ref.current;
|
|
2481
|
+
if (el === null) {
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2504
2484
|
invariant(el);
|
|
2505
2485
|
return dropTargetForElements({
|
|
2506
2486
|
element: el,
|
|
@@ -2572,7 +2552,7 @@ const TableViewer = () => {
|
|
|
2572
2552
|
const ViewDialog = ({ icon = jsx(IoMdEye, {}) }) => {
|
|
2573
2553
|
const viewModel = useDisclosure();
|
|
2574
2554
|
const { translate } = useDataTableContext();
|
|
2575
|
-
return (jsxs(DialogRoot, { children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", translate.t("
|
|
2555
|
+
return (jsxs(DialogRoot, { children: [jsx(DialogBackdrop, {}), jsx(DialogTrigger, { asChild: true, children: jsxs(Button$1, { as: Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", translate.t("view_dialog.button_text")] }) }), jsxs(DialogContent, { children: [jsx(DialogCloseTrigger, {}), jsx(DialogHeader, { children: jsx(DialogTitle, { children: translate.t("view_dialog.title") }) }), jsx(DialogBody, { children: jsx(TableViewer, {}) }), jsx(DialogFooter, {})] })] }));
|
|
2576
2556
|
};
|
|
2577
2557
|
|
|
2578
2558
|
const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
|
|
@@ -2623,7 +2603,7 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
|
|
|
2623
2603
|
return jsx(Fragment, { children: "null" });
|
|
2624
2604
|
}
|
|
2625
2605
|
return (jsx(Grid, { rowGap: 1, padding: 1, overflow: "auto", ...boxProps, children: Object.entries(object).map(([field, value]) => {
|
|
2626
|
-
return (jsxs(Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsx(Text, { color: "
|
|
2606
|
+
return (jsxs(Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsx(Text, { color: "colorPalette.400", children: getColumn({ field }) }), typeof value === "object" ? (jsx(RecordDisplay, { object: value, prefix: `${prefix}${field}.`, translate: translate })) : (jsx(Text, { children: JSON.stringify(value) }))] }, field));
|
|
2627
2607
|
}) }));
|
|
2628
2608
|
};
|
|
2629
2609
|
|
|
@@ -2673,7 +2653,7 @@ const CellRenderer = ({ cell }) => {
|
|
|
2673
2653
|
paddingY: 2,
|
|
2674
2654
|
}, object: value })] }, cell.id));
|
|
2675
2655
|
}
|
|
2676
|
-
return (jsxs(Box, { gridColumn, gridRow, children: [jsx(Box, { color:
|
|
2656
|
+
return (jsxs(Box, { gridColumn, gridRow, children: [jsx(Box, { color: "colorPalette.400", children: getLabel({ columnId: cell.column.id }) }), jsx(Box, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
|
|
2677
2657
|
};
|
|
2678
2658
|
const DataDisplay = ({ variant = "" }) => {
|
|
2679
2659
|
const { table, translate } = useDataTableContext();
|
|
@@ -2848,6 +2828,22 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
2848
2828
|
setGlobalFilter,
|
|
2849
2829
|
type: "client",
|
|
2850
2830
|
translate,
|
|
2831
|
+
columns,
|
|
2832
|
+
sorting,
|
|
2833
|
+
setSorting,
|
|
2834
|
+
columnFilters,
|
|
2835
|
+
setColumnFilters,
|
|
2836
|
+
pagination,
|
|
2837
|
+
setPagination,
|
|
2838
|
+
rowSelection,
|
|
2839
|
+
setRowSelection,
|
|
2840
|
+
columnOrder,
|
|
2841
|
+
setColumnOrder,
|
|
2842
|
+
density,
|
|
2843
|
+
setDensity,
|
|
2844
|
+
columnVisibility,
|
|
2845
|
+
setColumnVisibility,
|
|
2846
|
+
data,
|
|
2851
2847
|
}, children: children }));
|
|
2852
2848
|
}
|
|
2853
2849
|
|
|
@@ -2916,90 +2912,25 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
2916
2912
|
setGlobalFilter,
|
|
2917
2913
|
type: "server",
|
|
2918
2914
|
translate,
|
|
2915
|
+
columns,
|
|
2916
|
+
sorting,
|
|
2917
|
+
setSorting,
|
|
2918
|
+
columnFilters,
|
|
2919
|
+
setColumnFilters,
|
|
2920
|
+
pagination,
|
|
2921
|
+
setPagination,
|
|
2922
|
+
rowSelection,
|
|
2923
|
+
setRowSelection,
|
|
2924
|
+
columnOrder,
|
|
2925
|
+
setColumnOrder,
|
|
2926
|
+
density,
|
|
2927
|
+
setDensity,
|
|
2928
|
+
columnVisibility,
|
|
2929
|
+
setColumnVisibility,
|
|
2930
|
+
data: query.data?.data ?? [],
|
|
2919
2931
|
}, children: jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
2920
2932
|
}
|
|
2921
2933
|
|
|
2922
|
-
const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
2923
|
-
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
2924
|
-
return (jsxs(Checkbox$1.Root, { ref: rootRef, ...rest, children: [jsx(Checkbox$1.HiddenInput, { ref: ref, ...inputProps }), jsx(Checkbox$1.Control, { children: icon || jsx(Checkbox$1.Indicator, {}) }), children != null && (jsx(Checkbox$1.Label, { children: children }))] }));
|
|
2925
|
-
});
|
|
2926
|
-
|
|
2927
|
-
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
|
|
2928
|
-
const { table } = useDataTableContext();
|
|
2929
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2930
|
-
const [hoveredRow, setHoveredRow] = useState(-1);
|
|
2931
|
-
const handleRowHover = (index) => {
|
|
2932
|
-
setHoveredRow(index);
|
|
2933
|
-
};
|
|
2934
|
-
const getTdProps = (cell) => {
|
|
2935
|
-
const tdProps = cell.column.getIsPinned()
|
|
2936
|
-
? {
|
|
2937
|
-
left: showSelector
|
|
2938
|
-
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
2939
|
-
: `${cell.column.getStart("left")}px`,
|
|
2940
|
-
background: pinnedBgColor.light,
|
|
2941
|
-
position: "sticky",
|
|
2942
|
-
zIndex: -1,
|
|
2943
|
-
_dark: {
|
|
2944
|
-
backgroundColor: pinnedBgColor.dark,
|
|
2945
|
-
},
|
|
2946
|
-
}
|
|
2947
|
-
: {};
|
|
2948
|
-
return tdProps;
|
|
2949
|
-
};
|
|
2950
|
-
const getTrProps = ({ hoveredRow, index, }) => {
|
|
2951
|
-
if (hoveredRow === -1) {
|
|
2952
|
-
return {};
|
|
2953
|
-
}
|
|
2954
|
-
if (hoveredRow === index) {
|
|
2955
|
-
return {
|
|
2956
|
-
opacity: "1",
|
|
2957
|
-
};
|
|
2958
|
-
}
|
|
2959
|
-
return {
|
|
2960
|
-
opacity: "0.8",
|
|
2961
|
-
};
|
|
2962
|
-
};
|
|
2963
|
-
return (jsx(Table$1.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
2964
|
-
return (jsxs(Table$1.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
|
|
2965
|
-
return (jsx(Table$1.Cell, { padding: `${table.getDensityValue()}px`,
|
|
2966
|
-
// styling resize and pinning start
|
|
2967
|
-
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
|
|
2968
|
-
backgroundColor: "gray.950",
|
|
2969
|
-
}, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
2970
|
-
})] }, `chakra-table-row-${row.id}`));
|
|
2971
|
-
}) }));
|
|
2972
|
-
};
|
|
2973
|
-
const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, alwaysShowSelector = true, }) => {
|
|
2974
|
-
const { table } = useDataTableContext();
|
|
2975
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2976
|
-
const isCheckBoxVisible = (current_index, current_row) => {
|
|
2977
|
-
if (alwaysShowSelector) {
|
|
2978
|
-
return true;
|
|
2979
|
-
}
|
|
2980
|
-
if (current_row.getIsSelected()) {
|
|
2981
|
-
return true;
|
|
2982
|
-
}
|
|
2983
|
-
if (hoveredRow == current_index) {
|
|
2984
|
-
return true;
|
|
2985
|
-
}
|
|
2986
|
-
return false;
|
|
2987
|
-
};
|
|
2988
|
-
return (jsxs(Table$1.Cell, { padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
2989
|
-
? {
|
|
2990
|
-
left: `0px`,
|
|
2991
|
-
backgroundColor: pinnedBgColor.light,
|
|
2992
|
-
position: "sticky",
|
|
2993
|
-
zIndex: 1,
|
|
2994
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
2995
|
-
}
|
|
2996
|
-
: {}),
|
|
2997
|
-
// styling resize and pinning end
|
|
2998
|
-
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsx(Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsx(Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
|
|
2999
|
-
disabled: !row.getCanSelect(),
|
|
3000
|
-
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
3001
|
-
};
|
|
3002
|
-
|
|
3003
2934
|
const Tooltip = React.forwardRef(function Tooltip(props, ref) {
|
|
3004
2935
|
const { showArrow, children, disabled, portalled, content, contentProps, portalRef, ...rest } = props;
|
|
3005
2936
|
if (disabled)
|
|
@@ -3078,16 +3009,89 @@ const TableFilterTags = () => {
|
|
|
3078
3009
|
}) }));
|
|
3079
3010
|
};
|
|
3080
3011
|
|
|
3081
|
-
const TableControls = ({ fitTableWidth = false, fitTableHeight = false, children = jsx(Fragment, {}), showGlobalFilter = false, showFilter = false, showFilterName = false, showFilterTags = false, showReload = false, showPagination = true, showPageSizeControl = true, showPageCountText = true, showView = true, filterOptions = [], extraItems = jsx(Fragment, {}), loading = false, hasError = false, }) => {
|
|
3012
|
+
const TableControls = ({ fitTableWidth = false, fitTableHeight = false, children = jsx(Fragment, {}), showGlobalFilter = false, showFilter = false, showFilterName = false, showFilterTags = false, showReload = false, showPagination = true, showPageSizeControl = true, showPageCountText = true, showView = true, filterOptions = [], extraItems = jsx(Fragment, {}), loading = false, hasError = false, gridProps = {}, }) => {
|
|
3082
3013
|
const { translate } = useDataTableContext();
|
|
3083
|
-
return (jsxs(Grid, { templateRows: "auto 1fr
|
|
3014
|
+
return (jsxs(Grid, { templateRows: "auto 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", gap: "0.5rem", ...gridProps, children: [jsxs(Flex, { flexFlow: "column", gap: 2, children: [jsxs(Flex, { justifyContent: "space-between", children: [jsx(Box, { children: showView && jsx(ViewDialog, { icon: jsx(MdOutlineViewColumn, {}) }) }), jsxs(Flex, { gap: "0.5rem", alignItems: "center", justifySelf: "end", children: [loading && jsx(Spinner, { size: "sm" }), hasError && (jsx(Tooltip, { content: translate.t("has_error"), children: jsx(Icon, { as: BsExclamationCircleFill, color: "red.400" }) })), showGlobalFilter && jsx(GlobalFilter, {}), showFilter && jsx(FilterDialog, {}), showReload && jsx(ReloadButton, {}), extraItems] })] }), filterOptions.length > 0 && (jsx(Flex, { flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
|
|
3084
3015
|
return (jsxs(Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxs(Text, { children: [column, ":"] }), jsx(FilterOptions, { column: column })] }, column));
|
|
3085
|
-
}) })), showFilterTags && (jsx(Flex, { children: jsx(TableFilterTags, {}) }))] }), jsx(Grid, { overflow: "auto",
|
|
3086
|
-
|
|
3087
|
-
|
|
3016
|
+
}) })), showFilterTags && (jsx(Flex, { children: jsx(TableFilterTags, {}) }))] }), jsx(Grid, { overflow: "auto", bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, children: children }), (showPageSizeControl || showPageCountText || showPagination) && (jsxs(Flex, { justifyContent: "space-between", children: [jsxs(Flex, { gap: "1rem", alignItems: "center", children: [showPageSizeControl && jsx(PageSizeControl, {}), showPageCountText && (jsxs(Flex, { children: [jsx(Text, { paddingRight: "0.5rem", children: translate.t("rowcount.total") }), jsx(RowCountText, {})] }))] }), jsx(Box, { justifySelf: "end", children: showPagination && jsx(Pagination, {}) })] }))] }));
|
|
3017
|
+
};
|
|
3018
|
+
|
|
3019
|
+
const EmptyState = React.forwardRef(function EmptyState(props, ref) {
|
|
3020
|
+
const { title, description, icon, children, ...rest } = props;
|
|
3021
|
+
return (jsx(EmptyState$2.Root, { ref: ref, ...rest, children: jsxs(EmptyState$2.Content, { children: [icon && (jsx(EmptyState$2.Indicator, { children: icon })), description ? (jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })) : (jsx(EmptyState$2.Title, { children: title })), children] }) }));
|
|
3022
|
+
});
|
|
3023
|
+
|
|
3024
|
+
const EmptyResult = (jsx(EmptyState, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
|
|
3025
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3026
|
+
const { table } = useDataTableContext();
|
|
3027
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
3028
|
+
return emptyComponent;
|
|
3029
|
+
}
|
|
3030
|
+
return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, display: "grid", alignContent: "start", overflowY: "auto", bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, ...props, children: children }));
|
|
3031
|
+
};
|
|
3032
|
+
|
|
3033
|
+
const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
3034
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
3035
|
+
return (jsxs(Checkbox$1.Root, { ref: rootRef, ...rest, children: [jsx(Checkbox$1.HiddenInput, { ref: ref, ...inputProps }), jsx(Checkbox$1.Control, { children: icon || jsx(Checkbox$1.Indicator, {}) }), children != null && (jsx(Checkbox$1.Label, { children: children }))] }));
|
|
3036
|
+
});
|
|
3037
|
+
|
|
3038
|
+
const TableBody = ({ showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
|
|
3039
|
+
"use no memo";
|
|
3040
|
+
const { table } = useDataTableContext();
|
|
3041
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3042
|
+
const [hoveredRow, setHoveredRow] = useState(-1);
|
|
3043
|
+
const handleRowHover = (index) => {
|
|
3044
|
+
setHoveredRow(index);
|
|
3045
|
+
};
|
|
3046
|
+
const getTdProps = (cell) => {
|
|
3047
|
+
const tdProps = cell.column.getIsPinned()
|
|
3048
|
+
? {
|
|
3049
|
+
left: showSelector
|
|
3050
|
+
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3051
|
+
: `${cell.column.getStart("left")}px`,
|
|
3052
|
+
position: "relative",
|
|
3053
|
+
}
|
|
3054
|
+
: {};
|
|
3055
|
+
return tdProps;
|
|
3056
|
+
};
|
|
3057
|
+
const getTrProps = ({ hoveredRow, index, }) => {
|
|
3058
|
+
if (hoveredRow === -1) {
|
|
3059
|
+
return {};
|
|
3060
|
+
}
|
|
3061
|
+
if (hoveredRow === index) {
|
|
3062
|
+
return {
|
|
3063
|
+
opacity: "1",
|
|
3064
|
+
};
|
|
3065
|
+
}
|
|
3066
|
+
return {
|
|
3067
|
+
opacity: "0.8",
|
|
3068
|
+
};
|
|
3069
|
+
};
|
|
3070
|
+
return (jsx(Table$1.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
3071
|
+
return (jsxs(Table$1.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow })), row.getVisibleCells().map((cell, index) => {
|
|
3072
|
+
return (jsx(Table$1.Cell, { padding: `${table.getDensityValue()}px`,
|
|
3073
|
+
// styling resize and pinning start
|
|
3074
|
+
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, color: {
|
|
3075
|
+
base: "colorPalette.900",
|
|
3076
|
+
_dark: "colorPalette.100",
|
|
3077
|
+
},
|
|
3078
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, ...getTdProps(cell), children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
3079
|
+
})] }, `chakra-table-row-${row.id}`));
|
|
3080
|
+
}) }));
|
|
3081
|
+
};
|
|
3082
|
+
const TableRowSelector = ({ index, row, }) => {
|
|
3083
|
+
const { table } = useDataTableContext();
|
|
3084
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3085
|
+
return (jsx(Table$1.Cell, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3086
|
+
base: "colorPalette.900",
|
|
3087
|
+
_dark: "colorPalette.100",
|
|
3088
|
+
},
|
|
3089
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, checked: row.getIsSelected(),
|
|
3090
|
+
disabled: !row.getCanSelect(),
|
|
3091
|
+
onCheckedChange: row.getToggleSelectedHandler() }) }));
|
|
3088
3092
|
};
|
|
3089
3093
|
|
|
3090
|
-
const TableFooter = ({
|
|
3094
|
+
const TableFooter = ({ showSelector = false, alwaysShowSelector = true, }) => {
|
|
3091
3095
|
const table = useDataTableContext().table;
|
|
3092
3096
|
const SELECTION_BOX_WIDTH = 20;
|
|
3093
3097
|
const [hoveredCheckBox, setHoveredCheckBox] = useState(false);
|
|
@@ -3106,78 +3110,28 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
3106
3110
|
}
|
|
3107
3111
|
return false;
|
|
3108
3112
|
};
|
|
3109
|
-
|
|
3110
|
-
const thProps = header.column.getIsPinned()
|
|
3111
|
-
? {
|
|
3112
|
-
left: showSelector
|
|
3113
|
-
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3114
|
-
: `${header.getStart("left") + table.getDensityValue() * 2}px`,
|
|
3115
|
-
background: pinnedBgColor.light,
|
|
3116
|
-
position: "sticky",
|
|
3117
|
-
zIndex: 1,
|
|
3118
|
-
_dark: {
|
|
3119
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3120
|
-
},
|
|
3121
|
-
}
|
|
3122
|
-
: {};
|
|
3123
|
-
return thProps;
|
|
3124
|
-
};
|
|
3125
|
-
return (jsx(Table$1.Footer, { children: table.getFooterGroups().map((footerGroup) => (jsxs(Table$1.Row, { display: "flex", children: [showSelector && (jsxs(Table$1.Header
|
|
3126
|
-
// styling resize and pinning start
|
|
3127
|
-
, {
|
|
3128
|
-
// styling resize and pinning start
|
|
3129
|
-
padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
3130
|
-
? {
|
|
3131
|
-
left: `0px`,
|
|
3132
|
-
backgroundColor: pinnedBgColor.light,
|
|
3133
|
-
position: "sticky",
|
|
3134
|
-
zIndex: 1,
|
|
3135
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3136
|
-
}
|
|
3137
|
-
: {}),
|
|
3138
|
-
// styling resize and pinning end
|
|
3139
|
-
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsx(Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3113
|
+
return (jsx(Table$1.Footer, { children: table.getFooterGroups().map((footerGroup) => (jsxs(Table$1.Row, { display: "flex", children: [showSelector && (jsxs(Table$1.Header, { padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsx(Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3140
3114
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3141
3115
|
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsx(Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] })), footerGroup.headers.map((header) => (jsx(Table$1.Cell, { padding: "0", columnSpan: `${header.colSpan}`,
|
|
3142
3116
|
// styling resize and pinning start
|
|
3143
|
-
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid",
|
|
3117
|
+
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid", children: jsx(MenuRoot$1, { children: jsx(MenuTrigger$1, { asChild: true, children: jsx(Box, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", children: jsxs(Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3144
3118
|
? null
|
|
3145
3119
|
: flexRender(header.column.columnDef.footer, header.getContext()), jsx(Box, { children: header.column.getCanSort() && (jsxs(Fragment, { children: [header.column.getIsSorted() === false && (
|
|
3146
3120
|
// <UpDownIcon />
|
|
3147
3121
|
jsx(Fragment, {})), header.column.getIsSorted() === "asc" && (jsx(BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsx(BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${header.column.id}-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
|
|
3148
3122
|
};
|
|
3149
3123
|
|
|
3150
|
-
const TableHeader = ({ canResize = true,
|
|
3124
|
+
const TableHeader = ({ canResize = true, showSelector = false, isSticky = true, tableHeaderProps = {}, tableRowProps = {}, }) => {
|
|
3151
3125
|
const { table } = useDataTableContext();
|
|
3152
3126
|
const SELECTION_BOX_WIDTH = 20;
|
|
3153
|
-
const [hoveredCheckBox, setHoveredCheckBox] = useState(false);
|
|
3154
|
-
const handleRowHover = (isHovered) => {
|
|
3155
|
-
setHoveredCheckBox(isHovered);
|
|
3156
|
-
};
|
|
3157
|
-
const isCheckBoxVisible = () => {
|
|
3158
|
-
if (alwaysShowSelector) {
|
|
3159
|
-
return true;
|
|
3160
|
-
}
|
|
3161
|
-
if (table.getIsAllRowsSelected()) {
|
|
3162
|
-
return true;
|
|
3163
|
-
}
|
|
3164
|
-
if (hoveredCheckBox) {
|
|
3165
|
-
return true;
|
|
3166
|
-
}
|
|
3167
|
-
return false;
|
|
3168
|
-
};
|
|
3169
3127
|
const getThProps = (header) => {
|
|
3170
3128
|
const thProps = header.column.getIsPinned()
|
|
3171
3129
|
? {
|
|
3172
3130
|
left: showSelector
|
|
3173
3131
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3174
3132
|
: `${header.getStart("left")}px`,
|
|
3175
|
-
background: pinnedBgColor.light,
|
|
3176
3133
|
position: "sticky",
|
|
3177
3134
|
zIndex: 100 + 1,
|
|
3178
|
-
_dark: {
|
|
3179
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3180
|
-
},
|
|
3181
3135
|
}
|
|
3182
3136
|
: {};
|
|
3183
3137
|
return thProps;
|
|
@@ -3186,21 +3140,13 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3186
3140
|
position: "sticky",
|
|
3187
3141
|
top: 0,
|
|
3188
3142
|
};
|
|
3189
|
-
return (jsx(Table$1.Header, { ...(isSticky ? stickyProps : {}), ...
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
zIndex: 1,
|
|
3197
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3198
|
-
}
|
|
3199
|
-
: {}),
|
|
3200
|
-
// styling resize and pinning end
|
|
3201
|
-
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsx(Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3202
|
-
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3203
|
-
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsx(Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] })), headerGroup.headers.map((header) => {
|
|
3143
|
+
return (jsx(Table$1.Header, { ...(isSticky ? stickyProps : {}), bgColor: "transparent", ...tableHeaderProps, children: table.getHeaderGroups().map((headerGroup) => (jsxs(Table$1.Row, { display: "flex", bgColor: "transparent", ...tableRowProps, children: [showSelector && (jsx(Table$1.ColumnHeader, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3144
|
+
base: "colorPalette.900",
|
|
3145
|
+
_dark: "colorPalette.100",
|
|
3146
|
+
},
|
|
3147
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, justifyItems: "center", alignItems: "center", children: jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, checked: table.getIsAllRowsSelected(),
|
|
3148
|
+
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3149
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), headerGroup.headers.map((header) => {
|
|
3204
3150
|
const resizeProps = {
|
|
3205
3151
|
onMouseDown: header.getResizeHandler(),
|
|
3206
3152
|
onTouchStart: header.getResizeHandler(),
|
|
@@ -3208,10 +3154,24 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3208
3154
|
};
|
|
3209
3155
|
return (jsxs(Table$1.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
|
|
3210
3156
|
// styling resize and pinning start
|
|
3211
|
-
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index,
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3157
|
+
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index, color: {
|
|
3158
|
+
base: "colorPalette.800",
|
|
3159
|
+
_dark: "colorPalette.200",
|
|
3160
|
+
},
|
|
3161
|
+
bg: { base: "colorPalette.100", _dark: "colorPalette.900" }, ...getThProps(header), children: [jsxs(MenuRoot, { children: [jsx(MenuTrigger, { asChild: true, children: jsx(Flex, { padding: `${table.getDensityValue()}px`, alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", color: {
|
|
3162
|
+
base: "colorPalette.800",
|
|
3163
|
+
_dark: "colorPalette.200",
|
|
3164
|
+
_hover: {
|
|
3165
|
+
base: "colorPalette.700",
|
|
3166
|
+
_dark: "colorPalette.300",
|
|
3167
|
+
},
|
|
3168
|
+
},
|
|
3169
|
+
bg: {
|
|
3170
|
+
base: "colorPalette.100",
|
|
3171
|
+
_dark: "colorPalette.900",
|
|
3172
|
+
_hover: {
|
|
3173
|
+
base: "colorPalette.200",
|
|
3174
|
+
_dark: "colorPalette.800",
|
|
3215
3175
|
},
|
|
3216
3176
|
}, children: jsxs(Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3217
3177
|
? null
|
|
@@ -3239,29 +3199,17 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3239
3199
|
});
|
|
3240
3200
|
}, children: [jsx(GrDescend, {}), "Sort Descending"] }) }), header.column.getIsSorted() && (jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3241
3201
|
header.column.clearSorting();
|
|
3242
|
-
}, children: [jsx(MdClear, {}), "Clear Sorting"] }) }))] }))] })] }), canResize && (jsx(Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3202
|
+
}, children: [jsx(MdClear, {}), "Clear Sorting"] }) }))] }))] })] }), canResize && (jsx(Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3203
|
+
? "colorPalette.700"
|
|
3204
|
+
: "transparent", position: "relative", right: "0.1rem", width: "2px", height: "100%", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
3243
3205
|
borderRightColor: header.column.getIsResizing()
|
|
3244
|
-
? "
|
|
3245
|
-
: "
|
|
3206
|
+
? "colorPalette.700"
|
|
3207
|
+
: "colorPalette.400",
|
|
3246
3208
|
}, ...resizeProps }))] }, `chakra-table-header-${header.id}`));
|
|
3247
3209
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
3248
3210
|
};
|
|
3249
3211
|
|
|
3250
|
-
const
|
|
3251
|
-
const { title, description, icon, children, ...rest } = props;
|
|
3252
|
-
return (jsx(EmptyState$2.Root, { ref: ref, ...rest, children: jsxs(EmptyState$2.Content, { children: [icon && (jsx(EmptyState$2.Indicator, { children: icon })), description ? (jsxs(VStack, { textAlign: "center", children: [jsx(EmptyState$2.Title, { children: title }), jsx(EmptyState$2.Description, { children: description })] })) : (jsx(EmptyState$2.Title, { children: title })), children] }) }));
|
|
3253
|
-
});
|
|
3254
|
-
|
|
3255
|
-
const EmptyResult = (jsx(EmptyState, { icon: jsx(HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxs(List.Root, { variant: "marker", children: [jsx(List.Item, { children: "Try removing filters" }), jsx(List.Item, { children: "Try different keywords" })] }) }));
|
|
3256
|
-
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3257
|
-
const { table } = useDataTableContext();
|
|
3258
|
-
if (table.getRowModel().rows.length <= 0) {
|
|
3259
|
-
return emptyComponent;
|
|
3260
|
-
}
|
|
3261
|
-
return (jsx(Table$1.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, display: "grid", alignContent: "start", overflowY: "auto", ...props, children: children }));
|
|
3262
|
-
};
|
|
3263
|
-
|
|
3264
|
-
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
|
|
3212
|
+
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, tableFooterProps = {}, controlProps = {}, variant = "", }) => {
|
|
3265
3213
|
if (variant === "greedy") {
|
|
3266
3214
|
return (jsx(TableControls, { ...controlProps, children: jsxs(Table, { canResize: false, ...{ ...tableProps }, children: [jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
|
|
3267
3215
|
}
|
|
@@ -3521,6 +3469,73 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
|
|
|
3521
3469
|
return columns;
|
|
3522
3470
|
};
|
|
3523
3471
|
|
|
3472
|
+
const TableDataDisplay = ({ colorPalette, emptyComponent, }) => {
|
|
3473
|
+
const { table, columns, translate, data } = useDataTableContext();
|
|
3474
|
+
const columnDef = table._getColumnDefs();
|
|
3475
|
+
console.log(columnDef, "glp");
|
|
3476
|
+
console.log(columnDef, columns, table.getState().columnOrder, data, "glp");
|
|
3477
|
+
const columnsMap = Object.fromEntries(columns.map((def) => {
|
|
3478
|
+
const { accessorKey, id } = def;
|
|
3479
|
+
if (accessorKey) {
|
|
3480
|
+
return [accessorKey, def];
|
|
3481
|
+
}
|
|
3482
|
+
return [id, def];
|
|
3483
|
+
}));
|
|
3484
|
+
const columnHeaders = Object.keys(columnsMap);
|
|
3485
|
+
const totalWidths = columns
|
|
3486
|
+
.map(({ size }) => {
|
|
3487
|
+
if (!!size === false) {
|
|
3488
|
+
return 0;
|
|
3489
|
+
}
|
|
3490
|
+
if (typeof size === "number") {
|
|
3491
|
+
return size;
|
|
3492
|
+
}
|
|
3493
|
+
return 0;
|
|
3494
|
+
})
|
|
3495
|
+
.reduce((previous, current) => previous + current, 0);
|
|
3496
|
+
const columnWidths = columns
|
|
3497
|
+
.map(({ size }) => {
|
|
3498
|
+
if (!!size === false) {
|
|
3499
|
+
return "1fr";
|
|
3500
|
+
}
|
|
3501
|
+
return `minmax(${size}px, ${(size / totalWidths) * 100}%)`;
|
|
3502
|
+
})
|
|
3503
|
+
.join(" ");
|
|
3504
|
+
console.log({ columnWidths }, "hadfg");
|
|
3505
|
+
const cellProps = {
|
|
3506
|
+
flex: "1 0 0%",
|
|
3507
|
+
overflow: "auto",
|
|
3508
|
+
paddingX: "2",
|
|
3509
|
+
py: "1",
|
|
3510
|
+
color: { base: "colorPalette.900", _dark: "colorPalette.100" },
|
|
3511
|
+
bgColor: { base: "colorPalette.50", _dark: "colorPalette.950" },
|
|
3512
|
+
borderBottomColor: { base: "colorPalette.200", _dark: "colorPalette.800" },
|
|
3513
|
+
borderBottomWidth: "1px",
|
|
3514
|
+
...{ colorPalette },
|
|
3515
|
+
};
|
|
3516
|
+
if (data.length <= 0) {
|
|
3517
|
+
return jsx(Fragment, { children: emptyComponent });
|
|
3518
|
+
}
|
|
3519
|
+
return (jsxs(Grid, { templateColumns: `${columnWidths}`, overflow: "auto", borderWidth: "1px", color: { base: "colorPalette.900", _dark: "colorPalette.100" }, borderColor: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: [jsx(Grid, { templateColumns: `${columnWidths}`, column: `1/span ${columns.length}`, bg: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: columnHeaders.map((header) => {
|
|
3520
|
+
return (jsx(Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
|
|
3521
|
+
}) }), data.map((record) => {
|
|
3522
|
+
return (jsx(Fragment, { children: columnHeaders.map((header) => {
|
|
3523
|
+
const { cell } = columnsMap[header];
|
|
3524
|
+
const value = record[header];
|
|
3525
|
+
if (!!record === false) {
|
|
3526
|
+
return (jsx(Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
|
|
3527
|
+
}
|
|
3528
|
+
if (cell) {
|
|
3529
|
+
return (jsx(Box, { ...cellProps, children: cell({ row: { original: record } }) }));
|
|
3530
|
+
}
|
|
3531
|
+
if (typeof value === "object") {
|
|
3532
|
+
return (jsx(Box, { ...cellProps, children: jsx(RecordDisplay, { object: value }) }));
|
|
3533
|
+
}
|
|
3534
|
+
return jsx(Box, { ...cellProps, children: value });
|
|
3535
|
+
}) }));
|
|
3536
|
+
})] }));
|
|
3537
|
+
};
|
|
3538
|
+
|
|
3524
3539
|
const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
3525
3540
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
3526
3541
|
return (jsxs(Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsx(Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsx(LuChevronDown, {}) })), jsx(HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsx(Accordion.ItemIndicator, { children: jsx(LuChevronDown, {}) }))] }));
|
|
@@ -3616,11 +3631,11 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3616
3631
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3617
3632
|
const { formState: { errors }, setValue, watch, } = useFormContext();
|
|
3618
3633
|
const fields = (watch(colLabel) ?? []);
|
|
3619
|
-
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label",
|
|
3634
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsx("span", { children: "*" })] }), fields.map((field, index) => (jsxs(Flex, { flexFlow: "column", children: [jsx(Box, { children: index + 1 }), jsx(Grid, { gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsx(SchemaRenderer, { column: `${index}`,
|
|
3620
3635
|
prefix: `${colLabel}.`,
|
|
3621
3636
|
schema: items }) }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { variant: "ghost", onClick: () => {
|
|
3622
3637
|
setValue(colLabel, fields.filter((_, curIndex) => {
|
|
3623
|
-
return curIndex
|
|
3638
|
+
return curIndex !== index;
|
|
3624
3639
|
}));
|
|
3625
3640
|
}, children: translate.t(removeIndex(`${colLabel}.remove`)) }) })] }, `${colLabel}.${index}`))), jsx(Flex, { children: jsx(Button$1, { onClick: () => {
|
|
3626
3641
|
if (type === "number") {
|
|
@@ -3636,7 +3651,7 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3636
3651
|
return;
|
|
3637
3652
|
}
|
|
3638
3653
|
setValue(colLabel, [...fields, {}]);
|
|
3639
|
-
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3654
|
+
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3640
3655
|
};
|
|
3641
3656
|
|
|
3642
3657
|
const Field = React.forwardRef(function Field(props, ref) {
|
|
@@ -3647,14 +3662,26 @@ const Field = React.forwardRef(function Field(props, ref) {
|
|
|
3647
3662
|
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3648
3663
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3649
3664
|
const { translate } = useSchemaContext();
|
|
3650
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3665
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
3651
3666
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3652
3667
|
const colLabel = `${prefix}${column}`;
|
|
3653
3668
|
const value = watch(colLabel);
|
|
3654
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
3669
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3655
3670
|
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
|
|
3656
3671
|
setValue(colLabel, !value);
|
|
3657
|
-
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3672
|
+
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3673
|
+
};
|
|
3674
|
+
|
|
3675
|
+
const CustomInput = ({ column, schema, prefix }) => {
|
|
3676
|
+
const formContext = useFormContext();
|
|
3677
|
+
const { inputRender } = schema;
|
|
3678
|
+
return (inputRender &&
|
|
3679
|
+
inputRender({
|
|
3680
|
+
column,
|
|
3681
|
+
schema,
|
|
3682
|
+
prefix,
|
|
3683
|
+
formContext,
|
|
3684
|
+
}));
|
|
3658
3685
|
};
|
|
3659
3686
|
|
|
3660
3687
|
const monthNamesShort = [
|
|
@@ -3744,28 +3771,54 @@ const PopoverRoot = Popover.Root;
|
|
|
3744
3771
|
const PopoverBody = Popover.Body;
|
|
3745
3772
|
const PopoverTrigger = Popover.Trigger;
|
|
3746
3773
|
|
|
3774
|
+
dayjs.extend(utc);
|
|
3747
3775
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3748
3776
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3749
3777
|
const { translate } = useSchemaContext();
|
|
3750
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3778
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3751
3779
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3752
3780
|
const colLabel = `${prefix}${column}`;
|
|
3753
3781
|
const [open, setOpen] = useState(false);
|
|
3754
3782
|
const selectedDate = watch(colLabel);
|
|
3755
|
-
const
|
|
3756
|
-
|
|
3757
|
-
|
|
3783
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3784
|
+
useEffect(() => {
|
|
3785
|
+
try {
|
|
3786
|
+
if (selectedDate) {
|
|
3787
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3788
|
+
// For example, parse as UTC:
|
|
3789
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3790
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3791
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3792
|
+
if (!parsedDate.isValid())
|
|
3793
|
+
return;
|
|
3794
|
+
// Format according to dateFormat from schema
|
|
3795
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3796
|
+
// Update the form value only if different to avoid loops
|
|
3797
|
+
if (formatted !== selectedDate) {
|
|
3798
|
+
setValue(colLabel, formatted, {
|
|
3799
|
+
shouldValidate: true,
|
|
3800
|
+
shouldDirty: true,
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
catch (e) {
|
|
3806
|
+
console.error(e);
|
|
3807
|
+
}
|
|
3808
|
+
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3809
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3810
|
+
gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3758
3811
|
setOpen(true);
|
|
3759
|
-
}, children: selectedDate !== undefined ? `${
|
|
3812
|
+
}, justifyContent: "start", children: [jsx(MdDateRange, {}), selectedDate !== undefined ? `${displayDate}` : ""] }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
3760
3813
|
// @ts-expect-error TODO: find appropriate types
|
|
3761
3814
|
, {
|
|
3762
3815
|
// @ts-expect-error TODO: find appropriate types
|
|
3763
3816
|
selected: new Date(selectedDate),
|
|
3764
3817
|
// @ts-expect-error TODO: find appropriate types
|
|
3765
3818
|
onDateSelected: ({ date }) => {
|
|
3766
|
-
setValue(colLabel, dayjs(date).format(
|
|
3819
|
+
setValue(colLabel, dayjs(date).format(dateFormat));
|
|
3767
3820
|
setOpen(false);
|
|
3768
|
-
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3821
|
+
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3769
3822
|
};
|
|
3770
3823
|
|
|
3771
3824
|
function filterArray(array, searchTerm) {
|
|
@@ -3778,12 +3831,12 @@ function filterArray(array, searchTerm) {
|
|
|
3778
3831
|
});
|
|
3779
3832
|
}
|
|
3780
3833
|
|
|
3781
|
-
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3834
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, showTotalAndLimit = false, }) => {
|
|
3782
3835
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3783
3836
|
const { translate } = useSchemaContext();
|
|
3784
|
-
const { required } = schema;
|
|
3837
|
+
const { required, variant } = schema;
|
|
3785
3838
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3786
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3839
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
3787
3840
|
const [searchText, setSearchText] = useState();
|
|
3788
3841
|
const [limit, setLimit] = useState(10);
|
|
3789
3842
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
@@ -3798,28 +3851,61 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3798
3851
|
setSearchText(event.target.value);
|
|
3799
3852
|
setLimit(10);
|
|
3800
3853
|
};
|
|
3801
|
-
|
|
3854
|
+
if (variant === "radio") {
|
|
3855
|
+
return (jsx(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3856
|
+
gridRow, children: jsx(RadioGroup$1.Root, { defaultValue: "1", children: jsx(HStack, { gap: "6", children: filterArray(dataList, searchText ?? "").map((item) => {
|
|
3857
|
+
return (jsxs(RadioGroup$1.Item, { onClick: () => {
|
|
3858
|
+
if (!isMultiple) {
|
|
3859
|
+
setOpenSearchResult(false);
|
|
3860
|
+
setValue(colLabel, item);
|
|
3861
|
+
return;
|
|
3862
|
+
}
|
|
3863
|
+
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3864
|
+
setValue(colLabel, [...newSet]);
|
|
3865
|
+
}, value: item, children: [jsx(RadioGroup$1.ItemHiddenInput, {}), jsx(RadioGroup$1.ItemIndicator, {}), jsx(RadioGroup$1.ItemText, { children: !!renderDisplay === true
|
|
3866
|
+
? renderDisplay(item)
|
|
3867
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) })] }, `${colLabel}-${item}`));
|
|
3868
|
+
}) }) }) }));
|
|
3869
|
+
}
|
|
3870
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3802
3871
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3803
3872
|
const item = enumValue;
|
|
3804
|
-
if (item ===
|
|
3805
|
-
return jsx(Fragment, {
|
|
3873
|
+
if (!!item === false) {
|
|
3874
|
+
return jsx(Fragment, {});
|
|
3806
3875
|
}
|
|
3807
3876
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
3808
|
-
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3809
3877
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3810
3878
|
}, children: !!renderDisplay === true
|
|
3811
3879
|
? renderDisplay(item)
|
|
3812
3880
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3813
3881
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3814
3882
|
setOpenSearchResult(true);
|
|
3815
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
3883
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
3816
3884
|
setOpenSearchResult(true);
|
|
3817
|
-
}, children: watchEnum ===
|
|
3885
|
+
}, justifyContent: "start", children: !!watchEnum === false
|
|
3818
3886
|
? ""
|
|
3819
|
-
: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${
|
|
3887
|
+
: translate.t(removeIndex(`${colLabel}.${watchEnum ?? "null"}`)) })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${colLabel}.type_to_search`), onChange: (event) => {
|
|
3820
3888
|
onSearchChange(event);
|
|
3821
3889
|
setOpenSearchResult(true);
|
|
3822
|
-
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), jsx(Text, { children: `${translate.t(`${
|
|
3890
|
+
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), showTotalAndLimit && (jsx(Text, { children: `${translate.t(removeIndex(`${colLabel}.total`))}: ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit}` })), jsxs(Grid, { overflow: "auto", maxHeight: "20rem", children: [jsx(Flex, { flexFlow: "column wrap", children: dataList
|
|
3891
|
+
.filter((item) => {
|
|
3892
|
+
const searchTerm = (searchText || "").toLowerCase();
|
|
3893
|
+
if (!searchTerm)
|
|
3894
|
+
return true;
|
|
3895
|
+
// Check if the original enum value contains the search text
|
|
3896
|
+
const enumValueMatch = item
|
|
3897
|
+
.toLowerCase()
|
|
3898
|
+
.includes(searchTerm);
|
|
3899
|
+
// Check if the display value (translation) contains the search text
|
|
3900
|
+
const displayValue = !!renderDisplay === true
|
|
3901
|
+
? renderDisplay(item)
|
|
3902
|
+
: translate.t(removeIndex(`${colLabel}.${item}`));
|
|
3903
|
+
// Convert to string and check if it includes the search term
|
|
3904
|
+
const displayValueString = String(displayValue).toLowerCase();
|
|
3905
|
+
const displayValueMatch = displayValueString.includes(searchTerm);
|
|
3906
|
+
return enumValueMatch || displayValueMatch;
|
|
3907
|
+
})
|
|
3908
|
+
.map((item) => {
|
|
3823
3909
|
const selected = isMultiple
|
|
3824
3910
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3825
3911
|
: watchEnum == item;
|
|
@@ -3831,10 +3917,10 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3831
3917
|
}
|
|
3832
3918
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3833
3919
|
setValue(colLabel, [...newSet]);
|
|
3834
|
-
}, ...(selected ? { color: "
|
|
3920
|
+
}, ...(selected ? { color: "colorPalette.400/50" } : {}), children: !!renderDisplay === true
|
|
3835
3921
|
? renderDisplay(item)
|
|
3836
3922
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
|
|
3837
|
-
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(removeIndex(`${colLabel}.
|
|
3923
|
+
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(removeIndex(`${colLabel}.empty_search_result`)) })) }))] })] }) })] }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3838
3924
|
};
|
|
3839
3925
|
|
|
3840
3926
|
function isEnteringWindow(_ref) {
|
|
@@ -4186,17 +4272,17 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4186
4272
|
const filesArray = [...event.target.files];
|
|
4187
4273
|
onDrop({ files: filesArray });
|
|
4188
4274
|
};
|
|
4189
|
-
return (jsxs(Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "
|
|
4275
|
+
return (jsxs(Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "colorPalette.400", alignContent: "center", justifyContent: "center", borderWidth: 1, borderRadius: 4, ...gridProps, children: [children, !!children === false && (jsxs(Fragment, { children: [jsx(Flex, { children: placeholder }), jsx(Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
|
|
4190
4276
|
};
|
|
4191
4277
|
|
|
4192
4278
|
const FilePicker = ({ column, schema, prefix }) => {
|
|
4193
4279
|
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4194
4280
|
const { translate } = useSchemaContext();
|
|
4195
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4281
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4196
4282
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4197
4283
|
const currentFiles = (watch(column) ?? []);
|
|
4198
4284
|
const colLabel = `${prefix}${column}`;
|
|
4199
|
-
return (jsxs(Field, { label: `${translate.t(`${colLabel}.
|
|
4285
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.field_label`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4200
4286
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4201
4287
|
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4202
4288
|
}, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
@@ -4204,10 +4290,19 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4204
4290
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4205
4291
|
return name !== file.name;
|
|
4206
4292
|
}));
|
|
4207
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4208
|
-
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4293
|
+
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [file.type.startsWith("image/") && (jsx(Image, { src: URL.createObjectURL(file), alt: file.name, boxSize: "50px", objectFit: "cover", borderRadius: "md", marginRight: "2" })), jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4294
|
+
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4209
4295
|
};
|
|
4210
4296
|
|
|
4297
|
+
const ToggleTip = React.forwardRef(function ToggleTip(props, ref) {
|
|
4298
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
4299
|
+
return (jsxs(Popover.Root, { ...rest, positioning: { ...rest.positioning, gutter: 4 }, children: [jsx(Popover.Trigger, { asChild: true, children: children }), jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Popover.Positioner, { children: jsxs(Popover.Content, { width: "auto", px: "2", py: "1", textStyle: "xs", rounded: "sm", ref: ref, children: [showArrow && (jsx(Popover.Arrow, { children: jsx(Popover.ArrowTip, {}) })), content] }) }) })] }));
|
|
4300
|
+
});
|
|
4301
|
+
const InfoTip = React.forwardRef(function InfoTip(props, ref) {
|
|
4302
|
+
const { children, ...rest } = props;
|
|
4303
|
+
return (jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsx(IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "colorPalette", children: jsx(HiOutlineInformationCircle, {}) }) }));
|
|
4304
|
+
});
|
|
4305
|
+
|
|
4211
4306
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4212
4307
|
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4213
4308
|
throw new Error("The serverUrl is missing");
|
|
@@ -4239,15 +4334,18 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
4239
4334
|
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4240
4335
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
4241
4336
|
const { serverUrl, idMap, setIdMap, translate, schema: parentSchema, } = useSchemaContext();
|
|
4242
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4337
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4243
4338
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4244
4339
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4245
|
-
const [searchText, setSearchText] = useState();
|
|
4340
|
+
const [searchText, setSearchText] = useState("");
|
|
4246
4341
|
const [limit, setLimit] = useState(10);
|
|
4247
4342
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
4248
4343
|
const [page, setPage] = useState(0);
|
|
4249
4344
|
const ref = useRef(null);
|
|
4250
4345
|
const colLabel = `${prefix}${column}`;
|
|
4346
|
+
const watchId = watch(colLabel);
|
|
4347
|
+
const watchIds = isMultiple ? (watch(colLabel) ?? []) : [];
|
|
4348
|
+
// Query for search results
|
|
4251
4349
|
const query = useQuery({
|
|
4252
4350
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4253
4351
|
queryFn: async () => {
|
|
@@ -4256,7 +4354,7 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4256
4354
|
searching: searchText ?? "",
|
|
4257
4355
|
in_table: table,
|
|
4258
4356
|
limit: limit,
|
|
4259
|
-
offset: page *
|
|
4357
|
+
offset: page * limit,
|
|
4260
4358
|
});
|
|
4261
4359
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4262
4360
|
return [
|
|
@@ -4271,27 +4369,27 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4271
4369
|
});
|
|
4272
4370
|
return data;
|
|
4273
4371
|
},
|
|
4274
|
-
enabled:
|
|
4372
|
+
enabled: openSearchResult === true,
|
|
4275
4373
|
staleTime: 300000,
|
|
4276
4374
|
});
|
|
4277
|
-
|
|
4278
|
-
const
|
|
4279
|
-
const count = data?.count ?? 0;
|
|
4280
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
4281
|
-
const watchId = watch(colLabel);
|
|
4282
|
-
const watchIds = (watch(colLabel) ?? []);
|
|
4283
|
-
useQuery({
|
|
4375
|
+
// Query for currently selected items (to display them properly)
|
|
4376
|
+
const queryDefault = useQuery({
|
|
4284
4377
|
queryKey: [
|
|
4285
|
-
`idpicker`,
|
|
4286
|
-
{ form: parentSchema.title, column,
|
|
4378
|
+
`idpicker-default`,
|
|
4379
|
+
{ form: parentSchema.title, column, id: isMultiple ? watchIds : watchId },
|
|
4287
4380
|
],
|
|
4288
4381
|
queryFn: async () => {
|
|
4382
|
+
if (!watchId && (!watchIds || watchIds.length === 0)) {
|
|
4383
|
+
return { data: [] };
|
|
4384
|
+
}
|
|
4385
|
+
const searchValue = isMultiple ? watchIds.join(",") : watchId;
|
|
4289
4386
|
const data = await getTableData({
|
|
4290
4387
|
serverUrl,
|
|
4291
|
-
searching:
|
|
4388
|
+
searching: searchValue,
|
|
4292
4389
|
in_table: table,
|
|
4293
|
-
|
|
4294
|
-
|
|
4390
|
+
where: [{ id: column_ref, value: isMultiple ? watchIds : watchId }],
|
|
4391
|
+
limit: isMultiple ? watchIds.length : 1,
|
|
4392
|
+
offset: 0,
|
|
4295
4393
|
});
|
|
4296
4394
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4297
4395
|
return [
|
|
@@ -4306,12 +4404,45 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4306
4404
|
});
|
|
4307
4405
|
return data;
|
|
4308
4406
|
},
|
|
4407
|
+
enabled: isMultiple
|
|
4408
|
+
? Array.isArray(watchIds) && watchIds.length > 0
|
|
4409
|
+
: !!watchId,
|
|
4309
4410
|
});
|
|
4411
|
+
// Effect to load selected values when component mounts
|
|
4412
|
+
useEffect(() => {
|
|
4413
|
+
if (isMultiple ? watchIds.length > 0 : !!watchId) {
|
|
4414
|
+
queryDefault.refetch();
|
|
4415
|
+
}
|
|
4416
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4417
|
+
}, []);
|
|
4418
|
+
// Effect to trigger initial data fetch when popover opens
|
|
4419
|
+
useEffect(() => {
|
|
4420
|
+
if (openSearchResult) {
|
|
4421
|
+
// Reset search text when opening the popover
|
|
4422
|
+
setSearchText("");
|
|
4423
|
+
// Reset page to first page
|
|
4424
|
+
setPage(0);
|
|
4425
|
+
// Fetch initial data
|
|
4426
|
+
query.refetch();
|
|
4427
|
+
}
|
|
4428
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4429
|
+
}, [openSearchResult]);
|
|
4310
4430
|
const onSearchChange = async (event) => {
|
|
4311
4431
|
setSearchText(event.target.value);
|
|
4312
4432
|
setPage(0);
|
|
4313
|
-
|
|
4433
|
+
query.refetch();
|
|
4314
4434
|
};
|
|
4435
|
+
const handleLimitChange = (event) => {
|
|
4436
|
+
const newLimit = Number(event.target.value);
|
|
4437
|
+
setLimit(newLimit);
|
|
4438
|
+
// Reset to first page when changing limit
|
|
4439
|
+
setPage(0);
|
|
4440
|
+
// Trigger a new search with the updated limit
|
|
4441
|
+
query.refetch();
|
|
4442
|
+
};
|
|
4443
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4444
|
+
const dataList = data?.data ?? [];
|
|
4445
|
+
const count = data?.count ?? 0;
|
|
4315
4446
|
const getPickedValue = () => {
|
|
4316
4447
|
if (Object.keys(idMap).length <= 0) {
|
|
4317
4448
|
return "";
|
|
@@ -4320,47 +4451,57 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4320
4451
|
if (record === undefined) {
|
|
4321
4452
|
return "";
|
|
4322
4453
|
}
|
|
4454
|
+
if (!!renderDisplay === true) {
|
|
4455
|
+
return renderDisplay(record);
|
|
4456
|
+
}
|
|
4323
4457
|
return record[display_column];
|
|
4324
4458
|
};
|
|
4325
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.
|
|
4459
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.field_label`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4326
4460
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
|
|
4327
4461
|
const item = idMap[id];
|
|
4328
4462
|
if (item === undefined) {
|
|
4329
4463
|
return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4330
4464
|
}
|
|
4331
4465
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
4332
|
-
setValue(
|
|
4466
|
+
setValue(colLabel, watchIds.filter((itemId) => itemId !== item[column_ref]));
|
|
4333
4467
|
}, children: !!renderDisplay === true
|
|
4334
4468
|
? renderDisplay(item)
|
|
4335
4469
|
: item[display_column] }, id));
|
|
4336
4470
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4337
4471
|
setOpenSearchResult(true);
|
|
4338
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
4472
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4339
4473
|
setOpenSearchResult(true);
|
|
4340
|
-
}, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(removeIndex(`${colLabel}.
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4474
|
+
}, justifyContent: "start", children: queryDefault.isLoading ? jsx(Spinner, { size: "sm" }) : getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(removeIndex(`${colLabel}.type_to_search`)), onChange: onSearchChange, autoComplete: "off", ref: ref, value: searchText }), jsx(PopoverTitle, {}), openSearchResult && (jsxs(Fragment, { children: [(isFetching || isLoading || isPending) && jsx(Spinner, {}), isError && (jsx(Icon, { color: "red.400", children: jsx(BiError, {}) })), jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxs(Flex, { alignItems: "center", gap: "2", children: [jsx(InfoTip, { children: `${translate.t(removeIndex(`${colLabel}.total`))} ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit} ${translate.t(removeIndex(`${colLabel}.per_page`), "per page")}` }), jsxs(Text, { fontSize: "sm", fontWeight: "bold", children: [count, jsxs(Text, { as: "span", fontSize: "xs", ml: "1", color: "gray.500", children: ["/ ", count > 0 ? `${page * limit + 1}-${Math.min((page + 1) * limit, count)}` : '0'] })] })] }), jsx(Box, { children: jsxs("select", { value: limit, onChange: handleLimitChange, style: {
|
|
4475
|
+
padding: "4px 8px",
|
|
4476
|
+
borderRadius: "4px",
|
|
4477
|
+
border: "1px solid #ccc",
|
|
4478
|
+
fontSize: "14px",
|
|
4479
|
+
}, children: [jsx("option", { value: "5", children: "5" }), jsx("option", { value: "10", children: "10" }), jsx("option", { value: "20", children: "20" }), jsx("option", { value: "50", children: "50" })] }) })] }), jsx(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: dataList.length > 0 ? (jsx(Flex, { flexFlow: "column wrap", children: dataList.map((item) => {
|
|
4480
|
+
const selected = isMultiple
|
|
4481
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4482
|
+
: watchId === item[column_ref];
|
|
4483
|
+
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
4484
|
+
if (!isMultiple) {
|
|
4485
|
+
setOpenSearchResult(false);
|
|
4486
|
+
setValue(colLabel, item[column_ref]);
|
|
4487
|
+
return;
|
|
4488
|
+
}
|
|
4489
|
+
// For multiple selection, don't add if already selected
|
|
4490
|
+
if (selected)
|
|
4491
|
+
return;
|
|
4492
|
+
const newSet = new Set([
|
|
4493
|
+
...(watchIds ?? []),
|
|
4494
|
+
item[column_ref],
|
|
4495
|
+
]);
|
|
4496
|
+
setValue(colLabel, [...newSet]);
|
|
4497
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected
|
|
4498
|
+
? { color: "colorPalette.400/50", fontWeight: "bold" }
|
|
4499
|
+
: {}), children: !!renderDisplay === true
|
|
4500
|
+
? renderDisplay(item)
|
|
4501
|
+
: item[display_column] }, item[column_ref]));
|
|
4502
|
+
}) })) : (jsx(Text, { children: searchText
|
|
4503
|
+
? translate.t(removeIndex(`${colLabel}.empty_search_result`))
|
|
4504
|
+
: translate.t(removeIndex(`${colLabel}.initial_results`)) })) }), jsx(PaginationRoot, { justifySelf: "center", count: count, pageSize: limit, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), count > 0 && jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4364
4505
|
};
|
|
4365
4506
|
|
|
4366
4507
|
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
@@ -4374,17 +4515,17 @@ NumberInput.Label;
|
|
|
4374
4515
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4375
4516
|
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4376
4517
|
const { translate } = useSchemaContext();
|
|
4377
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4518
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4378
4519
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4379
4520
|
const colLabel = `${prefix}${column}`;
|
|
4380
4521
|
const value = watch(`${colLabel}`);
|
|
4381
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4522
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { required: isRequired, value: value, onChange: (event) => {
|
|
4382
4523
|
setValue(`${colLabel}`, Number(event.target.value));
|
|
4383
|
-
} }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4524
|
+
} }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4384
4525
|
};
|
|
4385
4526
|
|
|
4386
4527
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4387
|
-
const { properties,
|
|
4528
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, } = schema;
|
|
4388
4529
|
const { translate } = useSchemaContext();
|
|
4389
4530
|
const colLabel = `${prefix}${column}`;
|
|
4390
4531
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4392,25 +4533,25 @@ const ObjectInput = ({ schema, column, prefix }) => {
|
|
|
4392
4533
|
if (properties === undefined) {
|
|
4393
4534
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4394
4535
|
}
|
|
4395
|
-
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label",
|
|
4536
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: Object.keys(properties ?? {}).map((key) => {
|
|
4396
4537
|
return (
|
|
4397
4538
|
// @ts-expect-error find suitable types
|
|
4398
4539
|
jsx(ColumnRenderer, { column: `${key}`,
|
|
4399
4540
|
prefix: `${prefix}${column}.`,
|
|
4400
4541
|
properties }, `form-${colLabel}-${key}`));
|
|
4401
|
-
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4542
|
+
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4402
4543
|
};
|
|
4403
4544
|
|
|
4404
4545
|
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4405
4546
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4406
4547
|
const { translate } = useSchemaContext();
|
|
4407
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4548
|
+
const { required, gridColumn = "span 12", gridRow = "span 1" } = schema;
|
|
4408
4549
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4409
4550
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4410
4551
|
const [showNewEntries, setShowNewEntries] = useState(false);
|
|
4411
4552
|
const [newKey, setNewKey] = useState();
|
|
4412
4553
|
const [newValue, setNewValue] = useState();
|
|
4413
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.
|
|
4554
|
+
return (jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4414
4555
|
return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
|
|
4415
4556
|
const filtered = entries.filter(([target]) => {
|
|
4416
4557
|
return target !== key;
|
|
@@ -4450,16 +4591,16 @@ const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
|
4450
4591
|
setShowNewEntries(true);
|
|
4451
4592
|
setNewKey(undefined);
|
|
4452
4593
|
setNewValue(undefined);
|
|
4453
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.
|
|
4594
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4454
4595
|
};
|
|
4455
4596
|
|
|
4456
4597
|
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4457
4598
|
const { register, formState: { errors }, } = useFormContext();
|
|
4458
4599
|
const { translate } = useSchemaContext();
|
|
4459
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4600
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4460
4601
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4461
4602
|
const colLabel = `${prefix}${column}`;
|
|
4462
|
-
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4603
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, children: [jsx(Input, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4463
4604
|
};
|
|
4464
4605
|
|
|
4465
4606
|
const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4557,9 +4698,264 @@ const TagPicker = ({ column, schema, prefix }) => {
|
|
|
4557
4698
|
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4558
4699
|
};
|
|
4559
4700
|
|
|
4701
|
+
const TextAreaInput = ({ column, schema, prefix, }) => {
|
|
4702
|
+
const { register, formState: { errors }, } = useFormContext();
|
|
4703
|
+
const { translate } = useSchemaContext();
|
|
4704
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4705
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4706
|
+
const colLabel = `${prefix}${column}`;
|
|
4707
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Textarea, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4708
|
+
};
|
|
4709
|
+
|
|
4710
|
+
function TimePicker$1({ hour, setHour, minute, setMinute, meridiem, setMeridiem, meridiemLabel = {
|
|
4711
|
+
am: "am",
|
|
4712
|
+
pm: "pm",
|
|
4713
|
+
}, onChange = (_newValue) => { }, }) {
|
|
4714
|
+
// Refs for focus management
|
|
4715
|
+
const hourInputRef = useRef(null);
|
|
4716
|
+
const minuteInputRef = useRef(null);
|
|
4717
|
+
const meridiemInputRef = useRef(null);
|
|
4718
|
+
// Centralized handler for key events, value changes, and focus management
|
|
4719
|
+
const handleKeyDown = (e, field) => {
|
|
4720
|
+
const input = e.target;
|
|
4721
|
+
const value = input.value;
|
|
4722
|
+
// Handle navigation between fields
|
|
4723
|
+
if (e.key === "Tab") {
|
|
4724
|
+
// Tab is handled by the browser, no need to override
|
|
4725
|
+
return;
|
|
4726
|
+
}
|
|
4727
|
+
if (e.key === ":" && field === "hour") {
|
|
4728
|
+
e.preventDefault();
|
|
4729
|
+
minuteInputRef.current?.focus();
|
|
4730
|
+
return;
|
|
4731
|
+
}
|
|
4732
|
+
if (e.key === "Backspace" && value === "") {
|
|
4733
|
+
e.preventDefault();
|
|
4734
|
+
if (field === "minute") {
|
|
4735
|
+
hourInputRef.current?.focus();
|
|
4736
|
+
}
|
|
4737
|
+
else if (field === "meridiem") {
|
|
4738
|
+
minuteInputRef.current?.focus();
|
|
4739
|
+
}
|
|
4740
|
+
return;
|
|
4741
|
+
}
|
|
4742
|
+
// Handle number inputs
|
|
4743
|
+
if (field === "hour") {
|
|
4744
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4745
|
+
const newValue = value + e.key;
|
|
4746
|
+
const numValue = parseInt(newValue, 10);
|
|
4747
|
+
console.log("newValue", newValue, numValue);
|
|
4748
|
+
if (numValue > 12) {
|
|
4749
|
+
const digitValue = parseInt(e.key, 10);
|
|
4750
|
+
setHour(digitValue);
|
|
4751
|
+
onChange({ hour: digitValue, minute, meridiem });
|
|
4752
|
+
return;
|
|
4753
|
+
}
|
|
4754
|
+
// Auto-advance to minutes if we have a valid hour (1-12)
|
|
4755
|
+
if (numValue >= 1 && numValue <= 12) {
|
|
4756
|
+
// Set the hour value
|
|
4757
|
+
setHour(numValue);
|
|
4758
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4759
|
+
// Move to minute input
|
|
4760
|
+
e.preventDefault();
|
|
4761
|
+
minuteInputRef.current?.focus();
|
|
4762
|
+
}
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
else if (field === "minute") {
|
|
4766
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4767
|
+
const newValue = value + e.key;
|
|
4768
|
+
const numValue = parseInt(newValue, 10);
|
|
4769
|
+
if (numValue > 60) {
|
|
4770
|
+
const digitValue = parseInt(e.key, 10);
|
|
4771
|
+
setHour(digitValue);
|
|
4772
|
+
onChange({ hour, minute: digitValue, meridiem });
|
|
4773
|
+
return;
|
|
4774
|
+
}
|
|
4775
|
+
// Auto-advance to meridiem if we have a valid minute (0-59)
|
|
4776
|
+
if (numValue >= 0 && numValue <= 59) {
|
|
4777
|
+
// Set the minute value
|
|
4778
|
+
setMinute(numValue);
|
|
4779
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4780
|
+
// Move to meridiem input
|
|
4781
|
+
e.preventDefault();
|
|
4782
|
+
meridiemInputRef.current?.focus();
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
else if (field === "meridiem") {
|
|
4787
|
+
const key = e.key.toLowerCase();
|
|
4788
|
+
if (key === "a") {
|
|
4789
|
+
e.preventDefault();
|
|
4790
|
+
setMeridiem("am");
|
|
4791
|
+
onChange({ hour, minute, meridiem: "am" });
|
|
4792
|
+
input.value = "am";
|
|
4793
|
+
}
|
|
4794
|
+
else if (key === "p") {
|
|
4795
|
+
e.preventDefault();
|
|
4796
|
+
setMeridiem("pm");
|
|
4797
|
+
onChange({ hour, minute, meridiem: "pm" });
|
|
4798
|
+
input.value = "pm";
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4801
|
+
};
|
|
4802
|
+
// Handle input blur events to validate and format values
|
|
4803
|
+
const handleBlur = (e, field) => {
|
|
4804
|
+
const value = e.target.value;
|
|
4805
|
+
if (field === "hour") {
|
|
4806
|
+
if (value === "") {
|
|
4807
|
+
if (hour !== null) {
|
|
4808
|
+
setHour(null);
|
|
4809
|
+
onChange({ hour: null, minute, meridiem });
|
|
4810
|
+
}
|
|
4811
|
+
return;
|
|
4812
|
+
}
|
|
4813
|
+
const numValue = parseInt(value, 10);
|
|
4814
|
+
if (isNaN(numValue) || numValue < 1 || numValue > 12) {
|
|
4815
|
+
setHour(null);
|
|
4816
|
+
onChange({ hour: null, minute, meridiem });
|
|
4817
|
+
}
|
|
4818
|
+
else if (hour !== numValue) {
|
|
4819
|
+
setHour(numValue);
|
|
4820
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
else if (field === "minute") {
|
|
4824
|
+
if (value === "") {
|
|
4825
|
+
if (minute !== null) {
|
|
4826
|
+
setMinute(null);
|
|
4827
|
+
onChange({ hour, minute: null, meridiem });
|
|
4828
|
+
}
|
|
4829
|
+
return;
|
|
4830
|
+
}
|
|
4831
|
+
const numValue = parseInt(value, 10);
|
|
4832
|
+
if (isNaN(numValue) || numValue < 0 || numValue > 59) {
|
|
4833
|
+
setMinute(null);
|
|
4834
|
+
onChange({ hour, minute: null, meridiem });
|
|
4835
|
+
}
|
|
4836
|
+
else if (minute !== numValue) {
|
|
4837
|
+
setMinute(numValue);
|
|
4838
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
else if (field === "meridiem") {
|
|
4842
|
+
if (value === "") {
|
|
4843
|
+
if (meridiem !== null) {
|
|
4844
|
+
setMeridiem(null);
|
|
4845
|
+
onChange({ hour, minute, meridiem: null });
|
|
4846
|
+
}
|
|
4847
|
+
return;
|
|
4848
|
+
}
|
|
4849
|
+
const lowerValue = value.toLowerCase();
|
|
4850
|
+
if (lowerValue !== "am" && lowerValue !== "pm") {
|
|
4851
|
+
if (lowerValue === "a") {
|
|
4852
|
+
setMeridiem("am");
|
|
4853
|
+
onChange({ hour, minute, meridiem: "am" });
|
|
4854
|
+
}
|
|
4855
|
+
else if (lowerValue === "p") {
|
|
4856
|
+
setMeridiem("pm");
|
|
4857
|
+
onChange({ hour, minute, meridiem: "pm" });
|
|
4858
|
+
}
|
|
4859
|
+
else {
|
|
4860
|
+
setMeridiem(null);
|
|
4861
|
+
onChange({ hour, minute, meridiem: null });
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
else if (meridiem !== lowerValue) {
|
|
4865
|
+
setMeridiem(lowerValue);
|
|
4866
|
+
onChange({ hour, minute, meridiem: lowerValue });
|
|
4867
|
+
}
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
// Handle meridiem button click
|
|
4871
|
+
const handleMeridiemClick = (newMeridiem) => {
|
|
4872
|
+
setMeridiem(newMeridiem);
|
|
4873
|
+
onChange({ hour, minute, meridiem: newMeridiem });
|
|
4874
|
+
};
|
|
4875
|
+
const handleClear = () => {
|
|
4876
|
+
setHour(null);
|
|
4877
|
+
setMinute(null);
|
|
4878
|
+
setMeridiem(null);
|
|
4879
|
+
onChange({ hour: null, minute: null, meridiem: null });
|
|
4880
|
+
// Focus the hour field after clearing
|
|
4881
|
+
hourInputRef.current?.focus();
|
|
4882
|
+
};
|
|
4883
|
+
function handleFocus(event) {
|
|
4884
|
+
event.target.select();
|
|
4885
|
+
}
|
|
4886
|
+
return (jsx(Flex, { direction: "column", gap: 3, children: jsxs(Grid, { justifyContent: "center", alignItems: "center", templateColumns: "60px 10px 60px 90px auto", gap: "2", width: "auto", minWidth: "250px", children: [jsx(Input, { ref: hourInputRef, type: "text", value: hour === null ? "" : hour.toString().padStart(2, "0"), onKeyDown: (e) => handleKeyDown(e, "hour"), onBlur: (e) => handleBlur(e, "hour"), onFocus: handleFocus, placeholder: "HH", maxLength: 2, textAlign: "center" }), jsx(Text, { children: ":" }), jsx(Input, { ref: minuteInputRef, type: "text", value: minute === null ? "" : minute.toString().padStart(2, "0"), onKeyDown: (e) => handleKeyDown(e, "minute"), onBlur: (e) => handleBlur(e, "minute"), onFocus: handleFocus, placeholder: "MM", maxLength: 2, textAlign: "center" }), jsxs(Flex, { gap: "1", children: [jsx(Button$1, { size: "sm", colorScheme: meridiem === "am" ? "blue" : "gray", variant: meridiem === "am" ? "solid" : "outline", onClick: () => handleMeridiemClick("am"), width: "40px", children: meridiemLabel.am }), jsx(Button$1, { size: "sm", colorScheme: meridiem === "pm" ? "blue" : "gray", variant: meridiem === "pm" ? "solid" : "outline", onClick: () => handleMeridiemClick("pm"), width: "40px", children: meridiemLabel.pm })] }), jsx(Button$1, { onClick: handleClear, size: "sm", variant: "ghost", children: jsx(MdCancel, {}) })] }) }));
|
|
4887
|
+
}
|
|
4888
|
+
|
|
4889
|
+
const TimePicker = ({ column, schema, prefix }) => {
|
|
4890
|
+
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
4891
|
+
const { translate } = useSchemaContext();
|
|
4892
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", format } = schema;
|
|
4893
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4894
|
+
const colLabel = `${prefix}${column}`;
|
|
4895
|
+
const [open, setOpen] = useState(false);
|
|
4896
|
+
const value = watch(colLabel);
|
|
4897
|
+
const formatedTime = value ? dayjs(value).format("hh:mm A") : "";
|
|
4898
|
+
// Parse the initial time parts from the ISO time string (HH:mm:ss)
|
|
4899
|
+
const parseTime = (isoTime) => {
|
|
4900
|
+
if (!isoTime)
|
|
4901
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4902
|
+
const parsed = dayjs(isoTime);
|
|
4903
|
+
if (!parsed.isValid())
|
|
4904
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4905
|
+
let hour = parsed.hour();
|
|
4906
|
+
const minute = parsed.minute();
|
|
4907
|
+
const meridiem = hour >= 12 ? "pm" : "am";
|
|
4908
|
+
if (hour === 0)
|
|
4909
|
+
hour = 12;
|
|
4910
|
+
else if (hour > 12)
|
|
4911
|
+
hour -= 12;
|
|
4912
|
+
return { hour, minute, meridiem };
|
|
4913
|
+
};
|
|
4914
|
+
const initialTime = parseTime(value);
|
|
4915
|
+
const [hour, setHour] = useState(initialTime.hour);
|
|
4916
|
+
const [minute, setMinute] = useState(initialTime.minute);
|
|
4917
|
+
const [meridiem, setMeridiem] = useState(initialTime.meridiem);
|
|
4918
|
+
useEffect(() => {
|
|
4919
|
+
const { hour, minute, meridiem } = parseTime(value);
|
|
4920
|
+
setHour(hour);
|
|
4921
|
+
setMinute(minute);
|
|
4922
|
+
setMeridiem(meridiem);
|
|
4923
|
+
}, [value]);
|
|
4924
|
+
// Convert hour, minute, meridiem to 24-hour ISO time string
|
|
4925
|
+
const toIsoTime = (hour, minute, meridiem) => {
|
|
4926
|
+
if (hour === null || minute === null || meridiem === null)
|
|
4927
|
+
return null;
|
|
4928
|
+
let h = hour;
|
|
4929
|
+
if (meridiem === "am" && hour === 12)
|
|
4930
|
+
h = 0;
|
|
4931
|
+
else if (meridiem === "pm" && hour < 12)
|
|
4932
|
+
h = hour + 12;
|
|
4933
|
+
return dayjs().hour(h).minute(minute).second(0).format(format);
|
|
4934
|
+
};
|
|
4935
|
+
// Handle changes to time parts
|
|
4936
|
+
const handleTimeChange = ({ hour: newHour, minute: newMinute, meridiem: newMeridiem, }) => {
|
|
4937
|
+
setHour(newHour);
|
|
4938
|
+
setMinute(newMinute);
|
|
4939
|
+
setMeridiem(newMeridiem);
|
|
4940
|
+
const isoTime = toIsoTime(newHour, newMinute, newMeridiem);
|
|
4941
|
+
setValue(colLabel, isoTime, { shouldValidate: true, shouldDirty: true });
|
|
4942
|
+
};
|
|
4943
|
+
const containerRef = useRef(null);
|
|
4944
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4945
|
+
gridRow, children: [jsxs(Popover.Root, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(Popover.Trigger, { asChild: true, children: jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
4946
|
+
setOpen(true);
|
|
4947
|
+
}, justifyContent: "start", children: [jsx(IoMdClock, {}), value !== undefined ? `${formatedTime}` : ""] }) }), jsx(Portal, { children: jsx(Popover.Positioner, { children: jsx(Popover.Content, { ref: containerRef, children: jsx(Popover.Body, { children: jsx(TimePicker$1, { hour: hour, setHour: setHour, minute: minute, setMinute: setMinute, meridiem: meridiem, setMeridiem: setMeridiem, onChange: handleTimeChange, meridiemLabel: {
|
|
4948
|
+
am: translate.t(removeIndex(`common.am`)),
|
|
4949
|
+
pm: translate.t(removeIndex(`common.pm`)),
|
|
4950
|
+
} }) }) }) }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4951
|
+
};
|
|
4952
|
+
|
|
4560
4953
|
const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
4561
4954
|
const colSchema = schema;
|
|
4562
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4955
|
+
const { type, variant, properties: innerProperties, foreign_key, format, items, } = schema;
|
|
4956
|
+
if (variant === "custom-input") {
|
|
4957
|
+
return jsx(CustomInput, { schema: colSchema, prefix, column });
|
|
4958
|
+
}
|
|
4563
4959
|
if (type === "string") {
|
|
4564
4960
|
if ((schema.enum ?? []).length > 0) {
|
|
4565
4961
|
return jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
@@ -4568,9 +4964,15 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4568
4964
|
idPickerSanityCheck(column, foreign_key);
|
|
4569
4965
|
return jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4570
4966
|
}
|
|
4571
|
-
if (
|
|
4967
|
+
if (format === "date") {
|
|
4572
4968
|
return jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4573
4969
|
}
|
|
4970
|
+
if (format === "time") {
|
|
4971
|
+
return jsx(TimePicker, { schema: colSchema, prefix, column });
|
|
4972
|
+
}
|
|
4973
|
+
if (variant === "text-area") {
|
|
4974
|
+
return jsx(TextAreaInput, { schema: colSchema, prefix, column });
|
|
4975
|
+
}
|
|
4574
4976
|
return jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4575
4977
|
}
|
|
4576
4978
|
if (type === "number" || type === "integer") {
|
|
@@ -4617,39 +5019,52 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4617
5019
|
};
|
|
4618
5020
|
|
|
4619
5021
|
const ArrayViewer = ({ schema, column, prefix }) => {
|
|
4620
|
-
const {
|
|
5022
|
+
const { gridColumn = "span 4", gridRow = "span 1", required, items } = schema;
|
|
4621
5023
|
const { translate } = useSchemaContext();
|
|
4622
5024
|
const colLabel = `${prefix}${column}`;
|
|
4623
5025
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4624
5026
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4625
5027
|
const values = watch(colLabel) ?? [];
|
|
4626
|
-
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.
|
|
5028
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsx("span", { children: "*" })] }), values.map((field, index) => (jsx(Flex, { flexFlow: "column", children: jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsx(SchemaViewer, { column: `${index}`,
|
|
4627
5029
|
prefix: `${colLabel}.`,
|
|
4628
|
-
schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5030
|
+
schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4629
5031
|
};
|
|
4630
5032
|
|
|
4631
5033
|
const BooleanViewer = ({ schema, column, prefix, }) => {
|
|
4632
5034
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4633
5035
|
const { translate } = useSchemaContext();
|
|
4634
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5036
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4635
5037
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4636
5038
|
const colLabel = `${prefix}${column}`;
|
|
4637
5039
|
const value = watch(colLabel);
|
|
4638
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5040
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4639
5041
|
gridRow, children: [jsx(Text, { children: value
|
|
4640
5042
|
? translate.t(removeIndex(`${colLabel}.true`))
|
|
4641
|
-
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5043
|
+
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
5044
|
+
};
|
|
5045
|
+
|
|
5046
|
+
const CustomViewer = ({ column, schema, prefix }) => {
|
|
5047
|
+
const formContext = useFormContext();
|
|
5048
|
+
const { inputViewerRender } = schema;
|
|
5049
|
+
return (inputViewerRender &&
|
|
5050
|
+
inputViewerRender({
|
|
5051
|
+
column,
|
|
5052
|
+
schema,
|
|
5053
|
+
prefix,
|
|
5054
|
+
formContext,
|
|
5055
|
+
}));
|
|
4642
5056
|
};
|
|
4643
5057
|
|
|
4644
5058
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4645
5059
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4646
5060
|
const { translate } = useSchemaContext();
|
|
4647
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5061
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4648
5062
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4649
5063
|
const colLabel = `${prefix}${column}`;
|
|
4650
5064
|
const selectedDate = watch(colLabel);
|
|
4651
|
-
|
|
4652
|
-
|
|
5065
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
5066
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5067
|
+
gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ? displayDate : ""] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4653
5068
|
};
|
|
4654
5069
|
|
|
4655
5070
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
@@ -4657,11 +5072,11 @@ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
4657
5072
|
const { translate } = useSchemaContext();
|
|
4658
5073
|
const { required } = schema;
|
|
4659
5074
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4660
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
5075
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
4661
5076
|
const colLabel = `${prefix}${column}`;
|
|
4662
5077
|
const watchEnum = watch(colLabel);
|
|
4663
5078
|
const watchEnums = (watch(colLabel) ?? []);
|
|
4664
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5079
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4665
5080
|
gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
|
|
4666
5081
|
const item = enumValue;
|
|
4667
5082
|
if (item === undefined) {
|
|
@@ -4670,32 +5085,25 @@ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
4670
5085
|
return (jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4671
5086
|
? renderDisplay(item)
|
|
4672
5087
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
4673
|
-
}) })), !isMultiple && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5088
|
+
}) })), !isMultiple && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4674
5089
|
};
|
|
4675
5090
|
|
|
4676
5091
|
const FileViewer = ({ column, schema, prefix }) => {
|
|
4677
|
-
const {
|
|
5092
|
+
const { watch } = useFormContext();
|
|
4678
5093
|
const { translate } = useSchemaContext();
|
|
4679
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5094
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4680
5095
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4681
5096
|
const currentFiles = (watch(column) ?? []);
|
|
4682
5097
|
const colLabel = `${prefix}${column}`;
|
|
4683
|
-
return (
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
}, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4687
|
-
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4688
|
-
setValue(column, currentFiles.filter(({ name }) => {
|
|
4689
|
-
return name !== file.name;
|
|
4690
|
-
}));
|
|
4691
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4692
|
-
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
5098
|
+
return (jsx(Field, { label: `${translate.t(`${colLabel}.field_label`)}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
5099
|
+
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [file.type.startsWith("image/") && (jsx(Image, { src: URL.createObjectURL(file), alt: file.name, boxSize: "50px", objectFit: "cover", borderRadius: "md", marginRight: "2" })), jsx(Box, { children: file.name })] }) }, file.name));
|
|
5100
|
+
}) }) }));
|
|
4693
5101
|
};
|
|
4694
5102
|
|
|
4695
5103
|
const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4696
5104
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4697
5105
|
const { idMap, translate } = useSchemaContext();
|
|
4698
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
5106
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4699
5107
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4700
5108
|
const { display_column } = foreign_key;
|
|
4701
5109
|
const colLabel = `${prefix}${column}`;
|
|
@@ -4711,7 +5119,7 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4711
5119
|
}
|
|
4712
5120
|
return record[display_column];
|
|
4713
5121
|
};
|
|
4714
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5122
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4715
5123
|
gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
|
|
4716
5124
|
const item = idMap[id];
|
|
4717
5125
|
if (item === undefined) {
|
|
@@ -4720,21 +5128,21 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4720
5128
|
return (jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4721
5129
|
? renderDisplay(item)
|
|
4722
5130
|
: item[display_column] }, id));
|
|
4723
|
-
}) })), !isMultiple && jsx(Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5131
|
+
}) })), !isMultiple && jsx(Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4724
5132
|
};
|
|
4725
5133
|
|
|
4726
5134
|
const NumberViewer = ({ schema, column, prefix, }) => {
|
|
4727
5135
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4728
5136
|
const { translate } = useSchemaContext();
|
|
4729
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5137
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4730
5138
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4731
5139
|
const colLabel = `${prefix}${column}`;
|
|
4732
5140
|
const value = watch(colLabel);
|
|
4733
|
-
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5141
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(Text, { children: value }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4734
5142
|
};
|
|
4735
5143
|
|
|
4736
5144
|
const ObjectViewer = ({ schema, column, prefix }) => {
|
|
4737
|
-
const { properties,
|
|
5145
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, } = schema;
|
|
4738
5146
|
const { translate } = useSchemaContext();
|
|
4739
5147
|
const colLabel = `${prefix}${column}`;
|
|
4740
5148
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4742,25 +5150,26 @@ const ObjectViewer = ({ schema, column, prefix }) => {
|
|
|
4742
5150
|
if (properties === undefined) {
|
|
4743
5151
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4744
5152
|
}
|
|
4745
|
-
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label",
|
|
5153
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", gridColumn,
|
|
5154
|
+
gridRow, children: Object.keys(properties ?? {}).map((key) => {
|
|
4746
5155
|
return (
|
|
4747
5156
|
// @ts-expect-error find suitable types
|
|
4748
5157
|
jsx(ColumnViewer, { column: `${key}`,
|
|
4749
5158
|
prefix: `${prefix}${column}.`,
|
|
4750
5159
|
properties }, `form-objectviewer-${colLabel}-${key}`));
|
|
4751
|
-
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5160
|
+
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4752
5161
|
};
|
|
4753
5162
|
|
|
4754
5163
|
const RecordInput = ({ column, schema, prefix }) => {
|
|
4755
5164
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4756
5165
|
const { translate } = useSchemaContext();
|
|
4757
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5166
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4758
5167
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4759
5168
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4760
5169
|
const [showNewEntries, setShowNewEntries] = useState(false);
|
|
4761
5170
|
const [newKey, setNewKey] = useState();
|
|
4762
5171
|
const [newValue, setNewValue] = useState();
|
|
4763
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.
|
|
5172
|
+
return (jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4764
5173
|
return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
|
|
4765
5174
|
const filtered = entries.filter(([target]) => {
|
|
4766
5175
|
return target !== key;
|
|
@@ -4800,7 +5209,17 @@ const RecordInput = ({ column, schema, prefix }) => {
|
|
|
4800
5209
|
setShowNewEntries(true);
|
|
4801
5210
|
setNewKey(undefined);
|
|
4802
5211
|
setNewValue(undefined);
|
|
4803
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.
|
|
5212
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
5213
|
+
};
|
|
5214
|
+
|
|
5215
|
+
const StringViewer = ({ column, schema, prefix, }) => {
|
|
5216
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
5217
|
+
const { translate } = useSchemaContext();
|
|
5218
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5219
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5220
|
+
const colLabel = `${prefix}${column}`;
|
|
5221
|
+
const value = watch(colLabel);
|
|
5222
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: value }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4804
5223
|
};
|
|
4805
5224
|
|
|
4806
5225
|
const TagViewer = ({ column, schema, prefix }) => {
|
|
@@ -4888,19 +5307,35 @@ const TagViewer = ({ column, schema, prefix }) => {
|
|
|
4888
5307
|
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4889
5308
|
};
|
|
4890
5309
|
|
|
4891
|
-
const
|
|
5310
|
+
const TextAreaViewer = ({ column, schema, prefix, }) => {
|
|
4892
5311
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4893
5312
|
const { translate } = useSchemaContext();
|
|
4894
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5313
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4895
5314
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4896
5315
|
const colLabel = `${prefix}${column}`;
|
|
4897
5316
|
const value = watch(colLabel);
|
|
4898
|
-
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5317
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, children: [jsx(Text, { whiteSpace: "pre-wrap", children: value }), " ", errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
5318
|
+
};
|
|
5319
|
+
|
|
5320
|
+
const TimeViewer = ({ column, schema, prefix }) => {
|
|
5321
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
5322
|
+
const { translate } = useSchemaContext();
|
|
5323
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5324
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5325
|
+
const colLabel = `${prefix}${column}`;
|
|
5326
|
+
const selectedDate = watch(colLabel);
|
|
5327
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5328
|
+
gridRow, children: [jsx(Text, { children: selectedDate !== undefined
|
|
5329
|
+
? dayjs(selectedDate).format("hh:mm A")
|
|
5330
|
+
: "" }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4899
5331
|
};
|
|
4900
5332
|
|
|
4901
5333
|
const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
4902
5334
|
const colSchema = schema;
|
|
4903
5335
|
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
5336
|
+
if (variant === "custom-input") {
|
|
5337
|
+
return jsx(CustomViewer, { schema: colSchema, prefix, column });
|
|
5338
|
+
}
|
|
4904
5339
|
if (type === "string") {
|
|
4905
5340
|
if ((schema.enum ?? []).length > 0) {
|
|
4906
5341
|
return jsx(EnumViewer, { schema: colSchema, prefix, column });
|
|
@@ -4912,6 +5347,12 @@ const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
|
4912
5347
|
if (variant === "date-picker") {
|
|
4913
5348
|
return jsx(DateViewer, { schema: colSchema, prefix, column });
|
|
4914
5349
|
}
|
|
5350
|
+
if (variant === "time-picker") {
|
|
5351
|
+
return jsx(TimeViewer, { schema: colSchema, prefix, column });
|
|
5352
|
+
}
|
|
5353
|
+
if (variant === "text-area") {
|
|
5354
|
+
return jsx(TextAreaViewer, { schema: colSchema, prefix, column });
|
|
5355
|
+
}
|
|
4915
5356
|
return jsx(StringViewer, { schema: colSchema, prefix, column });
|
|
4916
5357
|
}
|
|
4917
5358
|
if (type === "number" || type === "integer") {
|
|
@@ -5034,7 +5475,7 @@ const FormBody = () => {
|
|
|
5034
5475
|
include,
|
|
5035
5476
|
});
|
|
5036
5477
|
if (isSuccess) {
|
|
5037
|
-
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("
|
|
5478
|
+
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submit_success") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { onClick: async () => {
|
|
5038
5479
|
setIsError(false);
|
|
5039
5480
|
setIsSubmiting(false);
|
|
5040
5481
|
setIsSuccess(false);
|
|
@@ -5042,10 +5483,10 @@ const FormBody = () => {
|
|
|
5042
5483
|
setValidatedData(undefined);
|
|
5043
5484
|
const data = await getUpdatedData();
|
|
5044
5485
|
methods.reset(data);
|
|
5045
|
-
}, formNoValidate: true, children: translate.t("
|
|
5486
|
+
}, formNoValidate: true, children: translate.t("submit_again") }) })] }));
|
|
5046
5487
|
}
|
|
5047
5488
|
if (isConfirming) {
|
|
5048
|
-
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows:
|
|
5489
|
+
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: "repeat(12, max-content)", autoFlow: "row", children: ordered.map((column) => {
|
|
5049
5490
|
return (jsx(ColumnViewer
|
|
5050
5491
|
// @ts-expect-error find suitable types
|
|
5051
5492
|
, {
|
|
@@ -5057,7 +5498,7 @@ const FormBody = () => {
|
|
|
5057
5498
|
onFormSubmit(validatedData);
|
|
5058
5499
|
}, children: translate.t("confirm") })] }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: [], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
|
|
5059
5500
|
}
|
|
5060
|
-
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)",
|
|
5501
|
+
return (jsxs(Flex, { flexFlow: "column", gap: "2", children: [jsx(Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: ordered.map((column) => {
|
|
5061
5502
|
return (jsx(ColumnRenderer
|
|
5062
5503
|
// @ts-expect-error find suitable types
|
|
5063
5504
|
, {
|
|
@@ -5073,8 +5514,8 @@ const FormTitle = () => {
|
|
|
5073
5514
|
return jsx(Heading, { children: translate.t("title") });
|
|
5074
5515
|
};
|
|
5075
5516
|
|
|
5076
|
-
const DefaultForm = ({ formConfig, }) => {
|
|
5077
|
-
return (jsx(FormRoot, { ...formConfig, children: jsxs(Grid, { gap: "2", children: [jsx(FormTitle, {}), jsx(FormBody, {})] }) }));
|
|
5517
|
+
const DefaultForm = ({ formConfig, showTitle = true, }) => {
|
|
5518
|
+
return (jsx(FormRoot, { ...formConfig, children: jsxs(Grid, { gap: "2", children: [showTitle && jsx(FormTitle, {}), jsx(FormBody, {})] }) }));
|
|
5078
5519
|
};
|
|
5079
5520
|
|
|
5080
5521
|
const useForm = ({ preLoadedValues, keyPrefix }) => {
|
|
@@ -5107,4 +5548,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
|
|
|
5107
5548
|
}
|
|
5108
5549
|
};
|
|
5109
5550
|
|
|
5110
|
-
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultForm, DefaultTable, DensityToggleButton,
|
|
5551
|
+
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultForm, DefaultTable, DensityToggleButton, EditSortingButton, EmptyState$1 as EmptyState, ErrorAlert, FilterDialog, FilterOptions, FormBody, FormRoot, FormTitle, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableDataDisplay, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
|