@bsol-oss/react-datatable5 12.0.0-beta.4 → 12.0.0-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +94 -76
- package/dist/index.js +815 -375
- package/dist/index.mjs +819 -378
- package/dist/types/components/DataTable/DataTable.d.ts +1 -1
- package/dist/types/components/DataTable/DataTableServer.d.ts +1 -1
- package/dist/types/components/DataTable/DefaultTable.d.ts +9 -12
- package/dist/types/components/DataTable/components/TextCell.d.ts +10 -0
- package/dist/types/components/DataTable/context/DataTableContext.d.ts +3 -2
- package/dist/types/components/DataTable/controls/DensityFeature.d.ts +23 -0
- package/dist/types/components/DataTable/controls/DensityToggleButton.d.ts +6 -0
- package/dist/types/components/DataTable/controls/EditSortingButton.d.ts +7 -0
- package/dist/types/components/DataTable/controls/FilterDialog.d.ts +5 -0
- package/dist/types/components/DataTable/controls/PageSizeControl.d.ts +4 -0
- package/dist/types/components/DataTable/controls/Pagination.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ReloadButton.d.ts +5 -0
- package/dist/types/components/DataTable/controls/ResetFilteringButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/ResetSelectionButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/ResetSortingButton.d.ts +4 -0
- package/dist/types/components/DataTable/controls/RowCountText.d.ts +1 -0
- package/dist/types/components/DataTable/controls/SelectAllRowsToggle.d.ts +8 -0
- package/dist/types/components/DataTable/controls/TableControls.d.ts +23 -0
- package/dist/types/components/DataTable/controls/TableFilterTags.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableFilters.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableSelector.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableSorter.d.ts +1 -0
- package/dist/types/components/DataTable/controls/TableViewer.d.ts +1 -0
- package/dist/types/components/DataTable/controls/ViewDialog.d.ts +5 -0
- package/dist/types/components/DataTable/display/CardHeader.d.ts +13 -0
- package/dist/types/components/DataTable/display/DataDisplay.d.ts +6 -0
- package/dist/types/components/DataTable/display/EmptyState.d.ts +5 -0
- package/dist/types/components/DataTable/display/ErrorAlert.d.ts +4 -0
- package/dist/types/components/DataTable/display/RecordDisplay.d.ts +9 -0
- package/dist/types/components/DataTable/display/Table.d.ts +10 -0
- package/dist/types/components/DataTable/display/TableBody.d.ts +21 -0
- package/dist/types/components/DataTable/display/TableCardContainer.d.ts +7 -0
- package/dist/types/components/DataTable/display/TableCards.d.ts +11 -0
- package/dist/types/components/DataTable/display/TableComponent.d.ts +6 -0
- package/dist/types/components/DataTable/display/TableDataDisplay.d.ts +6 -0
- package/dist/types/components/DataTable/display/TableFooter.d.ts +5 -0
- package/dist/types/components/DataTable/display/TableHeader.d.ts +9 -0
- package/dist/types/components/DataTable/display/TableLoadingComponent.d.ts +5 -0
- package/dist/types/components/DataTable/display/TextCell.d.ts +10 -0
- package/dist/types/components/DataTable/useDataTable.d.ts +1 -1
- package/dist/types/components/Form/components/core/DefaultForm.d.ts +2 -1
- package/dist/types/components/Form/components/core/FormRoot.d.ts +2 -1
- package/dist/types/components/Form/components/fields/CustomInput.d.ts +8 -0
- package/dist/types/components/Form/components/fields/DatePicker.d.ts +2 -7
- package/dist/types/components/Form/components/fields/EnumPicker.d.ts +2 -1
- package/dist/types/components/Form/components/fields/FilePicker.d.ts +2 -5
- package/dist/types/components/Form/components/fields/StringInputField.d.ts +2 -5
- package/dist/types/components/Form/components/fields/TextAreaInput.d.ts +12 -0
- package/dist/types/components/Form/components/fields/TimePicker.d.ts +7 -0
- package/dist/types/components/Form/components/fields/types.d.ts +6 -0
- package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +17 -1
- package/dist/types/components/Form/components/viewers/CustomViewer.d.ts +8 -0
- package/dist/types/components/Form/components/viewers/TextAreaViewer.d.ts +12 -0
- package/dist/types/components/Form/components/viewers/TimeViewer.d.ts +7 -0
- package/dist/types/components/TimePicker/TimePicker.d.ts +20 -0
- package/dist/types/index.d.ts +32 -33
- package/package.json +2 -2
package/dist/index.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,39 @@ 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: {},
|
|
60
94
|
});
|
|
61
95
|
|
|
62
96
|
const useDataTableContext = () => {
|
|
@@ -98,63 +132,6 @@ react.Dialog.Description;
|
|
|
98
132
|
const DialogTrigger = react.Dialog.Trigger;
|
|
99
133
|
react.Dialog.ActionTrigger;
|
|
100
134
|
|
|
101
|
-
const ColumnOrderChanger = ({ columns }) => {
|
|
102
|
-
const [order, setOrder] = React.useState([]);
|
|
103
|
-
const [originalOrder, setOriginalOrder] = React.useState([]);
|
|
104
|
-
const { table } = useDataTableContext();
|
|
105
|
-
const handleChangeOrder = (startIndex, endIndex) => {
|
|
106
|
-
const newOrder = Array.from(order);
|
|
107
|
-
const [removed] = newOrder.splice(startIndex, 1);
|
|
108
|
-
newOrder.splice(endIndex, 0, removed);
|
|
109
|
-
setOrder(newOrder);
|
|
110
|
-
};
|
|
111
|
-
React.useEffect(() => {
|
|
112
|
-
setOrder(columns);
|
|
113
|
-
}, [columns]);
|
|
114
|
-
React.useEffect(() => {
|
|
115
|
-
if (originalOrder.length > 0) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (columns.length <= 0) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
setOriginalOrder(columns);
|
|
122
|
-
}, [columns]);
|
|
123
|
-
return (jsxRuntime.jsxs(react.Flex, { gap: 2, flexFlow: "column", children: [jsxRuntime.jsx(react.Flex, { gap: 2, flexFlow: "column", children: order.map((columnId, index) => (jsxRuntime.jsxs(react.Flex, { gap: 2, alignItems: "center", justifyContent: "space-between", children: [jsxRuntime.jsx(react.IconButton, { onClick: () => {
|
|
124
|
-
const prevIndex = index - 1;
|
|
125
|
-
if (prevIndex >= 0) {
|
|
126
|
-
handleChangeOrder(index, prevIndex);
|
|
127
|
-
}
|
|
128
|
-
}, disabled: index === 0, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowUpward, {}) }), table
|
|
129
|
-
.getAllFlatColumns()
|
|
130
|
-
.filter((column) => {
|
|
131
|
-
return column.id === columnId;
|
|
132
|
-
})
|
|
133
|
-
.map((column) => {
|
|
134
|
-
const displayName = column.columnDef.meta === undefined
|
|
135
|
-
? column.id
|
|
136
|
-
: column.columnDef.meta.displayName;
|
|
137
|
-
return jsxRuntime.jsx("span", { children: displayName }, column.id);
|
|
138
|
-
}), jsxRuntime.jsx(react.IconButton, { onClick: () => {
|
|
139
|
-
const nextIndex = index + 1;
|
|
140
|
-
if (nextIndex < order.length) {
|
|
141
|
-
handleChangeOrder(index, nextIndex);
|
|
142
|
-
}
|
|
143
|
-
}, disabled: index === order.length - 1, "aria-label": "", children: jsxRuntime.jsx(md.MdArrowDownward, {}) })] }, columnId))) }), jsxRuntime.jsxs(react.Flex, { gap: "0.25rem", children: [jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
144
|
-
table.setColumnOrder(order);
|
|
145
|
-
}, children: "Apply" }), jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
146
|
-
table.setColumnOrder(originalOrder);
|
|
147
|
-
}, children: "Reset" })] })] }));
|
|
148
|
-
};
|
|
149
|
-
const TableOrderer = () => {
|
|
150
|
-
const { table } = useDataTableContext();
|
|
151
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
155
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(DialogRoot, { size: "cover", children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { as: react.Box, variant: "ghost", children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsxs(DialogHeader, { children: [jsxRuntime.jsx(DialogTitle, {}), title] }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) }), jsxRuntime.jsx(DialogFooter, {})] })] }) }));
|
|
156
|
-
};
|
|
157
|
-
|
|
158
135
|
const TableSorter = () => {
|
|
159
136
|
const { table } = useDataTableContext();
|
|
160
137
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
@@ -460,7 +437,7 @@ const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
|
460
437
|
const FilterDialog = ({ icon = jsxRuntime.jsx(md.MdFilterAlt, {}), }) => {
|
|
461
438
|
const filterModal = react.useDisclosure();
|
|
462
439
|
const { translate } = useDataTableContext();
|
|
463
|
-
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, " ", translate.t("
|
|
440
|
+
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, " ", translate.t("filter_dialog.button_text")] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsx(DialogTitle, { children: translate.t("filter_dialog.title") }) }), jsxRuntime.jsx(DialogBody, { display: "flex", flexFlow: "column", children: jsxRuntime.jsx(TableFilter, {}) }), jsxRuntime.jsxs(DialogFooter, { children: [jsxRuntime.jsx(ResetFilteringButton, { text: translate.t("filter_dialog.reset") }), jsxRuntime.jsx(react.Button, { onClick: filterModal.onClose, variant: "subtle", children: translate.t("filter_dialog.close") })] }), jsxRuntime.jsx(DialogCloseTrigger, { onClick: filterModal.onClose })] })] }));
|
|
464
441
|
};
|
|
465
442
|
|
|
466
443
|
const MenuContent = React__namespace.forwardRef(function MenuContent(props, ref) {
|
|
@@ -2498,8 +2475,8 @@ react.CheckboxCard.Indicator;
|
|
|
2498
2475
|
function ColumnCard({ columnId }) {
|
|
2499
2476
|
const ref = React.useRef(null);
|
|
2500
2477
|
const [dragging, setDragging] = React.useState(false); // NEW
|
|
2501
|
-
const { table } = useDataTableContext();
|
|
2502
|
-
const displayName = columnId;
|
|
2478
|
+
const { table, translate } = useDataTableContext();
|
|
2479
|
+
const displayName = translate.t(columnId);
|
|
2503
2480
|
const column = table.getColumn(columnId);
|
|
2504
2481
|
invariant(column);
|
|
2505
2482
|
React.useEffect(() => {
|
|
@@ -2514,13 +2491,16 @@ function ColumnCard({ columnId }) {
|
|
|
2514
2491
|
onDrop: () => setDragging(false), // NEW
|
|
2515
2492
|
});
|
|
2516
2493
|
}, [columnId, table]);
|
|
2517
|
-
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:
|
|
2494
|
+
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() }) })] }));
|
|
2518
2495
|
}
|
|
2519
2496
|
function CardContainer({ location, children }) {
|
|
2520
2497
|
const ref = React.useRef(null);
|
|
2521
2498
|
const [isDraggedOver, setIsDraggedOver] = React.useState(false);
|
|
2522
2499
|
React.useEffect(() => {
|
|
2523
2500
|
const el = ref.current;
|
|
2501
|
+
if (el === null) {
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2524
2504
|
invariant(el);
|
|
2525
2505
|
return dropTargetForElements({
|
|
2526
2506
|
element: el,
|
|
@@ -2592,7 +2572,7 @@ const TableViewer = () => {
|
|
|
2592
2572
|
const ViewDialog = ({ icon = jsxRuntime.jsx(io.IoMdEye, {}) }) => {
|
|
2593
2573
|
const viewModel = react.useDisclosure();
|
|
2594
2574
|
const { translate } = useDataTableContext();
|
|
2595
|
-
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, " ", translate.t("
|
|
2575
|
+
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, " ", translate.t("view_dialog.button_text")] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsx(DialogTitle, { children: translate.t("view_dialog.title") }) }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsx(TableViewer, {}) }), jsxRuntime.jsx(DialogFooter, {})] })] }));
|
|
2596
2576
|
};
|
|
2597
2577
|
|
|
2598
2578
|
const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
|
|
@@ -2643,7 +2623,7 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
|
|
|
2643
2623
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "null" });
|
|
2644
2624
|
}
|
|
2645
2625
|
return (jsxRuntime.jsx(react.Grid, { rowGap: 1, padding: 1, overflow: "auto", ...boxProps, children: Object.entries(object).map(([field, value]) => {
|
|
2646
|
-
return (jsxRuntime.jsxs(react.Grid, { columnGap: 2, gridTemplateColumns: "auto 1fr", children: [jsxRuntime.jsx(react.Text, { color: "
|
|
2626
|
+
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));
|
|
2647
2627
|
}) }));
|
|
2648
2628
|
};
|
|
2649
2629
|
|
|
@@ -2693,7 +2673,7 @@ const CellRenderer = ({ cell }) => {
|
|
|
2693
2673
|
paddingY: 2,
|
|
2694
2674
|
}, object: value })] }, cell.id));
|
|
2695
2675
|
}
|
|
2696
|
-
return (jsxRuntime.jsxs(react.Box, { gridColumn, gridRow, children: [jsxRuntime.jsx(react.Box, { color:
|
|
2676
|
+
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));
|
|
2697
2677
|
};
|
|
2698
2678
|
const DataDisplay = ({ variant = "" }) => {
|
|
2699
2679
|
const { table, translate } = useDataTableContext();
|
|
@@ -2868,6 +2848,22 @@ function DataTable({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
2868
2848
|
setGlobalFilter,
|
|
2869
2849
|
type: "client",
|
|
2870
2850
|
translate,
|
|
2851
|
+
columns,
|
|
2852
|
+
sorting,
|
|
2853
|
+
setSorting,
|
|
2854
|
+
columnFilters,
|
|
2855
|
+
setColumnFilters,
|
|
2856
|
+
pagination,
|
|
2857
|
+
setPagination,
|
|
2858
|
+
rowSelection,
|
|
2859
|
+
setRowSelection,
|
|
2860
|
+
columnOrder,
|
|
2861
|
+
setColumnOrder,
|
|
2862
|
+
density,
|
|
2863
|
+
setDensity,
|
|
2864
|
+
columnVisibility,
|
|
2865
|
+
setColumnVisibility,
|
|
2866
|
+
data,
|
|
2871
2867
|
}, children: children }));
|
|
2872
2868
|
}
|
|
2873
2869
|
|
|
@@ -2936,90 +2932,25 @@ function DataTableServer({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
2936
2932
|
setGlobalFilter,
|
|
2937
2933
|
type: "server",
|
|
2938
2934
|
translate,
|
|
2935
|
+
columns,
|
|
2936
|
+
sorting,
|
|
2937
|
+
setSorting,
|
|
2938
|
+
columnFilters,
|
|
2939
|
+
setColumnFilters,
|
|
2940
|
+
pagination,
|
|
2941
|
+
setPagination,
|
|
2942
|
+
rowSelection,
|
|
2943
|
+
setRowSelection,
|
|
2944
|
+
columnOrder,
|
|
2945
|
+
setColumnOrder,
|
|
2946
|
+
density,
|
|
2947
|
+
setDensity,
|
|
2948
|
+
columnVisibility,
|
|
2949
|
+
setColumnVisibility,
|
|
2950
|
+
data: query.data?.data ?? [],
|
|
2939
2951
|
}, children: jsxRuntime.jsx(DataTableServerContext.Provider, { value: { url, query }, children: children }) }));
|
|
2940
2952
|
}
|
|
2941
2953
|
|
|
2942
|
-
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
2943
|
-
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
2944
|
-
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 }))] }));
|
|
2945
|
-
});
|
|
2946
|
-
|
|
2947
|
-
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
|
|
2948
|
-
const { table } = useDataTableContext();
|
|
2949
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2950
|
-
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
2951
|
-
const handleRowHover = (index) => {
|
|
2952
|
-
setHoveredRow(index);
|
|
2953
|
-
};
|
|
2954
|
-
const getTdProps = (cell) => {
|
|
2955
|
-
const tdProps = cell.column.getIsPinned()
|
|
2956
|
-
? {
|
|
2957
|
-
left: showSelector
|
|
2958
|
-
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
2959
|
-
: `${cell.column.getStart("left")}px`,
|
|
2960
|
-
background: pinnedBgColor.light,
|
|
2961
|
-
position: "sticky",
|
|
2962
|
-
zIndex: -1,
|
|
2963
|
-
_dark: {
|
|
2964
|
-
backgroundColor: pinnedBgColor.dark,
|
|
2965
|
-
},
|
|
2966
|
-
}
|
|
2967
|
-
: {};
|
|
2968
|
-
return tdProps;
|
|
2969
|
-
};
|
|
2970
|
-
const getTrProps = ({ hoveredRow, index, }) => {
|
|
2971
|
-
if (hoveredRow === -1) {
|
|
2972
|
-
return {};
|
|
2973
|
-
}
|
|
2974
|
-
if (hoveredRow === index) {
|
|
2975
|
-
return {
|
|
2976
|
-
opacity: "1",
|
|
2977
|
-
};
|
|
2978
|
-
}
|
|
2979
|
-
return {
|
|
2980
|
-
opacity: "0.8",
|
|
2981
|
-
};
|
|
2982
|
-
};
|
|
2983
|
-
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
2984
|
-
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) => {
|
|
2985
|
-
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
2986
|
-
// styling resize and pinning start
|
|
2987
|
-
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, backgroundColor: "white", ...getTdProps(cell), _dark: {
|
|
2988
|
-
backgroundColor: "gray.950",
|
|
2989
|
-
}, children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
2990
|
-
})] }, `chakra-table-row-${row.id}`));
|
|
2991
|
-
}) }));
|
|
2992
|
-
};
|
|
2993
|
-
const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, alwaysShowSelector = true, }) => {
|
|
2994
|
-
const { table } = useDataTableContext();
|
|
2995
|
-
const SELECTION_BOX_WIDTH = 20;
|
|
2996
|
-
const isCheckBoxVisible = (current_index, current_row) => {
|
|
2997
|
-
if (alwaysShowSelector) {
|
|
2998
|
-
return true;
|
|
2999
|
-
}
|
|
3000
|
-
if (current_row.getIsSelected()) {
|
|
3001
|
-
return true;
|
|
3002
|
-
}
|
|
3003
|
-
if (hoveredRow == current_index) {
|
|
3004
|
-
return true;
|
|
3005
|
-
}
|
|
3006
|
-
return false;
|
|
3007
|
-
};
|
|
3008
|
-
return (jsxRuntime.jsxs(react.Table.Cell, { padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
3009
|
-
? {
|
|
3010
|
-
left: `0px`,
|
|
3011
|
-
backgroundColor: pinnedBgColor.light,
|
|
3012
|
-
position: "sticky",
|
|
3013
|
-
zIndex: 1,
|
|
3014
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3015
|
-
}
|
|
3016
|
-
: {}),
|
|
3017
|
-
// styling resize and pinning end
|
|
3018
|
-
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(),
|
|
3019
|
-
disabled: !row.getCanSelect(),
|
|
3020
|
-
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
3021
|
-
};
|
|
3022
|
-
|
|
3023
2954
|
const Tooltip = React__namespace.forwardRef(function Tooltip(props, ref) {
|
|
3024
2955
|
const { showArrow, children, disabled, portalled, content, contentProps, portalRef, ...rest } = props;
|
|
3025
2956
|
if (disabled)
|
|
@@ -3098,16 +3029,89 @@ const TableFilterTags = () => {
|
|
|
3098
3029
|
}) }));
|
|
3099
3030
|
};
|
|
3100
3031
|
|
|
3101
|
-
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, }) => {
|
|
3032
|
+
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 = {}, }) => {
|
|
3102
3033
|
const { translate } = useDataTableContext();
|
|
3103
|
-
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto 1fr
|
|
3034
|
+
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: translate.t("has_error"), 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((column) => {
|
|
3104
3035
|
return (jsxRuntime.jsxs(react.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react.Text, { children: [column, ":"] }), jsxRuntime.jsx(FilterOptions, { column: column })] }, column));
|
|
3105
|
-
}) })), showFilterTags && (jsxRuntime.jsx(react.Flex, { children: jsxRuntime.jsx(TableFilterTags, {}) }))] }), jsxRuntime.jsx(react.Grid, { overflow: "auto",
|
|
3106
|
-
|
|
3107
|
-
|
|
3036
|
+
}) })), 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: translate.t("rowcount.total") }), jsxRuntime.jsx(RowCountText, {})] }))] }), jsxRuntime.jsx(react.Box, { justifySelf: "end", children: showPagination && jsxRuntime.jsx(Pagination, {}) })] }))] }));
|
|
3037
|
+
};
|
|
3038
|
+
|
|
3039
|
+
const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
3040
|
+
const { title, description, icon, children, ...rest } = props;
|
|
3041
|
+
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] }) }));
|
|
3042
|
+
});
|
|
3043
|
+
|
|
3044
|
+
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" })] }) }));
|
|
3045
|
+
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3046
|
+
const { table } = useDataTableContext();
|
|
3047
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
3048
|
+
return emptyComponent;
|
|
3049
|
+
}
|
|
3050
|
+
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 }));
|
|
3051
|
+
};
|
|
3052
|
+
|
|
3053
|
+
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
3054
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
3055
|
+
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 }))] }));
|
|
3056
|
+
});
|
|
3057
|
+
|
|
3058
|
+
const TableBody = ({ showSelector = false, alwaysShowSelector = true, canResize = true, }) => {
|
|
3059
|
+
"use no memo";
|
|
3060
|
+
const { table } = useDataTableContext();
|
|
3061
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3062
|
+
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
3063
|
+
const handleRowHover = (index) => {
|
|
3064
|
+
setHoveredRow(index);
|
|
3065
|
+
};
|
|
3066
|
+
const getTdProps = (cell) => {
|
|
3067
|
+
const tdProps = cell.column.getIsPinned()
|
|
3068
|
+
? {
|
|
3069
|
+
left: showSelector
|
|
3070
|
+
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3071
|
+
: `${cell.column.getStart("left")}px`,
|
|
3072
|
+
position: "relative",
|
|
3073
|
+
}
|
|
3074
|
+
: {};
|
|
3075
|
+
return tdProps;
|
|
3076
|
+
};
|
|
3077
|
+
const getTrProps = ({ hoveredRow, index, }) => {
|
|
3078
|
+
if (hoveredRow === -1) {
|
|
3079
|
+
return {};
|
|
3080
|
+
}
|
|
3081
|
+
if (hoveredRow === index) {
|
|
3082
|
+
return {
|
|
3083
|
+
opacity: "1",
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
return {
|
|
3087
|
+
opacity: "0.8",
|
|
3088
|
+
};
|
|
3089
|
+
};
|
|
3090
|
+
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
3091
|
+
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) => {
|
|
3092
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
3093
|
+
// styling resize and pinning start
|
|
3094
|
+
flex: `${canResize ? "0" : "1"} 0 ${cell.column.getSize()}px`, color: {
|
|
3095
|
+
base: "colorPalette.900",
|
|
3096
|
+
_dark: "colorPalette.100",
|
|
3097
|
+
},
|
|
3098
|
+
bg: { base: "colorPalette.50", _dark: "colorPalette.950" }, ...getTdProps(cell), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
3099
|
+
})] }, `chakra-table-row-${row.id}`));
|
|
3100
|
+
}) }));
|
|
3101
|
+
};
|
|
3102
|
+
const TableRowSelector = ({ index, row, }) => {
|
|
3103
|
+
const { table } = useDataTableContext();
|
|
3104
|
+
const SELECTION_BOX_WIDTH = 20;
|
|
3105
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`, display: "grid", color: {
|
|
3106
|
+
base: "colorPalette.900",
|
|
3107
|
+
_dark: "colorPalette.100",
|
|
3108
|
+
},
|
|
3109
|
+
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(),
|
|
3110
|
+
disabled: !row.getCanSelect(),
|
|
3111
|
+
onCheckedChange: row.getToggleSelectedHandler() }) }));
|
|
3108
3112
|
};
|
|
3109
3113
|
|
|
3110
|
-
const TableFooter = ({
|
|
3114
|
+
const TableFooter = ({ showSelector = false, alwaysShowSelector = true, }) => {
|
|
3111
3115
|
const table = useDataTableContext().table;
|
|
3112
3116
|
const SELECTION_BOX_WIDTH = 20;
|
|
3113
3117
|
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
@@ -3126,78 +3130,28 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
3126
3130
|
}
|
|
3127
3131
|
return false;
|
|
3128
3132
|
};
|
|
3129
|
-
|
|
3130
|
-
const thProps = header.column.getIsPinned()
|
|
3131
|
-
? {
|
|
3132
|
-
left: showSelector
|
|
3133
|
-
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3134
|
-
: `${header.getStart("left") + table.getDensityValue() * 2}px`,
|
|
3135
|
-
background: pinnedBgColor.light,
|
|
3136
|
-
position: "sticky",
|
|
3137
|
-
zIndex: 1,
|
|
3138
|
-
_dark: {
|
|
3139
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3140
|
-
},
|
|
3141
|
-
}
|
|
3142
|
-
: {};
|
|
3143
|
-
return thProps;
|
|
3144
|
-
};
|
|
3145
|
-
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
|
|
3146
|
-
// styling resize and pinning start
|
|
3147
|
-
, {
|
|
3148
|
-
// styling resize and pinning start
|
|
3149
|
-
padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
3150
|
-
? {
|
|
3151
|
-
left: `0px`,
|
|
3152
|
-
backgroundColor: pinnedBgColor.light,
|
|
3153
|
-
position: "sticky",
|
|
3154
|
-
zIndex: 1,
|
|
3155
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3156
|
-
}
|
|
3157
|
-
: {}),
|
|
3158
|
-
// styling resize and pinning end
|
|
3159
|
-
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(),
|
|
3133
|
+
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(),
|
|
3160
3134
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3161
3135
|
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}`,
|
|
3162
3136
|
// styling resize and pinning start
|
|
3163
|
-
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid",
|
|
3137
|
+
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
|
|
3164
3138
|
? null
|
|
3165
3139
|
: 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 && (
|
|
3166
3140
|
// <UpDownIcon />
|
|
3167
3141
|
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}`))) }));
|
|
3168
3142
|
};
|
|
3169
3143
|
|
|
3170
|
-
const TableHeader = ({ canResize = true,
|
|
3144
|
+
const TableHeader = ({ canResize = true, showSelector = false, isSticky = true, tableHeaderProps = {}, tableRowProps = {}, }) => {
|
|
3171
3145
|
const { table } = useDataTableContext();
|
|
3172
3146
|
const SELECTION_BOX_WIDTH = 20;
|
|
3173
|
-
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
3174
|
-
const handleRowHover = (isHovered) => {
|
|
3175
|
-
setHoveredCheckBox(isHovered);
|
|
3176
|
-
};
|
|
3177
|
-
const isCheckBoxVisible = () => {
|
|
3178
|
-
if (alwaysShowSelector) {
|
|
3179
|
-
return true;
|
|
3180
|
-
}
|
|
3181
|
-
if (table.getIsAllRowsSelected()) {
|
|
3182
|
-
return true;
|
|
3183
|
-
}
|
|
3184
|
-
if (hoveredCheckBox) {
|
|
3185
|
-
return true;
|
|
3186
|
-
}
|
|
3187
|
-
return false;
|
|
3188
|
-
};
|
|
3189
3147
|
const getThProps = (header) => {
|
|
3190
3148
|
const thProps = header.column.getIsPinned()
|
|
3191
3149
|
? {
|
|
3192
3150
|
left: showSelector
|
|
3193
3151
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
3194
3152
|
: `${header.getStart("left")}px`,
|
|
3195
|
-
background: pinnedBgColor.light,
|
|
3196
3153
|
position: "sticky",
|
|
3197
3154
|
zIndex: 100 + 1,
|
|
3198
|
-
_dark: {
|
|
3199
|
-
backgroundColor: pinnedBgColor.dark,
|
|
3200
|
-
},
|
|
3201
3155
|
}
|
|
3202
3156
|
: {};
|
|
3203
3157
|
return thProps;
|
|
@@ -3206,21 +3160,13 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3206
3160
|
position: "sticky",
|
|
3207
3161
|
top: 0,
|
|
3208
3162
|
};
|
|
3209
|
-
return (jsxRuntime.jsx(react.Table.Header, { ...(isSticky ? stickyProps : {}), ...
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
zIndex: 1,
|
|
3217
|
-
_dark: { backgroundColor: pinnedBgColor.dark },
|
|
3218
|
-
}
|
|
3219
|
-
: {}),
|
|
3220
|
-
// styling resize and pinning end
|
|
3221
|
-
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(),
|
|
3222
|
-
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3223
|
-
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) => {
|
|
3163
|
+
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: {
|
|
3164
|
+
base: "colorPalette.900",
|
|
3165
|
+
_dark: "colorPalette.100",
|
|
3166
|
+
},
|
|
3167
|
+
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(),
|
|
3168
|
+
// indeterminate: table.getIsSomeRowsSelected(),
|
|
3169
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), headerGroup.headers.map((header) => {
|
|
3224
3170
|
const resizeProps = {
|
|
3225
3171
|
onMouseDown: header.getResizeHandler(),
|
|
3226
3172
|
onTouchStart: header.getResizeHandler(),
|
|
@@ -3228,10 +3174,24 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3228
3174
|
};
|
|
3229
3175
|
return (jsxRuntime.jsxs(react.Table.ColumnHeader, { padding: 0, columnSpan: `${header.colSpan}`,
|
|
3230
3176
|
// styling resize and pinning start
|
|
3231
|
-
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index,
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3177
|
+
flex: `${canResize ? "0" : "1"} 0 ${header.column.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: 1500 + header.index, color: {
|
|
3178
|
+
base: "colorPalette.800",
|
|
3179
|
+
_dark: "colorPalette.200",
|
|
3180
|
+
},
|
|
3181
|
+
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: {
|
|
3182
|
+
base: "colorPalette.800",
|
|
3183
|
+
_dark: "colorPalette.200",
|
|
3184
|
+
_hover: {
|
|
3185
|
+
base: "colorPalette.700",
|
|
3186
|
+
_dark: "colorPalette.300",
|
|
3187
|
+
},
|
|
3188
|
+
},
|
|
3189
|
+
bg: {
|
|
3190
|
+
base: "colorPalette.100",
|
|
3191
|
+
_dark: "colorPalette.900",
|
|
3192
|
+
_hover: {
|
|
3193
|
+
base: "colorPalette.200",
|
|
3194
|
+
_dark: "colorPalette.800",
|
|
3235
3195
|
},
|
|
3236
3196
|
}, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
3237
3197
|
? null
|
|
@@ -3259,29 +3219,17 @@ const TableHeader = ({ canResize = true, pinnedBgColor = { light: "gray.50", dar
|
|
|
3259
3219
|
});
|
|
3260
3220
|
}, children: [jsxRuntime.jsx(gr.GrDescend, {}), "Sort Descending"] }) }), header.column.getIsSorted() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
3261
3221
|
header.column.clearSorting();
|
|
3262
|
-
}, children: [jsxRuntime.jsx(md.MdClear, {}), "Clear Sorting"] }) }))] }))] })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3222
|
+
}, children: [jsxRuntime.jsx(md.MdClear, {}), "Clear Sorting"] }) }))] }))] })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing()
|
|
3223
|
+
? "colorPalette.700"
|
|
3224
|
+
: "transparent", position: "relative", right: "0.1rem", width: "2px", height: "100%", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
3263
3225
|
borderRightColor: header.column.getIsResizing()
|
|
3264
|
-
? "
|
|
3265
|
-
: "
|
|
3226
|
+
? "colorPalette.700"
|
|
3227
|
+
: "colorPalette.400",
|
|
3266
3228
|
}, ...resizeProps }))] }, `chakra-table-header-${header.id}`));
|
|
3267
3229
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
3268
3230
|
};
|
|
3269
3231
|
|
|
3270
|
-
const
|
|
3271
|
-
const { title, description, icon, children, ...rest } = props;
|
|
3272
|
-
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] }) }));
|
|
3273
|
-
});
|
|
3274
|
-
|
|
3275
|
-
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" })] }) }));
|
|
3276
|
-
const Table = ({ children, emptyComponent = EmptyResult, canResize = true, ...props }) => {
|
|
3277
|
-
const { table } = useDataTableContext();
|
|
3278
|
-
if (table.getRowModel().rows.length <= 0) {
|
|
3279
|
-
return emptyComponent;
|
|
3280
|
-
}
|
|
3281
|
-
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: canResize ? table.getCenterTotalSize() : undefined, display: "grid", alignContent: "start", overflowY: "auto", ...props, children: children }));
|
|
3282
|
-
};
|
|
3283
|
-
|
|
3284
|
-
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, controlProps = {}, tableFooterProps = {}, variant = "", }) => {
|
|
3232
|
+
const DefaultTable = ({ showFooter = false, tableProps = {}, tableHeaderProps = {}, tableBodyProps = {}, tableFooterProps = {}, controlProps = {}, variant = "", }) => {
|
|
3285
3233
|
if (variant === "greedy") {
|
|
3286
3234
|
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 }))] }) }));
|
|
3287
3235
|
}
|
|
@@ -3541,6 +3489,73 @@ const getColumns = ({ schema, include = [], ignore = [], width = [], meta = {},
|
|
|
3541
3489
|
return columns;
|
|
3542
3490
|
};
|
|
3543
3491
|
|
|
3492
|
+
const TableDataDisplay = ({ colorPalette, emptyComponent, }) => {
|
|
3493
|
+
const { table, columns, translate, data } = useDataTableContext();
|
|
3494
|
+
const columnDef = table._getColumnDefs();
|
|
3495
|
+
console.log(columnDef, "glp");
|
|
3496
|
+
console.log(columnDef, columns, table.getState().columnOrder, data, "glp");
|
|
3497
|
+
const columnsMap = Object.fromEntries(columns.map((def) => {
|
|
3498
|
+
const { accessorKey, id } = def;
|
|
3499
|
+
if (accessorKey) {
|
|
3500
|
+
return [accessorKey, def];
|
|
3501
|
+
}
|
|
3502
|
+
return [id, def];
|
|
3503
|
+
}));
|
|
3504
|
+
const columnHeaders = Object.keys(columnsMap);
|
|
3505
|
+
const totalWidths = columns
|
|
3506
|
+
.map(({ size }) => {
|
|
3507
|
+
if (!!size === false) {
|
|
3508
|
+
return 0;
|
|
3509
|
+
}
|
|
3510
|
+
if (typeof size === "number") {
|
|
3511
|
+
return size;
|
|
3512
|
+
}
|
|
3513
|
+
return 0;
|
|
3514
|
+
})
|
|
3515
|
+
.reduce((previous, current) => previous + current, 0);
|
|
3516
|
+
const columnWidths = columns
|
|
3517
|
+
.map(({ size }) => {
|
|
3518
|
+
if (!!size === false) {
|
|
3519
|
+
return "1fr";
|
|
3520
|
+
}
|
|
3521
|
+
return `minmax(${size}px, ${(size / totalWidths) * 100}%)`;
|
|
3522
|
+
})
|
|
3523
|
+
.join(" ");
|
|
3524
|
+
console.log({ columnWidths }, "hadfg");
|
|
3525
|
+
const cellProps = {
|
|
3526
|
+
flex: "1 0 0%",
|
|
3527
|
+
overflow: "auto",
|
|
3528
|
+
paddingX: "2",
|
|
3529
|
+
py: "1",
|
|
3530
|
+
color: { base: "colorPalette.900", _dark: "colorPalette.100" },
|
|
3531
|
+
bgColor: { base: "colorPalette.50", _dark: "colorPalette.950" },
|
|
3532
|
+
borderBottomColor: { base: "colorPalette.200", _dark: "colorPalette.800" },
|
|
3533
|
+
borderBottomWidth: "1px",
|
|
3534
|
+
...{ colorPalette },
|
|
3535
|
+
};
|
|
3536
|
+
if (data.length <= 0) {
|
|
3537
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: emptyComponent });
|
|
3538
|
+
}
|
|
3539
|
+
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) => {
|
|
3540
|
+
return (jsxRuntime.jsx(react.Box, { flex: "1 0 0%", paddingX: "2", py: "1", overflow: "auto", textOverflow: "ellipsis", children: translate.t(`column_header.${header}`) }));
|
|
3541
|
+
}) }), data.map((record) => {
|
|
3542
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: columnHeaders.map((header) => {
|
|
3543
|
+
const { cell } = columnsMap[header];
|
|
3544
|
+
const value = record[header];
|
|
3545
|
+
if (!!record === false) {
|
|
3546
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: translate.t(`column_cell.placeholder`) }));
|
|
3547
|
+
}
|
|
3548
|
+
if (cell) {
|
|
3549
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: cell({ row: { original: record } }) }));
|
|
3550
|
+
}
|
|
3551
|
+
if (typeof value === "object") {
|
|
3552
|
+
return (jsxRuntime.jsx(react.Box, { ...cellProps, children: jsxRuntime.jsx(RecordDisplay, { object: value }) }));
|
|
3553
|
+
}
|
|
3554
|
+
return jsxRuntime.jsx(react.Box, { ...cellProps, children: value });
|
|
3555
|
+
}) }));
|
|
3556
|
+
})] }));
|
|
3557
|
+
};
|
|
3558
|
+
|
|
3544
3559
|
const AccordionItemTrigger = React__namespace.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
3545
3560
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
3546
3561
|
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, {}) }))] }));
|
|
@@ -3636,11 +3651,11 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3636
3651
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3637
3652
|
const { formState: { errors }, setValue, watch, } = reactHookForm.useFormContext();
|
|
3638
3653
|
const fields = (watch(colLabel) ?? []);
|
|
3639
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
3654
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label", children: [`${translate.t(removeIndex(`${colLabel}.field_label`))}`, isRequired && jsxRuntime.jsx("span", { children: "*" })] }), fields.map((field, index) => (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", children: [jsxRuntime.jsx(react.Box, { children: index + 1 }), jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaRenderer, { column: `${index}`,
|
|
3640
3655
|
prefix: `${colLabel}.`,
|
|
3641
3656
|
schema: items }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "end", children: jsxRuntime.jsx(react.Button, { variant: "ghost", onClick: () => {
|
|
3642
3657
|
setValue(colLabel, fields.filter((_, curIndex) => {
|
|
3643
|
-
return curIndex
|
|
3658
|
+
return curIndex !== index;
|
|
3644
3659
|
}));
|
|
3645
3660
|
}, children: translate.t(removeIndex(`${colLabel}.remove`)) }) })] }, `${colLabel}.${index}`))), jsxRuntime.jsx(react.Flex, { children: jsxRuntime.jsx(react.Button, { onClick: () => {
|
|
3646
3661
|
if (type === "number") {
|
|
@@ -3656,7 +3671,7 @@ const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
|
3656
3671
|
return;
|
|
3657
3672
|
}
|
|
3658
3673
|
setValue(colLabel, [...fields, {}]);
|
|
3659
|
-
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3674
|
+
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3660
3675
|
};
|
|
3661
3676
|
|
|
3662
3677
|
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
@@ -3667,14 +3682,26 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
|
3667
3682
|
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3668
3683
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3669
3684
|
const { translate } = useSchemaContext();
|
|
3670
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3685
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
3671
3686
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3672
3687
|
const colLabel = `${prefix}${column}`;
|
|
3673
3688
|
const value = watch(colLabel);
|
|
3674
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
3689
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3675
3690
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
|
|
3676
3691
|
setValue(colLabel, !value);
|
|
3677
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3692
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3693
|
+
};
|
|
3694
|
+
|
|
3695
|
+
const CustomInput = ({ column, schema, prefix }) => {
|
|
3696
|
+
const formContext = reactHookForm.useFormContext();
|
|
3697
|
+
const { inputRender } = schema;
|
|
3698
|
+
return (inputRender &&
|
|
3699
|
+
inputRender({
|
|
3700
|
+
column,
|
|
3701
|
+
schema,
|
|
3702
|
+
prefix,
|
|
3703
|
+
formContext,
|
|
3704
|
+
}));
|
|
3678
3705
|
};
|
|
3679
3706
|
|
|
3680
3707
|
const monthNamesShort = [
|
|
@@ -3764,28 +3791,54 @@ const PopoverRoot = react.Popover.Root;
|
|
|
3764
3791
|
const PopoverBody = react.Popover.Body;
|
|
3765
3792
|
const PopoverTrigger = react.Popover.Trigger;
|
|
3766
3793
|
|
|
3794
|
+
dayjs.extend(utc);
|
|
3767
3795
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3768
3796
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3769
3797
|
const { translate } = useSchemaContext();
|
|
3770
|
-
const { required, gridColumn, gridRow } = schema;
|
|
3798
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3771
3799
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3772
3800
|
const colLabel = `${prefix}${column}`;
|
|
3773
3801
|
const [open, setOpen] = React.useState(false);
|
|
3774
3802
|
const selectedDate = watch(colLabel);
|
|
3775
|
-
const
|
|
3776
|
-
|
|
3777
|
-
|
|
3803
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3804
|
+
React.useEffect(() => {
|
|
3805
|
+
try {
|
|
3806
|
+
if (selectedDate) {
|
|
3807
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3808
|
+
// For example, parse as UTC:
|
|
3809
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3810
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3811
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3812
|
+
if (!parsedDate.isValid())
|
|
3813
|
+
return;
|
|
3814
|
+
// Format according to dateFormat from schema
|
|
3815
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3816
|
+
// Update the form value only if different to avoid loops
|
|
3817
|
+
if (formatted !== selectedDate) {
|
|
3818
|
+
setValue(colLabel, formatted, {
|
|
3819
|
+
shouldValidate: true,
|
|
3820
|
+
shouldDirty: true,
|
|
3821
|
+
});
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
catch (e) {
|
|
3826
|
+
console.error(e);
|
|
3827
|
+
}
|
|
3828
|
+
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3829
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3830
|
+
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: () => {
|
|
3778
3831
|
setOpen(true);
|
|
3779
|
-
}, children: selectedDate !== undefined ? `${
|
|
3832
|
+
}, 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
|
|
3780
3833
|
// @ts-expect-error TODO: find appropriate types
|
|
3781
3834
|
, {
|
|
3782
3835
|
// @ts-expect-error TODO: find appropriate types
|
|
3783
3836
|
selected: new Date(selectedDate),
|
|
3784
3837
|
// @ts-expect-error TODO: find appropriate types
|
|
3785
3838
|
onDateSelected: ({ date }) => {
|
|
3786
|
-
setValue(colLabel, dayjs(date).format(
|
|
3839
|
+
setValue(colLabel, dayjs(date).format(dateFormat));
|
|
3787
3840
|
setOpen(false);
|
|
3788
|
-
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
3841
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
3789
3842
|
};
|
|
3790
3843
|
|
|
3791
3844
|
function filterArray(array, searchTerm) {
|
|
@@ -3798,12 +3851,12 @@ function filterArray(array, searchTerm) {
|
|
|
3798
3851
|
});
|
|
3799
3852
|
}
|
|
3800
3853
|
|
|
3801
|
-
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3854
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, showTotalAndLimit = false, }) => {
|
|
3802
3855
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3803
3856
|
const { translate } = useSchemaContext();
|
|
3804
|
-
const { required } = schema;
|
|
3857
|
+
const { required, variant } = schema;
|
|
3805
3858
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3806
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3859
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
3807
3860
|
const [searchText, setSearchText] = React.useState();
|
|
3808
3861
|
const [limit, setLimit] = React.useState(10);
|
|
3809
3862
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -3818,28 +3871,61 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3818
3871
|
setSearchText(event.target.value);
|
|
3819
3872
|
setLimit(10);
|
|
3820
3873
|
};
|
|
3821
|
-
|
|
3874
|
+
if (variant === "radio") {
|
|
3875
|
+
return (jsxRuntime.jsx(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3876
|
+
gridRow, children: jsxRuntime.jsx(react.RadioGroup.Root, { defaultValue: "1", children: jsxRuntime.jsx(react.HStack, { gap: "6", children: filterArray(dataList, searchText ?? "").map((item) => {
|
|
3877
|
+
return (jsxRuntime.jsxs(react.RadioGroup.Item, { onClick: () => {
|
|
3878
|
+
if (!isMultiple) {
|
|
3879
|
+
setOpenSearchResult(false);
|
|
3880
|
+
setValue(colLabel, item);
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3884
|
+
setValue(colLabel, [...newSet]);
|
|
3885
|
+
}, value: item, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, {}), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), jsxRuntime.jsx(react.RadioGroup.ItemText, { children: !!renderDisplay === true
|
|
3886
|
+
? renderDisplay(item)
|
|
3887
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) })] }, `${colLabel}-${item}`));
|
|
3888
|
+
}) }) }) }));
|
|
3889
|
+
}
|
|
3890
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3822
3891
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3823
3892
|
const item = enumValue;
|
|
3824
|
-
if (item ===
|
|
3825
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
3893
|
+
if (!!item === false) {
|
|
3894
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
3826
3895
|
}
|
|
3827
3896
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3828
|
-
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3829
3897
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3830
3898
|
}, children: !!renderDisplay === true
|
|
3831
3899
|
? renderDisplay(item)
|
|
3832
3900
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3833
3901
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3834
3902
|
setOpenSearchResult(true);
|
|
3835
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
3903
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3836
3904
|
setOpenSearchResult(true);
|
|
3837
|
-
}, children: watchEnum ===
|
|
3905
|
+
}, justifyContent: "start", children: !!watchEnum === false
|
|
3838
3906
|
? ""
|
|
3839
|
-
: 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(`${
|
|
3907
|
+
: 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) => {
|
|
3840
3908
|
onSearchChange(event);
|
|
3841
3909
|
setOpenSearchResult(true);
|
|
3842
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${translate.t(`${
|
|
3910
|
+
}, 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
|
|
3911
|
+
.filter((item) => {
|
|
3912
|
+
const searchTerm = (searchText || "").toLowerCase();
|
|
3913
|
+
if (!searchTerm)
|
|
3914
|
+
return true;
|
|
3915
|
+
// Check if the original enum value contains the search text
|
|
3916
|
+
const enumValueMatch = item
|
|
3917
|
+
.toLowerCase()
|
|
3918
|
+
.includes(searchTerm);
|
|
3919
|
+
// Check if the display value (translation) contains the search text
|
|
3920
|
+
const displayValue = !!renderDisplay === true
|
|
3921
|
+
? renderDisplay(item)
|
|
3922
|
+
: translate.t(removeIndex(`${colLabel}.${item}`));
|
|
3923
|
+
// Convert to string and check if it includes the search term
|
|
3924
|
+
const displayValueString = String(displayValue).toLowerCase();
|
|
3925
|
+
const displayValueMatch = displayValueString.includes(searchTerm);
|
|
3926
|
+
return enumValueMatch || displayValueMatch;
|
|
3927
|
+
})
|
|
3928
|
+
.map((item) => {
|
|
3843
3929
|
const selected = isMultiple
|
|
3844
3930
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3845
3931
|
: watchEnum == item;
|
|
@@ -3851,10 +3937,10 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3851
3937
|
}
|
|
3852
3938
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3853
3939
|
setValue(colLabel, [...newSet]);
|
|
3854
|
-
}, ...(selected ? { color: "
|
|
3940
|
+
}, ...(selected ? { color: "colorPalette.400/50" } : {}), children: !!renderDisplay === true
|
|
3855
3941
|
? renderDisplay(item)
|
|
3856
3942
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
|
|
3857
|
-
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: translate.t(removeIndex(`${colLabel}.
|
|
3943
|
+
}) }), 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`)) }))] }));
|
|
3858
3944
|
};
|
|
3859
3945
|
|
|
3860
3946
|
function isEnteringWindow(_ref) {
|
|
@@ -4206,17 +4292,17 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4206
4292
|
const filesArray = [...event.target.files];
|
|
4207
4293
|
onDrop({ files: filesArray });
|
|
4208
4294
|
};
|
|
4209
|
-
return (jsxRuntime.jsxs(react.Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "
|
|
4295
|
+
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 })] }))] }));
|
|
4210
4296
|
};
|
|
4211
4297
|
|
|
4212
4298
|
const FilePicker = ({ column, schema, prefix }) => {
|
|
4213
4299
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4214
4300
|
const { translate } = useSchemaContext();
|
|
4215
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4301
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4216
4302
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4217
4303
|
const currentFiles = (watch(column) ?? []);
|
|
4218
4304
|
const colLabel = `${prefix}${column}`;
|
|
4219
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.
|
|
4305
|
+
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 }) => {
|
|
4220
4306
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4221
4307
|
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4222
4308
|
}, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
@@ -4224,10 +4310,19 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4224
4310
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4225
4311
|
return name !== file.name;
|
|
4226
4312
|
}));
|
|
4227
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4228
|
-
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4313
|
+
}, 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));
|
|
4314
|
+
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4229
4315
|
};
|
|
4230
4316
|
|
|
4317
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
4318
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
4319
|
+
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] }) }) })] }));
|
|
4320
|
+
});
|
|
4321
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
4322
|
+
const { children, ...rest } = props;
|
|
4323
|
+
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, {}) }) }));
|
|
4324
|
+
});
|
|
4325
|
+
|
|
4231
4326
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4232
4327
|
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4233
4328
|
throw new Error("The serverUrl is missing");
|
|
@@ -4259,15 +4354,18 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
4259
4354
|
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4260
4355
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4261
4356
|
const { serverUrl, idMap, setIdMap, translate, schema: parentSchema, } = useSchemaContext();
|
|
4262
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4357
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4263
4358
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4264
4359
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4265
|
-
const [searchText, setSearchText] = React.useState();
|
|
4360
|
+
const [searchText, setSearchText] = React.useState("");
|
|
4266
4361
|
const [limit, setLimit] = React.useState(10);
|
|
4267
4362
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
4268
4363
|
const [page, setPage] = React.useState(0);
|
|
4269
4364
|
const ref = React.useRef(null);
|
|
4270
4365
|
const colLabel = `${prefix}${column}`;
|
|
4366
|
+
const watchId = watch(colLabel);
|
|
4367
|
+
const watchIds = isMultiple ? (watch(colLabel) ?? []) : [];
|
|
4368
|
+
// Query for search results
|
|
4271
4369
|
const query = reactQuery.useQuery({
|
|
4272
4370
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4273
4371
|
queryFn: async () => {
|
|
@@ -4276,7 +4374,7 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4276
4374
|
searching: searchText ?? "",
|
|
4277
4375
|
in_table: table,
|
|
4278
4376
|
limit: limit,
|
|
4279
|
-
offset: page *
|
|
4377
|
+
offset: page * limit,
|
|
4280
4378
|
});
|
|
4281
4379
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4282
4380
|
return [
|
|
@@ -4291,27 +4389,27 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4291
4389
|
});
|
|
4292
4390
|
return data;
|
|
4293
4391
|
},
|
|
4294
|
-
enabled:
|
|
4392
|
+
enabled: openSearchResult === true,
|
|
4295
4393
|
staleTime: 300000,
|
|
4296
4394
|
});
|
|
4297
|
-
|
|
4298
|
-
const
|
|
4299
|
-
const count = data?.count ?? 0;
|
|
4300
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
4301
|
-
const watchId = watch(colLabel);
|
|
4302
|
-
const watchIds = (watch(colLabel) ?? []);
|
|
4303
|
-
reactQuery.useQuery({
|
|
4395
|
+
// Query for currently selected items (to display them properly)
|
|
4396
|
+
const queryDefault = reactQuery.useQuery({
|
|
4304
4397
|
queryKey: [
|
|
4305
|
-
`idpicker`,
|
|
4306
|
-
{ form: parentSchema.title, column,
|
|
4398
|
+
`idpicker-default`,
|
|
4399
|
+
{ form: parentSchema.title, column, id: isMultiple ? watchIds : watchId },
|
|
4307
4400
|
],
|
|
4308
4401
|
queryFn: async () => {
|
|
4402
|
+
if (!watchId && (!watchIds || watchIds.length === 0)) {
|
|
4403
|
+
return { data: [] };
|
|
4404
|
+
}
|
|
4405
|
+
const searchValue = isMultiple ? watchIds.join(",") : watchId;
|
|
4309
4406
|
const data = await getTableData({
|
|
4310
4407
|
serverUrl,
|
|
4311
|
-
searching:
|
|
4408
|
+
searching: searchValue,
|
|
4312
4409
|
in_table: table,
|
|
4313
|
-
|
|
4314
|
-
|
|
4410
|
+
where: [{ id: column_ref, value: isMultiple ? watchIds : watchId }],
|
|
4411
|
+
limit: isMultiple ? watchIds.length : 1,
|
|
4412
|
+
offset: 0,
|
|
4315
4413
|
});
|
|
4316
4414
|
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4317
4415
|
return [
|
|
@@ -4326,12 +4424,45 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4326
4424
|
});
|
|
4327
4425
|
return data;
|
|
4328
4426
|
},
|
|
4427
|
+
enabled: isMultiple
|
|
4428
|
+
? Array.isArray(watchIds) && watchIds.length > 0
|
|
4429
|
+
: !!watchId,
|
|
4329
4430
|
});
|
|
4431
|
+
// Effect to load selected values when component mounts
|
|
4432
|
+
React.useEffect(() => {
|
|
4433
|
+
if (isMultiple ? watchIds.length > 0 : !!watchId) {
|
|
4434
|
+
queryDefault.refetch();
|
|
4435
|
+
}
|
|
4436
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4437
|
+
}, []);
|
|
4438
|
+
// Effect to trigger initial data fetch when popover opens
|
|
4439
|
+
React.useEffect(() => {
|
|
4440
|
+
if (openSearchResult) {
|
|
4441
|
+
// Reset search text when opening the popover
|
|
4442
|
+
setSearchText("");
|
|
4443
|
+
// Reset page to first page
|
|
4444
|
+
setPage(0);
|
|
4445
|
+
// Fetch initial data
|
|
4446
|
+
query.refetch();
|
|
4447
|
+
}
|
|
4448
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4449
|
+
}, [openSearchResult]);
|
|
4330
4450
|
const onSearchChange = async (event) => {
|
|
4331
4451
|
setSearchText(event.target.value);
|
|
4332
4452
|
setPage(0);
|
|
4333
|
-
|
|
4453
|
+
query.refetch();
|
|
4334
4454
|
};
|
|
4455
|
+
const handleLimitChange = (event) => {
|
|
4456
|
+
const newLimit = Number(event.target.value);
|
|
4457
|
+
setLimit(newLimit);
|
|
4458
|
+
// Reset to first page when changing limit
|
|
4459
|
+
setPage(0);
|
|
4460
|
+
// Trigger a new search with the updated limit
|
|
4461
|
+
query.refetch();
|
|
4462
|
+
};
|
|
4463
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4464
|
+
const dataList = data?.data ?? [];
|
|
4465
|
+
const count = data?.count ?? 0;
|
|
4335
4466
|
const getPickedValue = () => {
|
|
4336
4467
|
if (Object.keys(idMap).length <= 0) {
|
|
4337
4468
|
return "";
|
|
@@ -4340,47 +4471,57 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4340
4471
|
if (record === undefined) {
|
|
4341
4472
|
return "";
|
|
4342
4473
|
}
|
|
4474
|
+
if (!!renderDisplay === true) {
|
|
4475
|
+
return renderDisplay(record);
|
|
4476
|
+
}
|
|
4343
4477
|
return record[display_column];
|
|
4344
4478
|
};
|
|
4345
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.
|
|
4479
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.field_label`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4346
4480
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
|
|
4347
4481
|
const item = idMap[id];
|
|
4348
4482
|
if (item === undefined) {
|
|
4349
4483
|
return (jsxRuntime.jsx(react.Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4350
4484
|
}
|
|
4351
4485
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
4352
|
-
setValue(
|
|
4486
|
+
setValue(colLabel, watchIds.filter((itemId) => itemId !== item[column_ref]));
|
|
4353
4487
|
}, children: !!renderDisplay === true
|
|
4354
4488
|
? renderDisplay(item)
|
|
4355
4489
|
: item[display_column] }, id));
|
|
4356
4490
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4357
4491
|
setOpenSearchResult(true);
|
|
4358
|
-
}, children: translate.t(removeIndex(`${colLabel}.
|
|
4492
|
+
}, children: translate.t(removeIndex(`${colLabel}.add_more`)) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
4359
4493
|
setOpenSearchResult(true);
|
|
4360
|
-
}, 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}.
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4494
|
+
}, 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: {
|
|
4495
|
+
padding: "4px 8px",
|
|
4496
|
+
borderRadius: "4px",
|
|
4497
|
+
border: "1px solid #ccc",
|
|
4498
|
+
fontSize: "14px",
|
|
4499
|
+
}, 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: "50", children: "50" })] }) })] }), jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: dataList.length > 0 ? (jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children: dataList.map((item) => {
|
|
4500
|
+
const selected = isMultiple
|
|
4501
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4502
|
+
: watchId === item[column_ref];
|
|
4503
|
+
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
4504
|
+
if (!isMultiple) {
|
|
4505
|
+
setOpenSearchResult(false);
|
|
4506
|
+
setValue(colLabel, item[column_ref]);
|
|
4507
|
+
return;
|
|
4508
|
+
}
|
|
4509
|
+
// For multiple selection, don't add if already selected
|
|
4510
|
+
if (selected)
|
|
4511
|
+
return;
|
|
4512
|
+
const newSet = new Set([
|
|
4513
|
+
...(watchIds ?? []),
|
|
4514
|
+
item[column_ref],
|
|
4515
|
+
]);
|
|
4516
|
+
setValue(colLabel, [...newSet]);
|
|
4517
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected
|
|
4518
|
+
? { color: "colorPalette.400/50", fontWeight: "bold" }
|
|
4519
|
+
: {}), children: !!renderDisplay === true
|
|
4520
|
+
? renderDisplay(item)
|
|
4521
|
+
: item[display_column] }, item[column_ref]));
|
|
4522
|
+
}) })) : (jsxRuntime.jsx(react.Text, { children: searchText
|
|
4523
|
+
? translate.t(removeIndex(`${colLabel}.empty_search_result`))
|
|
4524
|
+
: 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`)) }))] }));
|
|
4384
4525
|
};
|
|
4385
4526
|
|
|
4386
4527
|
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
@@ -4394,17 +4535,17 @@ react.NumberInput.Label;
|
|
|
4394
4535
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4395
4536
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4396
4537
|
const { translate } = useSchemaContext();
|
|
4397
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4538
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4398
4539
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4399
4540
|
const colLabel = `${prefix}${column}`;
|
|
4400
4541
|
const value = watch(`${colLabel}`);
|
|
4401
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4542
|
+
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) => {
|
|
4402
4543
|
setValue(`${colLabel}`, Number(event.target.value));
|
|
4403
|
-
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4544
|
+
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4404
4545
|
};
|
|
4405
4546
|
|
|
4406
4547
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4407
|
-
const { properties,
|
|
4548
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, } = schema;
|
|
4408
4549
|
const { translate } = useSchemaContext();
|
|
4409
4550
|
const colLabel = `${prefix}${column}`;
|
|
4410
4551
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4412,25 +4553,25 @@ const ObjectInput = ({ schema, column, prefix }) => {
|
|
|
4412
4553
|
if (properties === undefined) {
|
|
4413
4554
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4414
4555
|
}
|
|
4415
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
4556
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [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", children: Object.keys(properties ?? {}).map((key) => {
|
|
4416
4557
|
return (
|
|
4417
4558
|
// @ts-expect-error find suitable types
|
|
4418
4559
|
jsxRuntime.jsx(ColumnRenderer, { column: `${key}`,
|
|
4419
4560
|
prefix: `${prefix}${column}.`,
|
|
4420
4561
|
properties }, `form-${colLabel}-${key}`));
|
|
4421
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
4562
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4422
4563
|
};
|
|
4423
4564
|
|
|
4424
4565
|
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4425
4566
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4426
4567
|
const { translate } = useSchemaContext();
|
|
4427
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4568
|
+
const { required, gridColumn = "span 12", gridRow = "span 1" } = schema;
|
|
4428
4569
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4429
4570
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4430
4571
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4431
4572
|
const [newKey, setNewKey] = React.useState();
|
|
4432
4573
|
const [newValue, setNewValue] = React.useState();
|
|
4433
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
4574
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4434
4575
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4435
4576
|
const filtered = entries.filter(([target]) => {
|
|
4436
4577
|
return target !== key;
|
|
@@ -4470,16 +4611,16 @@ const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
|
4470
4611
|
setShowNewEntries(true);
|
|
4471
4612
|
setNewKey(undefined);
|
|
4472
4613
|
setNewValue(undefined);
|
|
4473
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
4614
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4474
4615
|
};
|
|
4475
4616
|
|
|
4476
4617
|
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4477
4618
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4478
4619
|
const { translate } = useSchemaContext();
|
|
4479
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4620
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4480
4621
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4481
4622
|
const colLabel = `${prefix}${column}`;
|
|
4482
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
4623
|
+
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`)) }))] }) }));
|
|
4483
4624
|
};
|
|
4484
4625
|
|
|
4485
4626
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4577,9 +4718,264 @@ const TagPicker = ({ column, schema, prefix }) => {
|
|
|
4577
4718
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4578
4719
|
};
|
|
4579
4720
|
|
|
4721
|
+
const TextAreaInput = ({ column, schema, prefix, }) => {
|
|
4722
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4723
|
+
const { translate } = useSchemaContext();
|
|
4724
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4725
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4726
|
+
const colLabel = `${prefix}${column}`;
|
|
4727
|
+
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`)) }))] }) }));
|
|
4728
|
+
};
|
|
4729
|
+
|
|
4730
|
+
function TimePicker$1({ hour, setHour, minute, setMinute, meridiem, setMeridiem, meridiemLabel = {
|
|
4731
|
+
am: "am",
|
|
4732
|
+
pm: "pm",
|
|
4733
|
+
}, onChange = (_newValue) => { }, }) {
|
|
4734
|
+
// Refs for focus management
|
|
4735
|
+
const hourInputRef = React.useRef(null);
|
|
4736
|
+
const minuteInputRef = React.useRef(null);
|
|
4737
|
+
const meridiemInputRef = React.useRef(null);
|
|
4738
|
+
// Centralized handler for key events, value changes, and focus management
|
|
4739
|
+
const handleKeyDown = (e, field) => {
|
|
4740
|
+
const input = e.target;
|
|
4741
|
+
const value = input.value;
|
|
4742
|
+
// Handle navigation between fields
|
|
4743
|
+
if (e.key === "Tab") {
|
|
4744
|
+
// Tab is handled by the browser, no need to override
|
|
4745
|
+
return;
|
|
4746
|
+
}
|
|
4747
|
+
if (e.key === ":" && field === "hour") {
|
|
4748
|
+
e.preventDefault();
|
|
4749
|
+
minuteInputRef.current?.focus();
|
|
4750
|
+
return;
|
|
4751
|
+
}
|
|
4752
|
+
if (e.key === "Backspace" && value === "") {
|
|
4753
|
+
e.preventDefault();
|
|
4754
|
+
if (field === "minute") {
|
|
4755
|
+
hourInputRef.current?.focus();
|
|
4756
|
+
}
|
|
4757
|
+
else if (field === "meridiem") {
|
|
4758
|
+
minuteInputRef.current?.focus();
|
|
4759
|
+
}
|
|
4760
|
+
return;
|
|
4761
|
+
}
|
|
4762
|
+
// Handle number inputs
|
|
4763
|
+
if (field === "hour") {
|
|
4764
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4765
|
+
const newValue = value + e.key;
|
|
4766
|
+
const numValue = parseInt(newValue, 10);
|
|
4767
|
+
console.log("newValue", newValue, numValue);
|
|
4768
|
+
if (numValue > 12) {
|
|
4769
|
+
const digitValue = parseInt(e.key, 10);
|
|
4770
|
+
setHour(digitValue);
|
|
4771
|
+
onChange({ hour: digitValue, minute, meridiem });
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4774
|
+
// Auto-advance to minutes if we have a valid hour (1-12)
|
|
4775
|
+
if (numValue >= 1 && numValue <= 12) {
|
|
4776
|
+
// Set the hour value
|
|
4777
|
+
setHour(numValue);
|
|
4778
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4779
|
+
// Move to minute input
|
|
4780
|
+
e.preventDefault();
|
|
4781
|
+
minuteInputRef.current?.focus();
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
else if (field === "minute") {
|
|
4786
|
+
if (e.key.match(/^[0-9]$/)) {
|
|
4787
|
+
const newValue = value + e.key;
|
|
4788
|
+
const numValue = parseInt(newValue, 10);
|
|
4789
|
+
if (numValue > 60) {
|
|
4790
|
+
const digitValue = parseInt(e.key, 10);
|
|
4791
|
+
setHour(digitValue);
|
|
4792
|
+
onChange({ hour, minute: digitValue, meridiem });
|
|
4793
|
+
return;
|
|
4794
|
+
}
|
|
4795
|
+
// Auto-advance to meridiem if we have a valid minute (0-59)
|
|
4796
|
+
if (numValue >= 0 && numValue <= 59) {
|
|
4797
|
+
// Set the minute value
|
|
4798
|
+
setMinute(numValue);
|
|
4799
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4800
|
+
// Move to meridiem input
|
|
4801
|
+
e.preventDefault();
|
|
4802
|
+
meridiemInputRef.current?.focus();
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
else if (field === "meridiem") {
|
|
4807
|
+
const key = e.key.toLowerCase();
|
|
4808
|
+
if (key === "a") {
|
|
4809
|
+
e.preventDefault();
|
|
4810
|
+
setMeridiem("am");
|
|
4811
|
+
onChange({ hour, minute, meridiem: "am" });
|
|
4812
|
+
input.value = "am";
|
|
4813
|
+
}
|
|
4814
|
+
else if (key === "p") {
|
|
4815
|
+
e.preventDefault();
|
|
4816
|
+
setMeridiem("pm");
|
|
4817
|
+
onChange({ hour, minute, meridiem: "pm" });
|
|
4818
|
+
input.value = "pm";
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
};
|
|
4822
|
+
// Handle input blur events to validate and format values
|
|
4823
|
+
const handleBlur = (e, field) => {
|
|
4824
|
+
const value = e.target.value;
|
|
4825
|
+
if (field === "hour") {
|
|
4826
|
+
if (value === "") {
|
|
4827
|
+
if (hour !== null) {
|
|
4828
|
+
setHour(null);
|
|
4829
|
+
onChange({ hour: null, minute, meridiem });
|
|
4830
|
+
}
|
|
4831
|
+
return;
|
|
4832
|
+
}
|
|
4833
|
+
const numValue = parseInt(value, 10);
|
|
4834
|
+
if (isNaN(numValue) || numValue < 1 || numValue > 12) {
|
|
4835
|
+
setHour(null);
|
|
4836
|
+
onChange({ hour: null, minute, meridiem });
|
|
4837
|
+
}
|
|
4838
|
+
else if (hour !== numValue) {
|
|
4839
|
+
setHour(numValue);
|
|
4840
|
+
onChange({ hour: numValue, minute, meridiem });
|
|
4841
|
+
}
|
|
4842
|
+
}
|
|
4843
|
+
else if (field === "minute") {
|
|
4844
|
+
if (value === "") {
|
|
4845
|
+
if (minute !== null) {
|
|
4846
|
+
setMinute(null);
|
|
4847
|
+
onChange({ hour, minute: null, meridiem });
|
|
4848
|
+
}
|
|
4849
|
+
return;
|
|
4850
|
+
}
|
|
4851
|
+
const numValue = parseInt(value, 10);
|
|
4852
|
+
if (isNaN(numValue) || numValue < 0 || numValue > 59) {
|
|
4853
|
+
setMinute(null);
|
|
4854
|
+
onChange({ hour, minute: null, meridiem });
|
|
4855
|
+
}
|
|
4856
|
+
else if (minute !== numValue) {
|
|
4857
|
+
setMinute(numValue);
|
|
4858
|
+
onChange({ hour, minute: numValue, meridiem });
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
else if (field === "meridiem") {
|
|
4862
|
+
if (value === "") {
|
|
4863
|
+
if (meridiem !== null) {
|
|
4864
|
+
setMeridiem(null);
|
|
4865
|
+
onChange({ hour, minute, meridiem: null });
|
|
4866
|
+
}
|
|
4867
|
+
return;
|
|
4868
|
+
}
|
|
4869
|
+
const lowerValue = value.toLowerCase();
|
|
4870
|
+
if (lowerValue !== "am" && lowerValue !== "pm") {
|
|
4871
|
+
if (lowerValue === "a") {
|
|
4872
|
+
setMeridiem("am");
|
|
4873
|
+
onChange({ hour, minute, meridiem: "am" });
|
|
4874
|
+
}
|
|
4875
|
+
else if (lowerValue === "p") {
|
|
4876
|
+
setMeridiem("pm");
|
|
4877
|
+
onChange({ hour, minute, meridiem: "pm" });
|
|
4878
|
+
}
|
|
4879
|
+
else {
|
|
4880
|
+
setMeridiem(null);
|
|
4881
|
+
onChange({ hour, minute, meridiem: null });
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
else if (meridiem !== lowerValue) {
|
|
4885
|
+
setMeridiem(lowerValue);
|
|
4886
|
+
onChange({ hour, minute, meridiem: lowerValue });
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
4889
|
+
};
|
|
4890
|
+
// Handle meridiem button click
|
|
4891
|
+
const handleMeridiemClick = (newMeridiem) => {
|
|
4892
|
+
setMeridiem(newMeridiem);
|
|
4893
|
+
onChange({ hour, minute, meridiem: newMeridiem });
|
|
4894
|
+
};
|
|
4895
|
+
const handleClear = () => {
|
|
4896
|
+
setHour(null);
|
|
4897
|
+
setMinute(null);
|
|
4898
|
+
setMeridiem(null);
|
|
4899
|
+
onChange({ hour: null, minute: null, meridiem: null });
|
|
4900
|
+
// Focus the hour field after clearing
|
|
4901
|
+
hourInputRef.current?.focus();
|
|
4902
|
+
};
|
|
4903
|
+
function handleFocus(event) {
|
|
4904
|
+
event.target.select();
|
|
4905
|
+
}
|
|
4906
|
+
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"), onBlur: (e) => handleBlur(e, "hour"), onFocus: handleFocus, 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"), onBlur: (e) => handleBlur(e, "minute"), onFocus: handleFocus, 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, {}) })] }) }));
|
|
4907
|
+
}
|
|
4908
|
+
|
|
4909
|
+
const TimePicker = ({ column, schema, prefix }) => {
|
|
4910
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4911
|
+
const { translate } = useSchemaContext();
|
|
4912
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", format } = schema;
|
|
4913
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4914
|
+
const colLabel = `${prefix}${column}`;
|
|
4915
|
+
const [open, setOpen] = React.useState(false);
|
|
4916
|
+
const value = watch(colLabel);
|
|
4917
|
+
const formatedTime = value ? dayjs(value).format("hh:mm A") : "";
|
|
4918
|
+
// Parse the initial time parts from the ISO time string (HH:mm:ss)
|
|
4919
|
+
const parseTime = (isoTime) => {
|
|
4920
|
+
if (!isoTime)
|
|
4921
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4922
|
+
const parsed = dayjs(isoTime);
|
|
4923
|
+
if (!parsed.isValid())
|
|
4924
|
+
return { hour: 12, minute: 0, meridiem: "am" };
|
|
4925
|
+
let hour = parsed.hour();
|
|
4926
|
+
const minute = parsed.minute();
|
|
4927
|
+
const meridiem = hour >= 12 ? "pm" : "am";
|
|
4928
|
+
if (hour === 0)
|
|
4929
|
+
hour = 12;
|
|
4930
|
+
else if (hour > 12)
|
|
4931
|
+
hour -= 12;
|
|
4932
|
+
return { hour, minute, meridiem };
|
|
4933
|
+
};
|
|
4934
|
+
const initialTime = parseTime(value);
|
|
4935
|
+
const [hour, setHour] = React.useState(initialTime.hour);
|
|
4936
|
+
const [minute, setMinute] = React.useState(initialTime.minute);
|
|
4937
|
+
const [meridiem, setMeridiem] = React.useState(initialTime.meridiem);
|
|
4938
|
+
React.useEffect(() => {
|
|
4939
|
+
const { hour, minute, meridiem } = parseTime(value);
|
|
4940
|
+
setHour(hour);
|
|
4941
|
+
setMinute(minute);
|
|
4942
|
+
setMeridiem(meridiem);
|
|
4943
|
+
}, [value]);
|
|
4944
|
+
// Convert hour, minute, meridiem to 24-hour ISO time string
|
|
4945
|
+
const toIsoTime = (hour, minute, meridiem) => {
|
|
4946
|
+
if (hour === null || minute === null || meridiem === null)
|
|
4947
|
+
return null;
|
|
4948
|
+
let h = hour;
|
|
4949
|
+
if (meridiem === "am" && hour === 12)
|
|
4950
|
+
h = 0;
|
|
4951
|
+
else if (meridiem === "pm" && hour < 12)
|
|
4952
|
+
h = hour + 12;
|
|
4953
|
+
return dayjs().hour(h).minute(minute).second(0).format(format);
|
|
4954
|
+
};
|
|
4955
|
+
// Handle changes to time parts
|
|
4956
|
+
const handleTimeChange = ({ hour: newHour, minute: newMinute, meridiem: newMeridiem, }) => {
|
|
4957
|
+
setHour(newHour);
|
|
4958
|
+
setMinute(newMinute);
|
|
4959
|
+
setMeridiem(newMeridiem);
|
|
4960
|
+
const isoTime = toIsoTime(newHour, newMinute, newMeridiem);
|
|
4961
|
+
setValue(colLabel, isoTime, { shouldValidate: true, shouldDirty: true });
|
|
4962
|
+
};
|
|
4963
|
+
const containerRef = React.useRef(null);
|
|
4964
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4965
|
+
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: () => {
|
|
4966
|
+
setOpen(true);
|
|
4967
|
+
}, justifyContent: "start", children: [jsxRuntime.jsx(io.IoMdClock, {}), value !== undefined ? `${formatedTime}` : ""] }) }), 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: {
|
|
4968
|
+
am: translate.t(removeIndex(`common.am`)),
|
|
4969
|
+
pm: translate.t(removeIndex(`common.pm`)),
|
|
4970
|
+
} }) }) }) }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4971
|
+
};
|
|
4972
|
+
|
|
4580
4973
|
const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
4581
4974
|
const colSchema = schema;
|
|
4582
|
-
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4975
|
+
const { type, variant, properties: innerProperties, foreign_key, format, items, } = schema;
|
|
4976
|
+
if (variant === "custom-input") {
|
|
4977
|
+
return jsxRuntime.jsx(CustomInput, { schema: colSchema, prefix, column });
|
|
4978
|
+
}
|
|
4583
4979
|
if (type === "string") {
|
|
4584
4980
|
if ((schema.enum ?? []).length > 0) {
|
|
4585
4981
|
return jsxRuntime.jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
@@ -4588,9 +4984,15 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4588
4984
|
idPickerSanityCheck(column, foreign_key);
|
|
4589
4985
|
return jsxRuntime.jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4590
4986
|
}
|
|
4591
|
-
if (
|
|
4987
|
+
if (format === "date") {
|
|
4592
4988
|
return jsxRuntime.jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4593
4989
|
}
|
|
4990
|
+
if (format === "time") {
|
|
4991
|
+
return jsxRuntime.jsx(TimePicker, { schema: colSchema, prefix, column });
|
|
4992
|
+
}
|
|
4993
|
+
if (variant === "text-area") {
|
|
4994
|
+
return jsxRuntime.jsx(TextAreaInput, { schema: colSchema, prefix, column });
|
|
4995
|
+
}
|
|
4594
4996
|
return jsxRuntime.jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4595
4997
|
}
|
|
4596
4998
|
if (type === "number" || type === "integer") {
|
|
@@ -4637,39 +5039,52 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4637
5039
|
};
|
|
4638
5040
|
|
|
4639
5041
|
const ArrayViewer = ({ schema, column, prefix }) => {
|
|
4640
|
-
const {
|
|
5042
|
+
const { gridColumn = "span 4", gridRow = "span 1", required, items } = schema;
|
|
4641
5043
|
const { translate } = useSchemaContext();
|
|
4642
5044
|
const colLabel = `${prefix}${column}`;
|
|
4643
5045
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4644
5046
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4645
5047
|
const values = watch(colLabel) ?? [];
|
|
4646
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.
|
|
5048
|
+
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: "*" })] }), values.map((field, index) => (jsxRuntime.jsx(react.Flex, { flexFlow: "column", children: jsxRuntime.jsx(react.Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", autoFlow: "row", children: jsxRuntime.jsx(SchemaViewer, { column: `${index}`,
|
|
4647
5049
|
prefix: `${colLabel}.`,
|
|
4648
|
-
schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5050
|
+
schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4649
5051
|
};
|
|
4650
5052
|
|
|
4651
5053
|
const BooleanViewer = ({ schema, column, prefix, }) => {
|
|
4652
5054
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4653
5055
|
const { translate } = useSchemaContext();
|
|
4654
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5056
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4655
5057
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4656
5058
|
const colLabel = `${prefix}${column}`;
|
|
4657
5059
|
const value = watch(colLabel);
|
|
4658
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5060
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4659
5061
|
gridRow, children: [jsxRuntime.jsx(react.Text, { children: value
|
|
4660
5062
|
? translate.t(removeIndex(`${colLabel}.true`))
|
|
4661
|
-
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5063
|
+
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
5064
|
+
};
|
|
5065
|
+
|
|
5066
|
+
const CustomViewer = ({ column, schema, prefix }) => {
|
|
5067
|
+
const formContext = reactHookForm.useFormContext();
|
|
5068
|
+
const { inputViewerRender } = schema;
|
|
5069
|
+
return (inputViewerRender &&
|
|
5070
|
+
inputViewerRender({
|
|
5071
|
+
column,
|
|
5072
|
+
schema,
|
|
5073
|
+
prefix,
|
|
5074
|
+
formContext,
|
|
5075
|
+
}));
|
|
4662
5076
|
};
|
|
4663
5077
|
|
|
4664
5078
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4665
5079
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4666
5080
|
const { translate } = useSchemaContext();
|
|
4667
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5081
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4668
5082
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4669
5083
|
const colLabel = `${prefix}${column}`;
|
|
4670
5084
|
const selectedDate = watch(colLabel);
|
|
4671
|
-
|
|
4672
|
-
|
|
5085
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
5086
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5087
|
+
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`) }))] }));
|
|
4673
5088
|
};
|
|
4674
5089
|
|
|
4675
5090
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
@@ -4677,11 +5092,11 @@ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
4677
5092
|
const { translate } = useSchemaContext();
|
|
4678
5093
|
const { required } = schema;
|
|
4679
5094
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4680
|
-
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
5095
|
+
const { gridColumn = "span 4", gridRow = "span 1", renderDisplay } = schema;
|
|
4681
5096
|
const colLabel = `${prefix}${column}`;
|
|
4682
5097
|
const watchEnum = watch(colLabel);
|
|
4683
5098
|
const watchEnums = (watch(colLabel) ?? []);
|
|
4684
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5099
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4685
5100
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
|
|
4686
5101
|
const item = enumValue;
|
|
4687
5102
|
if (item === undefined) {
|
|
@@ -4690,32 +5105,25 @@ const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
4690
5105
|
return (jsxRuntime.jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4691
5106
|
? renderDisplay(item)
|
|
4692
5107
|
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
4693
|
-
}) })), !isMultiple && (jsxRuntime.jsx(react.Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5108
|
+
}) })), !isMultiple && (jsxRuntime.jsx(react.Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4694
5109
|
};
|
|
4695
5110
|
|
|
4696
5111
|
const FileViewer = ({ column, schema, prefix }) => {
|
|
4697
|
-
const {
|
|
5112
|
+
const { watch } = reactHookForm.useFormContext();
|
|
4698
5113
|
const { translate } = useSchemaContext();
|
|
4699
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5114
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", } = schema;
|
|
4700
5115
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4701
5116
|
const currentFiles = (watch(column) ?? []);
|
|
4702
5117
|
const colLabel = `${prefix}${column}`;
|
|
4703
|
-
return (jsxRuntime.
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
}, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4707
|
-
return (jsxRuntime.jsx(react.Card.Root, { variant: "subtle", children: jsxRuntime.jsxs(react.Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4708
|
-
setValue(column, currentFiles.filter(({ name }) => {
|
|
4709
|
-
return name !== file.name;
|
|
4710
|
-
}));
|
|
4711
|
-
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4712
|
-
}) }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
5118
|
+
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) => {
|
|
5119
|
+
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));
|
|
5120
|
+
}) }) }));
|
|
4713
5121
|
};
|
|
4714
5122
|
|
|
4715
5123
|
const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4716
5124
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4717
5125
|
const { idMap, translate } = useSchemaContext();
|
|
4718
|
-
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
5126
|
+
const { required, gridColumn = "span 4", gridRow = "span 1", renderDisplay, foreign_key, } = schema;
|
|
4719
5127
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4720
5128
|
const { display_column } = foreign_key;
|
|
4721
5129
|
const colLabel = `${prefix}${column}`;
|
|
@@ -4731,7 +5139,7 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4731
5139
|
}
|
|
4732
5140
|
return record[display_column];
|
|
4733
5141
|
};
|
|
4734
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.
|
|
5142
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4735
5143
|
gridRow, children: [isMultiple && (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
|
|
4736
5144
|
const item = idMap[id];
|
|
4737
5145
|
if (item === undefined) {
|
|
@@ -4740,21 +5148,21 @@ const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4740
5148
|
return (jsxRuntime.jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4741
5149
|
? renderDisplay(item)
|
|
4742
5150
|
: item[display_column] }, id));
|
|
4743
|
-
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5151
|
+
}) })), !isMultiple && jsxRuntime.jsx(react.Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4744
5152
|
};
|
|
4745
5153
|
|
|
4746
5154
|
const NumberViewer = ({ schema, column, prefix, }) => {
|
|
4747
5155
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4748
5156
|
const { translate } = useSchemaContext();
|
|
4749
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5157
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4750
5158
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4751
5159
|
const colLabel = `${prefix}${column}`;
|
|
4752
5160
|
const value = watch(colLabel);
|
|
4753
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5161
|
+
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`)) }))] }));
|
|
4754
5162
|
};
|
|
4755
5163
|
|
|
4756
5164
|
const ObjectViewer = ({ schema, column, prefix }) => {
|
|
4757
|
-
const { properties,
|
|
5165
|
+
const { properties, gridColumn = "span 12", gridRow = "span 1", required, } = schema;
|
|
4758
5166
|
const { translate } = useSchemaContext();
|
|
4759
5167
|
const colLabel = `${prefix}${column}`;
|
|
4760
5168
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -4762,25 +5170,26 @@ const ObjectViewer = ({ schema, column, prefix }) => {
|
|
|
4762
5170
|
if (properties === undefined) {
|
|
4763
5171
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4764
5172
|
}
|
|
4765
|
-
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [jsxRuntime.jsxs(react.Box, { as: "label",
|
|
5173
|
+
return (jsxRuntime.jsxs(react.Box, { gridRow, gridColumn, children: [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", gridColumn,
|
|
5174
|
+
gridRow, children: Object.keys(properties ?? {}).map((key) => {
|
|
4766
5175
|
return (
|
|
4767
5176
|
// @ts-expect-error find suitable types
|
|
4768
5177
|
jsxRuntime.jsx(ColumnViewer, { column: `${key}`,
|
|
4769
5178
|
prefix: `${prefix}${column}.`,
|
|
4770
5179
|
properties }, `form-objectviewer-${colLabel}-${key}`));
|
|
4771
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.
|
|
5180
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.field_required`)) }))] }));
|
|
4772
5181
|
};
|
|
4773
5182
|
|
|
4774
5183
|
const RecordInput = ({ column, schema, prefix }) => {
|
|
4775
5184
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4776
5185
|
const { translate } = useSchemaContext();
|
|
4777
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5186
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4778
5187
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4779
5188
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4780
5189
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4781
5190
|
const [newKey, setNewKey] = React.useState();
|
|
4782
5191
|
const [newValue, setNewValue] = React.useState();
|
|
4783
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.
|
|
5192
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.field_label`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4784
5193
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4785
5194
|
const filtered = entries.filter(([target]) => {
|
|
4786
5195
|
return target !== key;
|
|
@@ -4820,7 +5229,17 @@ const RecordInput = ({ column, schema, prefix }) => {
|
|
|
4820
5229
|
setShowNewEntries(true);
|
|
4821
5230
|
setNewKey(undefined);
|
|
4822
5231
|
setNewValue(undefined);
|
|
4823
|
-
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.
|
|
5232
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
5233
|
+
};
|
|
5234
|
+
|
|
5235
|
+
const StringViewer = ({ column, schema, prefix, }) => {
|
|
5236
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5237
|
+
const { translate } = useSchemaContext();
|
|
5238
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5239
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5240
|
+
const colLabel = `${prefix}${column}`;
|
|
5241
|
+
const value = watch(colLabel);
|
|
5242
|
+
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`)) }))] }) }));
|
|
4824
5243
|
};
|
|
4825
5244
|
|
|
4826
5245
|
const TagViewer = ({ column, schema, prefix }) => {
|
|
@@ -4908,19 +5327,35 @@ const TagViewer = ({ column, schema, prefix }) => {
|
|
|
4908
5327
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4909
5328
|
};
|
|
4910
5329
|
|
|
4911
|
-
const
|
|
5330
|
+
const TextAreaViewer = ({ column, schema, prefix, }) => {
|
|
4912
5331
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4913
5332
|
const { translate } = useSchemaContext();
|
|
4914
|
-
const { required, gridColumn, gridRow } = schema;
|
|
5333
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
4915
5334
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4916
5335
|
const colLabel = `${prefix}${column}`;
|
|
4917
5336
|
const value = watch(colLabel);
|
|
4918
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.
|
|
5337
|
+
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`)) }))] }) }));
|
|
5338
|
+
};
|
|
5339
|
+
|
|
5340
|
+
const TimeViewer = ({ column, schema, prefix }) => {
|
|
5341
|
+
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
5342
|
+
const { translate } = useSchemaContext();
|
|
5343
|
+
const { required, gridColumn = "span 4", gridRow = "span 1" } = schema;
|
|
5344
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
5345
|
+
const colLabel = `${prefix}${column}`;
|
|
5346
|
+
const selectedDate = watch(colLabel);
|
|
5347
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
5348
|
+
gridRow, children: [jsxRuntime.jsx(react.Text, { children: selectedDate !== undefined
|
|
5349
|
+
? dayjs(selectedDate).format("hh:mm A")
|
|
5350
|
+
: "" }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4919
5351
|
};
|
|
4920
5352
|
|
|
4921
5353
|
const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
4922
5354
|
const colSchema = schema;
|
|
4923
5355
|
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
5356
|
+
if (variant === "custom-input") {
|
|
5357
|
+
return jsxRuntime.jsx(CustomViewer, { schema: colSchema, prefix, column });
|
|
5358
|
+
}
|
|
4924
5359
|
if (type === "string") {
|
|
4925
5360
|
if ((schema.enum ?? []).length > 0) {
|
|
4926
5361
|
return jsxRuntime.jsx(EnumViewer, { schema: colSchema, prefix, column });
|
|
@@ -4932,6 +5367,12 @@ const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
|
4932
5367
|
if (variant === "date-picker") {
|
|
4933
5368
|
return jsxRuntime.jsx(DateViewer, { schema: colSchema, prefix, column });
|
|
4934
5369
|
}
|
|
5370
|
+
if (variant === "time-picker") {
|
|
5371
|
+
return jsxRuntime.jsx(TimeViewer, { schema: colSchema, prefix, column });
|
|
5372
|
+
}
|
|
5373
|
+
if (variant === "text-area") {
|
|
5374
|
+
return jsxRuntime.jsx(TextAreaViewer, { schema: colSchema, prefix, column });
|
|
5375
|
+
}
|
|
4935
5376
|
return jsxRuntime.jsx(StringViewer, { schema: colSchema, prefix, column });
|
|
4936
5377
|
}
|
|
4937
5378
|
if (type === "number" || type === "integer") {
|
|
@@ -5054,7 +5495,7 @@ const FormBody = () => {
|
|
|
5054
5495
|
include,
|
|
5055
5496
|
});
|
|
5056
5497
|
if (isSuccess) {
|
|
5057
|
-
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("
|
|
5498
|
+
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 () => {
|
|
5058
5499
|
setIsError(false);
|
|
5059
5500
|
setIsSubmiting(false);
|
|
5060
5501
|
setIsSuccess(false);
|
|
@@ -5062,10 +5503,10 @@ const FormBody = () => {
|
|
|
5062
5503
|
setValidatedData(undefined);
|
|
5063
5504
|
const data = await getUpdatedData();
|
|
5064
5505
|
methods.reset(data);
|
|
5065
|
-
}, formNoValidate: true, children: translate.t("
|
|
5506
|
+
}, formNoValidate: true, children: translate.t("submit_again") }) })] }));
|
|
5066
5507
|
}
|
|
5067
5508
|
if (isConfirming) {
|
|
5068
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows:
|
|
5509
|
+
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) => {
|
|
5069
5510
|
return (jsxRuntime.jsx(ColumnViewer
|
|
5070
5511
|
// @ts-expect-error find suitable types
|
|
5071
5512
|
, {
|
|
@@ -5077,7 +5518,7 @@ const FormBody = () => {
|
|
|
5077
5518
|
onFormSubmit(validatedData);
|
|
5078
5519
|
}, 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)}` })] }) }) }) }) }))] }));
|
|
5079
5520
|
}
|
|
5080
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "2", children: [jsxRuntime.jsx(react.Grid, { gap: "4", gridTemplateColumns: "repeat(12, 1fr)",
|
|
5521
|
+
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) => {
|
|
5081
5522
|
return (jsxRuntime.jsx(ColumnRenderer
|
|
5082
5523
|
// @ts-expect-error find suitable types
|
|
5083
5524
|
, {
|
|
@@ -5093,8 +5534,8 @@ const FormTitle = () => {
|
|
|
5093
5534
|
return jsxRuntime.jsx(react.Heading, { children: translate.t("title") });
|
|
5094
5535
|
};
|
|
5095
5536
|
|
|
5096
|
-
const DefaultForm = ({ formConfig, }) => {
|
|
5097
|
-
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5537
|
+
const DefaultForm = ({ formConfig, showTitle = true, }) => {
|
|
5538
|
+
return (jsxRuntime.jsx(FormRoot, { ...formConfig, children: jsxRuntime.jsxs(react.Grid, { gap: "2", children: [showTitle && jsxRuntime.jsx(FormTitle, {}), jsxRuntime.jsx(FormBody, {})] }) }));
|
|
5098
5539
|
};
|
|
5099
5540
|
|
|
5100
5541
|
const useForm = ({ preLoadedValues, keyPrefix }) => {
|
|
@@ -5135,7 +5576,6 @@ exports.DefaultCardTitle = DefaultCardTitle;
|
|
|
5135
5576
|
exports.DefaultForm = DefaultForm;
|
|
5136
5577
|
exports.DefaultTable = DefaultTable;
|
|
5137
5578
|
exports.DensityToggleButton = DensityToggleButton;
|
|
5138
|
-
exports.EditOrderButton = EditOrderButton;
|
|
5139
5579
|
exports.EditSortingButton = EditSortingButton;
|
|
5140
5580
|
exports.EmptyState = EmptyState$1;
|
|
5141
5581
|
exports.ErrorAlert = ErrorAlert;
|
|
@@ -5159,12 +5599,12 @@ exports.TableCardContainer = TableCardContainer;
|
|
|
5159
5599
|
exports.TableCards = TableCards;
|
|
5160
5600
|
exports.TableComponent = TableComponent;
|
|
5161
5601
|
exports.TableControls = TableControls;
|
|
5602
|
+
exports.TableDataDisplay = TableDataDisplay;
|
|
5162
5603
|
exports.TableFilter = TableFilter;
|
|
5163
5604
|
exports.TableFilterTags = TableFilterTags;
|
|
5164
5605
|
exports.TableFooter = TableFooter;
|
|
5165
5606
|
exports.TableHeader = TableHeader;
|
|
5166
5607
|
exports.TableLoadingComponent = TableLoadingComponent;
|
|
5167
|
-
exports.TableOrderer = TableOrderer;
|
|
5168
5608
|
exports.TableSelector = TableSelector;
|
|
5169
5609
|
exports.TableSorter = TableSorter;
|
|
5170
5610
|
exports.TableViewer = TableViewer;
|