@bsol-oss/react-datatable5 12.0.0-beta.5 → 12.0.0-beta.50
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 +181 -86
- package/dist/index.js +873 -358
- package/dist/index.mjs +878 -364
- package/dist/types/components/DataTable/DataTable.d.ts +4 -2
- package/dist/types/components/DataTable/DataTableServer.d.ts +1 -1
- package/dist/types/components/DataTable/DefaultTable.d.ts +9 -12
- package/dist/types/components/DataTable/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
|
|
|
@@ -2831,7 +2918,7 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
2831
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, }) {
|
|
2832
2919
|
const table = reactTable.useReactTable({
|
|
2833
2920
|
_features: [DensityFeature],
|
|
2834
|
-
data: query.data?.data ?? [],
|
|
2921
|
+
data: (query.data?.data ?? []),
|
|
2835
2922
|
rowCount: query.data?.count ?? 0,
|
|
2836
2923
|
columns: columns,
|
|
2837
2924
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
@@ -2877,95 +2964,30 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
2877
2964
|
// for tanstack-table ts bug end
|
|
2878
2965
|
});
|
|
2879
2966
|
return (jsxRuntime.jsx(DataTableContext.Provider, { value: {
|
|
2880
|
-
table:
|
|
2967
|
+
table: table,
|
|
2881
2968
|
globalFilter,
|
|
2882
2969
|
setGlobalFilter,
|
|
2883
2970
|
type: "server",
|
|
2884
2971
|
translate,
|
|
2972
|
+
columns: columns,
|
|
2973
|
+
sorting,
|
|
2974
|
+
setSorting,
|
|
2975
|
+
columnFilters,
|
|
2976
|
+
setColumnFilters,
|
|
2977
|
+
pagination,
|
|
2978
|
+
setPagination,
|
|
2979
|
+
rowSelection,
|
|
2980
|
+
setRowSelection,
|
|
2981
|
+
columnOrder,
|
|
2982
|
+
setColumnOrder,
|
|
2983
|
+
density,
|
|
2984
|
+
setDensity,
|
|
2985
|
+
columnVisibility,
|
|
2986
|
+
setColumnVisibility,
|
|
2987
|
+
data: query.data?.data ?? [],
|
|
2885
2988
|
}, children: jsxRuntime.jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
2886
2989
|
}
|
|
2887
2990
|
|
|
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
2991
|
const Tooltip = React__namespace.forwardRef(function Tooltip(props, ref) {
|
|
2970
2992
|
const { showArrow, children, disabled, portalled, content, contentProps, portalRef, ...rest } = props;
|
|
2971
2993
|
if (disabled)
|
|
@@ -3000,17 +3022,19 @@ const GlobalFilter = () => {
|
|
|
3000
3022
|
} }) }) }));
|
|
3001
3023
|
};
|
|
3002
3024
|
|
|
3003
|
-
const ReloadButton = ({
|
|
3025
|
+
const ReloadButton = ({ variant = "icon", }) => {
|
|
3004
3026
|
const { url } = useDataTableServerContext();
|
|
3005
3027
|
const queryClient = reactQuery.useQueryClient();
|
|
3028
|
+
const { tableLabel } = useDataTableContext();
|
|
3029
|
+
const { reloadTooltip, reloadButtonText } = tableLabel;
|
|
3006
3030
|
if (variant === "icon") {
|
|
3007
|
-
return (jsxRuntime.jsx(Tooltip, { showArrow: true, content:
|
|
3031
|
+
return (jsxRuntime.jsx(Tooltip, { showArrow: true, content: reloadTooltip, children: jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => {
|
|
3008
3032
|
queryClient.invalidateQueries({ queryKey: [url] });
|
|
3009
3033
|
}, "aria-label": "refresh", children: jsxRuntime.jsx(io5.IoReload, {}) }) }));
|
|
3010
3034
|
}
|
|
3011
3035
|
return (jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3012
3036
|
queryClient.invalidateQueries({ queryKey: [url] });
|
|
3013
|
-
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ",
|
|
3037
|
+
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ", reloadButtonText] }));
|
|
3014
3038
|
};
|
|
3015
3039
|
|
|
3016
3040
|
const FilterOptions = ({ column }) => {
|
|
@@ -3019,6 +3043,7 @@ const FilterOptions = ({ column }) => {
|
|
|
3019
3043
|
const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
|
|
3020
3044
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.map((option) => {
|
|
3021
3045
|
const selected = table.getColumn(column)?.getFilterValue() === option;
|
|
3046
|
+
const { label, value } = option;
|
|
3022
3047
|
return (jsxRuntime.jsxs(react.Button, { size: "sm", onClick: () => {
|
|
3023
3048
|
if (selected) {
|
|
3024
3049
|
table.setColumnFilters((state) => {
|
|
@@ -3028,8 +3053,8 @@ const FilterOptions = ({ column }) => {
|
|
|
3028
3053
|
});
|
|
3029
3054
|
return;
|
|
3030
3055
|
}
|
|
3031
|
-
table.getColumn(column)?.setFilterValue(
|
|
3032
|
-
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [
|
|
3056
|
+
table.getColumn(column)?.setFilterValue(value);
|
|
3057
|
+
}, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [label, selected && jsxRuntime.jsx(md.MdClose, {})] }, option.value));
|
|
3033
3058
|
}) }));
|
|
3034
3059
|
};
|
|
3035
3060
|
|
|
@@ -3044,16 +3069,91 @@ const TableFilterTags = () => {
|
|
|
3044
3069
|
}) }));
|
|
3045
3070
|
};
|
|
3046
3071
|
|
|
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
|
-
|
|
3072
|
+
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 = {}, }) => {
|
|
3073
|
+
const { tableLabel } = useDataTableContext();
|
|
3074
|
+
const { rowCountText, hasErrorText } = tableLabel;
|
|
3075
|
+
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) => {
|
|
3076
|
+
const { label, value } = option;
|
|
3077
|
+
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));
|
|
3078
|
+
}) })), 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, {}) })] }))] }));
|
|
3079
|
+
};
|
|
3080
|
+
|
|
3081
|
+
const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
3082
|
+
const { title, description, icon, children, ...rest } = props;
|
|
3083
|
+
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] }) }));
|
|
3084
|
+
});
|
|
3085
|
+
|
|
3086
|
+
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" })] }) }));
|
|
3087
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3088
|
+
const { table } = useDataTableContext();
|
|
3089
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
3090
|
+
return emptyComponent;
|
|
3091
|
+
}
|
|
3092
|
+
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 }));
|
|
3093
|
+
};
|
|
3094
|
+
|
|
3095
|
+
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
3096
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
3097
|
+
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 }))] }));
|
|
3098
|
+
});
|
|
3099
|
+
|
|
3100
|
+
const TableBody = ({ showSelector = false, canResize = true, }) => {
|
|
3101
|
+
"use no memo";
|
|
3102
|
+
const { table } = useDataTableContext();
|
|
3103
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3104
|
+
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
3105
|
+
const handleRowHover = (index) => {
|
|
3106
|
+
setHoveredRow(index);
|
|
3107
|
+
};
|
|
3108
|
+
const getTdProps = (cell) => {
|
|
3109
|
+
const tdProps = cell.column.getIsPinned()
|
|
3110
|
+
? {
|
|
3111
|
+
left: showSelector
|
|
3112
|
+
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3113
|
+
: `${cell.column.getStart("left")}px`,
|
|
3114
|
+
position: "relative",
|
|
3115
|
+
}
|
|
3116
|
+
: {};
|
|
3117
|
+
return tdProps;
|
|
3118
|
+
};
|
|
3119
|
+
const getTrProps = ({ hoveredRow, index, }) => {
|
|
3120
|
+
if (hoveredRow === -1) {
|
|
3121
|
+
return {};
|
|
3122
|
+
}
|
|
3123
|
+
if (hoveredRow === index) {
|
|
3124
|
+
return {
|
|
3125
|
+
opacity: "1",
|
|
3126
|
+
};
|
|
3127
|
+
}
|
|
3128
|
+
return {
|
|
3129
|
+
opacity: "0.8",
|
|
3130
|
+
};
|
|
3131
|
+
};
|
|
3132
|
+
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
3133
|
+
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) => {
|
|
3134
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
3135
|
+
// styling resize and pinning start
|
|
3136
|
+
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, color: {
|
|
3137
|
+
base: "colorPalette.900",
|
|
3138
|
+
_dark: "colorPalette.100",
|
|
3139
|
+
},
|
|
3140
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, ...getTdProps(cell), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
3141
|
+
})] }, `chakra-table-row-${row.id}`));
|
|
3142
|
+
}) }));
|
|
3143
|
+
};
|
|
3144
|
+
const TableRowSelector = ({ row, }) => {
|
|
3145
|
+
const { table } = useDataTableContext();
|
|
3146
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3147
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3148
|
+
base: "colorPalette.900",
|
|
3149
|
+
_dark: "colorPalette.100",
|
|
3150
|
+
},
|
|
3151
|
+
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(),
|
|
3152
|
+
disabled: !row.getCanSelect(),
|
|
3153
|
+
onCheckedChange: row.getToggleSelectedHandler() }) }));
|
|
3054
3154
|
};
|
|
3055
3155
|
|
|
3056
|
-
const TableFooter = ({
|
|
3156
|
+
const TableFooter = ({ showSelector = false, alwaysShowSelector = true, }) => {
|
|
3057
3157
|
const table = useDataTableContext().table;
|
|
3058
3158
|
const SELECTION_BOX_WIDTH = 20;
|
|
3059
3159
|
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
@@ -3072,65 +3172,62 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
3072
3172
|
}
|
|
3073
3173
|
return false;
|
|
3074
3174
|
};
|
|
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(),
|
|
3175
|
+
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
3176
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3107
3177
|
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
3178
|
// styling resize and pinning start
|
|
3109
|
-
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid",
|
|
3179
|
+
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
3180
|
? 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}`))) }));
|
|
3181
|
+
: 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
3182
|
};
|
|
3115
3183
|
|
|
3116
|
-
|
|
3184
|
+
// Default text values
|
|
3185
|
+
const DEFAULT_HEADER_TEXTS = {
|
|
3186
|
+
pinColumn: "Pin Column",
|
|
3187
|
+
cancelPin: "Cancel Pin",
|
|
3188
|
+
sortAscending: "Sort Ascending",
|
|
3189
|
+
sortDescending: "Sort Descending",
|
|
3190
|
+
clearSorting: "Clear Sorting",
|
|
3191
|
+
};
|
|
3192
|
+
/**
|
|
3193
|
+
* TableHeader component with configurable text strings.
|
|
3194
|
+
*
|
|
3195
|
+
* @example
|
|
3196
|
+
* // Using default texts
|
|
3197
|
+
* <TableHeader />
|
|
3198
|
+
*
|
|
3199
|
+
* @example
|
|
3200
|
+
* // Customizing default texts for all columns
|
|
3201
|
+
* <TableHeader
|
|
3202
|
+
* defaultTexts={{
|
|
3203
|
+
* pinColumn: "Pin This Column",
|
|
3204
|
+
* sortAscending: "Sort A-Z"
|
|
3205
|
+
* }}
|
|
3206
|
+
* />
|
|
3207
|
+
*
|
|
3208
|
+
* @example
|
|
3209
|
+
* // Customizing texts per column via meta
|
|
3210
|
+
* const columns = [
|
|
3211
|
+
* columnHelper.accessor("name", {
|
|
3212
|
+
* header: "Name",
|
|
3213
|
+
* meta: {
|
|
3214
|
+
* headerTexts: {
|
|
3215
|
+
* pinColumn: "Pin Name Column",
|
|
3216
|
+
* sortAscending: "Sort Names A-Z"
|
|
3217
|
+
* }
|
|
3218
|
+
* }
|
|
3219
|
+
* })
|
|
3220
|
+
* ];
|
|
3221
|
+
*/
|
|
3222
|
+
const TableHeader = ({ canResize = true, showSelector = false, isSticky = true, tableHeaderProps = {}, tableRowProps = {}, defaultTexts = {}, }) => {
|
|
3117
3223
|
const { table } = useDataTableContext();
|
|
3118
3224
|
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;
|
|
3225
|
+
// Merge default texts with provided defaults
|
|
3226
|
+
const mergedDefaultTexts = { ...DEFAULT_HEADER_TEXTS, ...defaultTexts };
|
|
3227
|
+
// Helper function to get text for a specific header
|
|
3228
|
+
const getHeaderText = (header, key) => {
|
|
3229
|
+
const columnMeta = header.column.columnDef.meta;
|
|
3230
|
+
return columnMeta?.headerTexts?.[key] || mergedDefaultTexts[key];
|
|
3134
3231
|
};
|
|
3135
3232
|
const getThProps = (header) => {
|
|
3136
3233
|
const thProps = header.column.getIsPinned()
|
|
@@ -3138,12 +3235,8 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3138
3235
|
left: showSelector
|
|
3139
3236
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3140
3237
|
: `${header.getStart("left")}px`,
|
|
3141
|
-
background: pinnedBgColor.light,
|
|
3142
3238
|
position: "sticky",
|
|
3143
3239
|
zIndex: 100 + 1,
|
|
3144
|
-
_dark: {
|
|
3145
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3146
|
-
},
|
|
3147
3240
|
}
|
|
3148
3241
|
: {};
|
|
3149
3242
|
return thProps;
|
|
@@ -3152,21 +3245,13 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3152
3245
|
position: "sticky",
|
|
3153
3246
|
top: 0,
|
|
3154
3247
|
};
|
|
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) => {
|
|
3248
|
+
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: {
|
|
3249
|
+
base: "colorPalette.900",
|
|
3250
|
+
_dark: "colorPalette.100",
|
|
3251
|
+
},
|
|
3252
|
+
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(),
|
|
3253
|
+
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3254
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), headerGroup.headers.map((header) => {
|
|
3170
3255
|
const resizeProps = {
|
|
3171
3256
|
onMouseDown: header.getResizeHandler(),
|
|
3172
3257
|
onTouchStart: header.getResizeHandler(),
|
|
@@ -3174,18 +3259,32 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3174
3259
|
};
|
|
3175
3260
|
return (jsxRuntime.jsxs(react.Table.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
|
|
3176
3261
|
// 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
|
-
|
|
3262
|
+
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index, color: {
|
|
3263
|
+
base: "colorPalette.800",
|
|
3264
|
+
_dark: "colorPalette.200",
|
|
3265
|
+
},
|
|
3266
|
+
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: {
|
|
3267
|
+
base: "colorPalette.800",
|
|
3268
|
+
_dark: "colorPalette.200",
|
|
3269
|
+
_hover: {
|
|
3270
|
+
base: "colorPalette.700",
|
|
3271
|
+
_dark: "colorPalette.300",
|
|
3272
|
+
},
|
|
3273
|
+
},
|
|
3274
|
+
bg: {
|
|
3275
|
+
base: "colorPalette.100",
|
|
3276
|
+
_dark: "colorPalette.900",
|
|
3277
|
+
_hover: {
|
|
3278
|
+
base: "colorPalette.200",
|
|
3279
|
+
_dark: "colorPalette.800",
|
|
3181
3280
|
},
|
|
3182
3281
|
}, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3183
3282
|
? null
|
|
3184
3283
|
: 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
3284
|
header.column.pin("left");
|
|
3186
|
-
}, children: [jsxRuntime.jsx(md.MdPushPin, {}),
|
|
3285
|
+
}, 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
3286
|
header.column.pin(false);
|
|
3188
|
-
}, children: [jsxRuntime.jsx(md.MdCancel, {}),
|
|
3287
|
+
}, 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
3288
|
table.setSorting((state) => {
|
|
3190
3289
|
return [
|
|
3191
3290
|
...state.filter((column) => {
|
|
@@ -3194,7 +3293,7 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3194
3293
|
{ id: header.id, desc: false },
|
|
3195
3294
|
];
|
|
3196
3295
|
});
|
|
3197
|
-
}, children: [jsxRuntime.jsx(gr.GrAscend, {}),
|
|
3296
|
+
}, children: [jsxRuntime.jsx(gr.GrAscend, {}), getHeaderText(header, "sortAscending")] }) }), jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3198
3297
|
table.setSorting((state) => {
|
|
3199
3298
|
return [
|
|
3200
3299
|
...state.filter((column) => {
|
|
@@ -3203,42 +3302,30 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3203
3302
|
{ id: header.id, desc: true },
|
|
3204
3303
|
];
|
|
3205
3304
|
});
|
|
3206
|
-
}, children: [jsxRuntime.jsx(gr.GrDescend, {}),
|
|
3305
|
+
}, 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
3306
|
header.column.clearSorting();
|
|
3208
|
-
}, children: [jsxRuntime.jsx(md.MdClear, {}),
|
|
3307
|
+
}, children: [jsxRuntime.jsx(md.MdClear, {}), getHeaderText(header, "clearSorting")] }) }))] }))] })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3308
|
+
? "colorPalette.700"
|
|
3309
|
+
: "transparent", position: "relative", right: "0.1rem", width: "2px", height: "100%", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
3209
3310
|
borderRightColor: header.column.getIsResizing()
|
|
3210
|
-
? "
|
|
3211
|
-
: "
|
|
3311
|
+
? "colorPalette.700"
|
|
3312
|
+
: "colorPalette.400",
|
|
3212
3313
|
}, ...resizeProps }))] }, `chakra-table-header-${header.id}`));
|
|
3213
3314
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
3214
3315
|
};
|
|
3215
3316
|
|
|
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 = "", }) => {
|
|
3317
|
+
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, tableFooterProps = {}, controlProps = {}, variant = "", }) => {
|
|
3231
3318
|
if (variant === "greedy") {
|
|
3232
3319
|
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
3320
|
}
|
|
3234
3321
|
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
3322
|
};
|
|
3236
3323
|
|
|
3237
|
-
const TableCardContainer = ({ children, variant = "", ...props }) => {
|
|
3324
|
+
const TableCardContainer = ({ children, variant = "", gap = "1rem", gridTemplateColumns = "repeat(auto-fit, minmax(20rem, 1fr))", direction = "row", ...props }) => {
|
|
3238
3325
|
if (variant === "carousel") {
|
|
3239
|
-
return (jsxRuntime.jsx(react.Flex, { overflow: "
|
|
3326
|
+
return (jsxRuntime.jsx(react.Flex, { overflow: "auto", gap: gap, direction: direction, ...props, children: children }));
|
|
3240
3327
|
}
|
|
3241
|
-
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns:
|
|
3328
|
+
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns: gridTemplateColumns, gap: gap, ...props, children: children }));
|
|
3242
3329
|
};
|
|
3243
3330
|
|
|
3244
3331
|
const DefaultCardTitle = () => {
|
|
@@ -3267,8 +3354,8 @@ const TableComponent = ({ render = () => {
|
|
|
3267
3354
|
};
|
|
3268
3355
|
|
|
3269
3356
|
const TableLoadingComponent = ({ render, }) => {
|
|
3270
|
-
const {
|
|
3271
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(
|
|
3357
|
+
const { query } = useDataTableServerContext();
|
|
3358
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: render(query.isLoading) });
|
|
3272
3359
|
};
|
|
3273
3360
|
|
|
3274
3361
|
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
@@ -3487,6 +3574,70 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
|
|
|
3487
3574
|
return columns;
|
|
3488
3575
|
};
|
|
3489
3576
|
|
|
3577
|
+
const TableDataDisplay = ({ colorPalette, emptyComponent, }) => {
|
|
3578
|
+
const { columns, translate, data } = useDataTableContext();
|
|
3579
|
+
const columnsMap = Object.fromEntries(columns.map((def) => {
|
|
3580
|
+
const { accessorKey, id } = def;
|
|
3581
|
+
if (accessorKey) {
|
|
3582
|
+
return [accessorKey, def];
|
|
3583
|
+
}
|
|
3584
|
+
return [id, def];
|
|
3585
|
+
}));
|
|
3586
|
+
const columnHeaders = Object.keys(columnsMap);
|
|
3587
|
+
const totalWidths = columns
|
|
3588
|
+
.map(({ size }) => {
|
|
3589
|
+
if (!!size === false) {
|
|
3590
|
+
return 0;
|
|
3591
|
+
}
|
|
3592
|
+
if (typeof size === "number") {
|
|
3593
|
+
return size;
|
|
3594
|
+
}
|
|
3595
|
+
return 0;
|
|
3596
|
+
})
|
|
3597
|
+
.reduce((previous, current) => previous + current, 0);
|
|
3598
|
+
const columnWidths = columns
|
|
3599
|
+
.map(({ size }) => {
|
|
3600
|
+
if (!!size === false) {
|
|
3601
|
+
return "1fr";
|
|
3602
|
+
}
|
|
3603
|
+
return `minmax(${size}px, ${(size / totalWidths) * 100}%)`;
|
|
3604
|
+
})
|
|
3605
|
+
.join(" ");
|
|
3606
|
+
console.log({ columnWidths }, "hadfg");
|
|
3607
|
+
const cellProps = {
|
|
3608
|
+
flex: "1 0 0%",
|
|
3609
|
+
overflow: "auto",
|
|
3610
|
+
paddingX: "2",
|
|
3611
|
+
py: "1",
|
|
3612
|
+
color: { base: "colorPalette.900", _dark: "colorPalette.100" },
|
|
3613
|
+
bgColor: { base: "colorPalette.50", _dark: "colorPalette.950" },
|
|
3614
|
+
borderBottomColor: { base: "colorPalette.200", _dark: "colorPalette.800" },
|
|
3615
|
+
borderBottomWidth: "1px",
|
|
3616
|
+
...{ colorPalette },
|
|
3617
|
+
};
|
|
3618
|
+
if (data.length <= 0) {
|
|
3619
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: emptyComponent });
|
|
3620
|
+
}
|
|
3621
|
+
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) => {
|
|
3622
|
+
return (jsxRuntime.jsx(react.Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
|
|
3623
|
+
}) }), data.map((record) => {
|
|
3624
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: columnHeaders.map((header) => {
|
|
3625
|
+
const { cell } = columnsMap[header];
|
|
3626
|
+
const value = record[header];
|
|
3627
|
+
if (!!record === false) {
|
|
3628
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
|
|
3629
|
+
}
|
|
3630
|
+
if (cell) {
|
|
3631
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: cell({ row: { original: record } }) }));
|
|
3632
|
+
}
|
|
3633
|
+
if (typeof value === "object") {
|
|
3634
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: jsxRuntime.jsx(RecordDisplay, { object: value }) }));
|
|
3635
|
+
}
|
|
3636
|
+
return jsxRuntime.jsx(react.Box, { ...cellProps, children: value });
|
|
3637
|
+
}) }));
|
|
3638
|
+
})] }));
|
|
3639
|
+
};
|
|
3640
|
+
|
|
3490
3641
|
const AccordionItemTrigger = React__namespace.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
3491
3642
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
3492
3643
|
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 +3721,7 @@ const FormRoot = ({ schema, idMap, setIdMap, form, serverUrl, translate, childre
|
|
|
3570
3721
|
};
|
|
3571
3722
|
|
|
3572
3723
|
function removeIndex(str) {
|
|
3573
|
-
return str.replace(/\.\d+\./g,
|
|
3724
|
+
return str.replace(/\.\d+\./g, ".");
|
|
3574
3725
|
}
|
|
3575
3726
|
|
|
3576
3727
|
const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
@@ -3582,13 +3733,17 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3582
3733
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3583
3734
|
const { formState: { errors }, setValue, watch, } = reactHookForm.useFormContext();
|
|
3584
3735
|
const fields = (watch(colLabel) ?? []);
|
|
3585
|
-
return (jsxRuntime.jsxs(react.
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3736
|
+
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: {
|
|
3737
|
+
base: "colorPalette.200",
|
|
3738
|
+
_dark: "colorPalette.800",
|
|
3739
|
+
}, children: [jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaRenderer, { column: `${index}`,
|
|
3740
|
+
prefix: `${colLabel}.`,
|
|
3741
|
+
// @ts-expect-error find suitable types
|
|
3742
|
+
schema: { showLabel: false, ...(items ?? {}) } }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "end", children: jsxRuntime.jsx(react.Button, { variant: "ghost", onClick: () => {
|
|
3743
|
+
setValue(colLabel, fields.filter((_, curIndex) => {
|
|
3744
|
+
return curIndex !== index;
|
|
3745
|
+
}));
|
|
3746
|
+
}, children: jsxRuntime.jsx(react.Icon, { children: jsxRuntime.jsx(cg.CgTrash, {}) }) }) })] }, `${colLabel}.${index}`))) }), jsxRuntime.jsx(react.Flex, { children: jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
3592
3747
|
if (type === "number") {
|
|
3593
3748
|
setValue(colLabel, [...fields, 0]);
|
|
3594
3749
|
return;
|
|
@@ -3602,7 +3757,7 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3602
3757
|
return;
|
|
3603
3758
|
}
|
|
3604
3759
|
setValue(colLabel, [...fields, {}]);
|
|
3605
|
-
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3760
|
+
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3606
3761
|
};
|
|
3607
3762
|
|
|
3608
3763
|
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
@@ -3613,14 +3768,26 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
|
3613
3768
|
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3614
3769
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3615
3770
|
const { translate } = useSchemaContext();
|
|
3616
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3771
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
3617
3772
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3618
3773
|
const colLabel = `${prefix}${column}`;
|
|
3619
3774
|
const value = watch(colLabel);
|
|
3620
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
3775
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3621
3776
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
|
|
3622
3777
|
setValue(colLabel, !value);
|
|
3623
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3778
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3779
|
+
};
|
|
3780
|
+
|
|
3781
|
+
const CustomInput = ({ column, schema, prefix }) => {
|
|
3782
|
+
const formContext = reactHookForm.useFormContext();
|
|
3783
|
+
const { inputRender } = schema;
|
|
3784
|
+
return (inputRender &&
|
|
3785
|
+
inputRender({
|
|
3786
|
+
column,
|
|
3787
|
+
schema,
|
|
3788
|
+
prefix,
|
|
3789
|
+
formContext,
|
|
3790
|
+
}));
|
|
3624
3791
|
};
|
|
3625
3792
|
|
|
3626
3793
|
const monthNamesShort = [
|
|
@@ -3710,28 +3877,54 @@ const PopoverRoot = react.Popover.Root;
|
|
|
3710
3877
|
const PopoverBody = react.Popover.Body;
|
|
3711
3878
|
const PopoverTrigger = react.Popover.Trigger;
|
|
3712
3879
|
|
|
3880
|
+
dayjs.extend(utc);
|
|
3713
3881
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3714
3882
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3715
3883
|
const { translate } = useSchemaContext();
|
|
3716
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3884
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3717
3885
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3718
3886
|
const colLabel = `${prefix}${column}`;
|
|
3719
3887
|
const [open, setOpen] = React.useState(false);
|
|
3720
3888
|
const selectedDate = watch(colLabel);
|
|
3721
|
-
const
|
|
3722
|
-
|
|
3723
|
-
|
|
3889
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3890
|
+
React.useEffect(() => {
|
|
3891
|
+
try {
|
|
3892
|
+
if (selectedDate) {
|
|
3893
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3894
|
+
// For example, parse as UTC:
|
|
3895
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3896
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3897
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3898
|
+
if (!parsedDate.isValid())
|
|
3899
|
+
return;
|
|
3900
|
+
// Format according to dateFormat from schema
|
|
3901
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3902
|
+
// Update the form value only if different to avoid loops
|
|
3903
|
+
if (formatted !== selectedDate) {
|
|
3904
|
+
setValue(colLabel, formatted, {
|
|
3905
|
+
shouldValidate: true,
|
|
3906
|
+
shouldDirty: true,
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
catch (e) {
|
|
3912
|
+
console.error(e);
|
|
3913
|
+
}
|
|
3914
|
+
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3915
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3916
|
+
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
3917
|
setOpen(true);
|
|
3725
|
-
}, children: selectedDate !== undefined ? `${
|
|
3918
|
+
}, 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
3919
|
// @ts-expect-error TODO: find appropriate types
|
|
3727
3920
|
, {
|
|
3728
3921
|
// @ts-expect-error TODO: find appropriate types
|
|
3729
3922
|
selected: new Date(selectedDate),
|
|
3730
3923
|
// @ts-expect-error TODO: find appropriate types
|
|
3731
3924
|
onDateSelected: ({ date }) => {
|
|
3732
|
-
setValue(colLabel, dayjs(date).format(
|
|
3925
|
+
setValue(colLabel, dayjs(date).format(dateFormat));
|
|
3733
3926
|
setOpen(false);
|
|
3734
|
-
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3927
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3735
3928
|
};
|
|
3736
3929
|
|
|
3737
3930
|
function filterArray(array, searchTerm) {
|
|
@@ -3744,12 +3937,12 @@ function filterArray(array, searchTerm) {
|
|
|
3744
3937
|
});
|
|
3745
3938
|
}
|
|
3746
3939
|
|
|
3747
|
-
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3940
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, showTotalAndLimit = false, }) => {
|
|
3748
3941
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3749
3942
|
const { translate } = useSchemaContext();
|
|
3750
|
-
const { required } = schema;
|
|
3943
|
+
const { required, variant } = schema;
|
|
3751
3944
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3752
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3945
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
3753
3946
|
const [searchText, setSearchText] = React.useState();
|
|
3754
3947
|
const [limit, setLimit] = React.useState(10);
|
|
3755
3948
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -3764,28 +3957,61 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3764
3957
|
setSearchText(event.target.value);
|
|
3765
3958
|
setLimit(10);
|
|
3766
3959
|
};
|
|
3767
|
-
|
|
3960
|
+
if (variant === "radio") {
|
|
3961
|
+
return (jsxRuntime.jsx(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3962
|
+
gridRow, children: jsxRuntime.jsx(react.RadioGroup.Root, { defaultValue: "1", children: jsxRuntime.jsx(react.HStack, { gap: "6", children: filterArray(dataList, searchText ?? "").map((item) => {
|
|
3963
|
+
return (jsxRuntime.jsxs(react.RadioGroup.Item, { onClick: () => {
|
|
3964
|
+
if (!isMultiple) {
|
|
3965
|
+
setOpenSearchResult(false);
|
|
3966
|
+
setValue(colLabel, item);
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3970
|
+
setValue(colLabel, [...newSet]);
|
|
3971
|
+
}, value: item, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, {}), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), jsxRuntime.jsx(react.RadioGroup.ItemText, { children: !!renderDisplay === true
|
|
3972
|
+
? renderDisplay(item)
|
|
3973
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) })] }, `${colLabel}-${item}`));
|
|
3974
|
+
}) }) }) }));
|
|
3975
|
+
}
|
|
3976
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3768
3977
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3769
3978
|
const item = enumValue;
|
|
3770
|
-
if (item ===
|
|
3771
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
3979
|
+
if (!!item === false) {
|
|
3980
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
3772
3981
|
}
|
|
3773
3982
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3774
|
-
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3775
3983
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3776
3984
|
}, children: !!renderDisplay === true
|
|
3777
3985
|
? renderDisplay(item)
|
|
3778
3986
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3779
3987
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3780
3988
|
setOpenSearchResult(true);
|
|
3781
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
3989
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3782
3990
|
setOpenSearchResult(true);
|
|
3783
|
-
}, children: watchEnum ===
|
|
3991
|
+
}, justifyContent: "start", children: !!watchEnum === false
|
|
3784
3992
|
? ""
|
|
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(`${
|
|
3993
|
+
: 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
3994
|
onSearchChange(event);
|
|
3787
3995
|
setOpenSearchResult(true);
|
|
3788
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${translate.t(`${
|
|
3996
|
+
}, 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
|
|
3997
|
+
.filter((item) => {
|
|
3998
|
+
const searchTerm = (searchText || "").toLowerCase();
|
|
3999
|
+
if (!searchTerm)
|
|
4000
|
+
return true;
|
|
4001
|
+
// Check if the original enum value contains the search text
|
|
4002
|
+
const enumValueMatch = item
|
|
4003
|
+
.toLowerCase()
|
|
4004
|
+
.includes(searchTerm);
|
|
4005
|
+
// Check if the display value (translation) contains the search text
|
|
4006
|
+
const displayValue = !!renderDisplay === true
|
|
4007
|
+
? renderDisplay(item)
|
|
4008
|
+
: translate.t(removeIndex(`${colLabel}.${item}`));
|
|
4009
|
+
// Convert to string and check if it includes the search term
|
|
4010
|
+
const displayValueString = String(displayValue).toLowerCase();
|
|
4011
|
+
const displayValueMatch = displayValueString.includes(searchTerm);
|
|
4012
|
+
return enumValueMatch || displayValueMatch;
|
|
4013
|
+
})
|
|
4014
|
+
.map((item) => {
|
|
3789
4015
|
const selected = isMultiple
|
|
3790
4016
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3791
4017
|
: watchEnum == item;
|
|
@@ -3797,10 +4023,10 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3797
4023
|
}
|
|
3798
4024
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3799
4025
|
setValue(colLabel, [...newSet]);
|
|
3800
|
-
}, ...(selected ? { color: "
|
|
4026
|
+
}, ...(selected ? { color: "colorPalette.400/50" } : {}), children: !!renderDisplay === true
|
|
3801
4027
|
? renderDisplay(item)
|
|
3802
4028
|
: 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}.
|
|
4029
|
+
}) }), 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
4030
|
};
|
|
3805
4031
|
|
|
3806
4032
|
function isEnteringWindow(_ref) {
|
|
@@ -4152,17 +4378,17 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4152
4378
|
const filesArray = [...event.target.files];
|
|
4153
4379
|
onDrop({ files: filesArray });
|
|
4154
4380
|
};
|
|
4155
|
-
return (jsxRuntime.jsxs(react.Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "
|
|
4381
|
+
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
4382
|
};
|
|
4157
4383
|
|
|
4158
4384
|
const FilePicker = ({ column, schema, prefix }) => {
|
|
4159
4385
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4160
4386
|
const { translate } = useSchemaContext();
|
|
4161
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4387
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4162
4388
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4163
4389
|
const currentFiles = (watch(column) ?? []);
|
|
4164
4390
|
const colLabel = `${prefix}${column}`;
|
|
4165
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.
|
|
4391
|
+
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
4392
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4167
4393
|
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4168
4394
|
}, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
@@ -4170,10 +4396,19 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4170
4396
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4171
4397
|
return name !== file.name;
|
|
4172
4398
|
}));
|
|
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}.
|
|
4399
|
+
}, 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));
|
|
4400
|
+
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4175
4401
|
};
|
|
4176
4402
|
|
|
4403
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
4404
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
4405
|
+
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] }) }) })] }));
|
|
4406
|
+
});
|
|
4407
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
4408
|
+
const { children, ...rest } = props;
|
|
4409
|
+
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, {}) }) }));
|
|
4410
|
+
});
|
|
4411
|
+
|
|
4177
4412
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4178
4413
|
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4179
4414
|
throw new Error("The serverUrl is missing");
|
|
@@ -4205,15 +4440,18 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
4205
4440
|
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4206
4441
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4207
4442
|
const { serverUrl, idMap, setIdMap, translate, schema: parentSchema, } = useSchemaContext();
|
|
4208
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4443
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4209
4444
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4210
4445
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4211
|
-
const [searchText, setSearchText] = React.useState();
|
|
4446
|
+
const [searchText, setSearchText] = React.useState("");
|
|
4212
4447
|
const [limit, setLimit] = React.useState(10);
|
|
4213
4448
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
4214
4449
|
const [page, setPage] = React.useState(0);
|
|
4215
4450
|
const ref = React.useRef(null);
|
|
4216
4451
|
const colLabel = `${prefix}${column}`;
|
|
4452
|
+
const watchId = watch(colLabel);
|
|
4453
|
+
const watchIds = isMultiple ? (watch(colLabel) ?? []) : [];
|
|
4454
|
+
// Query for search results
|
|
4217
4455
|
const query = reactQuery.useQuery({
|
|
4218
4456
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4219
4457
|
queryFn: async () => {
|
|
@@ -4222,7 +4460,7 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4222
4460
|
searching: searchText ?? "",
|
|
4223
4461
|
in_table: table,
|
|
4224
4462
|
limit: limit,
|
|
4225
|
-
offset: page *
|
|
4463
|
+
offset: page * limit,
|
|
4226
4464
|
});
|
|
4227
4465
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4228
4466
|
return [
|
|
@@ -4237,27 +4475,27 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4237
4475
|
});
|
|
4238
4476
|
return data;
|
|
4239
4477
|
},
|
|
4240
|
-
enabled:
|
|
4478
|
+
enabled: openSearchResult === true,
|
|
4241
4479
|
staleTime: 300000,
|
|
4242
4480
|
});
|
|
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({
|
|
4481
|
+
// Query for currently selected items (to display them properly)
|
|
4482
|
+
const queryDefault = reactQuery.useQuery({
|
|
4250
4483
|
queryKey: [
|
|
4251
|
-
`idpicker`,
|
|
4252
|
-
{ form: parentSchema.title, column,
|
|
4484
|
+
`idpicker-default`,
|
|
4485
|
+
{ form: parentSchema.title, column, id: isMultiple ? watchIds : watchId },
|
|
4253
4486
|
],
|
|
4254
4487
|
queryFn: async () => {
|
|
4488
|
+
if (!watchId && (!watchIds || watchIds.length === 0)) {
|
|
4489
|
+
return { data: [] };
|
|
4490
|
+
}
|
|
4491
|
+
const searchValue = isMultiple ? watchIds.join(",") : watchId;
|
|
4255
4492
|
const data = await getTableData({
|
|
4256
4493
|
serverUrl,
|
|
4257
|
-
searching:
|
|
4494
|
+
searching: searchValue,
|
|
4258
4495
|
in_table: table,
|
|
4259
|
-
|
|
4260
|
-
|
|
4496
|
+
where: [{ id: column_ref, value: isMultiple ? watchIds : watchId }],
|
|
4497
|
+
limit: isMultiple ? watchIds.length : 1,
|
|
4498
|
+
offset: 0,
|
|
4261
4499
|
});
|
|
4262
4500
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4263
4501
|
return [
|
|
@@ -4272,12 +4510,45 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4272
4510
|
});
|
|
4273
4511
|
return data;
|
|
4274
4512
|
},
|
|
4513
|
+
enabled: isMultiple
|
|
4514
|
+
? Array.isArray(watchIds) && watchIds.length > 0
|
|
4515
|
+
: !!watchId,
|
|
4275
4516
|
});
|
|
4517
|
+
// Effect to load selected values when component mounts
|
|
4518
|
+
React.useEffect(() => {
|
|
4519
|
+
if (isMultiple ? watchIds.length > 0 : !!watchId) {
|
|
4520
|
+
queryDefault.refetch();
|
|
4521
|
+
}
|
|
4522
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4523
|
+
}, []);
|
|
4524
|
+
// Effect to trigger initial data fetch when popover opens
|
|
4525
|
+
React.useEffect(() => {
|
|
4526
|
+
if (openSearchResult) {
|
|
4527
|
+
// Reset search text when opening the popover
|
|
4528
|
+
setSearchText("");
|
|
4529
|
+
// Reset page to first page
|
|
4530
|
+
setPage(0);
|
|
4531
|
+
// Fetch initial data
|
|
4532
|
+
query.refetch();
|
|
4533
|
+
}
|
|
4534
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4535
|
+
}, [openSearchResult]);
|
|
4276
4536
|
const onSearchChange = async (event) => {
|
|
4277
4537
|
setSearchText(event.target.value);
|
|
4278
4538
|
setPage(0);
|
|
4279
|
-
|
|
4539
|
+
query.refetch();
|
|
4540
|
+
};
|
|
4541
|
+
const handleLimitChange = (event) => {
|
|
4542
|
+
const newLimit = Number(event.target.value);
|
|
4543
|
+
setLimit(newLimit);
|
|
4544
|
+
// Reset to first page when changing limit
|
|
4545
|
+
setPage(0);
|
|
4546
|
+
// Trigger a new search with the updated limit
|
|
4547
|
+
query.refetch();
|
|
4280
4548
|
};
|
|
4549
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4550
|
+
const dataList = data?.data ?? [];
|
|
4551
|
+
const count = data?.count ?? 0;
|
|
4281
4552
|
const getPickedValue = () => {
|
|
4282
4553
|
if (Object.keys(idMap).length <= 0) {
|
|
4283
4554
|
return "";
|
|
@@ -4286,47 +4557,57 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4286
4557
|
if (record === undefined) {
|
|
4287
4558
|
return "";
|
|
4288
4559
|
}
|
|
4560
|
+
if (!!renderDisplay === true) {
|
|
4561
|
+
return renderDisplay(record);
|
|
4562
|
+
}
|
|
4289
4563
|
return record[display_column];
|
|
4290
4564
|
};
|
|
4291
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.
|
|
4565
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.field_label`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4292
4566
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
|
|
4293
4567
|
const item = idMap[id];
|
|
4294
4568
|
if (item === undefined) {
|
|
4295
4569
|
return (jsxRuntime.jsx(react.Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4296
4570
|
}
|
|
4297
4571
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
4298
|
-
setValue(
|
|
4572
|
+
setValue(colLabel, watchIds.filter((itemId) => itemId !== item[column_ref]));
|
|
4299
4573
|
}, children: !!renderDisplay === true
|
|
4300
4574
|
? renderDisplay(item)
|
|
4301
4575
|
: item[display_column] }, id));
|
|
4302
4576
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4303
4577
|
setOpenSearchResult(true);
|
|
4304
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
4578
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
4305
4579
|
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
|
-
|
|
4580
|
+
}, 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: {
|
|
4581
|
+
padding: "4px 8px",
|
|
4582
|
+
borderRadius: "4px",
|
|
4583
|
+
border: "1px solid #ccc",
|
|
4584
|
+
fontSize: "14px",
|
|
4585
|
+
}, 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) => {
|
|
4586
|
+
const selected = isMultiple
|
|
4587
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4588
|
+
: watchId === item[column_ref];
|
|
4589
|
+
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
4590
|
+
if (!isMultiple) {
|
|
4591
|
+
setOpenSearchResult(false);
|
|
4592
|
+
setValue(colLabel, item[column_ref]);
|
|
4593
|
+
return;
|
|
4594
|
+
}
|
|
4595
|
+
// For multiple selection, don't add if already selected
|
|
4596
|
+
if (selected)
|
|
4597
|
+
return;
|
|
4598
|
+
const newSet = new Set([
|
|
4599
|
+
...(watchIds ?? []),
|
|
4600
|
+
item[column_ref],
|
|
4601
|
+
]);
|
|
4602
|
+
setValue(colLabel, [...newSet]);
|
|
4603
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected
|
|
4604
|
+
? { color: "colorPalette.400/50", fontWeight: "bold" }
|
|
4605
|
+
: {}), children: !!renderDisplay === true
|
|
4606
|
+
? renderDisplay(item)
|
|
4607
|
+
: item[display_column] }, item[column_ref]));
|
|
4608
|
+
}) })) : (jsxRuntime.jsx(react.Text, { children: searchText
|
|
4609
|
+
? translate.t(removeIndex(`${colLabel}.empty_search_result`))
|
|
4610
|
+
: 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
4611
|
};
|
|
4331
4612
|
|
|
4332
4613
|
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
@@ -4340,17 +4621,17 @@ react.NumberInput.Label;
|
|
|
4340
4621
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4341
4622
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4342
4623
|
const { translate } = useSchemaContext();
|
|
4343
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4624
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4344
4625
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4345
4626
|
const colLabel = `${prefix}${column}`;
|
|
4346
4627
|
const value = watch(`${colLabel}`);
|
|
4347
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4628
|
+
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
4629
|
setValue(`${colLabel}`, Number(event.target.value));
|
|
4349
|
-
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4630
|
+
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4350
4631
|
};
|
|
4351
4632
|
|
|
4352
4633
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4353
|
-
const { properties,
|
|
4634
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, showLabel = true, } = schema;
|
|
4354
4635
|
const { translate } = useSchemaContext();
|
|
4355
4636
|
const colLabel = `${prefix}${column}`;
|
|
4356
4637
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4358,25 +4639,28 @@ const ObjectInput = ({ schema, column, prefix }) => {
|
|
|
4358
4639
|
if (properties === undefined) {
|
|
4359
4640
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4360
4641
|
}
|
|
4361
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
4642
|
+
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: {
|
|
4643
|
+
base: "colorPalette.200",
|
|
4644
|
+
_dark: "colorPalette.800",
|
|
4645
|
+
}, gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: Object.keys(properties ?? {}).map((key) => {
|
|
4362
4646
|
return (
|
|
4363
4647
|
// @ts-expect-error find suitable types
|
|
4364
4648
|
jsxRuntime.jsx(ColumnRenderer, { column: `${key}`,
|
|
4365
4649
|
prefix: `${prefix}${column}.`,
|
|
4366
4650
|
properties }, `form-${colLabel}-${key}`));
|
|
4367
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4651
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4368
4652
|
};
|
|
4369
4653
|
|
|
4370
4654
|
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4371
4655
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4372
4656
|
const { translate } = useSchemaContext();
|
|
4373
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4657
|
+
const { required, gridColumn = "span 12", gridRow = "span 1" } = schema;
|
|
4374
4658
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4375
4659
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4376
4660
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4377
4661
|
const [newKey, setNewKey] = React.useState();
|
|
4378
4662
|
const [newValue, setNewValue] = React.useState();
|
|
4379
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
4663
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4380
4664
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4381
4665
|
const filtered = entries.filter(([target]) => {
|
|
4382
4666
|
return target !== key;
|
|
@@ -4416,16 +4700,16 @@ const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
|
4416
4700
|
setShowNewEntries(true);
|
|
4417
4701
|
setNewKey(undefined);
|
|
4418
4702
|
setNewValue(undefined);
|
|
4419
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
4703
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4420
4704
|
};
|
|
4421
4705
|
|
|
4422
4706
|
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4423
4707
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4424
4708
|
const { translate } = useSchemaContext();
|
|
4425
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4709
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4426
4710
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4427
4711
|
const colLabel = `${prefix}${column}`;
|
|
4428
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4712
|
+
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
4713
|
};
|
|
4430
4714
|
|
|
4431
4715
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4523,9 +4807,180 @@ const TagPicker = ({ column, schema, prefix }) => {
|
|
|
4523
4807
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4524
4808
|
};
|
|
4525
4809
|
|
|
4810
|
+
const TextAreaInput = ({ column, schema, prefix, }) => {
|
|
4811
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4812
|
+
const { translate } = useSchemaContext();
|
|
4813
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4814
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4815
|
+
const colLabel = `${prefix}${column}`;
|
|
4816
|
+
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`)) }))] }) }));
|
|
4817
|
+
};
|
|
4818
|
+
|
|
4819
|
+
function TimePicker$1({ hour, setHour, minute, setMinute, meridiem, setMeridiem, meridiemLabel = {
|
|
4820
|
+
am: "am",
|
|
4821
|
+
pm: "pm",
|
|
4822
|
+
}, onChange = (_newValue) => { }, }) {
|
|
4823
|
+
// Refs for focus management
|
|
4824
|
+
const hourInputRef = React.useRef(null);
|
|
4825
|
+
const minuteInputRef = React.useRef(null);
|
|
4826
|
+
React.useRef(null);
|
|
4827
|
+
// Centralized handler for key events, value changes, and focus management
|
|
4828
|
+
const handleKeyDown = (e, field) => {
|
|
4829
|
+
const input = e.target;
|
|
4830
|
+
const value = input.value;
|
|
4831
|
+
// Handle navigation between fields
|
|
4832
|
+
if (e.key === "Tab") {
|
|
4833
|
+
// Tab is handled by the browser, no need to override
|
|
4834
|
+
return;
|
|
4835
|
+
}
|
|
4836
|
+
if (e.key === ":" && field === "hour") {
|
|
4837
|
+
e.preventDefault();
|
|
4838
|
+
minuteInputRef.current?.focus();
|
|
4839
|
+
return;
|
|
4840
|
+
}
|
|
4841
|
+
if (e.key === "Backspace" && value === "") {
|
|
4842
|
+
e.preventDefault();
|
|
4843
|
+
if (field === "minute") {
|
|
4844
|
+
hourInputRef.current?.focus();
|
|
4845
|
+
}
|
|
4846
|
+
else if (field === "meridiem") {
|
|
4847
|
+
minuteInputRef.current?.focus();
|
|
4848
|
+
}
|
|
4849
|
+
return;
|
|
4850
|
+
}
|
|
4851
|
+
// Handle number inputs
|
|
4852
|
+
if (field === "hour") {
|
|
4853
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4854
|
+
const newValue = value + e.key;
|
|
4855
|
+
const numValue = parseInt(newValue, 10);
|
|
4856
|
+
console.log("newValue", newValue, numValue);
|
|
4857
|
+
if (numValue > 12) {
|
|
4858
|
+
const digitValue = parseInt(e.key, 10);
|
|
4859
|
+
setHour(digitValue);
|
|
4860
|
+
onChange({ hour: digitValue, minute, meridiem });
|
|
4861
|
+
return;
|
|
4862
|
+
}
|
|
4863
|
+
// Auto-advance to minutes if we have a valid hour (1-12)
|
|
4864
|
+
if (numValue >= 1 && numValue <= 12) {
|
|
4865
|
+
// Set the hour value
|
|
4866
|
+
setHour(numValue);
|
|
4867
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4868
|
+
// Move to minute input
|
|
4869
|
+
e.preventDefault();
|
|
4870
|
+
minuteInputRef.current?.focus();
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
else if (field === "minute") {
|
|
4875
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4876
|
+
const newValue = value + e.key;
|
|
4877
|
+
const numValue = parseInt(newValue, 10);
|
|
4878
|
+
console.log("newValue minute", newValue, numValue, numValue > 60, numValue >= 0 && numValue <= 59, e.key);
|
|
4879
|
+
if (numValue > 60) {
|
|
4880
|
+
const digitValue = parseInt(e.key, 10);
|
|
4881
|
+
setMinute(digitValue);
|
|
4882
|
+
onChange({ hour, minute: digitValue, meridiem });
|
|
4883
|
+
return;
|
|
4884
|
+
}
|
|
4885
|
+
// Auto-advance to meridiem if we have a valid minute (0-59)
|
|
4886
|
+
if (numValue >= 0 && numValue <= 59) {
|
|
4887
|
+
// Set the minute value
|
|
4888
|
+
setMinute(numValue);
|
|
4889
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4890
|
+
}
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
};
|
|
4894
|
+
// Handle meridiem button click
|
|
4895
|
+
const handleMeridiemClick = (newMeridiem) => {
|
|
4896
|
+
setMeridiem(newMeridiem);
|
|
4897
|
+
onChange({ hour, minute, meridiem: newMeridiem });
|
|
4898
|
+
};
|
|
4899
|
+
const handleClear = () => {
|
|
4900
|
+
setHour(null);
|
|
4901
|
+
setMinute(null);
|
|
4902
|
+
setMeridiem(null);
|
|
4903
|
+
onChange({ hour: null, minute: null, meridiem: null });
|
|
4904
|
+
// Focus the hour field after clearing
|
|
4905
|
+
hourInputRef.current?.focus();
|
|
4906
|
+
};
|
|
4907
|
+
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, {}) })] }) }));
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
const TimePicker = ({ column, schema, prefix }) => {
|
|
4911
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4912
|
+
const { translate } = useSchemaContext();
|
|
4913
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", timeFormat = "HH:mm:ss", displayTimeFormat = "hh:mm A", } = schema;
|
|
4914
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4915
|
+
const colLabel = `${prefix}${column}`;
|
|
4916
|
+
const [open, setOpen] = React.useState(false);
|
|
4917
|
+
const value = watch(colLabel);
|
|
4918
|
+
const displayedTime = dayjs(`1970-01-01T${value}Z`).isValid()
|
|
4919
|
+
? dayjs(`1970-01-01T${value}Z`).utc().format(displayTimeFormat)
|
|
4920
|
+
: "";
|
|
4921
|
+
// Parse the initial time parts from the ISO time string (HH:mm:ss)
|
|
4922
|
+
const parseTime = (isoTime) => {
|
|
4923
|
+
if (!isoTime)
|
|
4924
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4925
|
+
const parsed = dayjs(`1970-01-01T${isoTime}Z`).utc();
|
|
4926
|
+
if (!parsed.isValid())
|
|
4927
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4928
|
+
let hour = parsed.hour();
|
|
4929
|
+
const minute = parsed.minute();
|
|
4930
|
+
const meridiem = hour >= 12 ? "pm" : "am";
|
|
4931
|
+
if (hour === 0)
|
|
4932
|
+
hour = 12;
|
|
4933
|
+
else if (hour > 12)
|
|
4934
|
+
hour -= 12;
|
|
4935
|
+
return { hour, minute, meridiem };
|
|
4936
|
+
};
|
|
4937
|
+
const initialTime = parseTime(value);
|
|
4938
|
+
const [hour, setHour] = React.useState(initialTime.hour);
|
|
4939
|
+
const [minute, setMinute] = React.useState(initialTime.minute);
|
|
4940
|
+
const [meridiem, setMeridiem] = React.useState(initialTime.meridiem);
|
|
4941
|
+
React.useEffect(() => {
|
|
4942
|
+
const { hour, minute, meridiem } = parseTime(value);
|
|
4943
|
+
setHour(hour);
|
|
4944
|
+
setMinute(minute);
|
|
4945
|
+
setMeridiem(meridiem);
|
|
4946
|
+
}, [value]);
|
|
4947
|
+
// Convert hour, minute, meridiem to 24-hour ISO time string
|
|
4948
|
+
const toIsoTime = (hour, minute, meridiem) => {
|
|
4949
|
+
if (hour === null || minute === null || meridiem === null)
|
|
4950
|
+
return null;
|
|
4951
|
+
let h = hour;
|
|
4952
|
+
if (meridiem === "am" && hour === 12)
|
|
4953
|
+
h = 0;
|
|
4954
|
+
else if (meridiem === "pm" && hour < 12)
|
|
4955
|
+
h = hour + 12;
|
|
4956
|
+
return dayjs(`1970-01-01T${h.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}:00Z`)
|
|
4957
|
+
.utc()
|
|
4958
|
+
.format(timeFormat);
|
|
4959
|
+
};
|
|
4960
|
+
// Handle changes to time parts
|
|
4961
|
+
const handleTimeChange = ({ hour: newHour, minute: newMinute, meridiem: newMeridiem, }) => {
|
|
4962
|
+
setHour(newHour);
|
|
4963
|
+
setMinute(newMinute);
|
|
4964
|
+
setMeridiem(newMeridiem);
|
|
4965
|
+
const isoTime = toIsoTime(newHour, newMinute, newMeridiem);
|
|
4966
|
+
setValue(colLabel, isoTime, { shouldValidate: true, shouldDirty: true });
|
|
4967
|
+
};
|
|
4968
|
+
const containerRef = React.useRef(null);
|
|
4969
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4970
|
+
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: () => {
|
|
4971
|
+
setOpen(true);
|
|
4972
|
+
}, 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: {
|
|
4973
|
+
am: translate.t(removeIndex(`common.am`)),
|
|
4974
|
+
pm: translate.t(removeIndex(`common.pm`)),
|
|
4975
|
+
} }) }) }) }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4976
|
+
};
|
|
4977
|
+
|
|
4526
4978
|
const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
4527
4979
|
const colSchema = schema;
|
|
4528
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4980
|
+
const { type, variant, properties: innerProperties, foreign_key, format, items, } = schema;
|
|
4981
|
+
if (variant === "custom-input") {
|
|
4982
|
+
return jsxRuntime.jsx(CustomInput, { schema: colSchema, prefix, column });
|
|
4983
|
+
}
|
|
4529
4984
|
if (type === "string") {
|
|
4530
4985
|
if ((schema.enum ?? []).length > 0) {
|
|
4531
4986
|
return jsxRuntime.jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
@@ -4534,9 +4989,15 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4534
4989
|
idPickerSanityCheck(column, foreign_key);
|
|
4535
4990
|
return jsxRuntime.jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4536
4991
|
}
|
|
4537
|
-
if (
|
|
4992
|
+
if (format === "date") {
|
|
4538
4993
|
return jsxRuntime.jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4539
4994
|
}
|
|
4995
|
+
if (format === "time") {
|
|
4996
|
+
return jsxRuntime.jsx(TimePicker, { schema: colSchema, prefix, column });
|
|
4997
|
+
}
|
|
4998
|
+
if (variant === "text-area") {
|
|
4999
|
+
return jsxRuntime.jsx(TextAreaInput, { schema: colSchema, prefix, column });
|
|
5000
|
+
}
|
|
4540
5001
|
return jsxRuntime.jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4541
5002
|
}
|
|
4542
5003
|
if (type === "number" || type === "integer") {
|
|
@@ -4583,85 +5044,102 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4583
5044
|
};
|
|
4584
5045
|
|
|
4585
5046
|
const ArrayViewer = ({ schema, column, prefix }) => {
|
|
4586
|
-
const {
|
|
5047
|
+
const { gridColumn = "span 12", gridRow = "span 1", required, items, } = schema;
|
|
4587
5048
|
const { translate } = useSchemaContext();
|
|
4588
5049
|
const colLabel = `${prefix}${column}`;
|
|
4589
5050
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4590
5051
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4591
5052
|
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
|
-
|
|
5053
|
+
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: {
|
|
5054
|
+
base: "colorPalette.200",
|
|
5055
|
+
_dark: "colorPalette.800",
|
|
5056
|
+
}, children: jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaViewer, { column: `${index}`,
|
|
5057
|
+
prefix: `${colLabel}.`,
|
|
5058
|
+
// @ts-expect-error find suitable types
|
|
5059
|
+
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
5060
|
};
|
|
4596
5061
|
|
|
4597
5062
|
const BooleanViewer = ({ schema, column, prefix, }) => {
|
|
4598
5063
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4599
5064
|
const { translate } = useSchemaContext();
|
|
4600
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5065
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4601
5066
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4602
5067
|
const colLabel = `${prefix}${column}`;
|
|
4603
5068
|
const value = watch(colLabel);
|
|
4604
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5069
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4605
5070
|
gridRow, children: [jsxRuntime.jsx(react.Text, { children: value
|
|
4606
5071
|
? 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}.
|
|
5072
|
+
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
5073
|
+
};
|
|
5074
|
+
|
|
5075
|
+
const CustomViewer = ({ column, schema, prefix }) => {
|
|
5076
|
+
const formContext = reactHookForm.useFormContext();
|
|
5077
|
+
const { inputViewerRender } = schema;
|
|
5078
|
+
return (inputViewerRender &&
|
|
5079
|
+
inputViewerRender({
|
|
5080
|
+
column,
|
|
5081
|
+
schema,
|
|
5082
|
+
prefix,
|
|
5083
|
+
formContext,
|
|
5084
|
+
}));
|
|
4608
5085
|
};
|
|
4609
5086
|
|
|
4610
5087
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4611
5088
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4612
5089
|
const { translate } = useSchemaContext();
|
|
4613
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5090
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4614
5091
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4615
5092
|
const colLabel = `${prefix}${column}`;
|
|
4616
5093
|
const selectedDate = watch(colLabel);
|
|
4617
|
-
|
|
4618
|
-
|
|
5094
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
5095
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5096
|
+
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
5097
|
};
|
|
4620
5098
|
|
|
5099
|
+
function translateWrapper({ prefix, column, label, translate, }) {
|
|
5100
|
+
return translate.t(removeIndex(`${prefix}${column}.${label}`));
|
|
5101
|
+
}
|
|
5102
|
+
|
|
4621
5103
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
4622
5104
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4623
5105
|
const { translate } = useSchemaContext();
|
|
4624
5106
|
const { required } = schema;
|
|
4625
5107
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4626
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
5108
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
4627
5109
|
const colLabel = `${prefix}${column}`;
|
|
4628
5110
|
const watchEnum = watch(colLabel);
|
|
4629
5111
|
const watchEnums = (watch(colLabel) ?? []);
|
|
4630
|
-
|
|
5112
|
+
const customTranslate = (label) => {
|
|
5113
|
+
return translateWrapper({ prefix, column, label, translate });
|
|
5114
|
+
};
|
|
5115
|
+
return (jsxRuntime.jsxs(Field, { label: `${customTranslate(`field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4631
5116
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
|
|
4632
5117
|
const item = enumValue;
|
|
4633
5118
|
if (item === undefined) {
|
|
4634
5119
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
4635
5120
|
}
|
|
4636
|
-
return (jsxRuntime.jsx(Tag, {
|
|
5121
|
+
return (jsxRuntime.jsx(Tag, { children: !!renderDisplay === true
|
|
4637
5122
|
? renderDisplay(item)
|
|
4638
|
-
:
|
|
4639
|
-
}) })), !isMultiple &&
|
|
5123
|
+
: customTranslate(item) }));
|
|
5124
|
+
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: customTranslate(watchEnum) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: customTranslate(`field_required`) }))] }));
|
|
4640
5125
|
};
|
|
4641
5126
|
|
|
4642
5127
|
const FileViewer = ({ column, schema, prefix }) => {
|
|
4643
|
-
const {
|
|
5128
|
+
const { watch } = reactHookForm.useFormContext();
|
|
4644
5129
|
const { translate } = useSchemaContext();
|
|
4645
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5130
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4646
5131
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4647
5132
|
const currentFiles = (watch(column) ?? []);
|
|
4648
5133
|
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`)) }))] }));
|
|
5134
|
+
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) => {
|
|
5135
|
+
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));
|
|
5136
|
+
}) }) }));
|
|
4659
5137
|
};
|
|
4660
5138
|
|
|
4661
5139
|
const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4662
5140
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4663
5141
|
const { idMap, translate } = useSchemaContext();
|
|
4664
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
5142
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4665
5143
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4666
5144
|
const { display_column } = foreign_key;
|
|
4667
5145
|
const colLabel = `${prefix}${column}`;
|
|
@@ -4677,7 +5155,7 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4677
5155
|
}
|
|
4678
5156
|
return record[display_column];
|
|
4679
5157
|
};
|
|
4680
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5158
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4681
5159
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
|
|
4682
5160
|
const item = idMap[id];
|
|
4683
5161
|
if (item === undefined) {
|
|
@@ -4686,21 +5164,21 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4686
5164
|
return (jsxRuntime.jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4687
5165
|
? renderDisplay(item)
|
|
4688
5166
|
: 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}.
|
|
5167
|
+
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4690
5168
|
};
|
|
4691
5169
|
|
|
4692
5170
|
const NumberViewer = ({ schema, column, prefix, }) => {
|
|
4693
5171
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4694
5172
|
const { translate } = useSchemaContext();
|
|
4695
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5173
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4696
5174
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4697
5175
|
const colLabel = `${prefix}${column}`;
|
|
4698
5176
|
const value = watch(colLabel);
|
|
4699
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5177
|
+
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
5178
|
};
|
|
4701
5179
|
|
|
4702
5180
|
const ObjectViewer = ({ schema, column, prefix }) => {
|
|
4703
|
-
const { properties,
|
|
5181
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, showLabel = true, } = schema;
|
|
4704
5182
|
const { translate } = useSchemaContext();
|
|
4705
5183
|
const colLabel = `${prefix}${column}`;
|
|
4706
5184
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4708,25 +5186,28 @@ const ObjectViewer = ({ schema, column, prefix }) => {
|
|
|
4708
5186
|
if (properties === undefined) {
|
|
4709
5187
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4710
5188
|
}
|
|
4711
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
5189
|
+
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: {
|
|
5190
|
+
base: "colorPalette.200",
|
|
5191
|
+
_dark: "colorPalette.800",
|
|
5192
|
+
}, children: Object.keys(properties ?? {}).map((key) => {
|
|
4712
5193
|
return (
|
|
4713
5194
|
// @ts-expect-error find suitable types
|
|
4714
5195
|
jsxRuntime.jsx(ColumnViewer, { column: `${key}`,
|
|
4715
5196
|
prefix: `${prefix}${column}.`,
|
|
4716
5197
|
properties }, `form-objectviewer-${colLabel}-${key}`));
|
|
4717
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5198
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4718
5199
|
};
|
|
4719
5200
|
|
|
4720
5201
|
const RecordInput = ({ column, schema, prefix }) => {
|
|
4721
5202
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4722
5203
|
const { translate } = useSchemaContext();
|
|
4723
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5204
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4724
5205
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4725
5206
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4726
5207
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4727
5208
|
const [newKey, setNewKey] = React.useState();
|
|
4728
5209
|
const [newValue, setNewValue] = React.useState();
|
|
4729
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
5210
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4730
5211
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4731
5212
|
const filtered = entries.filter(([target]) => {
|
|
4732
5213
|
return target !== key;
|
|
@@ -4766,7 +5247,17 @@ const RecordInput = ({ column, schema, prefix }) => {
|
|
|
4766
5247
|
setShowNewEntries(true);
|
|
4767
5248
|
setNewKey(undefined);
|
|
4768
5249
|
setNewValue(undefined);
|
|
4769
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
5250
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
5251
|
+
};
|
|
5252
|
+
|
|
5253
|
+
const StringViewer = ({ column, schema, prefix, }) => {
|
|
5254
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5255
|
+
const { translate } = useSchemaContext();
|
|
5256
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5257
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5258
|
+
const colLabel = `${prefix}${column}`;
|
|
5259
|
+
const value = watch(colLabel);
|
|
5260
|
+
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
5261
|
};
|
|
4771
5262
|
|
|
4772
5263
|
const TagViewer = ({ column, schema, prefix }) => {
|
|
@@ -4854,19 +5345,36 @@ const TagViewer = ({ column, schema, prefix }) => {
|
|
|
4854
5345
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4855
5346
|
};
|
|
4856
5347
|
|
|
4857
|
-
const
|
|
5348
|
+
const TextAreaViewer = ({ column, schema, prefix, }) => {
|
|
4858
5349
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4859
5350
|
const { translate } = useSchemaContext();
|
|
4860
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5351
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4861
5352
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4862
5353
|
const colLabel = `${prefix}${column}`;
|
|
4863
5354
|
const value = watch(colLabel);
|
|
4864
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5355
|
+
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`)) }))] }) }));
|
|
5356
|
+
};
|
|
5357
|
+
|
|
5358
|
+
const TimeViewer = ({ column, schema, prefix, }) => {
|
|
5359
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5360
|
+
const { translate } = useSchemaContext();
|
|
5361
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayTimeFormat = "hh:mm A" } = schema;
|
|
5362
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5363
|
+
const colLabel = `${prefix}${column}`;
|
|
5364
|
+
const selectedDate = watch(colLabel);
|
|
5365
|
+
const displayedTime = dayjs(`1970-01-01T${selectedDate}Z`).isValid()
|
|
5366
|
+
? dayjs(`1970-01-01T${selectedDate}Z`).utc().format(displayTimeFormat)
|
|
5367
|
+
: "";
|
|
5368
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5369
|
+
gridRow, children: [jsxRuntime.jsx(react.Text, { children: displayedTime }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4865
5370
|
};
|
|
4866
5371
|
|
|
4867
5372
|
const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
4868
5373
|
const colSchema = schema;
|
|
4869
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
5374
|
+
const { type, variant, properties: innerProperties, foreign_key, items, format, } = schema;
|
|
5375
|
+
if (variant === "custom-input") {
|
|
5376
|
+
return jsxRuntime.jsx(CustomViewer, { schema: colSchema, prefix, column });
|
|
5377
|
+
}
|
|
4870
5378
|
if (type === "string") {
|
|
4871
5379
|
if ((schema.enum ?? []).length > 0) {
|
|
4872
5380
|
return jsxRuntime.jsx(EnumViewer, { schema: colSchema, prefix, column });
|
|
@@ -4875,9 +5383,15 @@ const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
|
4875
5383
|
idPickerSanityCheck(column, foreign_key);
|
|
4876
5384
|
return jsxRuntime.jsx(IdViewer, { schema: colSchema, prefix, column });
|
|
4877
5385
|
}
|
|
4878
|
-
if (
|
|
5386
|
+
if (format === "time") {
|
|
5387
|
+
return jsxRuntime.jsx(TimeViewer, { schema: colSchema, prefix, column });
|
|
5388
|
+
}
|
|
5389
|
+
if (format === "date") {
|
|
4879
5390
|
return jsxRuntime.jsx(DateViewer, { schema: colSchema, prefix, column });
|
|
4880
5391
|
}
|
|
5392
|
+
if (variant === "text-area") {
|
|
5393
|
+
return jsxRuntime.jsx(TextAreaViewer, { schema: colSchema, prefix, column });
|
|
5394
|
+
}
|
|
4881
5395
|
return jsxRuntime.jsx(StringViewer, { schema: colSchema, prefix, column });
|
|
4882
5396
|
}
|
|
4883
5397
|
if (type === "number" || type === "integer") {
|
|
@@ -5000,7 +5514,7 @@ const FormBody = () => {
|
|
|
5000
5514
|
include,
|
|
5001
5515
|
});
|
|
5002
5516
|
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("
|
|
5517
|
+
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
5518
|
setIsError(false);
|
|
5005
5519
|
setIsSubmiting(false);
|
|
5006
5520
|
setIsSuccess(false);
|
|
@@ -5008,10 +5522,10 @@ const FormBody = () => {
|
|
|
5008
5522
|
setValidatedData(undefined);
|
|
5009
5523
|
const data = await getUpdatedData();
|
|
5010
5524
|
methods.reset(data);
|
|
5011
|
-
}, formNoValidate: true, children: translate.t("
|
|
5525
|
+
}, formNoValidate: true, children: translate.t("submit_again") }) })] }));
|
|
5012
5526
|
}
|
|
5013
5527
|
if (isConfirming) {
|
|
5014
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows:
|
|
5528
|
+
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
5529
|
return (jsxRuntime.jsx(ColumnViewer
|
|
5016
5530
|
// @ts-expect-error find suitable types
|
|
5017
5531
|
, {
|
|
@@ -5023,7 +5537,7 @@ const FormBody = () => {
|
|
|
5023
5537
|
onFormSubmit(validatedData);
|
|
5024
5538
|
}, 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
5539
|
}
|
|
5026
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)",
|
|
5540
|
+
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
5541
|
return (jsxRuntime.jsx(ColumnRenderer
|
|
5028
5542
|
// @ts-expect-error find suitable types
|
|
5029
5543
|
, {
|
|
@@ -5039,8 +5553,8 @@ const FormTitle = () => {
|
|
|
5039
5553
|
return jsxRuntime.jsx(react.Heading, { children: translate.t("title") });
|
|
5040
5554
|
};
|
|
5041
5555
|
|
|
5042
|
-
const DefaultForm = ({ formConfig, }) => {
|
|
5043
|
-
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5556
|
+
const DefaultForm = ({ formConfig, showTitle = true, }) => {
|
|
5557
|
+
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [showTitle && jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5044
5558
|
};
|
|
5045
5559
|
|
|
5046
5560
|
const useForm = ({ preLoadedValues, keyPrefix }) => {
|
|
@@ -5104,6 +5618,7 @@ exports.TableCardContainer = TableCardContainer;
|
|
|
5104
5618
|
exports.TableCards = TableCards;
|
|
5105
5619
|
exports.TableComponent = TableComponent;
|
|
5106
5620
|
exports.TableControls = TableControls;
|
|
5621
|
+
exports.TableDataDisplay = TableDataDisplay;
|
|
5107
5622
|
exports.TableFilter = TableFilter;
|
|
5108
5623
|
exports.TableFilterTags = TableFilterTags;
|
|
5109
5624
|
exports.TableFooter = TableFooter;
|