@bsol-oss/react-datatable5 12.0.0-beta.5 → 12.0.0-beta.51
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 +183 -87
- package/dist/index.js +888 -359
- package/dist/index.mjs +893 -365
- package/dist/types/components/DataTable/DataTable.d.ts +4 -2
- package/dist/types/components/DataTable/DataTableServer.d.ts +4 -2
- package/dist/types/components/DataTable/DefaultTable.d.ts +9 -12
- package/dist/types/components/DataTable/context/DataTableContext.d.ts +19 -3
- package/dist/types/components/DataTable/context/useDataTableContext.d.ts +2 -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 +4 -0
- package/dist/types/components/DataTable/controls/ResetFilteringButton.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ResetSelectionButton.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ResetSortingButton.d.ts +1 -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 +26 -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 +20 -0
- package/dist/types/components/DataTable/display/TableCardContainer.d.ts +10 -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 +51 -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 +19 -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/Form/utils/translateWrapper.d.ts +6 -0
- package/dist/types/components/TimePicker/TimePicker.d.ts +20 -0
- package/dist/types/index.d.ts +48 -32
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var reactI18next = require('react-i18next');
|
|
|
30
30
|
var axios = require('axios');
|
|
31
31
|
var reactHookForm = require('react-hook-form');
|
|
32
32
|
var dayjs = require('dayjs');
|
|
33
|
+
var utc = require('dayjs/plugin/utc');
|
|
33
34
|
var ti = require('react-icons/ti');
|
|
34
35
|
|
|
35
36
|
function _interopNamespaceDefault(e) {
|
|
@@ -57,6 +58,53 @@ const DataTableContext = React.createContext({
|
|
|
57
58
|
setGlobalFilter: () => { },
|
|
58
59
|
type: "client",
|
|
59
60
|
translate: {},
|
|
61
|
+
data: [],
|
|
62
|
+
columns: [],
|
|
63
|
+
columnOrder: [],
|
|
64
|
+
columnFilters: [],
|
|
65
|
+
density: "sm",
|
|
66
|
+
sorting: [],
|
|
67
|
+
setPagination: function () {
|
|
68
|
+
throw new Error("Function not implemented.");
|
|
69
|
+
},
|
|
70
|
+
setSorting: function () {
|
|
71
|
+
throw new Error("Function not implemented.");
|
|
72
|
+
},
|
|
73
|
+
setColumnFilters: function () {
|
|
74
|
+
throw new Error("Function not implemented.");
|
|
75
|
+
},
|
|
76
|
+
setRowSelection: function () {
|
|
77
|
+
throw new Error("Function not implemented.");
|
|
78
|
+
},
|
|
79
|
+
setColumnOrder: function () {
|
|
80
|
+
throw new Error("Function not implemented.");
|
|
81
|
+
},
|
|
82
|
+
setDensity: function () {
|
|
83
|
+
throw new Error("Function not implemented.");
|
|
84
|
+
},
|
|
85
|
+
setColumnVisibility: function () {
|
|
86
|
+
throw new Error("Function not implemented.");
|
|
87
|
+
},
|
|
88
|
+
pagination: {
|
|
89
|
+
pageIndex: 0,
|
|
90
|
+
pageSize: 10,
|
|
91
|
+
},
|
|
92
|
+
rowSelection: {},
|
|
93
|
+
columnVisibility: {},
|
|
94
|
+
tableLabel: {
|
|
95
|
+
view: "View",
|
|
96
|
+
edit: "Edit",
|
|
97
|
+
filterButtonText: "Filter",
|
|
98
|
+
filterTitle: "Filter",
|
|
99
|
+
filterReset: "Reset",
|
|
100
|
+
filterClose: "Close",
|
|
101
|
+
reloadTooltip: "Reload",
|
|
102
|
+
reloadButtonText: "Reload",
|
|
103
|
+
resetSelection: "Reset Selection",
|
|
104
|
+
resetSorting: "Reset Sorting",
|
|
105
|
+
rowCountText: "Row Count",
|
|
106
|
+
hasErrorText: "Has Error",
|
|
107
|
+
},
|
|
60
108
|
});
|
|
61
109
|
|
|
62
110
|
const useDataTableContext = () => {
|
|
@@ -112,11 +160,13 @@ const TableSorter = () => {
|
|
|
112
160
|
}) }))) }));
|
|
113
161
|
};
|
|
114
162
|
|
|
115
|
-
const ResetSortingButton = (
|
|
163
|
+
const ResetSortingButton = () => {
|
|
116
164
|
const { table } = useDataTableContext();
|
|
165
|
+
const { tableLabel } = useDataTableContext();
|
|
166
|
+
const { resetSorting } = tableLabel;
|
|
117
167
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
118
168
|
table.resetSorting();
|
|
119
|
-
}, children:
|
|
169
|
+
}, children: resetSorting }));
|
|
120
170
|
};
|
|
121
171
|
|
|
122
172
|
const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}), title = "Edit Sorting", }) => {
|
|
@@ -327,10 +377,11 @@ const Filter = ({ column }) => {
|
|
|
327
377
|
if (filterVariant === "select") {
|
|
328
378
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(RadioGroup, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onValueChange: (details) => {
|
|
329
379
|
column.setFilterValue(details.value);
|
|
330
|
-
}, children: jsxRuntime.
|
|
380
|
+
}, children: jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: "0.5rem", children: [filterOptions.length === 0 && jsxRuntime.jsx(react.Text, { children: "No filter options" }), filterOptions.length > 0 &&
|
|
381
|
+
filterOptions.map((item) => (jsxRuntime.jsx(Radio, { value: item.value, children: item.label }, item.value)))] }) })] }, column.id));
|
|
331
382
|
}
|
|
332
383
|
if (filterVariant === "tag") {
|
|
333
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
384
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions.map((item) => item.value), selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
334
385
|
if (tags.length === 0) {
|
|
335
386
|
return column.setFilterValue(undefined);
|
|
336
387
|
}
|
|
@@ -393,17 +444,20 @@ const TableFilter = () => {
|
|
|
393
444
|
}) }));
|
|
394
445
|
};
|
|
395
446
|
|
|
396
|
-
const ResetFilteringButton = (
|
|
447
|
+
const ResetFilteringButton = () => {
|
|
397
448
|
const { table } = useDataTableContext();
|
|
449
|
+
const { tableLabel } = useDataTableContext();
|
|
450
|
+
const { filterReset } = tableLabel;
|
|
398
451
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
399
452
|
table.resetColumnFilters();
|
|
400
|
-
}, children:
|
|
453
|
+
}, children: filterReset }));
|
|
401
454
|
};
|
|
402
455
|
|
|
403
456
|
const FilterDialog = ({ icon = jsxRuntime.jsx(md.MdFilterAlt, {}), }) => {
|
|
404
457
|
const filterModal = react.useDisclosure();
|
|
405
|
-
const {
|
|
406
|
-
|
|
458
|
+
const { tableLabel } = useDataTableContext();
|
|
459
|
+
const { filterButtonText, filterTitle, filterClose } = tableLabel;
|
|
460
|
+
return (jsxRuntime.jsxs(DialogRoot, { size: ["full", "full", "md", "md"], open: filterModal.open, children: [jsxRuntime.jsx(DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { as: react.Box, variant: "ghost", onClick: filterModal.onOpen, children: [icon, " ", filterButtonText] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsx(DialogTitle, { children: filterTitle }) }), jsxRuntime.jsx(DialogBody, { display: "flex", flexFlow: "column", children: jsxRuntime.jsx(TableFilter, {}) }), jsxRuntime.jsxs(DialogFooter, { children: [jsxRuntime.jsx(ResetFilteringButton, {}), jsxRuntime.jsx(react.Button, { onClick: filterModal.onClose, variant: "subtle", children: filterClose })] }), jsxRuntime.jsx(DialogCloseTrigger, { onClick: filterModal.onClose })] })] }));
|
|
407
461
|
};
|
|
408
462
|
|
|
409
463
|
const MenuContent = React__namespace.forwardRef(function MenuContent(props, ref) {
|
|
@@ -522,11 +576,13 @@ const Pagination = () => {
|
|
|
522
576
|
}, children: jsxRuntime.jsxs(react.HStack, { children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationItems, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) }));
|
|
523
577
|
};
|
|
524
578
|
|
|
525
|
-
const ResetSelectionButton = (
|
|
579
|
+
const ResetSelectionButton = () => {
|
|
526
580
|
const { table } = useDataTableContext();
|
|
581
|
+
const { tableLabel } = useDataTableContext();
|
|
582
|
+
const { resetSelection } = tableLabel;
|
|
527
583
|
return (jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
528
584
|
table.resetRowSelection();
|
|
529
|
-
}, children:
|
|
585
|
+
}, children: resetSelection }));
|
|
530
586
|
};
|
|
531
587
|
|
|
532
588
|
const RowCountText = () => {
|
|
@@ -2441,8 +2497,8 @@ react.CheckboxCard.Indicator;
|
|
|
2441
2497
|
function ColumnCard({ columnId }) {
|
|
2442
2498
|
const ref = React.useRef(null);
|
|
2443
2499
|
const [dragging, setDragging] = React.useState(false); // NEW
|
|
2444
|
-
const { table } = useDataTableContext();
|
|
2445
|
-
const displayName = columnId;
|
|
2500
|
+
const { table, translate } = useDataTableContext();
|
|
2501
|
+
const displayName = translate.t(columnId);
|
|
2446
2502
|
const column = table.getColumn(columnId);
|
|
2447
2503
|
invariant(column);
|
|
2448
2504
|
React.useEffect(() => {
|
|
@@ -2457,7 +2513,7 @@ function ColumnCard({ columnId }) {
|
|
|
2457
2513
|
onDrop: () => setDragging(false), // NEW
|
|
2458
2514
|
});
|
|
2459
2515
|
}, [columnId, table]);
|
|
2460
|
-
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", cursor: "grab", children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "
|
|
2516
|
+
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", cursor: "grab", children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "colorPalette.400" }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "space-between", alignItems: "center", children: jsxRuntime.jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2461
2517
|
}
|
|
2462
2518
|
function CardContainer({ location, children }) {
|
|
2463
2519
|
const ref = React.useRef(null);
|
|
@@ -2537,8 +2593,9 @@ const TableViewer = () => {
|
|
|
2537
2593
|
|
|
2538
2594
|
const ViewDialog = ({ icon = jsxRuntime.jsx(io.IoMdEye, {}) }) => {
|
|
2539
2595
|
const viewModel = react.useDisclosure();
|
|
2540
|
-
const {
|
|
2541
|
-
|
|
2596
|
+
const { tableLabel } = useDataTableContext();
|
|
2597
|
+
const { view } = tableLabel;
|
|
2598
|
+
return (jsxRuntime.jsxs(DialogRoot, { children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { as: react.Box, variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", view] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsx(DialogTitle, { children: view }) }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsx(TableViewer, {}) }), jsxRuntime.jsx(DialogFooter, {})] })] }));
|
|
2542
2599
|
};
|
|
2543
2600
|
|
|
2544
2601
|
const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
|
|
@@ -2589,7 +2646,7 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
|
|
|
2589
2646
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "null" });
|
|
2590
2647
|
}
|
|
2591
2648
|
return (jsxRuntime.jsx(react.Grid, { rowGap: 1, padding: 1, overflow: "auto", ...boxProps, children: Object.entries(object).map(([field, value]) => {
|
|
2592
|
-
return (jsxRuntime.jsxs(react.Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsxRuntime.jsx(react.Text, { color: "
|
|
2649
|
+
return (jsxRuntime.jsxs(react.Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsxRuntime.jsx(react.Text, { color: "colorPalette.400", children: getColumn({ field }) }), typeof value === "object" ? (jsxRuntime.jsx(RecordDisplay, { object: value, prefix: `${prefix}${field}.`, translate: translate })) : (jsxRuntime.jsx(react.Text, { children: JSON.stringify(value) }))] }, field));
|
|
2593
2650
|
}) }));
|
|
2594
2651
|
};
|
|
2595
2652
|
|
|
@@ -2639,7 +2696,7 @@ const CellRenderer = ({ cell }) => {
|
|
|
2639
2696
|
paddingY: 2,
|
|
2640
2697
|
}, object: value })] }, cell.id));
|
|
2641
2698
|
}
|
|
2642
|
-
return (jsxRuntime.jsxs(react.Box, { gridColumn, gridRow, children: [jsxRuntime.jsx(react.Box, { color:
|
|
2699
|
+
return (jsxRuntime.jsxs(react.Box, { gridColumn, gridRow, children: [jsxRuntime.jsx(react.Box, { color: "colorPalette.400", children: getLabel({ columnId: cell.column.id }) }), jsxRuntime.jsx(react.Box, { wordBreak: "break-word", textOverflow: "ellipsis", overflow: "hidden", children: `${formatValue(cell.getValue())}` })] }, cell.id));
|
|
2643
2700
|
};
|
|
2644
2701
|
const DataDisplay = ({ variant = "" }) => {
|
|
2645
2702
|
const { table, translate } = useDataTableContext();
|
|
@@ -2761,7 +2818,20 @@ const fuzzyFilter = (row, columnId, value, addMeta) => {
|
|
|
2761
2818
|
*
|
|
2762
2819
|
* @link https://tanstack.com/table/latest/docs/guide/column-defs
|
|
2763
2820
|
*/
|
|
2764
|
-
function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, translate, children,
|
|
2821
|
+
function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, translate, children, tableLabel = {
|
|
2822
|
+
view: "View",
|
|
2823
|
+
edit: "Edit",
|
|
2824
|
+
filterButtonText: "Filter",
|
|
2825
|
+
filterTitle: "Filter",
|
|
2826
|
+
filterReset: "Reset",
|
|
2827
|
+
filterClose: "Close",
|
|
2828
|
+
reloadTooltip: "Reload",
|
|
2829
|
+
reloadButtonText: "Reload",
|
|
2830
|
+
resetSelection: "Reset Selection",
|
|
2831
|
+
resetSorting: "Reset Sorting",
|
|
2832
|
+
rowCountText: "Row Count",
|
|
2833
|
+
hasErrorText: "Has Error",
|
|
2834
|
+
}, }) {
|
|
2765
2835
|
const table = reactTable.useReactTable({
|
|
2766
2836
|
_features: [DensityFeature],
|
|
2767
2837
|
data: data,
|
|
@@ -2814,6 +2884,23 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
2814
2884
|
setGlobalFilter,
|
|
2815
2885
|
type: "client",
|
|
2816
2886
|
translate,
|
|
2887
|
+
columns: columns,
|
|
2888
|
+
sorting,
|
|
2889
|
+
setSorting,
|
|
2890
|
+
columnFilters,
|
|
2891
|
+
setColumnFilters,
|
|
2892
|
+
pagination,
|
|
2893
|
+
setPagination,
|
|
2894
|
+
rowSelection,
|
|
2895
|
+
setRowSelection,
|
|
2896
|
+
columnOrder,
|
|
2897
|
+
setColumnOrder,
|
|
2898
|
+
density,
|
|
2899
|
+
setDensity,
|
|
2900
|
+
columnVisibility,
|
|
2901
|
+
setColumnVisibility,
|
|
2902
|
+
data,
|
|
2903
|
+
tableLabel,
|
|
2817
2904
|
}, children: children }));
|
|
2818
2905
|
}
|
|
2819
2906
|
|
|
@@ -2828,10 +2915,23 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
2828
2915
|
*
|
|
2829
2916
|
* @link https://tanstack.com/table/latest/docs/guide/column-defs
|
|
2830
2917
|
*/
|
|
2831
|
-
function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, url, translate, children,
|
|
2918
|
+
function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, query, url, translate, children, tableLabel = {
|
|
2919
|
+
view: "View",
|
|
2920
|
+
edit: "Edit",
|
|
2921
|
+
filterButtonText: "Filter",
|
|
2922
|
+
filterTitle: "Filter",
|
|
2923
|
+
filterReset: "Reset",
|
|
2924
|
+
filterClose: "Close",
|
|
2925
|
+
reloadTooltip: "Reload",
|
|
2926
|
+
reloadButtonText: "Reload",
|
|
2927
|
+
resetSelection: "Reset Selection",
|
|
2928
|
+
resetSorting: "Reset Sorting",
|
|
2929
|
+
rowCountText: "Row Count",
|
|
2930
|
+
hasErrorText: "Has Error",
|
|
2931
|
+
}, }) {
|
|
2832
2932
|
const table = reactTable.useReactTable({
|
|
2833
2933
|
_features: [DensityFeature],
|
|
2834
|
-
data: query.data?.data ?? [],
|
|
2934
|
+
data: (query.data?.data ?? []),
|
|
2835
2935
|
rowCount: query.data?.count ?? 0,
|
|
2836
2936
|
columns: columns,
|
|
2837
2937
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
@@ -2877,95 +2977,31 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
2877
2977
|
// for tanstack-table ts bug end
|
|
2878
2978
|
});
|
|
2879
2979
|
return (jsxRuntime.jsx(DataTableContext.Provider, { value: {
|
|
2880
|
-
table:
|
|
2980
|
+
table: table,
|
|
2881
2981
|
globalFilter,
|
|
2882
2982
|
setGlobalFilter,
|
|
2883
2983
|
type: "server",
|
|
2884
2984
|
translate,
|
|
2985
|
+
columns: columns,
|
|
2986
|
+
sorting,
|
|
2987
|
+
setSorting,
|
|
2988
|
+
columnFilters,
|
|
2989
|
+
setColumnFilters,
|
|
2990
|
+
pagination,
|
|
2991
|
+
setPagination,
|
|
2992
|
+
rowSelection,
|
|
2993
|
+
setRowSelection,
|
|
2994
|
+
columnOrder,
|
|
2995
|
+
setColumnOrder,
|
|
2996
|
+
density,
|
|
2997
|
+
setDensity,
|
|
2998
|
+
columnVisibility,
|
|
2999
|
+
setColumnVisibility,
|
|
3000
|
+
data: query.data?.data ?? [],
|
|
3001
|
+
tableLabel,
|
|
2885
3002
|
}, children: jsxRuntime.jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
2886
3003
|
}
|
|
2887
3004
|
|
|
2888
|
-
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
2889
|
-
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
2890
|
-
return (jsxRuntime.jsxs(react.Checkbox.Root, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.Checkbox.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.Checkbox.Control, { children: icon || jsxRuntime.jsx(react.Checkbox.Indicator, {}) }), children != null && (jsxRuntime.jsx(react.Checkbox.Label, { children: children }))] }));
|
|
2891
|
-
});
|
|
2892
|
-
|
|
2893
|
-
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
|
|
2894
|
-
const { table } = useDataTableContext();
|
|
2895
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2896
|
-
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
2897
|
-
const handleRowHover = (index) => {
|
|
2898
|
-
setHoveredRow(index);
|
|
2899
|
-
};
|
|
2900
|
-
const getTdProps = (cell) => {
|
|
2901
|
-
const tdProps = cell.column.getIsPinned()
|
|
2902
|
-
? {
|
|
2903
|
-
left: showSelector
|
|
2904
|
-
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
2905
|
-
: `${cell.column.getStart("left")}px`,
|
|
2906
|
-
background: pinnedBgColor.light,
|
|
2907
|
-
position: "sticky",
|
|
2908
|
-
zIndex: -1,
|
|
2909
|
-
_dark: {
|
|
2910
|
-
backgroundColor: pinnedBgColor.dark,
|
|
2911
|
-
},
|
|
2912
|
-
}
|
|
2913
|
-
: {};
|
|
2914
|
-
return tdProps;
|
|
2915
|
-
};
|
|
2916
|
-
const getTrProps = ({ hoveredRow, index, }) => {
|
|
2917
|
-
if (hoveredRow === -1) {
|
|
2918
|
-
return {};
|
|
2919
|
-
}
|
|
2920
|
-
if (hoveredRow === index) {
|
|
2921
|
-
return {
|
|
2922
|
-
opacity: "1",
|
|
2923
|
-
};
|
|
2924
|
-
}
|
|
2925
|
-
return {
|
|
2926
|
-
opacity: "0.8",
|
|
2927
|
-
};
|
|
2928
|
-
};
|
|
2929
|
-
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
2930
|
-
return (jsxRuntime.jsxs(react.Table.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsxRuntime.jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
|
|
2931
|
-
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
2932
|
-
// styling resize and pinning start
|
|
2933
|
-
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
|
|
2934
|
-
backgroundColor: "gray.950",
|
|
2935
|
-
}, children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
2936
|
-
})] }, `chakra-table-row-${row.id}`));
|
|
2937
|
-
}) }));
|
|
2938
|
-
};
|
|
2939
|
-
const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, alwaysShowSelector = true, }) => {
|
|
2940
|
-
const { table } = useDataTableContext();
|
|
2941
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2942
|
-
const isCheckBoxVisible = (current_index, current_row) => {
|
|
2943
|
-
if (alwaysShowSelector) {
|
|
2944
|
-
return true;
|
|
2945
|
-
}
|
|
2946
|
-
if (current_row.getIsSelected()) {
|
|
2947
|
-
return true;
|
|
2948
|
-
}
|
|
2949
|
-
if (hoveredRow == current_index) {
|
|
2950
|
-
return true;
|
|
2951
|
-
}
|
|
2952
|
-
return false;
|
|
2953
|
-
};
|
|
2954
|
-
return (jsxRuntime.jsxs(react.Table.Cell, { padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
2955
|
-
? {
|
|
2956
|
-
left: `0px`,
|
|
2957
|
-
backgroundColor: pinnedBgColor.light,
|
|
2958
|
-
position: "sticky",
|
|
2959
|
-
zIndex: 1,
|
|
2960
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
2961
|
-
}
|
|
2962
|
-
: {}),
|
|
2963
|
-
// styling resize and pinning end
|
|
2964
|
-
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
|
|
2965
|
-
disabled: !row.getCanSelect(),
|
|
2966
|
-
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
2967
|
-
};
|
|
2968
|
-
|
|
2969
3005
|
const Tooltip = React__namespace.forwardRef(function Tooltip(props, ref) {
|
|
2970
3006
|
const { showArrow, children, disabled, portalled, content, contentProps, portalRef, ...rest } = props;
|
|
2971
3007
|
if (disabled)
|
|
@@ -3000,17 +3036,19 @@ const GlobalFilter = () => {
|
|
|
3000
3036
|
} }) }) }));
|
|
3001
3037
|
};
|
|
3002
3038
|
|
|
3003
|
-
const ReloadButton = ({
|
|
3039
|
+
const ReloadButton = ({ variant = "icon", }) => {
|
|
3004
3040
|
const { url } = useDataTableServerContext();
|
|
3005
3041
|
const queryClient = reactQuery.useQueryClient();
|
|
3042
|
+
const { tableLabel } = useDataTableContext();
|
|
3043
|
+
const { reloadTooltip, reloadButtonText } = tableLabel;
|
|
3006
3044
|
if (variant === "icon") {
|
|
3007
|
-
return (jsxRuntime.jsx(Tooltip, { showArrow: true, content:
|
|
3045
|
+
return (jsxRuntime.jsx(Tooltip, { showArrow: true, content: reloadTooltip, children: jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => {
|
|
3008
3046
|
queryClient.invalidateQueries({ queryKey: [url] });
|
|
3009
3047
|
}, "aria-label": "refresh", children: jsxRuntime.jsx(io5.IoReload, {}) }) }));
|
|
3010
3048
|
}
|
|
3011
3049
|
return (jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3012
3050
|
queryClient.invalidateQueries({ queryKey: [url] });
|
|
3013
|
-
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ",
|
|
3051
|
+
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ", reloadButtonText] }));
|
|
3014
3052
|
};
|
|
3015
3053
|
|
|
3016
3054
|
const FilterOptions = ({ column }) => {
|
|
@@ -3019,6 +3057,7 @@ const FilterOptions = ({ column }) => {
|
|
|
3019
3057
|
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
3020
3058
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
3021
3059
|
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
3060
|
+
const { label, value } = option;
|
|
3022
3061
|
return (jsxRuntime.jsxs(react.Button, { size: "sm", onClick: () => {
|
|
3023
3062
|
if (selected) {
|
|
3024
3063
|
table.setColumnFilters((state) => {
|
|
@@ -3028,8 +3067,8 @@ const FilterOptions = ({ column }) => {
|
|
|
3028
3067
|
});
|
|
3029
3068
|
return;
|
|
3030
3069
|
}
|
|
3031
|
-
table.getColumn(column)?.setFilterValue(
|
|
3032
|
-
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [
|
|
3070
|
+
table.getColumn(column)?.setFilterValue(value);
|
|
3071
|
+
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [label, selected && jsxRuntime.jsx(md.MdClose, {})] }, option.value));
|
|
3033
3072
|
}) }));
|
|
3034
3073
|
};
|
|
3035
3074
|
|
|
@@ -3044,16 +3083,91 @@ const TableFilterTags = () => {
|
|
|
3044
3083
|
}) }));
|
|
3045
3084
|
};
|
|
3046
3085
|
|
|
3047
|
-
const TableControls = ({ fitTableWidth = false, fitTableHeight = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showGlobalFilter = false, showFilter = false, showFilterName = false, showFilterTags = false, showReload = false, showPagination = true, showPageSizeControl = true, showPageCountText = true, showView = true, filterOptions = [], extraItems = jsxRuntime.jsx(jsxRuntime.Fragment, {}), loading = false, hasError = false, }) => {
|
|
3048
|
-
const {
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3086
|
+
const TableControls = ({ fitTableWidth = false, fitTableHeight = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showGlobalFilter = false, showFilter = false, showFilterName = false, showFilterTags = false, showReload = false, showPagination = true, showPageSizeControl = true, showPageCountText = true, showView = true, filterOptions = [], extraItems = jsxRuntime.jsx(jsxRuntime.Fragment, {}), loading = false, hasError = false, gridProps = {}, }) => {
|
|
3087
|
+
const { tableLabel } = useDataTableContext();
|
|
3088
|
+
const { rowCountText, hasErrorText } = tableLabel;
|
|
3089
|
+
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", gap: "0.5rem", ...gridProps, children: [jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, children: [jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", children: [jsxRuntime.jsx(react.Box, { children: showView && jsxRuntime.jsx(ViewDialog, { icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", justifySelf: "end", children: [loading && jsxRuntime.jsx(react.Spinner, { size: "sm" }), hasError && (jsxRuntime.jsx(Tooltip, { content: hasErrorText, children: jsxRuntime.jsx(react.Icon, { as: bs.BsExclamationCircleFill, color: "red.400" }) })), showGlobalFilter && jsxRuntime.jsx(GlobalFilter, {}), showFilter && jsxRuntime.jsx(FilterDialog, {}), showReload && jsxRuntime.jsx(ReloadButton, {}), extraItems] })] }), filterOptions.length > 0 && (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.5rem", children: filterOptions.map((option) => {
|
|
3090
|
+
const { label, value } = option;
|
|
3091
|
+
return (jsxRuntime.jsxs(react.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react.Text, { children: [label, ":"] }), jsxRuntime.jsx(FilterOptions, { column: value })] }, value));
|
|
3092
|
+
}) })), showFilterTags && (jsxRuntime.jsx(react.Flex, { children: jsxRuntime.jsx(TableFilterTags, {}) }))] }), jsxRuntime.jsx(react.Grid, { overflow: "auto", bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, children: children }), (showPageSizeControl || showPageCountText || showPagination) && (jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", children: [jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", children: [showPageSizeControl && jsxRuntime.jsx(PageSizeControl, {}), showPageCountText && (jsxRuntime.jsxs(react.Flex, { children: [jsxRuntime.jsx(react.Text, { paddingRight: "0.5rem", children: rowCountText }), jsxRuntime.jsx(RowCountText, {})] }))] }), jsxRuntime.jsx(react.Box, { justifySelf: "end", children: showPagination && jsxRuntime.jsx(Pagination, {}) })] }))] }));
|
|
3093
|
+
};
|
|
3094
|
+
|
|
3095
|
+
const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
3096
|
+
const { title, description, icon, children, ...rest } = props;
|
|
3097
|
+
return (jsxRuntime.jsx(react.EmptyState.Root, { ref: ref, ...rest, children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [icon && (jsxRuntime.jsx(react.EmptyState.Indicator, { children: icon })), description ? (jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })) : (jsxRuntime.jsx(react.EmptyState.Title, { children: title })), children] }) }));
|
|
3098
|
+
});
|
|
3099
|
+
|
|
3100
|
+
const EmptyResult = (jsxRuntime.jsx(EmptyState, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
|
|
3101
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3102
|
+
const { table } = useDataTableContext();
|
|
3103
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
3104
|
+
return emptyComponent;
|
|
3105
|
+
}
|
|
3106
|
+
return (jsxRuntime.jsx(react.Table.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 }));
|
|
3107
|
+
};
|
|
3108
|
+
|
|
3109
|
+
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
3110
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
3111
|
+
return (jsxRuntime.jsxs(react.Checkbox.Root, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.Checkbox.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.Checkbox.Control, { children: icon || jsxRuntime.jsx(react.Checkbox.Indicator, {}) }), children != null && (jsxRuntime.jsx(react.Checkbox.Label, { children: children }))] }));
|
|
3112
|
+
});
|
|
3113
|
+
|
|
3114
|
+
const TableBody = ({ showSelector = false, canResize = true, }) => {
|
|
3115
|
+
"use no memo";
|
|
3116
|
+
const { table } = useDataTableContext();
|
|
3117
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3118
|
+
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
3119
|
+
const handleRowHover = (index) => {
|
|
3120
|
+
setHoveredRow(index);
|
|
3121
|
+
};
|
|
3122
|
+
const getTdProps = (cell) => {
|
|
3123
|
+
const tdProps = cell.column.getIsPinned()
|
|
3124
|
+
? {
|
|
3125
|
+
left: showSelector
|
|
3126
|
+
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3127
|
+
: `${cell.column.getStart("left")}px`,
|
|
3128
|
+
position: "relative",
|
|
3129
|
+
}
|
|
3130
|
+
: {};
|
|
3131
|
+
return tdProps;
|
|
3132
|
+
};
|
|
3133
|
+
const getTrProps = ({ hoveredRow, index, }) => {
|
|
3134
|
+
if (hoveredRow === -1) {
|
|
3135
|
+
return {};
|
|
3136
|
+
}
|
|
3137
|
+
if (hoveredRow === index) {
|
|
3138
|
+
return {
|
|
3139
|
+
opacity: "1",
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
return {
|
|
3143
|
+
opacity: "0.8",
|
|
3144
|
+
};
|
|
3145
|
+
};
|
|
3146
|
+
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
3147
|
+
return (jsxRuntime.jsxs(react.Table.Row, { display: "flex", zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), ...getTrProps({ hoveredRow, index }), children: [showSelector && (jsxRuntime.jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow })), row.getVisibleCells().map((cell, index) => {
|
|
3148
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
3149
|
+
// styling resize and pinning start
|
|
3150
|
+
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, color: {
|
|
3151
|
+
base: "colorPalette.900",
|
|
3152
|
+
_dark: "colorPalette.100",
|
|
3153
|
+
},
|
|
3154
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, ...getTdProps(cell), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
3155
|
+
})] }, `chakra-table-row-${row.id}`));
|
|
3156
|
+
}) }));
|
|
3157
|
+
};
|
|
3158
|
+
const TableRowSelector = ({ row, }) => {
|
|
3159
|
+
const { table } = useDataTableContext();
|
|
3160
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3161
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3162
|
+
base: "colorPalette.900",
|
|
3163
|
+
_dark: "colorPalette.100",
|
|
3164
|
+
},
|
|
3165
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, checked: row.getIsSelected(),
|
|
3166
|
+
disabled: !row.getCanSelect(),
|
|
3167
|
+
onCheckedChange: row.getToggleSelectedHandler() }) }));
|
|
3054
3168
|
};
|
|
3055
3169
|
|
|
3056
|
-
const TableFooter = ({
|
|
3170
|
+
const TableFooter = ({ showSelector = false, alwaysShowSelector = true, }) => {
|
|
3057
3171
|
const table = useDataTableContext().table;
|
|
3058
3172
|
const SELECTION_BOX_WIDTH = 20;
|
|
3059
3173
|
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
@@ -3072,65 +3186,62 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
3072
3186
|
}
|
|
3073
3187
|
return false;
|
|
3074
3188
|
};
|
|
3075
|
-
|
|
3076
|
-
const thProps = header.column.getIsPinned()
|
|
3077
|
-
? {
|
|
3078
|
-
left: showSelector
|
|
3079
|
-
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3080
|
-
: `${header.getStart("left") + table.getDensityValue() * 2}px`,
|
|
3081
|
-
background: pinnedBgColor.light,
|
|
3082
|
-
position: "sticky",
|
|
3083
|
-
zIndex: 1,
|
|
3084
|
-
_dark: {
|
|
3085
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3086
|
-
},
|
|
3087
|
-
}
|
|
3088
|
-
: {};
|
|
3089
|
-
return thProps;
|
|
3090
|
-
};
|
|
3091
|
-
return (jsxRuntime.jsx(react.Table.Footer, { children: table.getFooterGroups().map((footerGroup) => (jsxRuntime.jsxs(react.Table.Row, { display: "flex", children: [showSelector && (jsxRuntime.jsxs(react.Table.Header
|
|
3092
|
-
// styling resize and pinning start
|
|
3093
|
-
, {
|
|
3094
|
-
// styling resize and pinning start
|
|
3095
|
-
padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
3096
|
-
? {
|
|
3097
|
-
left: `0px`,
|
|
3098
|
-
backgroundColor: pinnedBgColor.light,
|
|
3099
|
-
position: "sticky",
|
|
3100
|
-
zIndex: 1,
|
|
3101
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3102
|
-
}
|
|
3103
|
-
: {}),
|
|
3104
|
-
// styling resize and pinning end
|
|
3105
|
-
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3189
|
+
return (jsxRuntime.jsx(react.Table.Footer, { children: table.getFooterGroups().map((footerGroup) => (jsxRuntime.jsxs(react.Table.Row, { display: "flex", children: [showSelector && (jsxRuntime.jsxs(react.Table.Header, { padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3106
3190
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3107
3191
|
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.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) => (jsxRuntime.jsx(react.Table.Cell, { padding: "0", columnSpan: `${header.colSpan}`,
|
|
3108
3192
|
// styling resize and pinning start
|
|
3109
|
-
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid",
|
|
3193
|
+
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid", children: jsxRuntime.jsx(react.MenuRoot, { children: jsxRuntime.jsx(react.MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Box, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3110
3194
|
? null
|
|
3111
|
-
: reactTable.flexRender(header.column.columnDef.footer, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && (
|
|
3112
|
-
// <UpDownIcon />
|
|
3113
|
-
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${header.column.id}-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
|
|
3195
|
+
: reactTable.flexRender(header.column.columnDef.footer, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && jsxRuntime.jsx(jsxRuntime.Fragment, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${header.column.id}-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
|
|
3114
3196
|
};
|
|
3115
3197
|
|
|
3116
|
-
|
|
3198
|
+
// Default text values
|
|
3199
|
+
const DEFAULT_HEADER_TEXTS = {
|
|
3200
|
+
pinColumn: "Pin Column",
|
|
3201
|
+
cancelPin: "Cancel Pin",
|
|
3202
|
+
sortAscending: "Sort Ascending",
|
|
3203
|
+
sortDescending: "Sort Descending",
|
|
3204
|
+
clearSorting: "Clear Sorting",
|
|
3205
|
+
};
|
|
3206
|
+
/**
|
|
3207
|
+
* TableHeader component with configurable text strings.
|
|
3208
|
+
*
|
|
3209
|
+
* @example
|
|
3210
|
+
* // Using default texts
|
|
3211
|
+
* <TableHeader />
|
|
3212
|
+
*
|
|
3213
|
+
* @example
|
|
3214
|
+
* // Customizing default texts for all columns
|
|
3215
|
+
* <TableHeader
|
|
3216
|
+
* defaultTexts={{
|
|
3217
|
+
* pinColumn: "Pin This Column",
|
|
3218
|
+
* sortAscending: "Sort A-Z"
|
|
3219
|
+
* }}
|
|
3220
|
+
* />
|
|
3221
|
+
*
|
|
3222
|
+
* @example
|
|
3223
|
+
* // Customizing texts per column via meta
|
|
3224
|
+
* const columns = [
|
|
3225
|
+
* columnHelper.accessor("name", {
|
|
3226
|
+
* header: "Name",
|
|
3227
|
+
* meta: {
|
|
3228
|
+
* headerTexts: {
|
|
3229
|
+
* pinColumn: "Pin Name Column",
|
|
3230
|
+
* sortAscending: "Sort Names A-Z"
|
|
3231
|
+
* }
|
|
3232
|
+
* }
|
|
3233
|
+
* })
|
|
3234
|
+
* ];
|
|
3235
|
+
*/
|
|
3236
|
+
const TableHeader = ({ canResize = true, showSelector = false, isSticky = true, tableHeaderProps = {}, tableRowProps = {}, defaultTexts = {}, }) => {
|
|
3117
3237
|
const { table } = useDataTableContext();
|
|
3118
3238
|
const SELECTION_BOX_WIDTH = 20;
|
|
3119
|
-
|
|
3120
|
-
const
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
return true;
|
|
3126
|
-
}
|
|
3127
|
-
if (table.getIsAllRowsSelected()) {
|
|
3128
|
-
return true;
|
|
3129
|
-
}
|
|
3130
|
-
if (hoveredCheckBox) {
|
|
3131
|
-
return true;
|
|
3132
|
-
}
|
|
3133
|
-
return false;
|
|
3239
|
+
// Merge default texts with provided defaults
|
|
3240
|
+
const mergedDefaultTexts = { ...DEFAULT_HEADER_TEXTS, ...defaultTexts };
|
|
3241
|
+
// Helper function to get text for a specific header
|
|
3242
|
+
const getHeaderText = (header, key) => {
|
|
3243
|
+
const columnMeta = header.column.columnDef.meta;
|
|
3244
|
+
return columnMeta?.headerTexts?.[key] || mergedDefaultTexts[key];
|
|
3134
3245
|
};
|
|
3135
3246
|
const getThProps = (header) => {
|
|
3136
3247
|
const thProps = header.column.getIsPinned()
|
|
@@ -3138,12 +3249,8 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3138
3249
|
left: showSelector
|
|
3139
3250
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3140
3251
|
: `${header.getStart("left")}px`,
|
|
3141
|
-
background: pinnedBgColor.light,
|
|
3142
3252
|
position: "sticky",
|
|
3143
3253
|
zIndex: 100 + 1,
|
|
3144
|
-
_dark: {
|
|
3145
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3146
|
-
},
|
|
3147
3254
|
}
|
|
3148
3255
|
: {};
|
|
3149
3256
|
return thProps;
|
|
@@ -3152,21 +3259,13 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3152
3259
|
position: "sticky",
|
|
3153
3260
|
top: 0,
|
|
3154
3261
|
};
|
|
3155
|
-
return (jsxRuntime.jsx(react.Table.Header, { ...(isSticky ? stickyProps : {}), ...
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
zIndex: 1,
|
|
3163
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3164
|
-
}
|
|
3165
|
-
: {}),
|
|
3166
|
-
// styling resize and pinning end
|
|
3167
|
-
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
3168
|
-
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3169
|
-
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.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) => {
|
|
3262
|
+
return (jsxRuntime.jsx(react.Table.Header, { ...(isSticky ? stickyProps : {}), bgColor: "transparent", ...tableHeaderProps, children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsxs(react.Table.Row, { display: "flex", bgColor: "transparent", ...tableRowProps, children: [showSelector && (jsxRuntime.jsx(react.Table.ColumnHeader, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3263
|
+
base: "colorPalette.900",
|
|
3264
|
+
_dark: "colorPalette.100",
|
|
3265
|
+
},
|
|
3266
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, checked: table.getIsAllRowsSelected(),
|
|
3267
|
+
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3268
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), headerGroup.headers.map((header) => {
|
|
3170
3269
|
const resizeProps = {
|
|
3171
3270
|
onMouseDown: header.getResizeHandler(),
|
|
3172
3271
|
onTouchStart: header.getResizeHandler(),
|
|
@@ -3174,18 +3273,32 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3174
3273
|
};
|
|
3175
3274
|
return (jsxRuntime.jsxs(react.Table.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
|
|
3176
3275
|
// styling resize and pinning start
|
|
3177
|
-
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index,
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3276
|
+
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index, color: {
|
|
3277
|
+
base: "colorPalette.800",
|
|
3278
|
+
_dark: "colorPalette.200",
|
|
3279
|
+
},
|
|
3280
|
+
bg: { base: "colorPalette.100", _dark: "colorPalette.900" }, ...getThProps(header), children: [jsxRuntime.jsxs(MenuRoot, { children: [jsxRuntime.jsx(MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Flex, { padding: `${table.getDensityValue()}px`, alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", color: {
|
|
3281
|
+
base: "colorPalette.800",
|
|
3282
|
+
_dark: "colorPalette.200",
|
|
3283
|
+
_hover: {
|
|
3284
|
+
base: "colorPalette.700",
|
|
3285
|
+
_dark: "colorPalette.300",
|
|
3286
|
+
},
|
|
3287
|
+
},
|
|
3288
|
+
bg: {
|
|
3289
|
+
base: "colorPalette.100",
|
|
3290
|
+
_dark: "colorPalette.900",
|
|
3291
|
+
_hover: {
|
|
3292
|
+
base: "colorPalette.200",
|
|
3293
|
+
_dark: "colorPalette.800",
|
|
3181
3294
|
},
|
|
3182
3295
|
}, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3183
3296
|
? null
|
|
3184
3297
|
: reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && jsxRuntime.jsx(jsxRuntime.Fragment, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) }), jsxRuntime.jsx(react.Box, { children: header.column.getIsFiltered() && jsxRuntime.jsx(md.MdFilterListAlt, {}) })] }) }) }), jsxRuntime.jsxs(MenuContent, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "pin-column", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3185
3298
|
header.column.pin("left");
|
|
3186
|
-
}, children: [jsxRuntime.jsx(md.MdPushPin, {}),
|
|
3299
|
+
}, children: [jsxRuntime.jsx(md.MdPushPin, {}), getHeaderText(header, "pinColumn")] }) })), header.column.getIsPinned() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "cancel-pin", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3187
3300
|
header.column.pin(false);
|
|
3188
|
-
}, children: [jsxRuntime.jsx(md.MdCancel, {}),
|
|
3301
|
+
}, children: [jsxRuntime.jsx(md.MdCancel, {}), getHeaderText(header, "cancelPin")] }) })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-ascend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3189
3302
|
table.setSorting((state) => {
|
|
3190
3303
|
return [
|
|
3191
3304
|
...state.filter((column) => {
|
|
@@ -3194,7 +3307,7 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3194
3307
|
{ id: header.id, desc: false },
|
|
3195
3308
|
];
|
|
3196
3309
|
});
|
|
3197
|
-
}, children: [jsxRuntime.jsx(gr.GrAscend, {}),
|
|
3310
|
+
}, children: [jsxRuntime.jsx(gr.GrAscend, {}), getHeaderText(header, "sortAscending")] }) }), jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3198
3311
|
table.setSorting((state) => {
|
|
3199
3312
|
return [
|
|
3200
3313
|
...state.filter((column) => {
|
|
@@ -3203,42 +3316,30 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3203
3316
|
{ id: header.id, desc: true },
|
|
3204
3317
|
];
|
|
3205
3318
|
});
|
|
3206
|
-
}, children: [jsxRuntime.jsx(gr.GrDescend, {}),
|
|
3319
|
+
}, children: [jsxRuntime.jsx(gr.GrDescend, {}), getHeaderText(header, "sortDescending")] }) }), header.column.getIsSorted() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "clear-sorting", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3207
3320
|
header.column.clearSorting();
|
|
3208
|
-
}, children: [jsxRuntime.jsx(md.MdClear, {}),
|
|
3321
|
+
}, children: [jsxRuntime.jsx(md.MdClear, {}), getHeaderText(header, "clearSorting")] }) }))] }))] })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3322
|
+
? "colorPalette.700"
|
|
3323
|
+
: "transparent", position: "relative", right: "0.1rem", width: "2px", height: "100%", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
3209
3324
|
borderRightColor: header.column.getIsResizing()
|
|
3210
|
-
? "
|
|
3211
|
-
: "
|
|
3325
|
+
? "colorPalette.700"
|
|
3326
|
+
: "colorPalette.400",
|
|
3212
3327
|
}, ...resizeProps }))] }, `chakra-table-header-${header.id}`));
|
|
3213
3328
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
3214
3329
|
};
|
|
3215
3330
|
|
|
3216
|
-
const
|
|
3217
|
-
const { title, description, icon, children, ...rest } = props;
|
|
3218
|
-
return (jsxRuntime.jsx(react.EmptyState.Root, { ref: ref, ...rest, children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [icon && (jsxRuntime.jsx(react.EmptyState.Indicator, { children: icon })), description ? (jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })) : (jsxRuntime.jsx(react.EmptyState.Title, { children: title })), children] }) }));
|
|
3219
|
-
});
|
|
3220
|
-
|
|
3221
|
-
const EmptyResult = (jsxRuntime.jsx(EmptyState, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
|
|
3222
|
-
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3223
|
-
const { table } = useDataTableContext();
|
|
3224
|
-
if (table.getRowModel().rows.length <= 0) {
|
|
3225
|
-
return emptyComponent;
|
|
3226
|
-
}
|
|
3227
|
-
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, display: "grid", alignContent: "start", overflowY: "auto", ...props, children: children }));
|
|
3228
|
-
};
|
|
3229
|
-
|
|
3230
|
-
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
|
|
3331
|
+
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, tableFooterProps = {}, controlProps = {}, variant = "", }) => {
|
|
3231
3332
|
if (variant === "greedy") {
|
|
3232
3333
|
return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { canResize: false, ...{ ...tableProps }, children: [jsxRuntime.jsx(TableHeader, { canResize: false, ...tableHeaderProps }), jsxRuntime.jsx(TableBody, { canResize: false, ...tableBodyProps }), showFooter && (jsxRuntime.jsx(TableFooter, { canResize: false, ...tableFooterProps }))] }) }));
|
|
3233
3334
|
}
|
|
3234
3335
|
return (jsxRuntime.jsx(TableControls, { ...controlProps, children: jsxRuntime.jsxs(Table, { ...tableProps, children: [jsxRuntime.jsx(TableHeader, { ...tableHeaderProps }), jsxRuntime.jsx(TableBody, { ...tableBodyProps }), showFooter && jsxRuntime.jsx(TableFooter, { ...tableFooterProps })] }) }));
|
|
3235
3336
|
};
|
|
3236
3337
|
|
|
3237
|
-
const TableCardContainer = ({ children, variant = "", ...props }) => {
|
|
3338
|
+
const TableCardContainer = ({ children, variant = "", gap = "1rem", gridTemplateColumns = "repeat(auto-fit, minmax(20rem, 1fr))", direction = "row", ...props }) => {
|
|
3238
3339
|
if (variant === "carousel") {
|
|
3239
|
-
return (jsxRuntime.jsx(react.Flex, { overflow: "
|
|
3340
|
+
return (jsxRuntime.jsx(react.Flex, { overflow: "auto", gap: gap, direction: direction, ...props, children: children }));
|
|
3240
3341
|
}
|
|
3241
|
-
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns:
|
|
3342
|
+
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns: gridTemplateColumns, gap: gap, ...props, children: children }));
|
|
3242
3343
|
};
|
|
3243
3344
|
|
|
3244
3345
|
const DefaultCardTitle = () => {
|
|
@@ -3267,8 +3368,8 @@ const TableComponent = ({ render = () => {
|
|
|
3267
3368
|
};
|
|
3268
3369
|
|
|
3269
3370
|
const TableLoadingComponent = ({ render, }) => {
|
|
3270
|
-
const {
|
|
3271
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(
|
|
3371
|
+
const { query } = useDataTableServerContext();
|
|
3372
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(query.isLoading) });
|
|
3272
3373
|
};
|
|
3273
3374
|
|
|
3274
3375
|
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
@@ -3487,6 +3588,70 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
|
|
|
3487
3588
|
return columns;
|
|
3488
3589
|
};
|
|
3489
3590
|
|
|
3591
|
+
const TableDataDisplay = ({ colorPalette, emptyComponent, }) => {
|
|
3592
|
+
const { columns, translate, data } = useDataTableContext();
|
|
3593
|
+
const columnsMap = Object.fromEntries(columns.map((def) => {
|
|
3594
|
+
const { accessorKey, id } = def;
|
|
3595
|
+
if (accessorKey) {
|
|
3596
|
+
return [accessorKey, def];
|
|
3597
|
+
}
|
|
3598
|
+
return [id, def];
|
|
3599
|
+
}));
|
|
3600
|
+
const columnHeaders = Object.keys(columnsMap);
|
|
3601
|
+
const totalWidths = columns
|
|
3602
|
+
.map(({ size }) => {
|
|
3603
|
+
if (!!size === false) {
|
|
3604
|
+
return 0;
|
|
3605
|
+
}
|
|
3606
|
+
if (typeof size === "number") {
|
|
3607
|
+
return size;
|
|
3608
|
+
}
|
|
3609
|
+
return 0;
|
|
3610
|
+
})
|
|
3611
|
+
.reduce((previous, current) => previous + current, 0);
|
|
3612
|
+
const columnWidths = columns
|
|
3613
|
+
.map(({ size }) => {
|
|
3614
|
+
if (!!size === false) {
|
|
3615
|
+
return "1fr";
|
|
3616
|
+
}
|
|
3617
|
+
return `minmax(${size}px, ${(size / totalWidths) * 100}%)`;
|
|
3618
|
+
})
|
|
3619
|
+
.join(" ");
|
|
3620
|
+
console.log({ columnWidths }, "hadfg");
|
|
3621
|
+
const cellProps = {
|
|
3622
|
+
flex: "1 0 0%",
|
|
3623
|
+
overflow: "auto",
|
|
3624
|
+
paddingX: "2",
|
|
3625
|
+
py: "1",
|
|
3626
|
+
color: { base: "colorPalette.900", _dark: "colorPalette.100" },
|
|
3627
|
+
bgColor: { base: "colorPalette.50", _dark: "colorPalette.950" },
|
|
3628
|
+
borderBottomColor: { base: "colorPalette.200", _dark: "colorPalette.800" },
|
|
3629
|
+
borderBottomWidth: "1px",
|
|
3630
|
+
...{ colorPalette },
|
|
3631
|
+
};
|
|
3632
|
+
if (data.length <= 0) {
|
|
3633
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: emptyComponent });
|
|
3634
|
+
}
|
|
3635
|
+
return (jsxRuntime.jsxs(react.Grid, { templateColumns: `${columnWidths}`, overflow: "auto", borderWidth: "1px", color: { base: "colorPalette.900", _dark: "colorPalette.100" }, borderColor: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: [jsxRuntime.jsx(react.Grid, { templateColumns: `${columnWidths}`, column: `1/span ${columns.length}`, bg: { base: "colorPalette.200", _dark: "colorPalette.800" }, colorPalette, children: columnHeaders.map((header) => {
|
|
3636
|
+
return (jsxRuntime.jsx(react.Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
|
|
3637
|
+
}) }), data.map((record) => {
|
|
3638
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: columnHeaders.map((header) => {
|
|
3639
|
+
const { cell } = columnsMap[header];
|
|
3640
|
+
const value = record[header];
|
|
3641
|
+
if (!!record === false) {
|
|
3642
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
|
|
3643
|
+
}
|
|
3644
|
+
if (cell) {
|
|
3645
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: cell({ row: { original: record } }) }));
|
|
3646
|
+
}
|
|
3647
|
+
if (typeof value === "object") {
|
|
3648
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: jsxRuntime.jsx(RecordDisplay, { object: value }) }));
|
|
3649
|
+
}
|
|
3650
|
+
return jsxRuntime.jsx(react.Box, { ...cellProps, children: value });
|
|
3651
|
+
}) }));
|
|
3652
|
+
})] }));
|
|
3653
|
+
};
|
|
3654
|
+
|
|
3490
3655
|
const AccordionItemTrigger = React__namespace.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
3491
3656
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
3492
3657
|
return (jsxRuntime.jsxs(react.Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsxRuntime.jsx(react.Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsxRuntime.jsx(lu.LuChevronDown, {}) })), jsxRuntime.jsx(react.HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsxRuntime.jsx(react.Accordion.ItemIndicator, { children: jsxRuntime.jsx(lu.LuChevronDown, {}) }))] }));
|
|
@@ -3570,7 +3735,7 @@ const FormRoot = ({ schema, idMap, setIdMap, form, serverUrl, translate, childre
|
|
|
3570
3735
|
};
|
|
3571
3736
|
|
|
3572
3737
|
function removeIndex(str) {
|
|
3573
|
-
return str.replace(/\.\d+\./g,
|
|
3738
|
+
return str.replace(/\.\d+\./g, ".");
|
|
3574
3739
|
}
|
|
3575
3740
|
|
|
3576
3741
|
const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
@@ -3582,13 +3747,17 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3582
3747
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3583
3748
|
const { formState: { errors }, setValue, watch, } = reactHookForm.useFormContext();
|
|
3584
3749
|
const fields = (watch(colLabel) ?? []);
|
|
3585
|
-
return (jsxRuntime.jsxs(react.
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3750
|
+
return (jsxRuntime.jsxs(react.Flex, { gridRow, gridColumn, flexFlow: "column", gap: 2, children: [jsxRuntime.jsxs(react.Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsxRuntime.jsx("span", { children: "*" })] }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 2, children: fields.map((field, index) => (jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: '1fr auto', gap: 2, bgColor: { base: "colorPalette.100", _dark: "colorPalette.900" }, p: 2, borderRadius: 4, borderWidth: 1, borderColor: {
|
|
3751
|
+
base: "colorPalette.200",
|
|
3752
|
+
_dark: "colorPalette.800",
|
|
3753
|
+
}, children: [jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaRenderer, { column: `${index}`,
|
|
3754
|
+
prefix: `${colLabel}.`,
|
|
3755
|
+
// @ts-expect-error find suitable types
|
|
3756
|
+
schema: { showLabel: false, ...(items ?? {}) } }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "end", children: jsxRuntime.jsx(react.Button, { variant: "ghost", onClick: () => {
|
|
3757
|
+
setValue(colLabel, fields.filter((_, curIndex) => {
|
|
3758
|
+
return curIndex !== index;
|
|
3759
|
+
}));
|
|
3760
|
+
}, children: jsxRuntime.jsx(react.Icon, { children: jsxRuntime.jsx(cg.CgTrash, {}) }) }) })] }, `${colLabel}.${index}`))) }), jsxRuntime.jsx(react.Flex, { children: jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
3592
3761
|
if (type === "number") {
|
|
3593
3762
|
setValue(colLabel, [...fields, 0]);
|
|
3594
3763
|
return;
|
|
@@ -3602,7 +3771,7 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3602
3771
|
return;
|
|
3603
3772
|
}
|
|
3604
3773
|
setValue(colLabel, [...fields, {}]);
|
|
3605
|
-
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3774
|
+
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3606
3775
|
};
|
|
3607
3776
|
|
|
3608
3777
|
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
@@ -3613,14 +3782,26 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
|
3613
3782
|
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3614
3783
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3615
3784
|
const { translate } = useSchemaContext();
|
|
3616
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3785
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
3617
3786
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3618
3787
|
const colLabel = `${prefix}${column}`;
|
|
3619
3788
|
const value = watch(colLabel);
|
|
3620
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
3789
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3621
3790
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
|
|
3622
3791
|
setValue(colLabel, !value);
|
|
3623
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3792
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3793
|
+
};
|
|
3794
|
+
|
|
3795
|
+
const CustomInput = ({ column, schema, prefix }) => {
|
|
3796
|
+
const formContext = reactHookForm.useFormContext();
|
|
3797
|
+
const { inputRender } = schema;
|
|
3798
|
+
return (inputRender &&
|
|
3799
|
+
inputRender({
|
|
3800
|
+
column,
|
|
3801
|
+
schema,
|
|
3802
|
+
prefix,
|
|
3803
|
+
formContext,
|
|
3804
|
+
}));
|
|
3624
3805
|
};
|
|
3625
3806
|
|
|
3626
3807
|
const monthNamesShort = [
|
|
@@ -3710,28 +3891,54 @@ const PopoverRoot = react.Popover.Root;
|
|
|
3710
3891
|
const PopoverBody = react.Popover.Body;
|
|
3711
3892
|
const PopoverTrigger = react.Popover.Trigger;
|
|
3712
3893
|
|
|
3894
|
+
dayjs.extend(utc);
|
|
3713
3895
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3714
3896
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3715
3897
|
const { translate } = useSchemaContext();
|
|
3716
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3898
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3717
3899
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3718
3900
|
const colLabel = `${prefix}${column}`;
|
|
3719
3901
|
const [open, setOpen] = React.useState(false);
|
|
3720
3902
|
const selectedDate = watch(colLabel);
|
|
3721
|
-
const
|
|
3722
|
-
|
|
3723
|
-
|
|
3903
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3904
|
+
React.useEffect(() => {
|
|
3905
|
+
try {
|
|
3906
|
+
if (selectedDate) {
|
|
3907
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3908
|
+
// For example, parse as UTC:
|
|
3909
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3910
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3911
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3912
|
+
if (!parsedDate.isValid())
|
|
3913
|
+
return;
|
|
3914
|
+
// Format according to dateFormat from schema
|
|
3915
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3916
|
+
// Update the form value only if different to avoid loops
|
|
3917
|
+
if (formatted !== selectedDate) {
|
|
3918
|
+
setValue(colLabel, formatted, {
|
|
3919
|
+
shouldValidate: true,
|
|
3920
|
+
shouldDirty: true,
|
|
3921
|
+
});
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
catch (e) {
|
|
3926
|
+
console.error(e);
|
|
3927
|
+
}
|
|
3928
|
+
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3929
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3930
|
+
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3724
3931
|
setOpen(true);
|
|
3725
|
-
}, children: selectedDate !== undefined ? `${
|
|
3932
|
+
}, justifyContent: "start", children: [jsxRuntime.jsx(md.MdDateRange, {}), selectedDate !== undefined ? `${displayDate}` : ""] }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3726
3933
|
// @ts-expect-error TODO: find appropriate types
|
|
3727
3934
|
, {
|
|
3728
3935
|
// @ts-expect-error TODO: find appropriate types
|
|
3729
3936
|
selected: new Date(selectedDate),
|
|
3730
3937
|
// @ts-expect-error TODO: find appropriate types
|
|
3731
3938
|
onDateSelected: ({ date }) => {
|
|
3732
|
-
setValue(colLabel, dayjs(date).format(
|
|
3939
|
+
setValue(colLabel, dayjs(date).format(dateFormat));
|
|
3733
3940
|
setOpen(false);
|
|
3734
|
-
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3941
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3735
3942
|
};
|
|
3736
3943
|
|
|
3737
3944
|
function filterArray(array, searchTerm) {
|
|
@@ -3744,12 +3951,12 @@ function filterArray(array, searchTerm) {
|
|
|
3744
3951
|
});
|
|
3745
3952
|
}
|
|
3746
3953
|
|
|
3747
|
-
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3954
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, showTotalAndLimit = false, }) => {
|
|
3748
3955
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3749
3956
|
const { translate } = useSchemaContext();
|
|
3750
|
-
const { required } = schema;
|
|
3957
|
+
const { required, variant } = schema;
|
|
3751
3958
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3752
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3959
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
3753
3960
|
const [searchText, setSearchText] = React.useState();
|
|
3754
3961
|
const [limit, setLimit] = React.useState(10);
|
|
3755
3962
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -3764,28 +3971,61 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3764
3971
|
setSearchText(event.target.value);
|
|
3765
3972
|
setLimit(10);
|
|
3766
3973
|
};
|
|
3767
|
-
|
|
3974
|
+
if (variant === "radio") {
|
|
3975
|
+
return (jsxRuntime.jsx(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3976
|
+
gridRow, children: jsxRuntime.jsx(react.RadioGroup.Root, { defaultValue: "1", children: jsxRuntime.jsx(react.HStack, { gap: "6", children: filterArray(dataList, searchText ?? "").map((item) => {
|
|
3977
|
+
return (jsxRuntime.jsxs(react.RadioGroup.Item, { onClick: () => {
|
|
3978
|
+
if (!isMultiple) {
|
|
3979
|
+
setOpenSearchResult(false);
|
|
3980
|
+
setValue(colLabel, item);
|
|
3981
|
+
return;
|
|
3982
|
+
}
|
|
3983
|
+
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3984
|
+
setValue(colLabel, [...newSet]);
|
|
3985
|
+
}, value: item, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, {}), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), jsxRuntime.jsx(react.RadioGroup.ItemText, { children: !!renderDisplay === true
|
|
3986
|
+
? renderDisplay(item)
|
|
3987
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) })] }, `${colLabel}-${item}`));
|
|
3988
|
+
}) }) }) }));
|
|
3989
|
+
}
|
|
3990
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3768
3991
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3769
3992
|
const item = enumValue;
|
|
3770
|
-
if (item ===
|
|
3771
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
3993
|
+
if (!!item === false) {
|
|
3994
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
3772
3995
|
}
|
|
3773
3996
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3774
|
-
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3775
3997
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3776
3998
|
}, children: !!renderDisplay === true
|
|
3777
3999
|
? renderDisplay(item)
|
|
3778
4000
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3779
4001
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3780
4002
|
setOpenSearchResult(true);
|
|
3781
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
4003
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3782
4004
|
setOpenSearchResult(true);
|
|
3783
|
-
}, children: watchEnum ===
|
|
4005
|
+
}, justifyContent: "start", children: !!watchEnum === false
|
|
3784
4006
|
? ""
|
|
3785
|
-
: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${
|
|
4007
|
+
: translate.t(removeIndex(`${colLabel}.${watchEnum ?? "null"}`)) })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${colLabel}.type_to_search`), onChange: (event) => {
|
|
3786
4008
|
onSearchChange(event);
|
|
3787
4009
|
setOpenSearchResult(true);
|
|
3788
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${translate.t(`${
|
|
4010
|
+
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), showTotalAndLimit && (jsxRuntime.jsx(react.Text, { children: `${translate.t(removeIndex(`${colLabel}.total`))}: ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit}` })), jsxRuntime.jsxs(react.Grid, { overflow: "auto", maxHeight: "20rem", children: [jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children: dataList
|
|
4011
|
+
.filter((item) => {
|
|
4012
|
+
const searchTerm = (searchText || "").toLowerCase();
|
|
4013
|
+
if (!searchTerm)
|
|
4014
|
+
return true;
|
|
4015
|
+
// Check if the original enum value contains the search text
|
|
4016
|
+
const enumValueMatch = item
|
|
4017
|
+
.toLowerCase()
|
|
4018
|
+
.includes(searchTerm);
|
|
4019
|
+
// Check if the display value (translation) contains the search text
|
|
4020
|
+
const displayValue = !!renderDisplay === true
|
|
4021
|
+
? renderDisplay(item)
|
|
4022
|
+
: translate.t(removeIndex(`${colLabel}.${item}`));
|
|
4023
|
+
// Convert to string and check if it includes the search term
|
|
4024
|
+
const displayValueString = String(displayValue).toLowerCase();
|
|
4025
|
+
const displayValueMatch = displayValueString.includes(searchTerm);
|
|
4026
|
+
return enumValueMatch || displayValueMatch;
|
|
4027
|
+
})
|
|
4028
|
+
.map((item) => {
|
|
3789
4029
|
const selected = isMultiple
|
|
3790
4030
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3791
4031
|
: watchEnum == item;
|
|
@@ -3797,10 +4037,10 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3797
4037
|
}
|
|
3798
4038
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3799
4039
|
setValue(colLabel, [...newSet]);
|
|
3800
|
-
}, ...(selected ? { color: "
|
|
4040
|
+
}, ...(selected ? { color: "colorPalette.400/50" } : {}), children: !!renderDisplay === true
|
|
3801
4041
|
? renderDisplay(item)
|
|
3802
4042
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
|
|
3803
|
-
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: translate.t(removeIndex(`${colLabel}.
|
|
4043
|
+
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: translate.t(removeIndex(`${colLabel}.empty_search_result`)) })) }))] })] }) })] }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3804
4044
|
};
|
|
3805
4045
|
|
|
3806
4046
|
function isEnteringWindow(_ref) {
|
|
@@ -4152,17 +4392,17 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4152
4392
|
const filesArray = [...event.target.files];
|
|
4153
4393
|
onDrop({ files: filesArray });
|
|
4154
4394
|
};
|
|
4155
|
-
return (jsxRuntime.jsxs(react.Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "
|
|
4395
|
+
return (jsxRuntime.jsxs(react.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 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Flex, { children: placeholder }), jsxRuntime.jsx(react.Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
|
|
4156
4396
|
};
|
|
4157
4397
|
|
|
4158
4398
|
const FilePicker = ({ column, schema, prefix }) => {
|
|
4159
4399
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4160
4400
|
const { translate } = useSchemaContext();
|
|
4161
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4401
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4162
4402
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4163
4403
|
const currentFiles = (watch(column) ?? []);
|
|
4164
4404
|
const colLabel = `${prefix}${column}`;
|
|
4165
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.
|
|
4405
|
+
return (jsxRuntime.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: [jsxRuntime.jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4166
4406
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4167
4407
|
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4168
4408
|
}, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
@@ -4170,10 +4410,19 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4170
4410
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4171
4411
|
return name !== file.name;
|
|
4172
4412
|
}));
|
|
4173
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4174
|
-
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4413
|
+
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [file.type.startsWith("image/") && (jsxRuntime.jsx(react.Image, { src: URL.createObjectURL(file), alt: file.name, boxSize: "50px", objectFit: "cover", borderRadius: "md", marginRight: "2" })), jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4414
|
+
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4175
4415
|
};
|
|
4176
4416
|
|
|
4417
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
4418
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
4419
|
+
return (jsxRuntime.jsxs(react.Popover.Root, { ...rest, positioning: { ...rest.positioning, gutter: 4 }, children: [jsxRuntime.jsx(react.Popover.Trigger, { asChild: true, children: children }), jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Popover.Positioner, { children: jsxRuntime.jsxs(react.Popover.Content, { width: "auto", px: "2", py: "1", textStyle: "xs", rounded: "sm", ref: ref, children: [showArrow && (jsxRuntime.jsx(react.Popover.Arrow, { children: jsxRuntime.jsx(react.Popover.ArrowTip, {}) })), content] }) }) })] }));
|
|
4420
|
+
});
|
|
4421
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
4422
|
+
const { children, ...rest } = props;
|
|
4423
|
+
return (jsxRuntime.jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "colorPalette", children: jsxRuntime.jsx(hi.HiOutlineInformationCircle, {}) }) }));
|
|
4424
|
+
});
|
|
4425
|
+
|
|
4177
4426
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4178
4427
|
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4179
4428
|
throw new Error("The serverUrl is missing");
|
|
@@ -4205,15 +4454,18 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
4205
4454
|
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4206
4455
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4207
4456
|
const { serverUrl, idMap, setIdMap, translate, schema: parentSchema, } = useSchemaContext();
|
|
4208
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4457
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4209
4458
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4210
4459
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4211
|
-
const [searchText, setSearchText] = React.useState();
|
|
4460
|
+
const [searchText, setSearchText] = React.useState("");
|
|
4212
4461
|
const [limit, setLimit] = React.useState(10);
|
|
4213
4462
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
4214
4463
|
const [page, setPage] = React.useState(0);
|
|
4215
4464
|
const ref = React.useRef(null);
|
|
4216
4465
|
const colLabel = `${prefix}${column}`;
|
|
4466
|
+
const watchId = watch(colLabel);
|
|
4467
|
+
const watchIds = isMultiple ? (watch(colLabel) ?? []) : [];
|
|
4468
|
+
// Query for search results
|
|
4217
4469
|
const query = reactQuery.useQuery({
|
|
4218
4470
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4219
4471
|
queryFn: async () => {
|
|
@@ -4222,7 +4474,7 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4222
4474
|
searching: searchText ?? "",
|
|
4223
4475
|
in_table: table,
|
|
4224
4476
|
limit: limit,
|
|
4225
|
-
offset: page *
|
|
4477
|
+
offset: page * limit,
|
|
4226
4478
|
});
|
|
4227
4479
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4228
4480
|
return [
|
|
@@ -4237,27 +4489,27 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4237
4489
|
});
|
|
4238
4490
|
return data;
|
|
4239
4491
|
},
|
|
4240
|
-
enabled:
|
|
4492
|
+
enabled: openSearchResult === true,
|
|
4241
4493
|
staleTime: 300000,
|
|
4242
4494
|
});
|
|
4243
|
-
|
|
4244
|
-
const
|
|
4245
|
-
const count = data?.count ?? 0;
|
|
4246
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
4247
|
-
const watchId = watch(colLabel);
|
|
4248
|
-
const watchIds = (watch(colLabel) ?? []);
|
|
4249
|
-
reactQuery.useQuery({
|
|
4495
|
+
// Query for currently selected items (to display them properly)
|
|
4496
|
+
const queryDefault = reactQuery.useQuery({
|
|
4250
4497
|
queryKey: [
|
|
4251
|
-
`idpicker`,
|
|
4252
|
-
{ form: parentSchema.title, column,
|
|
4498
|
+
`idpicker-default`,
|
|
4499
|
+
{ form: parentSchema.title, column, id: isMultiple ? watchIds : watchId },
|
|
4253
4500
|
],
|
|
4254
4501
|
queryFn: async () => {
|
|
4502
|
+
if (!watchId && (!watchIds || watchIds.length === 0)) {
|
|
4503
|
+
return { data: [] };
|
|
4504
|
+
}
|
|
4505
|
+
const searchValue = isMultiple ? watchIds.join(",") : watchId;
|
|
4255
4506
|
const data = await getTableData({
|
|
4256
4507
|
serverUrl,
|
|
4257
|
-
searching:
|
|
4508
|
+
searching: searchValue,
|
|
4258
4509
|
in_table: table,
|
|
4259
|
-
|
|
4260
|
-
|
|
4510
|
+
where: [{ id: column_ref, value: isMultiple ? watchIds : watchId }],
|
|
4511
|
+
limit: isMultiple ? watchIds.length : 1,
|
|
4512
|
+
offset: 0,
|
|
4261
4513
|
});
|
|
4262
4514
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4263
4515
|
return [
|
|
@@ -4272,12 +4524,45 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4272
4524
|
});
|
|
4273
4525
|
return data;
|
|
4274
4526
|
},
|
|
4527
|
+
enabled: isMultiple
|
|
4528
|
+
? Array.isArray(watchIds) && watchIds.length > 0
|
|
4529
|
+
: !!watchId,
|
|
4275
4530
|
});
|
|
4531
|
+
// Effect to load selected values when component mounts
|
|
4532
|
+
React.useEffect(() => {
|
|
4533
|
+
if (isMultiple ? watchIds.length > 0 : !!watchId) {
|
|
4534
|
+
queryDefault.refetch();
|
|
4535
|
+
}
|
|
4536
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4537
|
+
}, []);
|
|
4538
|
+
// Effect to trigger initial data fetch when popover opens
|
|
4539
|
+
React.useEffect(() => {
|
|
4540
|
+
if (openSearchResult) {
|
|
4541
|
+
// Reset search text when opening the popover
|
|
4542
|
+
setSearchText("");
|
|
4543
|
+
// Reset page to first page
|
|
4544
|
+
setPage(0);
|
|
4545
|
+
// Fetch initial data
|
|
4546
|
+
query.refetch();
|
|
4547
|
+
}
|
|
4548
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4549
|
+
}, [openSearchResult]);
|
|
4276
4550
|
const onSearchChange = async (event) => {
|
|
4277
4551
|
setSearchText(event.target.value);
|
|
4278
4552
|
setPage(0);
|
|
4279
|
-
|
|
4553
|
+
query.refetch();
|
|
4554
|
+
};
|
|
4555
|
+
const handleLimitChange = (event) => {
|
|
4556
|
+
const newLimit = Number(event.target.value);
|
|
4557
|
+
setLimit(newLimit);
|
|
4558
|
+
// Reset to first page when changing limit
|
|
4559
|
+
setPage(0);
|
|
4560
|
+
// Trigger a new search with the updated limit
|
|
4561
|
+
query.refetch();
|
|
4280
4562
|
};
|
|
4563
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4564
|
+
const dataList = data?.data ?? [];
|
|
4565
|
+
const count = data?.count ?? 0;
|
|
4281
4566
|
const getPickedValue = () => {
|
|
4282
4567
|
if (Object.keys(idMap).length <= 0) {
|
|
4283
4568
|
return "";
|
|
@@ -4286,47 +4571,57 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4286
4571
|
if (record === undefined) {
|
|
4287
4572
|
return "";
|
|
4288
4573
|
}
|
|
4574
|
+
if (!!renderDisplay === true) {
|
|
4575
|
+
return renderDisplay(record);
|
|
4576
|
+
}
|
|
4289
4577
|
return record[display_column];
|
|
4290
4578
|
};
|
|
4291
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.
|
|
4579
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.field_label`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4292
4580
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
|
|
4293
4581
|
const item = idMap[id];
|
|
4294
4582
|
if (item === undefined) {
|
|
4295
4583
|
return (jsxRuntime.jsx(react.Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4296
4584
|
}
|
|
4297
4585
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
4298
|
-
setValue(
|
|
4586
|
+
setValue(colLabel, watchIds.filter((itemId) => itemId !== item[column_ref]));
|
|
4299
4587
|
}, children: !!renderDisplay === true
|
|
4300
4588
|
? renderDisplay(item)
|
|
4301
4589
|
: item[display_column] }, id));
|
|
4302
4590
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4303
4591
|
setOpenSearchResult(true);
|
|
4304
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
4592
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
4305
4593
|
setOpenSearchResult(true);
|
|
4306
|
-
}, children: getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(removeIndex(`${colLabel}.
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4594
|
+
}, justifyContent: "start", children: queryDefault.isLoading ? jsxRuntime.jsx(react.Spinner, { size: "sm" }) : getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(removeIndex(`${colLabel}.type_to_search`)), onChange: onSearchChange, autoComplete: "off", ref: ref, value: searchText }), jsxRuntime.jsx(PopoverTitle, {}), openSearchResult && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [(isFetching || isLoading || isPending) && jsxRuntime.jsx(react.Spinner, {}), isError && (jsxRuntime.jsx(react.Icon, { color: "red.400", children: jsxRuntime.jsx(bi.BiError, {}) })), jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsxs(react.Flex, { alignItems: "center", gap: "2", children: [jsxRuntime.jsx(InfoTip, { children: `${translate.t(removeIndex(`${colLabel}.total`))} ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit} ${translate.t(removeIndex(`${colLabel}.per_page`), "per page")}` }), jsxRuntime.jsxs(react.Text, { fontSize: "sm", fontWeight: "bold", children: [count, jsxRuntime.jsxs(react.Text, { as: "span", fontSize: "xs", ml: "1", color: "gray.500", children: ["/ ", count > 0 ? `${page * limit + 1}-${Math.min((page + 1) * limit, count)}` : '0'] })] })] }), jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsxs("select", { value: limit, onChange: handleLimitChange, style: {
|
|
4595
|
+
padding: "4px 8px",
|
|
4596
|
+
borderRadius: "4px",
|
|
4597
|
+
border: "1px solid #ccc",
|
|
4598
|
+
fontSize: "14px",
|
|
4599
|
+
}, children: [jsxRuntime.jsx("option", { value: "5", children: "5" }), jsxRuntime.jsx("option", { value: "10", children: "10" }), jsxRuntime.jsx("option", { value: "20", children: "20" }), jsxRuntime.jsx("option", { value: "30", children: "30" })] }) })] }), jsxRuntime.jsx(react.Grid, { overflowY: "auto", children: dataList.length > 0 ? (jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", gap: 1, children: dataList.map((item) => {
|
|
4600
|
+
const selected = isMultiple
|
|
4601
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4602
|
+
: watchId === item[column_ref];
|
|
4603
|
+
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
4604
|
+
if (!isMultiple) {
|
|
4605
|
+
setOpenSearchResult(false);
|
|
4606
|
+
setValue(colLabel, item[column_ref]);
|
|
4607
|
+
return;
|
|
4608
|
+
}
|
|
4609
|
+
// For multiple selection, don't add if already selected
|
|
4610
|
+
if (selected)
|
|
4611
|
+
return;
|
|
4612
|
+
const newSet = new Set([
|
|
4613
|
+
...(watchIds ?? []),
|
|
4614
|
+
item[column_ref],
|
|
4615
|
+
]);
|
|
4616
|
+
setValue(colLabel, [...newSet]);
|
|
4617
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected
|
|
4618
|
+
? { color: "colorPalette.400/50", fontWeight: "bold" }
|
|
4619
|
+
: {}), children: !!renderDisplay === true
|
|
4620
|
+
? renderDisplay(item)
|
|
4621
|
+
: item[display_column] }, item[column_ref]));
|
|
4622
|
+
}) })) : (jsxRuntime.jsx(react.Text, { children: searchText
|
|
4623
|
+
? translate.t(removeIndex(`${colLabel}.empty_search_result`))
|
|
4624
|
+
: translate.t(removeIndex(`${colLabel}.initial_results`)) })) }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: count, pageSize: limit, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), count > 0 && jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4330
4625
|
};
|
|
4331
4626
|
|
|
4332
4627
|
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
@@ -4340,17 +4635,17 @@ react.NumberInput.Label;
|
|
|
4340
4635
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4341
4636
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4342
4637
|
const { translate } = useSchemaContext();
|
|
4343
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4638
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4344
4639
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4345
4640
|
const colLabel = `${prefix}${column}`;
|
|
4346
4641
|
const value = watch(`${colLabel}`);
|
|
4347
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4642
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(NumberInputRoot, { children: jsxRuntime.jsx(NumberInputField$1, { required: isRequired, value: value, onChange: (event) => {
|
|
4348
4643
|
setValue(`${colLabel}`, Number(event.target.value));
|
|
4349
|
-
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4644
|
+
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4350
4645
|
};
|
|
4351
4646
|
|
|
4352
4647
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4353
|
-
const { properties,
|
|
4648
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, showLabel = true, } = schema;
|
|
4354
4649
|
const { translate } = useSchemaContext();
|
|
4355
4650
|
const colLabel = `${prefix}${column}`;
|
|
4356
4651
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4358,25 +4653,28 @@ const ObjectInput = ({ schema, column, prefix }) => {
|
|
|
4358
4653
|
if (properties === undefined) {
|
|
4359
4654
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4360
4655
|
}
|
|
4361
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
4656
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [showLabel && (jsxRuntime.jsxs(react.Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsxRuntime.jsx("span", { children: "*" })] })), jsxRuntime.jsx(react.Grid, { bgColor: { base: "colorPalette.100", _dark: "colorPalette.900" }, p: 2, borderRadius: 4, borderWidth: 1, borderColor: {
|
|
4657
|
+
base: "colorPalette.200",
|
|
4658
|
+
_dark: "colorPalette.800",
|
|
4659
|
+
}, gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: Object.keys(properties ?? {}).map((key) => {
|
|
4362
4660
|
return (
|
|
4363
4661
|
// @ts-expect-error find suitable types
|
|
4364
4662
|
jsxRuntime.jsx(ColumnRenderer, { column: `${key}`,
|
|
4365
4663
|
prefix: `${prefix}${column}.`,
|
|
4366
4664
|
properties }, `form-${colLabel}-${key}`));
|
|
4367
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4665
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4368
4666
|
};
|
|
4369
4667
|
|
|
4370
4668
|
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4371
4669
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4372
4670
|
const { translate } = useSchemaContext();
|
|
4373
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4671
|
+
const { required, gridColumn = "span 12", gridRow = "span 1" } = schema;
|
|
4374
4672
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4375
4673
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4376
4674
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4377
4675
|
const [newKey, setNewKey] = React.useState();
|
|
4378
4676
|
const [newValue, setNewValue] = React.useState();
|
|
4379
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
4677
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4380
4678
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4381
4679
|
const filtered = entries.filter(([target]) => {
|
|
4382
4680
|
return target !== key;
|
|
@@ -4416,16 +4714,16 @@ const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
|
4416
4714
|
setShowNewEntries(true);
|
|
4417
4715
|
setNewKey(undefined);
|
|
4418
4716
|
setNewValue(undefined);
|
|
4419
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
4717
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4420
4718
|
};
|
|
4421
4719
|
|
|
4422
4720
|
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4423
4721
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4424
4722
|
const { translate } = useSchemaContext();
|
|
4425
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4723
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4426
4724
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4427
4725
|
const colLabel = `${prefix}${column}`;
|
|
4428
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4726
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, children: [jsxRuntime.jsx(react.Input, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4429
4727
|
};
|
|
4430
4728
|
|
|
4431
4729
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4523,9 +4821,180 @@ const TagPicker = ({ column, schema, prefix }) => {
|
|
|
4523
4821
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4524
4822
|
};
|
|
4525
4823
|
|
|
4824
|
+
const TextAreaInput = ({ column, schema, prefix, }) => {
|
|
4825
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4826
|
+
const { translate } = useSchemaContext();
|
|
4827
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4828
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4829
|
+
const colLabel = `${prefix}${column}`;
|
|
4830
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Textarea, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4831
|
+
};
|
|
4832
|
+
|
|
4833
|
+
function TimePicker$1({ hour, setHour, minute, setMinute, meridiem, setMeridiem, meridiemLabel = {
|
|
4834
|
+
am: "am",
|
|
4835
|
+
pm: "pm",
|
|
4836
|
+
}, onChange = (_newValue) => { }, }) {
|
|
4837
|
+
// Refs for focus management
|
|
4838
|
+
const hourInputRef = React.useRef(null);
|
|
4839
|
+
const minuteInputRef = React.useRef(null);
|
|
4840
|
+
React.useRef(null);
|
|
4841
|
+
// Centralized handler for key events, value changes, and focus management
|
|
4842
|
+
const handleKeyDown = (e, field) => {
|
|
4843
|
+
const input = e.target;
|
|
4844
|
+
const value = input.value;
|
|
4845
|
+
// Handle navigation between fields
|
|
4846
|
+
if (e.key === "Tab") {
|
|
4847
|
+
// Tab is handled by the browser, no need to override
|
|
4848
|
+
return;
|
|
4849
|
+
}
|
|
4850
|
+
if (e.key === ":" && field === "hour") {
|
|
4851
|
+
e.preventDefault();
|
|
4852
|
+
minuteInputRef.current?.focus();
|
|
4853
|
+
return;
|
|
4854
|
+
}
|
|
4855
|
+
if (e.key === "Backspace" && value === "") {
|
|
4856
|
+
e.preventDefault();
|
|
4857
|
+
if (field === "minute") {
|
|
4858
|
+
hourInputRef.current?.focus();
|
|
4859
|
+
}
|
|
4860
|
+
else if (field === "meridiem") {
|
|
4861
|
+
minuteInputRef.current?.focus();
|
|
4862
|
+
}
|
|
4863
|
+
return;
|
|
4864
|
+
}
|
|
4865
|
+
// Handle number inputs
|
|
4866
|
+
if (field === "hour") {
|
|
4867
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4868
|
+
const newValue = value + e.key;
|
|
4869
|
+
const numValue = parseInt(newValue, 10);
|
|
4870
|
+
console.log("newValue", newValue, numValue);
|
|
4871
|
+
if (numValue > 12) {
|
|
4872
|
+
const digitValue = parseInt(e.key, 10);
|
|
4873
|
+
setHour(digitValue);
|
|
4874
|
+
onChange({ hour: digitValue, minute, meridiem });
|
|
4875
|
+
return;
|
|
4876
|
+
}
|
|
4877
|
+
// Auto-advance to minutes if we have a valid hour (1-12)
|
|
4878
|
+
if (numValue >= 1 && numValue <= 12) {
|
|
4879
|
+
// Set the hour value
|
|
4880
|
+
setHour(numValue);
|
|
4881
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4882
|
+
// Move to minute input
|
|
4883
|
+
e.preventDefault();
|
|
4884
|
+
minuteInputRef.current?.focus();
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
}
|
|
4888
|
+
else if (field === "minute") {
|
|
4889
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4890
|
+
const newValue = value + e.key;
|
|
4891
|
+
const numValue = parseInt(newValue, 10);
|
|
4892
|
+
console.log("newValue minute", newValue, numValue, numValue > 60, numValue >= 0 && numValue <= 59, e.key);
|
|
4893
|
+
if (numValue > 60) {
|
|
4894
|
+
const digitValue = parseInt(e.key, 10);
|
|
4895
|
+
setMinute(digitValue);
|
|
4896
|
+
onChange({ hour, minute: digitValue, meridiem });
|
|
4897
|
+
return;
|
|
4898
|
+
}
|
|
4899
|
+
// Auto-advance to meridiem if we have a valid minute (0-59)
|
|
4900
|
+
if (numValue >= 0 && numValue <= 59) {
|
|
4901
|
+
// Set the minute value
|
|
4902
|
+
setMinute(numValue);
|
|
4903
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4904
|
+
}
|
|
4905
|
+
}
|
|
4906
|
+
}
|
|
4907
|
+
};
|
|
4908
|
+
// Handle meridiem button click
|
|
4909
|
+
const handleMeridiemClick = (newMeridiem) => {
|
|
4910
|
+
setMeridiem(newMeridiem);
|
|
4911
|
+
onChange({ hour, minute, meridiem: newMeridiem });
|
|
4912
|
+
};
|
|
4913
|
+
const handleClear = () => {
|
|
4914
|
+
setHour(null);
|
|
4915
|
+
setMinute(null);
|
|
4916
|
+
setMeridiem(null);
|
|
4917
|
+
onChange({ hour: null, minute: null, meridiem: null });
|
|
4918
|
+
// Focus the hour field after clearing
|
|
4919
|
+
hourInputRef.current?.focus();
|
|
4920
|
+
};
|
|
4921
|
+
return (jsxRuntime.jsx(react.Flex, { direction: "column", gap: 3, children: jsxRuntime.jsxs(react.Grid, { justifyContent: "center", alignItems: "center", templateColumns: "60px 10px 60px 90px auto", gap: "2", width: "auto", minWidth: "250px", children: [jsxRuntime.jsx(react.Input, { ref: hourInputRef, type: "text", value: hour === null ? "" : hour.toString().padStart(2, "0"), onKeyDown: (e) => handleKeyDown(e, "hour"), placeholder: "HH", maxLength: 2, textAlign: "center" }), jsxRuntime.jsx(react.Text, { children: ":" }), jsxRuntime.jsx(react.Input, { ref: minuteInputRef, type: "text", value: minute === null ? "" : minute.toString().padStart(2, "0"), onKeyDown: (e) => handleKeyDown(e, "minute"), placeholder: "MM", maxLength: 2, textAlign: "center" }), jsxRuntime.jsxs(react.Flex, { gap: "1", children: [jsxRuntime.jsx(react.Button, { size: "sm", colorScheme: meridiem === "am" ? "blue" : "gray", variant: meridiem === "am" ? "solid" : "outline", onClick: () => handleMeridiemClick("am"), width: "40px", children: meridiemLabel.am }), jsxRuntime.jsx(react.Button, { size: "sm", colorScheme: meridiem === "pm" ? "blue" : "gray", variant: meridiem === "pm" ? "solid" : "outline", onClick: () => handleMeridiemClick("pm"), width: "40px", children: meridiemLabel.pm })] }), jsxRuntime.jsx(react.Button, { onClick: handleClear, size: "sm", variant: "ghost", children: jsxRuntime.jsx(md.MdCancel, {}) })] }) }));
|
|
4922
|
+
}
|
|
4923
|
+
|
|
4924
|
+
const TimePicker = ({ column, schema, prefix }) => {
|
|
4925
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4926
|
+
const { translate } = useSchemaContext();
|
|
4927
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", timeFormat = "HH:mm:ss", displayTimeFormat = "hh:mm A", } = schema;
|
|
4928
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4929
|
+
const colLabel = `${prefix}${column}`;
|
|
4930
|
+
const [open, setOpen] = React.useState(false);
|
|
4931
|
+
const value = watch(colLabel);
|
|
4932
|
+
const displayedTime = dayjs(`1970-01-01T${value}Z`).isValid()
|
|
4933
|
+
? dayjs(`1970-01-01T${value}Z`).utc().format(displayTimeFormat)
|
|
4934
|
+
: "";
|
|
4935
|
+
// Parse the initial time parts from the ISO time string (HH:mm:ss)
|
|
4936
|
+
const parseTime = (isoTime) => {
|
|
4937
|
+
if (!isoTime)
|
|
4938
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4939
|
+
const parsed = dayjs(`1970-01-01T${isoTime}Z`).utc();
|
|
4940
|
+
if (!parsed.isValid())
|
|
4941
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4942
|
+
let hour = parsed.hour();
|
|
4943
|
+
const minute = parsed.minute();
|
|
4944
|
+
const meridiem = hour >= 12 ? "pm" : "am";
|
|
4945
|
+
if (hour === 0)
|
|
4946
|
+
hour = 12;
|
|
4947
|
+
else if (hour > 12)
|
|
4948
|
+
hour -= 12;
|
|
4949
|
+
return { hour, minute, meridiem };
|
|
4950
|
+
};
|
|
4951
|
+
const initialTime = parseTime(value);
|
|
4952
|
+
const [hour, setHour] = React.useState(initialTime.hour);
|
|
4953
|
+
const [minute, setMinute] = React.useState(initialTime.minute);
|
|
4954
|
+
const [meridiem, setMeridiem] = React.useState(initialTime.meridiem);
|
|
4955
|
+
React.useEffect(() => {
|
|
4956
|
+
const { hour, minute, meridiem } = parseTime(value);
|
|
4957
|
+
setHour(hour);
|
|
4958
|
+
setMinute(minute);
|
|
4959
|
+
setMeridiem(meridiem);
|
|
4960
|
+
}, [value]);
|
|
4961
|
+
// Convert hour, minute, meridiem to 24-hour ISO time string
|
|
4962
|
+
const toIsoTime = (hour, minute, meridiem) => {
|
|
4963
|
+
if (hour === null || minute === null || meridiem === null)
|
|
4964
|
+
return null;
|
|
4965
|
+
let h = hour;
|
|
4966
|
+
if (meridiem === "am" && hour === 12)
|
|
4967
|
+
h = 0;
|
|
4968
|
+
else if (meridiem === "pm" && hour < 12)
|
|
4969
|
+
h = hour + 12;
|
|
4970
|
+
return dayjs(`1970-01-01T${h.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}:00Z`)
|
|
4971
|
+
.utc()
|
|
4972
|
+
.format(timeFormat);
|
|
4973
|
+
};
|
|
4974
|
+
// Handle changes to time parts
|
|
4975
|
+
const handleTimeChange = ({ hour: newHour, minute: newMinute, meridiem: newMeridiem, }) => {
|
|
4976
|
+
setHour(newHour);
|
|
4977
|
+
setMinute(newMinute);
|
|
4978
|
+
setMeridiem(newMeridiem);
|
|
4979
|
+
const isoTime = toIsoTime(newHour, newMinute, newMeridiem);
|
|
4980
|
+
setValue(colLabel, isoTime, { shouldValidate: true, shouldDirty: true });
|
|
4981
|
+
};
|
|
4982
|
+
const containerRef = React.useRef(null);
|
|
4983
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4984
|
+
gridRow, children: [jsxRuntime.jsxs(react.Popover.Root, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsxRuntime.jsx(react.Popover.Trigger, { asChild: true, children: jsxRuntime.jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
4985
|
+
setOpen(true);
|
|
4986
|
+
}, justifyContent: "start", children: [jsxRuntime.jsx(io.IoMdClock, {}), !!value ? `${displayedTime}` : ""] }) }), jsxRuntime.jsx(react.Portal, { children: jsxRuntime.jsx(react.Popover.Positioner, { children: jsxRuntime.jsx(react.Popover.Content, { ref: containerRef, children: jsxRuntime.jsx(react.Popover.Body, { children: jsxRuntime.jsx(TimePicker$1, { hour: hour, setHour: setHour, minute: minute, setMinute: setMinute, meridiem: meridiem, setMeridiem: setMeridiem, onChange: handleTimeChange, meridiemLabel: {
|
|
4987
|
+
am: translate.t(removeIndex(`common.am`)),
|
|
4988
|
+
pm: translate.t(removeIndex(`common.pm`)),
|
|
4989
|
+
} }) }) }) }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4990
|
+
};
|
|
4991
|
+
|
|
4526
4992
|
const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
4527
4993
|
const colSchema = schema;
|
|
4528
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4994
|
+
const { type, variant, properties: innerProperties, foreign_key, format, items, } = schema;
|
|
4995
|
+
if (variant === "custom-input") {
|
|
4996
|
+
return jsxRuntime.jsx(CustomInput, { schema: colSchema, prefix, column });
|
|
4997
|
+
}
|
|
4529
4998
|
if (type === "string") {
|
|
4530
4999
|
if ((schema.enum ?? []).length > 0) {
|
|
4531
5000
|
return jsxRuntime.jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
@@ -4534,9 +5003,15 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4534
5003
|
idPickerSanityCheck(column, foreign_key);
|
|
4535
5004
|
return jsxRuntime.jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4536
5005
|
}
|
|
4537
|
-
if (
|
|
5006
|
+
if (format === "date") {
|
|
4538
5007
|
return jsxRuntime.jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4539
5008
|
}
|
|
5009
|
+
if (format === "time") {
|
|
5010
|
+
return jsxRuntime.jsx(TimePicker, { schema: colSchema, prefix, column });
|
|
5011
|
+
}
|
|
5012
|
+
if (variant === "text-area") {
|
|
5013
|
+
return jsxRuntime.jsx(TextAreaInput, { schema: colSchema, prefix, column });
|
|
5014
|
+
}
|
|
4540
5015
|
return jsxRuntime.jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4541
5016
|
}
|
|
4542
5017
|
if (type === "number" || type === "integer") {
|
|
@@ -4583,85 +5058,102 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4583
5058
|
};
|
|
4584
5059
|
|
|
4585
5060
|
const ArrayViewer = ({ schema, column, prefix }) => {
|
|
4586
|
-
const {
|
|
5061
|
+
const { gridColumn = "span 12", gridRow = "span 1", required, items, } = schema;
|
|
4587
5062
|
const { translate } = useSchemaContext();
|
|
4588
5063
|
const colLabel = `${prefix}${column}`;
|
|
4589
5064
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4590
5065
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4591
5066
|
const values = watch(colLabel) ?? [];
|
|
4592
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.
|
|
4593
|
-
|
|
4594
|
-
|
|
5067
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsxRuntime.jsx("span", { children: "*" })] }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: values.map((field, index) => (jsxRuntime.jsx(react.Flex, { flexFlow: "column", bgColor: { base: "colorPalette.100", _dark: "colorPalette.900" }, p: "2", borderRadius: "md", borderWidth: "thin", borderColor: {
|
|
5068
|
+
base: "colorPalette.200",
|
|
5069
|
+
_dark: "colorPalette.800",
|
|
5070
|
+
}, children: jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaViewer, { column: `${index}`,
|
|
5071
|
+
prefix: `${colLabel}.`,
|
|
5072
|
+
// @ts-expect-error find suitable types
|
|
5073
|
+
schema: { showLabel: false, ...(items ?? {}) } }) }) }, `form-${prefix}${column}.${index}`))) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4595
5074
|
};
|
|
4596
5075
|
|
|
4597
5076
|
const BooleanViewer = ({ schema, column, prefix, }) => {
|
|
4598
5077
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4599
5078
|
const { translate } = useSchemaContext();
|
|
4600
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5079
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4601
5080
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4602
5081
|
const colLabel = `${prefix}${column}`;
|
|
4603
5082
|
const value = watch(colLabel);
|
|
4604
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5083
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4605
5084
|
gridRow, children: [jsxRuntime.jsx(react.Text, { children: value
|
|
4606
5085
|
? translate.t(removeIndex(`${colLabel}.true`))
|
|
4607
|
-
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5086
|
+
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
5087
|
+
};
|
|
5088
|
+
|
|
5089
|
+
const CustomViewer = ({ column, schema, prefix }) => {
|
|
5090
|
+
const formContext = reactHookForm.useFormContext();
|
|
5091
|
+
const { inputViewerRender } = schema;
|
|
5092
|
+
return (inputViewerRender &&
|
|
5093
|
+
inputViewerRender({
|
|
5094
|
+
column,
|
|
5095
|
+
schema,
|
|
5096
|
+
prefix,
|
|
5097
|
+
formContext,
|
|
5098
|
+
}));
|
|
4608
5099
|
};
|
|
4609
5100
|
|
|
4610
5101
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4611
5102
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4612
5103
|
const { translate } = useSchemaContext();
|
|
4613
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5104
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4614
5105
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4615
5106
|
const colLabel = `${prefix}${column}`;
|
|
4616
5107
|
const selectedDate = watch(colLabel);
|
|
4617
|
-
|
|
4618
|
-
|
|
5108
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
5109
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5110
|
+
gridRow, children: [jsxRuntime.jsxs(react.Text, { children: [" ", selectedDate !== undefined ? displayDate : ""] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4619
5111
|
};
|
|
4620
5112
|
|
|
5113
|
+
function translateWrapper({ prefix, column, label, translate, }) {
|
|
5114
|
+
return translate.t(removeIndex(`${prefix}${column}.${label}`));
|
|
5115
|
+
}
|
|
5116
|
+
|
|
4621
5117
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
4622
5118
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4623
5119
|
const { translate } = useSchemaContext();
|
|
4624
5120
|
const { required } = schema;
|
|
4625
5121
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4626
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
5122
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
4627
5123
|
const colLabel = `${prefix}${column}`;
|
|
4628
5124
|
const watchEnum = watch(colLabel);
|
|
4629
5125
|
const watchEnums = (watch(colLabel) ?? []);
|
|
4630
|
-
|
|
5126
|
+
const customTranslate = (label) => {
|
|
5127
|
+
return translateWrapper({ prefix, column, label, translate });
|
|
5128
|
+
};
|
|
5129
|
+
return (jsxRuntime.jsxs(Field, { label: `${customTranslate(`field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4631
5130
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
|
|
4632
5131
|
const item = enumValue;
|
|
4633
5132
|
if (item === undefined) {
|
|
4634
5133
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
4635
5134
|
}
|
|
4636
|
-
return (jsxRuntime.jsx(Tag, {
|
|
5135
|
+
return (jsxRuntime.jsx(Tag, { children: !!renderDisplay === true
|
|
4637
5136
|
? renderDisplay(item)
|
|
4638
|
-
:
|
|
4639
|
-
}) })), !isMultiple &&
|
|
5137
|
+
: customTranslate(item) }));
|
|
5138
|
+
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: customTranslate(watchEnum) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: customTranslate(`field_required`) }))] }));
|
|
4640
5139
|
};
|
|
4641
5140
|
|
|
4642
5141
|
const FileViewer = ({ column, schema, prefix }) => {
|
|
4643
|
-
const {
|
|
5142
|
+
const { watch } = reactHookForm.useFormContext();
|
|
4644
5143
|
const { translate } = useSchemaContext();
|
|
4645
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5144
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4646
5145
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4647
5146
|
const currentFiles = (watch(column) ?? []);
|
|
4648
5147
|
const colLabel = `${prefix}${column}`;
|
|
4649
|
-
return (jsxRuntime.
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
}, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4653
|
-
return (jsxRuntime.jsx(react.Card.Root, { variant: "subtle", children: jsxRuntime.jsxs(react.Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4654
|
-
setValue(column, currentFiles.filter(({ name }) => {
|
|
4655
|
-
return name !== file.name;
|
|
4656
|
-
}));
|
|
4657
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4658
|
-
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
5148
|
+
return (jsxRuntime.jsx(Field, { label: `${translate.t(`${colLabel}.field_label`)}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
5149
|
+
return (jsxRuntime.jsx(react.Card.Root, { variant: "subtle", children: jsxRuntime.jsxs(react.Card.Body, { gap: "2", display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [file.type.startsWith("image/") && (jsxRuntime.jsx(react.Image, { src: URL.createObjectURL(file), alt: file.name, boxSize: "50px", objectFit: "cover", borderRadius: "md", marginRight: "2" })), jsxRuntime.jsx(react.Box, { children: file.name })] }) }, file.name));
|
|
5150
|
+
}) }) }));
|
|
4659
5151
|
};
|
|
4660
5152
|
|
|
4661
5153
|
const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4662
5154
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4663
5155
|
const { idMap, translate } = useSchemaContext();
|
|
4664
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
5156
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4665
5157
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4666
5158
|
const { display_column } = foreign_key;
|
|
4667
5159
|
const colLabel = `${prefix}${column}`;
|
|
@@ -4677,7 +5169,7 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4677
5169
|
}
|
|
4678
5170
|
return record[display_column];
|
|
4679
5171
|
};
|
|
4680
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5172
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4681
5173
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
|
|
4682
5174
|
const item = idMap[id];
|
|
4683
5175
|
if (item === undefined) {
|
|
@@ -4686,21 +5178,21 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4686
5178
|
return (jsxRuntime.jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4687
5179
|
? renderDisplay(item)
|
|
4688
5180
|
: item[display_column] }, id));
|
|
4689
|
-
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5181
|
+
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4690
5182
|
};
|
|
4691
5183
|
|
|
4692
5184
|
const NumberViewer = ({ schema, column, prefix, }) => {
|
|
4693
5185
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4694
5186
|
const { translate } = useSchemaContext();
|
|
4695
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5187
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4696
5188
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4697
5189
|
const colLabel = `${prefix}${column}`;
|
|
4698
5190
|
const value = watch(colLabel);
|
|
4699
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5191
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(react.Text, { children: value }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4700
5192
|
};
|
|
4701
5193
|
|
|
4702
5194
|
const ObjectViewer = ({ schema, column, prefix }) => {
|
|
4703
|
-
const { properties,
|
|
5195
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, showLabel = true, } = schema;
|
|
4704
5196
|
const { translate } = useSchemaContext();
|
|
4705
5197
|
const colLabel = `${prefix}${column}`;
|
|
4706
5198
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4708,25 +5200,28 @@ const ObjectViewer = ({ schema, column, prefix }) => {
|
|
|
4708
5200
|
if (properties === undefined) {
|
|
4709
5201
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4710
5202
|
}
|
|
4711
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
5203
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [showLabel && (jsxRuntime.jsxs(react.Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsxRuntime.jsx("span", { children: "*" })] })), jsxRuntime.jsx(react.Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", bgColor: { base: "colorPalette.100", _dark: "colorPalette.900" }, p: "1", borderRadius: "md", borderWidth: "thin", borderColor: {
|
|
5204
|
+
base: "colorPalette.200",
|
|
5205
|
+
_dark: "colorPalette.800",
|
|
5206
|
+
}, children: Object.keys(properties ?? {}).map((key) => {
|
|
4712
5207
|
return (
|
|
4713
5208
|
// @ts-expect-error find suitable types
|
|
4714
5209
|
jsxRuntime.jsx(ColumnViewer, { column: `${key}`,
|
|
4715
5210
|
prefix: `${prefix}${column}.`,
|
|
4716
5211
|
properties }, `form-objectviewer-${colLabel}-${key}`));
|
|
4717
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5212
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4718
5213
|
};
|
|
4719
5214
|
|
|
4720
5215
|
const RecordInput = ({ column, schema, prefix }) => {
|
|
4721
5216
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4722
5217
|
const { translate } = useSchemaContext();
|
|
4723
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5218
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4724
5219
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4725
5220
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4726
5221
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4727
5222
|
const [newKey, setNewKey] = React.useState();
|
|
4728
5223
|
const [newValue, setNewValue] = React.useState();
|
|
4729
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
5224
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4730
5225
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4731
5226
|
const filtered = entries.filter(([target]) => {
|
|
4732
5227
|
return target !== key;
|
|
@@ -4766,7 +5261,17 @@ const RecordInput = ({ column, schema, prefix }) => {
|
|
|
4766
5261
|
setShowNewEntries(true);
|
|
4767
5262
|
setNewKey(undefined);
|
|
4768
5263
|
setNewValue(undefined);
|
|
4769
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
5264
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
5265
|
+
};
|
|
5266
|
+
|
|
5267
|
+
const StringViewer = ({ column, schema, prefix, }) => {
|
|
5268
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5269
|
+
const { translate } = useSchemaContext();
|
|
5270
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5271
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5272
|
+
const colLabel = `${prefix}${column}`;
|
|
5273
|
+
const value = watch(colLabel);
|
|
5274
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children: value }), errors[colLabel] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
4770
5275
|
};
|
|
4771
5276
|
|
|
4772
5277
|
const TagViewer = ({ column, schema, prefix }) => {
|
|
@@ -4854,19 +5359,36 @@ const TagViewer = ({ column, schema, prefix }) => {
|
|
|
4854
5359
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4855
5360
|
};
|
|
4856
5361
|
|
|
4857
|
-
const
|
|
5362
|
+
const TextAreaViewer = ({ column, schema, prefix, }) => {
|
|
4858
5363
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4859
5364
|
const { translate } = useSchemaContext();
|
|
4860
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5365
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4861
5366
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4862
5367
|
const colLabel = `${prefix}${column}`;
|
|
4863
5368
|
const value = watch(colLabel);
|
|
4864
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5369
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, gridColumn: gridColumn, gridRow: gridRow, children: [jsxRuntime.jsx(react.Text, { whiteSpace: "pre-wrap", children: value }), " ", errors[colLabel] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }) }));
|
|
5370
|
+
};
|
|
5371
|
+
|
|
5372
|
+
const TimeViewer = ({ column, schema, prefix, }) => {
|
|
5373
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5374
|
+
const { translate } = useSchemaContext();
|
|
5375
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayTimeFormat = "hh:mm A" } = schema;
|
|
5376
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5377
|
+
const colLabel = `${prefix}${column}`;
|
|
5378
|
+
const selectedDate = watch(colLabel);
|
|
5379
|
+
const displayedTime = dayjs(`1970-01-01T${selectedDate}Z`).isValid()
|
|
5380
|
+
? dayjs(`1970-01-01T${selectedDate}Z`).utc().format(displayTimeFormat)
|
|
5381
|
+
: "";
|
|
5382
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5383
|
+
gridRow, children: [jsxRuntime.jsx(react.Text, { children: displayedTime }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4865
5384
|
};
|
|
4866
5385
|
|
|
4867
5386
|
const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
4868
5387
|
const colSchema = schema;
|
|
4869
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
5388
|
+
const { type, variant, properties: innerProperties, foreign_key, items, format, } = schema;
|
|
5389
|
+
if (variant === "custom-input") {
|
|
5390
|
+
return jsxRuntime.jsx(CustomViewer, { schema: colSchema, prefix, column });
|
|
5391
|
+
}
|
|
4870
5392
|
if (type === "string") {
|
|
4871
5393
|
if ((schema.enum ?? []).length > 0) {
|
|
4872
5394
|
return jsxRuntime.jsx(EnumViewer, { schema: colSchema, prefix, column });
|
|
@@ -4875,9 +5397,15 @@ const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
|
4875
5397
|
idPickerSanityCheck(column, foreign_key);
|
|
4876
5398
|
return jsxRuntime.jsx(IdViewer, { schema: colSchema, prefix, column });
|
|
4877
5399
|
}
|
|
4878
|
-
if (
|
|
5400
|
+
if (format === "time") {
|
|
5401
|
+
return jsxRuntime.jsx(TimeViewer, { schema: colSchema, prefix, column });
|
|
5402
|
+
}
|
|
5403
|
+
if (format === "date") {
|
|
4879
5404
|
return jsxRuntime.jsx(DateViewer, { schema: colSchema, prefix, column });
|
|
4880
5405
|
}
|
|
5406
|
+
if (variant === "text-area") {
|
|
5407
|
+
return jsxRuntime.jsx(TextAreaViewer, { schema: colSchema, prefix, column });
|
|
5408
|
+
}
|
|
4881
5409
|
return jsxRuntime.jsx(StringViewer, { schema: colSchema, prefix, column });
|
|
4882
5410
|
}
|
|
4883
5411
|
if (type === "number" || type === "integer") {
|
|
@@ -5000,7 +5528,7 @@ const FormBody = () => {
|
|
|
5000
5528
|
include,
|
|
5001
5529
|
});
|
|
5002
5530
|
if (isSuccess) {
|
|
5003
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsxs(react.Alert.Root, { status: "success", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsx(react.Alert.Title, { children: translate.t("
|
|
5531
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsxs(react.Alert.Root, { status: "success", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsx(react.Alert.Title, { children: translate.t("submit_success") })] }), jsxRuntime.jsx(react.Flex, { justifyContent: "end", children: jsxRuntime.jsx(react.Button, { onClick: async () => {
|
|
5004
5532
|
setIsError(false);
|
|
5005
5533
|
setIsSubmiting(false);
|
|
5006
5534
|
setIsSuccess(false);
|
|
@@ -5008,10 +5536,10 @@ const FormBody = () => {
|
|
|
5008
5536
|
setValidatedData(undefined);
|
|
5009
5537
|
const data = await getUpdatedData();
|
|
5010
5538
|
methods.reset(data);
|
|
5011
|
-
}, formNoValidate: true, children: translate.t("
|
|
5539
|
+
}, formNoValidate: true, children: translate.t("submit_again") }) })] }));
|
|
5012
5540
|
}
|
|
5013
5541
|
if (isConfirming) {
|
|
5014
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows:
|
|
5542
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: "repeat(12, max-content)", autoFlow: "row", children: ordered.map((column) => {
|
|
5015
5543
|
return (jsxRuntime.jsx(ColumnViewer
|
|
5016
5544
|
// @ts-expect-error find suitable types
|
|
5017
5545
|
, {
|
|
@@ -5023,7 +5551,7 @@ const FormBody = () => {
|
|
|
5023
5551
|
onFormSubmit(validatedData);
|
|
5024
5552
|
}, children: translate.t("confirm") })] }), isSubmiting && (jsxRuntime.jsx(react.Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsxRuntime.jsx(react.Center, { h: "full", children: jsxRuntime.jsx(react.Spinner, { color: "teal.500" }) }) })), isError && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Alert.Root, { status: "error", children: jsxRuntime.jsx(react.Alert.Title, { children: jsxRuntime.jsx(AccordionRoot, { collapsible: true, defaultValue: [], children: jsxRuntime.jsxs(AccordionItem, { value: "b", children: [jsxRuntime.jsxs(AccordionItemTrigger, { children: [jsxRuntime.jsx(react.Alert.Indicator, {}), `${error}`] }), jsxRuntime.jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
|
|
5025
5553
|
}
|
|
5026
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)",
|
|
5554
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: ordered.map((column) => {
|
|
5027
5555
|
return (jsxRuntime.jsx(ColumnRenderer
|
|
5028
5556
|
// @ts-expect-error find suitable types
|
|
5029
5557
|
, {
|
|
@@ -5039,8 +5567,8 @@ const FormTitle = () => {
|
|
|
5039
5567
|
return jsxRuntime.jsx(react.Heading, { children: translate.t("title") });
|
|
5040
5568
|
};
|
|
5041
5569
|
|
|
5042
|
-
const DefaultForm = ({ formConfig, }) => {
|
|
5043
|
-
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5570
|
+
const DefaultForm = ({ formConfig, showTitle = true, }) => {
|
|
5571
|
+
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [showTitle && jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5044
5572
|
};
|
|
5045
5573
|
|
|
5046
5574
|
const useForm = ({ preLoadedValues, keyPrefix }) => {
|
|
@@ -5104,6 +5632,7 @@ exports.TableCardContainer = TableCardContainer;
|
|
|
5104
5632
|
exports.TableCards = TableCards;
|
|
5105
5633
|
exports.TableComponent = TableComponent;
|
|
5106
5634
|
exports.TableControls = TableControls;
|
|
5635
|
+
exports.TableDataDisplay = TableDataDisplay;
|
|
5107
5636
|
exports.TableFilter = TableFilter;
|
|
5108
5637
|
exports.TableFilterTags = TableFilterTags;
|
|
5109
5638
|
exports.TableFooter = TableFooter;
|