@bsol-oss/react-datatable5 5.0.1 → 6.0.1
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 +124 -26
- package/dist/index.js +1090 -93
- package/dist/index.mjs +1090 -99
- package/dist/types/components/Controls/TablePagination.d.ts +1 -0
- package/dist/types/components/DataTable/CardHeader.d.ts +13 -0
- package/dist/types/components/DataTable/DataDisplay.d.ts +4 -0
- package/dist/types/components/DataTable/DataTable.d.ts +1 -1
- package/dist/types/components/DataTable/DataTableContext.d.ts +2 -1
- package/dist/types/components/DataTable/DataTableServer.d.ts +1 -1
- package/dist/types/components/DataTable/Table.d.ts +1 -1
- package/dist/types/components/DataTable/TableCardContainer.d.ts +2 -1
- package/dist/types/components/DataTable/TableCards.d.ts +1 -1
- package/dist/types/components/DataTable/useDataFromUrl.d.ts +5 -4
- package/dist/types/components/DataTable/useDataTableContext.d.ts +1 -1
- package/dist/types/components/DataTable/useDataTableServer.d.ts +1 -2
- package/dist/types/components/DataTable/utils/getColumns.d.ts +13 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +21 -0
- package/dist/types/components/DatePicker/RangeDatePicker.d.ts +18 -0
- package/dist/types/components/DatePicker/getMultiDates.d.ts +7 -0
- package/dist/types/components/DatePicker/getRangeDates.d.ts +6 -0
- package/dist/types/components/Form/Form.d.ts +33 -0
- package/dist/types/components/Form/SchemaFormContext.d.ts +15 -0
- package/dist/types/components/Form/components/BooleanPicker.d.ts +4 -0
- package/dist/types/components/Form/components/DatePicker.d.ts +4 -0
- package/dist/types/components/Form/components/IdPicker.d.ts +7 -0
- package/dist/types/components/Form/components/IdViewer.d.ts +8 -0
- package/dist/types/components/Form/components/NumberInputField.d.ts +4 -0
- package/dist/types/components/Form/components/ObjectInput.d.ts +4 -0
- package/dist/types/components/Form/components/StringInputField.d.ts +10 -0
- package/dist/types/components/Form/useSchemaContext.d.ts +10 -0
- package/dist/types/components/Form/utils/clearEmptyString.d.ts +3 -0
- package/dist/types/components/Form/utils/getTableData.d.ts +12 -0
- package/dist/types/components/Form/utils/idListSanityCheck.d.ts +1 -0
- package/dist/types/components/Form/utils/snakeToLabel.d.ts +1 -0
- package/dist/types/components/ui/accordion.d.ts +12 -0
- package/dist/types/components/ui/checkbox-card.d.ts +13 -0
- package/dist/types/components/ui/data-list.d.ts +11 -0
- package/dist/types/components/ui/link-button.d.ts +5 -0
- package/dist/types/components/ui/number-input.d.ts +8 -0
- package/dist/types/components/ui/pagination.d.ts +20 -0
- package/dist/types/components/ui/radio-card.d.ts +16 -0
- package/dist/types/components/ui/toggle-tip.d.ts +10 -0
- package/dist/types/index.d.ts +9 -2
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('@chakra-ui/react');
|
|
5
5
|
var ai = require('react-icons/ai');
|
|
6
|
-
var md = require('react-icons/md');
|
|
7
6
|
var React = require('react');
|
|
7
|
+
var md = require('react-icons/md');
|
|
8
8
|
var lu = require('react-icons/lu');
|
|
9
9
|
var fa6 = require('react-icons/fa6');
|
|
10
10
|
var bi = require('react-icons/bi');
|
|
@@ -16,9 +16,14 @@ var bs = require('react-icons/bs');
|
|
|
16
16
|
var gr = require('react-icons/gr');
|
|
17
17
|
var io5 = require('react-icons/io5');
|
|
18
18
|
var hi = require('react-icons/hi');
|
|
19
|
+
var hi2 = require('react-icons/hi2');
|
|
19
20
|
var adapter = require('@atlaskit/pragmatic-drag-and-drop/element/adapter');
|
|
20
21
|
var invariant = require('tiny-invariant');
|
|
21
22
|
var axios = require('axios');
|
|
23
|
+
var reactHookForm = require('react-hook-form');
|
|
24
|
+
var reactQuery = require('@tanstack/react-query');
|
|
25
|
+
var dayjs = require('dayjs');
|
|
26
|
+
var Dayzed = require('dayzed');
|
|
22
27
|
|
|
23
28
|
function _interopNamespaceDefault(e) {
|
|
24
29
|
var n = Object.create(null);
|
|
@@ -39,13 +44,39 @@ function _interopNamespaceDefault(e) {
|
|
|
39
44
|
|
|
40
45
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
41
46
|
|
|
47
|
+
const TableContext = React.createContext({
|
|
48
|
+
table: {},
|
|
49
|
+
refreshData: () => { },
|
|
50
|
+
globalFilter: "",
|
|
51
|
+
setGlobalFilter: () => { },
|
|
52
|
+
loading: false,
|
|
53
|
+
hasError: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const useDataTableContext = () => {
|
|
57
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } = React.useContext(TableContext);
|
|
58
|
+
return {
|
|
59
|
+
table,
|
|
60
|
+
refreshData,
|
|
61
|
+
globalFilter,
|
|
62
|
+
setGlobalFilter,
|
|
63
|
+
loading,
|
|
64
|
+
hasError,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const Button = React__namespace.forwardRef(function Button(props, ref) {
|
|
69
|
+
const { loading, disabled, loadingText, children, ...rest } = props;
|
|
70
|
+
return (jsxRuntime.jsx(react.Button, { disabled: loading || disabled, ref: ref, ...rest, children: loading && !loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.AbsoluteCenter, { display: "inline-flex", children: jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }) }), jsxRuntime.jsx(react.Span, { opacity: 0, children: children })] })) : loading && loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }), loadingText] })) : (children) }));
|
|
71
|
+
});
|
|
72
|
+
|
|
42
73
|
const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWidth, {}), }) => {
|
|
43
74
|
const { table } = useDataTableContext();
|
|
44
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Toggle Density",
|
|
75
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Toggle Density", onClick: () => {
|
|
45
76
|
table.toggleDensity();
|
|
46
|
-
} })), !!text !== false && (jsxRuntime.
|
|
77
|
+
}, children: icon })), !!text !== false && (jsxRuntime.jsxs(Button, { variant: "ghost", "aria-label": "Toggle Density", onClick: () => {
|
|
47
78
|
table.toggleDensity();
|
|
48
|
-
}, children: text }))] }));
|
|
79
|
+
}, children: [icon, text] }))] }));
|
|
49
80
|
};
|
|
50
81
|
|
|
51
82
|
const CloseButton = React__namespace.forwardRef(function CloseButton(props, ref) {
|
|
@@ -78,27 +109,6 @@ const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {})
|
|
|
78
109
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react.DialogRoot, { size: "cover", children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(react.DialogTrigger, { children: jsxRuntime.jsxs(react.Button, { variant: "ghost", children: [icon, text] }) }), jsxRuntime.jsxs(react.DialogContent, { children: [jsxRuntime.jsx(react.DialogCloseTrigger, {}), jsxRuntime.jsxs(react.DialogHeader, { children: [jsxRuntime.jsx(react.DialogTitle, {}), title] }), jsxRuntime.jsx(react.DialogBody, { children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) }), jsxRuntime.jsx(react.DialogFooter, {})] })] }) }));
|
|
79
110
|
};
|
|
80
111
|
|
|
81
|
-
const TableContext = React.createContext({
|
|
82
|
-
table: {},
|
|
83
|
-
refreshData: () => { },
|
|
84
|
-
globalFilter: "",
|
|
85
|
-
setGlobalFilter: () => { },
|
|
86
|
-
loading: false,
|
|
87
|
-
hasError: false,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const useDataTableContext = () => {
|
|
91
|
-
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } = React.useContext(TableContext);
|
|
92
|
-
return {
|
|
93
|
-
table,
|
|
94
|
-
refreshData,
|
|
95
|
-
globalFilter,
|
|
96
|
-
setGlobalFilter,
|
|
97
|
-
loading,
|
|
98
|
-
hasError,
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
112
|
const TableSorter = () => {
|
|
103
113
|
const { table } = useDataTableContext();
|
|
104
114
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsx(jsxRuntime.Fragment, { children: headerGroup.headers.map((header) => {
|
|
@@ -187,6 +197,49 @@ const RowCountText = () => {
|
|
|
187
197
|
return jsxRuntime.jsx(react.Text, { children: table.getRowCount() });
|
|
188
198
|
};
|
|
189
199
|
|
|
200
|
+
const Tag = React__namespace.forwardRef(function Tag(props, ref) {
|
|
201
|
+
const { startElement, endElement, onClose, closable = !!onClose, children, ...rest } = props;
|
|
202
|
+
return (jsxRuntime.jsxs(react.Tag.Root, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.Tag.StartElement, { children: startElement })), jsxRuntime.jsx(react.Tag.Label, { children: children }), endElement && (jsxRuntime.jsx(react.Tag.EndElement, { children: endElement })), closable && (jsxRuntime.jsx(react.Tag.EndElement, { children: jsxRuntime.jsx(react.Tag.CloseTrigger, { onClick: onClose }) }))] }));
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const CardHeader = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, imageProps = {}, }) => {
|
|
206
|
+
if (!!row.original === false) {
|
|
207
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
208
|
+
}
|
|
209
|
+
const isShowFirstColumn = !!titleColumnId || showTag;
|
|
210
|
+
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto", gap: "1rem", children: [!!imageColumnId && (jsxRuntime.jsx(react.Image, { width: "100%", src: row.original[imageColumnId], ...imageProps })), isShowFirstColumn && (jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: [!!titleColumnId && (jsxRuntime.jsx(react.Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] })), showTag && (jsxRuntime.jsx(Tag, { fontSize: "large", startElement: tagIcon && tagIcon({}), children: row.original[tagColumnId] }))] }))] }));
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const snakeToLabel = (str) => {
|
|
214
|
+
return str
|
|
215
|
+
.split("_") // Split by underscore
|
|
216
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize each word
|
|
217
|
+
.join(" "); // Join with space
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const DataDisplay = ({ variant = "" }) => {
|
|
221
|
+
const { table } = React.useContext(TableContext);
|
|
222
|
+
if (variant == "horizontal") {
|
|
223
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
|
|
224
|
+
return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", orientation: "horizontal", overflow: 'auto', children: row.getVisibleCells().map((cell) => {
|
|
225
|
+
return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${cell.getValue()}` })] }, cell.id));
|
|
226
|
+
}) }) }) }, `chakra-table-card-${row.id}`));
|
|
227
|
+
}) }));
|
|
228
|
+
}
|
|
229
|
+
if (variant == "stats") {
|
|
230
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
|
|
231
|
+
return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "flex", flexFlow: "row", variant: "subtle", overflow: 'auto', children: row.getVisibleCells().map((cell) => {
|
|
232
|
+
return (jsxRuntime.jsxs(react.DataList.Item, { display: "flex", justifyContent: "center", alignItems: "center", flex: "1 0 10rem", children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${cell.getValue()}` })] }, cell.id));
|
|
233
|
+
}) }) }) }, `chakra-table-card-${row.id}`));
|
|
234
|
+
}) }));
|
|
235
|
+
}
|
|
236
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
|
|
237
|
+
return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsx(react.Card.Body, { children: jsxRuntime.jsx(react.DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", children: row.getVisibleCells().map((cell) => {
|
|
238
|
+
return (jsxRuntime.jsxs(react.DataList.Item, { children: [jsxRuntime.jsx(react.DataList.ItemLabel, { children: snakeToLabel(cell.column.id) }), jsxRuntime.jsx(react.DataList.ItemValue, { children: `${cell.getValue()}` })] }, cell.id));
|
|
239
|
+
}) }) }) }, `chakra-table-card-${row.id}`));
|
|
240
|
+
}) }));
|
|
241
|
+
};
|
|
242
|
+
|
|
190
243
|
// Reference: https://tanstack.com/table/latest/docs/framework/react/examples/custom-features
|
|
191
244
|
// TypeScript setup for our new feature with all of the same type-safety as stock TanStack Table features
|
|
192
245
|
// end of TS setup!
|
|
@@ -320,10 +373,10 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
320
373
|
});
|
|
321
374
|
React.useEffect(() => {
|
|
322
375
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
323
|
-
}, []);
|
|
376
|
+
}, [table, setColumnOrder]);
|
|
324
377
|
React.useEffect(() => {
|
|
325
378
|
onRowSelect(table.getState().rowSelection, data);
|
|
326
|
-
}, [table
|
|
379
|
+
}, [data, onRowSelect, table]);
|
|
327
380
|
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
328
381
|
table: { ...table },
|
|
329
382
|
refreshData: () => {
|
|
@@ -339,7 +392,7 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
339
392
|
const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder, columnFilters, columnVisibility, density, globalFilter, pagination, sorting, rowSelection, setPagination, setSorting, setColumnFilters, setRowSelection, setGlobalFilter, setColumnOrder, setDensity, setColumnVisibility, data, loading, hasError, refreshData, children, }) => {
|
|
340
393
|
const table = reactTable.useReactTable({
|
|
341
394
|
_features: [DensityFeature],
|
|
342
|
-
data: data.
|
|
395
|
+
data: data.data,
|
|
343
396
|
rowCount: data.count ?? 0,
|
|
344
397
|
columns: columns,
|
|
345
398
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
@@ -388,7 +441,7 @@ const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
388
441
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
389
442
|
}, []);
|
|
390
443
|
React.useEffect(() => {
|
|
391
|
-
onRowSelect(table.getState().rowSelection, data.
|
|
444
|
+
onRowSelect(table.getState().rowSelection, data.data);
|
|
392
445
|
}, [table.getState().rowSelection]);
|
|
393
446
|
React.useEffect(() => {
|
|
394
447
|
table.resetPagination();
|
|
@@ -403,27 +456,6 @@ const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
403
456
|
}, children: children }));
|
|
404
457
|
};
|
|
405
458
|
|
|
406
|
-
const Tag = React__namespace.forwardRef(function Tag(props, ref) {
|
|
407
|
-
const { startElement, endElement, onClose, closable = !!onClose, children, ...rest } = props;
|
|
408
|
-
return (jsxRuntime.jsxs(react.Tag.Root, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.Tag.StartElement, { children: startElement })), jsxRuntime.jsx(react.Tag.Label, { children: children }), endElement && (jsxRuntime.jsx(react.Tag.EndElement, { children: endElement })), closable && (jsxRuntime.jsx(react.Tag.EndElement, { children: jsxRuntime.jsx(react.Tag.CloseTrigger, { onClick: onClose }) }))] }));
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
const DefaultCard = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, }) => {
|
|
412
|
-
if (!!row.original === false) {
|
|
413
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
414
|
-
}
|
|
415
|
-
// const imageIdExists = Object.keys(row.original).some((key) => {
|
|
416
|
-
// return key === imageColumnId;
|
|
417
|
-
// });
|
|
418
|
-
// const titleIdExists = Object.keys(row.original).some((key) => {
|
|
419
|
-
// return key === titleColumnId;
|
|
420
|
-
// });
|
|
421
|
-
// const tagIdExists = Object.keys(row.original).some((key) => {
|
|
422
|
-
// return key === tagColumnId;
|
|
423
|
-
// });
|
|
424
|
-
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto", gap: "1rem", children: [jsxRuntime.jsx(react.Flex, { justifyContent: "center", alignItems: "center", children: jsxRuntime.jsx(react.Image, { src: row.original[imageColumnId] }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: [jsxRuntime.jsx(react.Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] }), showTag && (jsxRuntime.jsx(Tag, { fontSize: "large", startElement: tagIcon && tagIcon({}), children: row.original[tagColumnId] }))] })] }));
|
|
425
|
-
};
|
|
426
|
-
|
|
427
459
|
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
428
460
|
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
429
461
|
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 }))] }));
|
|
@@ -565,11 +597,6 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
565
597
|
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(bi.BiUpArrow, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(bi.BiDownArrow, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
|
|
566
598
|
};
|
|
567
599
|
|
|
568
|
-
const Button = React__namespace.forwardRef(function Button(props, ref) {
|
|
569
|
-
const { loading, disabled, loadingText, children, ...rest } = props;
|
|
570
|
-
return (jsxRuntime.jsx(react.Button, { disabled: loading || disabled, ref: ref, ...rest, children: loading && !loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.AbsoluteCenter, { display: "inline-flex", children: jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }) }), jsxRuntime.jsx(react.Span, { opacity: 0, children: children })] })) : loading && loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }), loadingText] })) : (children) }));
|
|
571
|
-
});
|
|
572
|
-
|
|
573
600
|
const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
|
|
574
601
|
const { table } = useDataTableContext();
|
|
575
602
|
const SELECTION_BOX_WIDTH = 20;
|
|
@@ -676,9 +703,9 @@ const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
|
676
703
|
refreshData();
|
|
677
704
|
}, "aria-label": "refresh", children: jsxRuntime.jsx(io5.IoReload, {}) }) }));
|
|
678
705
|
}
|
|
679
|
-
return (jsxRuntime.
|
|
706
|
+
return (jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
680
707
|
refreshData();
|
|
681
|
-
}, children: text }));
|
|
708
|
+
}, children: [jsxRuntime.jsx(io5.IoReload, {}), " ", text] }));
|
|
682
709
|
};
|
|
683
710
|
|
|
684
711
|
const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
@@ -695,17 +722,20 @@ const Table = ({ children, emptyComponent = EmptyResult, ...props }) => {
|
|
|
695
722
|
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: table.getCenterTotalSize(), ...props, children: children }));
|
|
696
723
|
};
|
|
697
724
|
|
|
698
|
-
const TableCardContainer = ({ children, ...props }) => {
|
|
699
|
-
|
|
725
|
+
const TableCardContainer = ({ children, variant = "", ...props }) => {
|
|
726
|
+
if (variant === "carousel") {
|
|
727
|
+
return (jsxRuntime.jsx(react.Flex, { overflow: "scroll", gap: "1rem", children: children }));
|
|
728
|
+
}
|
|
729
|
+
return (jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", gap: "0.5rem", ...props, children: children }));
|
|
700
730
|
};
|
|
701
731
|
|
|
702
732
|
const DefaultCardTitle = () => {
|
|
703
733
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
704
734
|
};
|
|
705
|
-
const TableCards = ({ isSelectable = false, showDisplayNameOnly = false, renderTitle = DefaultCardTitle, cardBodyProps = {} }) => {
|
|
735
|
+
const TableCards = ({ isSelectable = false, showDisplayNameOnly = false, renderTitle = DefaultCardTitle, cardBodyProps = {}, }) => {
|
|
706
736
|
const { table } = React.useContext(TableContext);
|
|
707
737
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getRowModel().rows.map((row) => {
|
|
708
|
-
return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsxs(react.Card.Body, { display: "flex", flexFlow: "column", gap: "0.5rem", ...cardBodyProps, children: [isSelectable && (jsxRuntime.jsx(Checkbox, { isChecked: row.getIsSelected(),
|
|
738
|
+
return (jsxRuntime.jsx(react.Card.Root, { flex: "1 0 20rem", children: jsxRuntime.jsxs(react.Card.Body, { display: "flex", flexFlow: "column", gap: "0.5rem", ...cardBodyProps, children: [isSelectable && (jsxRuntime.jsx(Checkbox, { isChecked: row.getIsSelected(),
|
|
709
739
|
disabled: !row.getCanSelect(),
|
|
710
740
|
// indeterminate: row.getIsSomeSelected(),
|
|
711
741
|
onChange: row.getToggleSelectedHandler() })), renderTitle(row), jsxRuntime.jsx(react.Grid, { templateColumns: "auto 1fr", gap: "1rem", children: row.getVisibleCells().map((cell) => {
|
|
@@ -756,9 +786,9 @@ const SliderMarks = React__namespace.forwardRef(function SliderMarks(props, ref)
|
|
|
756
786
|
});
|
|
757
787
|
|
|
758
788
|
const RangeFilter = ({ range, setRange, defaultValue, min, max, step, }) => {
|
|
759
|
-
return (jsxRuntime.
|
|
760
|
-
|
|
761
|
-
|
|
789
|
+
return (jsxRuntime.jsxs(react.Flex, { p: 2, gap: 2, flexFlow: 'column', children: [jsxRuntime.jsx(react.Text, { children: `${range[0]} - ${range[1]}` }), jsxRuntime.jsx(Slider, { width: "full", min: min, max: max, defaultValue: defaultValue, step: step, name: `Selected Range: ${range[0]} - ${range[1]}`,
|
|
790
|
+
// value={field.value}
|
|
791
|
+
onValueChange: (val) => setRange(val.value) })] }));
|
|
762
792
|
};
|
|
763
793
|
|
|
764
794
|
const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
@@ -787,9 +817,9 @@ const Filter = ({ column }) => {
|
|
|
787
817
|
// items: filterOptions,
|
|
788
818
|
// });
|
|
789
819
|
if (column.columns.length > 0) {
|
|
790
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap:
|
|
791
|
-
|
|
792
|
-
|
|
820
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 1, children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(20rem, 1fr))", gap: 1, children: column.columns.map((column) => {
|
|
821
|
+
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
822
|
+
}) }, column.id)] }));
|
|
793
823
|
}
|
|
794
824
|
if (!column.getCanFilter()) {
|
|
795
825
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
@@ -797,7 +827,7 @@ const Filter = ({ column }) => {
|
|
|
797
827
|
if (filterVariant === "select") {
|
|
798
828
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(RadioGroup, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onValueChange: (details) => {
|
|
799
829
|
column.setFilterValue(details.value);
|
|
800
|
-
}, children: jsxRuntime.jsx(react.Flex, { flexFlow:
|
|
830
|
+
}, children: jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", gap: "0.5rem", children: filterOptions.map((item) => (jsxRuntime.jsx(Radio, { value: item, children: item }, item))) }) })] }, column.id));
|
|
801
831
|
}
|
|
802
832
|
if (filterVariant === "tag") {
|
|
803
833
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
@@ -827,10 +857,10 @@ const Filter = ({ column }) => {
|
|
|
827
857
|
step: 1,
|
|
828
858
|
defaultValue: [4, 50],
|
|
829
859
|
};
|
|
830
|
-
return (jsxRuntime.jsx(RangeFilter, { range: filterValue, setRange: function (value) {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
860
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(RangeFilter, { range: filterValue, setRange: function (value) {
|
|
861
|
+
// throw new Error("Function not implemented.");
|
|
862
|
+
column.setFilterValue(value);
|
|
863
|
+
}, defaultValue: defaultValue, min: min, max: max, step: step })] }, column.id));
|
|
834
864
|
}
|
|
835
865
|
if (filterVariant === "dateRange") {
|
|
836
866
|
const [start, end] = column.getFilterValue() ?? [
|
|
@@ -934,25 +964,91 @@ const TableOrderer = () => {
|
|
|
934
964
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
935
965
|
};
|
|
936
966
|
|
|
967
|
+
const { withContext } = react.createRecipeContext({ key: "button" });
|
|
968
|
+
// Replace "a" with your framework's link component
|
|
969
|
+
const LinkButton = withContext("a");
|
|
970
|
+
|
|
971
|
+
const [RootPropsProvider, useRootProps] = react.createContext({
|
|
972
|
+
name: "RootPropsProvider",
|
|
973
|
+
});
|
|
974
|
+
const variantMap = {
|
|
975
|
+
outline: { default: "ghost", ellipsis: "plain", current: "outline" },
|
|
976
|
+
solid: { default: "outline", ellipsis: "outline", current: "solid" },
|
|
977
|
+
subtle: { default: "ghost", ellipsis: "plain", current: "subtle" },
|
|
978
|
+
};
|
|
979
|
+
const PaginationRoot = React__namespace.forwardRef(function PaginationRoot(props, ref) {
|
|
980
|
+
const { size = "sm", variant = "outline", getHref, ...rest } = props;
|
|
981
|
+
return (jsxRuntime.jsx(RootPropsProvider, { value: { size, variantMap: variantMap[variant], getHref }, children: jsxRuntime.jsx(react.Pagination.Root, { ref: ref, type: getHref ? "link" : "button", ...rest }) }));
|
|
982
|
+
});
|
|
983
|
+
const PaginationEllipsis = React__namespace.forwardRef(function PaginationEllipsis(props, ref) {
|
|
984
|
+
const { size, variantMap } = useRootProps();
|
|
985
|
+
return (jsxRuntime.jsx(react.Pagination.Ellipsis, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { as: "span", variant: variantMap.ellipsis, size: size, children: jsxRuntime.jsx(hi2.HiMiniEllipsisHorizontal, {}) }) }));
|
|
986
|
+
});
|
|
987
|
+
const PaginationItem = React__namespace.forwardRef(function PaginationItem(props, ref) {
|
|
988
|
+
const { page } = react.usePaginationContext();
|
|
989
|
+
const { size, variantMap, getHref } = useRootProps();
|
|
990
|
+
const current = page === props.value;
|
|
991
|
+
const variant = current ? variantMap.current : variantMap.default;
|
|
992
|
+
if (getHref) {
|
|
993
|
+
return (jsxRuntime.jsx(LinkButton, { href: getHref(props.value), variant: variant, size: size, children: props.value }));
|
|
994
|
+
}
|
|
995
|
+
return (jsxRuntime.jsx(react.Pagination.Item, { ref: ref, ...props, asChild: true, children: jsxRuntime.jsx(react.Button, { variant: variant, size: size, children: props.value }) }));
|
|
996
|
+
});
|
|
997
|
+
const PaginationPrevTrigger = React__namespace.forwardRef(function PaginationPrevTrigger(props, ref) {
|
|
998
|
+
const { size, variantMap, getHref } = useRootProps();
|
|
999
|
+
const { previousPage } = react.usePaginationContext();
|
|
1000
|
+
if (getHref) {
|
|
1001
|
+
return (jsxRuntime.jsx(LinkButton, { href: previousPage != null ? getHref(previousPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }));
|
|
1002
|
+
}
|
|
1003
|
+
return (jsxRuntime.jsx(react.Pagination.PrevTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronLeft, {}) }) }));
|
|
1004
|
+
});
|
|
1005
|
+
const PaginationNextTrigger = React__namespace.forwardRef(function PaginationNextTrigger(props, ref) {
|
|
1006
|
+
const { size, variantMap, getHref } = useRootProps();
|
|
1007
|
+
const { nextPage } = react.usePaginationContext();
|
|
1008
|
+
if (getHref) {
|
|
1009
|
+
return (jsxRuntime.jsx(LinkButton, { href: nextPage != null ? getHref(nextPage) : undefined, variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }));
|
|
1010
|
+
}
|
|
1011
|
+
return (jsxRuntime.jsx(react.Pagination.NextTrigger, { ref: ref, asChild: true, ...props, children: jsxRuntime.jsx(react.IconButton, { variant: variantMap.default, size: size, children: jsxRuntime.jsx(hi2.HiChevronRight, {}) }) }));
|
|
1012
|
+
});
|
|
1013
|
+
const PaginationItems = (props) => {
|
|
1014
|
+
return (jsxRuntime.jsx(react.Pagination.Context, { children: ({ pages }) => pages.map((page, index) => {
|
|
1015
|
+
return page.type === "ellipsis" ? (jsxRuntime.jsx(PaginationEllipsis, { index: index, ...props }, index)) : (jsxRuntime.jsx(PaginationItem, { type: "page", value: page.value, ...props }, index));
|
|
1016
|
+
}) }));
|
|
1017
|
+
};
|
|
1018
|
+
const PaginationPageText = React__namespace.forwardRef(function PaginationPageText(props, ref) {
|
|
1019
|
+
const { format = "compact", ...rest } = props;
|
|
1020
|
+
const { page, totalPages, pageRange, count } = react.usePaginationContext();
|
|
1021
|
+
const content = React__namespace.useMemo(() => {
|
|
1022
|
+
if (format === "short")
|
|
1023
|
+
return `${page} / ${totalPages}`;
|
|
1024
|
+
if (format === "compact")
|
|
1025
|
+
return `${page} of ${totalPages}`;
|
|
1026
|
+
return `${pageRange.start + 1} - ${Math.min(pageRange.end, count)} of ${count}`;
|
|
1027
|
+
}, [format, page, totalPages, pageRange, count]);
|
|
1028
|
+
return (jsxRuntime.jsx(react.Text, { fontWeight: "medium", ref: ref, ...rest, children: content }));
|
|
1029
|
+
});
|
|
1030
|
+
|
|
937
1031
|
const TablePagination = () => {
|
|
938
|
-
const {
|
|
939
|
-
return (jsxRuntime.
|
|
1032
|
+
const { table } = useDataTableContext();
|
|
1033
|
+
return (jsxRuntime.jsx(PaginationRoot, { page: table.getState().pagination.pageIndex + 1, count: table.getRowCount(), pageSize: table.getState().pagination.pageSize, onPageChange: (e) => {
|
|
1034
|
+
table.setPageIndex(e.page - 1);
|
|
1035
|
+
}, children: jsxRuntime.jsxs(react.HStack, { children: [jsxRuntime.jsx(PaginationPageText, { format: "long" }), jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationItems, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) }));
|
|
940
1036
|
};
|
|
941
1037
|
|
|
942
1038
|
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
943
1039
|
const { table } = useDataTableContext();
|
|
944
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react.IconButton, {
|
|
1040
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!selectAllText === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
|
|
945
1041
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
946
|
-
} })), !!selectAllText !== false && (jsxRuntime.
|
|
1042
|
+
}, children: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon })), !!selectAllText !== false && (jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: (event) => {
|
|
947
1043
|
table.getToggleAllRowsSelectedHandler()(event);
|
|
948
|
-
}, children: table.getIsAllRowsSelected() ? clearAllText : selectAllText }))] }));
|
|
1044
|
+
}, children: [table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, table.getIsAllRowsSelected() ? clearAllText : selectAllText] }))] }));
|
|
949
1045
|
};
|
|
950
1046
|
|
|
951
1047
|
const TableSelector = () => {
|
|
952
1048
|
const { table } = React.useContext(TableContext);
|
|
953
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsxs(react.Button, { onClick: () => { }, variant: "ghost", display: "flex", gap: "0.25rem", children: [jsxRuntime.jsx(react.Box, { fontSize: "sm", children: `${table.getSelectedRowModel().rows.length}` }), jsxRuntime.jsx(react.Icon, { as: io.IoMdCheckbox })] })), !table.getIsAllPageRowsSelected() && jsxRuntime.jsx(SelectAllRowsToggle, {}), table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsx(react.IconButton, { variant: "ghost",
|
|
1049
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsxs(react.Button, { onClick: () => { }, variant: "ghost", display: "flex", gap: "0.25rem", children: [jsxRuntime.jsx(react.Box, { fontSize: "sm", children: `${table.getSelectedRowModel().rows.length}` }), jsxRuntime.jsx(react.Icon, { as: io.IoMdCheckbox })] })), !table.getIsAllPageRowsSelected() && jsxRuntime.jsx(SelectAllRowsToggle, {}), table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", onClick: () => {
|
|
954
1050
|
table.resetRowSelection();
|
|
955
|
-
}, "aria-label": "reset selection" }))] }));
|
|
1051
|
+
}, "aria-label": "reset selection", children: jsxRuntime.jsx(md.MdClear, {}) }))] }));
|
|
956
1052
|
};
|
|
957
1053
|
|
|
958
1054
|
const Switch = React__namespace.forwardRef(function Switch(props, ref) {
|
|
@@ -1055,7 +1151,11 @@ const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSu
|
|
|
1055
1151
|
const [hasError, setHasError] = React.useState(false);
|
|
1056
1152
|
const [data, setData] = React.useState(defaultData);
|
|
1057
1153
|
const [timer, setTimer] = React.useState();
|
|
1058
|
-
const refreshData = async (
|
|
1154
|
+
const refreshData = async (config = {
|
|
1155
|
+
debounce: false,
|
|
1156
|
+
delay: 1000,
|
|
1157
|
+
}) => {
|
|
1158
|
+
const { debounce, delay } = config;
|
|
1059
1159
|
if (debounce) {
|
|
1060
1160
|
await debouncedGetData(delay);
|
|
1061
1161
|
return;
|
|
@@ -1182,30 +1282,25 @@ const useDataTableServer = ({ url, onFetchSuccess = () => { }, default: { sortin
|
|
|
1182
1282
|
const { data, loading, hasError, refreshData } = useDataFromUrl({
|
|
1183
1283
|
url: url,
|
|
1184
1284
|
defaultData: {
|
|
1185
|
-
|
|
1186
|
-
results: [],
|
|
1285
|
+
data: [],
|
|
1187
1286
|
count: 0,
|
|
1188
1287
|
},
|
|
1189
1288
|
params: {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
sorting: JSON.stringify(sorting.length > 0
|
|
1195
|
-
? { field: sorting[0].id, sort: sorting[0].desc ? "desc" : "asc" }
|
|
1196
|
-
: {}),
|
|
1197
|
-
where: JSON.stringify(columnFilters.reduce((accumulator, filter) => {
|
|
1289
|
+
offset: pagination.pageIndex * pagination.pageSize,
|
|
1290
|
+
limit: pagination.pageSize,
|
|
1291
|
+
sorting,
|
|
1292
|
+
where: columnFilters.reduce((accumulator, filter) => {
|
|
1198
1293
|
const obj = {};
|
|
1199
1294
|
obj[filter.id] = filter.value;
|
|
1200
1295
|
return { ...accumulator, ...obj };
|
|
1201
|
-
}, {})
|
|
1296
|
+
}, {}),
|
|
1202
1297
|
searching: globalFilter,
|
|
1203
1298
|
},
|
|
1204
1299
|
disableFirstFetch: true,
|
|
1205
1300
|
onFetchSuccess: onFetchSuccess,
|
|
1206
1301
|
});
|
|
1207
1302
|
React.useEffect(() => {
|
|
1208
|
-
refreshData({ debounce, debounceDelay });
|
|
1303
|
+
refreshData({ debounce, delay: debounceDelay });
|
|
1209
1304
|
}, [pagination, sorting, columnFilters, globalFilter, url]);
|
|
1210
1305
|
return {
|
|
1211
1306
|
sorting,
|
|
@@ -1258,6 +1353,7 @@ const InputGroup = React__namespace.forwardRef(function InputGroup(props, ref) {
|
|
|
1258
1353
|
ps: `calc(var(--input-height) - ${startOffset})`,
|
|
1259
1354
|
}),
|
|
1260
1355
|
...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
|
|
1356
|
+
// @ts-expect-error chakra generated files
|
|
1261
1357
|
...children.props,
|
|
1262
1358
|
}), endElement && (jsxRuntime.jsx(react.InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
|
|
1263
1359
|
});
|
|
@@ -1269,9 +1365,905 @@ const GlobalFilter = () => {
|
|
|
1269
1365
|
} }) }) }));
|
|
1270
1366
|
};
|
|
1271
1367
|
|
|
1368
|
+
const idListSanityCheck = (param, idList, properties) => {
|
|
1369
|
+
const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
|
|
1370
|
+
if (!allKeyExists) {
|
|
1371
|
+
const wrongKey = idList.find((key) => !Object.keys(properties).some((column) => column == key));
|
|
1372
|
+
throw new Error(`The key ${wrongKey} in ${param} does not exist in schema.`);
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
const widthSanityCheck = (widthList, ignoreList, properties) => {
|
|
1377
|
+
const widthListToolong = widthList.length > Object.keys(properties).length;
|
|
1378
|
+
if (widthListToolong) {
|
|
1379
|
+
throw new Error(`The width list is too long given from the number of properties.`);
|
|
1380
|
+
}
|
|
1381
|
+
const widthListToolongWithIgnore = widthList.length > Object.keys(properties).length - ignoreList.length;
|
|
1382
|
+
if (widthListToolongWithIgnore) {
|
|
1383
|
+
throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, }) => {
|
|
1387
|
+
const { properties } = schema;
|
|
1388
|
+
idListSanityCheck("ignore", ignore, properties);
|
|
1389
|
+
widthSanityCheck(width, ignore, properties);
|
|
1390
|
+
idListSanityCheck("meta", Object.keys(meta), properties);
|
|
1391
|
+
const keys = Object.keys(properties);
|
|
1392
|
+
const ignored = keys.filter((key) => {
|
|
1393
|
+
return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
|
|
1394
|
+
});
|
|
1395
|
+
const columnHelper = reactTable.createColumnHelper();
|
|
1396
|
+
// @ts-expect-error find type for unknown
|
|
1397
|
+
const columns = [
|
|
1398
|
+
...ignored.map((column, index) => {
|
|
1399
|
+
return columnHelper.accessor(column, {
|
|
1400
|
+
cell: (props) => {
|
|
1401
|
+
// @ts-expect-error find type for unknown
|
|
1402
|
+
return jsxRuntime.jsx(TextCell, { children: props.row.original[column] });
|
|
1403
|
+
},
|
|
1404
|
+
header: (columnHeader) => {
|
|
1405
|
+
const displayName = columnHeader.column.columnDef.meta?.displayName ??
|
|
1406
|
+
snakeToLabel(column);
|
|
1407
|
+
return jsxRuntime.jsx("span", { children: displayName });
|
|
1408
|
+
},
|
|
1409
|
+
footer: (columnFooter) => {
|
|
1410
|
+
const displayName = columnFooter.column.columnDef.meta?.displayName ??
|
|
1411
|
+
snakeToLabel(column);
|
|
1412
|
+
return jsxRuntime.jsx("span", { children: displayName });
|
|
1413
|
+
},
|
|
1414
|
+
size: width[index] ?? defaultWidth,
|
|
1415
|
+
meta: Object.keys(meta).length > 0 ? meta[column] : {},
|
|
1416
|
+
});
|
|
1417
|
+
}),
|
|
1418
|
+
];
|
|
1419
|
+
return columns;
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
//@ts-expect-error TODO: find appropriate type
|
|
1423
|
+
const SchemaFormContext = React.createContext({
|
|
1424
|
+
schema: {},
|
|
1425
|
+
serverUrl: "",
|
|
1426
|
+
order: [],
|
|
1427
|
+
ignore: [],
|
|
1428
|
+
onSubmit: () => { },
|
|
1429
|
+
preLoadedValues: {},
|
|
1430
|
+
rowNumber: 0,
|
|
1431
|
+
displayText: {},
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
const PopoverContent = React__namespace.forwardRef(function PopoverContent(props, ref) {
|
|
1435
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
1436
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Popover.Positioner, { children: jsxRuntime.jsx(react.Popover.Content, { ref: ref, ...rest }) }) }));
|
|
1437
|
+
});
|
|
1438
|
+
React__namespace.forwardRef(function PopoverArrow(props, ref) {
|
|
1439
|
+
return (jsxRuntime.jsx(react.Popover.Arrow, { ...props, ref: ref, children: jsxRuntime.jsx(react.Popover.ArrowTip, {}) }));
|
|
1440
|
+
});
|
|
1441
|
+
React__namespace.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
1442
|
+
return (jsxRuntime.jsx(react.Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsxRuntime.jsx(CloseButton, { size: "sm" }) }));
|
|
1443
|
+
});
|
|
1444
|
+
const PopoverTitle = react.Popover.Title;
|
|
1445
|
+
react.Popover.Description;
|
|
1446
|
+
react.Popover.Footer;
|
|
1447
|
+
react.Popover.Header;
|
|
1448
|
+
const PopoverRoot = react.Popover.Root;
|
|
1449
|
+
const PopoverBody = react.Popover.Body;
|
|
1450
|
+
const PopoverTrigger = react.Popover.Trigger;
|
|
1451
|
+
|
|
1452
|
+
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
1453
|
+
const { inputProps, label, description, addon, icon, indicator = jsxRuntime.jsx(react.RadioCard.ItemIndicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
1454
|
+
const hasContent = label || description || icon;
|
|
1455
|
+
const ContentWrapper = indicator ? react.RadioCard.ItemContent : React__namespace.Fragment;
|
|
1456
|
+
return (jsxRuntime.jsxs(react.RadioCard.Item, { ...rest, children: [jsxRuntime.jsx(react.RadioCard.ItemHiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsxs(react.RadioCard.ItemControl, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxRuntime.jsxs(ContentWrapper, { children: [icon, label && jsxRuntime.jsx(react.RadioCard.ItemText, { children: label }), description && (jsxRuntime.jsx(react.RadioCard.ItemDescription, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsxRuntime.jsx(react.RadioCard.ItemAddon, { children: addon })] }));
|
|
1457
|
+
});
|
|
1458
|
+
const RadioCardRoot = react.RadioCard.Root;
|
|
1459
|
+
react.RadioCard.Label;
|
|
1460
|
+
react.RadioCard.ItemIndicator;
|
|
1461
|
+
|
|
1462
|
+
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
1463
|
+
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
1464
|
+
return (jsxRuntime.jsxs(react.Field.Root, { ref: ref, ...rest, children: [label && (jsxRuntime.jsxs(react.Field.Label, { children: [label, jsxRuntime.jsx(react.Field.RequiredIndicator, { fallback: optionalText })] })), children, helperText && (jsxRuntime.jsx(react.Field.HelperText, { children: helperText })), errorText && (jsxRuntime.jsx(react.Field.ErrorText, { children: errorText }))] }));
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
const useSchemaContext = () => {
|
|
1468
|
+
const { schema, serverUrl, order, ignore, onSubmit, preLoadedValues, rowNumber, displayText, } = React.useContext(SchemaFormContext);
|
|
1469
|
+
return {
|
|
1470
|
+
schema,
|
|
1471
|
+
serverUrl,
|
|
1472
|
+
order,
|
|
1473
|
+
ignore,
|
|
1474
|
+
onSubmit,
|
|
1475
|
+
preLoadedValues,
|
|
1476
|
+
rowNumber,
|
|
1477
|
+
displayText,
|
|
1478
|
+
};
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
const getTableData = async ({ serverUrl, in_table, searching = '', where = [], limit = 10, }) => {
|
|
1482
|
+
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
1483
|
+
throw new Error('The serverUrl is missing');
|
|
1484
|
+
}
|
|
1485
|
+
if (in_table === undefined || in_table.length == 0) {
|
|
1486
|
+
throw new Error('The in_table is missing');
|
|
1487
|
+
}
|
|
1488
|
+
const options = {
|
|
1489
|
+
method: "GET",
|
|
1490
|
+
url: `${serverUrl}/api/g/${in_table}`,
|
|
1491
|
+
headers: {
|
|
1492
|
+
Apikey: "YOUR_SECRET_TOKEN",
|
|
1493
|
+
"Content-Type": "application/json",
|
|
1494
|
+
},
|
|
1495
|
+
params: {
|
|
1496
|
+
searching,
|
|
1497
|
+
where,
|
|
1498
|
+
limit,
|
|
1499
|
+
},
|
|
1500
|
+
};
|
|
1501
|
+
try {
|
|
1502
|
+
const { data } = await axios.request(options);
|
|
1503
|
+
console.log(data);
|
|
1504
|
+
return data;
|
|
1505
|
+
}
|
|
1506
|
+
catch (error) {
|
|
1507
|
+
console.error(error);
|
|
1508
|
+
throw error;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
|
|
1512
|
+
const IdPicker = ({ column, in_table, column_ref, display_column, }) => {
|
|
1513
|
+
const { formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
1514
|
+
const { schema, serverUrl, displayText } = useSchemaContext();
|
|
1515
|
+
const { fieldRequired } = displayText;
|
|
1516
|
+
const { required } = schema;
|
|
1517
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1518
|
+
if (schema.properties == undefined) {
|
|
1519
|
+
throw new Error("schema properties when using DatePicker");
|
|
1520
|
+
}
|
|
1521
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1522
|
+
const [selectedId, setSelectedId] = React.useState();
|
|
1523
|
+
const [searchText, setSearchText] = React.useState();
|
|
1524
|
+
const [limit, setLimit] = React.useState(10);
|
|
1525
|
+
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
1526
|
+
const ref = React.useRef(null);
|
|
1527
|
+
const query = reactQuery.useQuery({
|
|
1528
|
+
queryKey: [`idpicker`, searchText, in_table, limit],
|
|
1529
|
+
queryFn: async () => {
|
|
1530
|
+
return await getTableData({
|
|
1531
|
+
serverUrl,
|
|
1532
|
+
searching: searchText ?? "",
|
|
1533
|
+
in_table: in_table,
|
|
1534
|
+
limit: limit,
|
|
1535
|
+
});
|
|
1536
|
+
},
|
|
1537
|
+
staleTime: 10000,
|
|
1538
|
+
});
|
|
1539
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
1540
|
+
const dataList = data?.data ?? [];
|
|
1541
|
+
const count = data?.count ?? 0;
|
|
1542
|
+
const isDirty = (searchText?.length ?? 0) > 0;
|
|
1543
|
+
const onSearchChange = async (event) => {
|
|
1544
|
+
setSearchText(event.target.value);
|
|
1545
|
+
setLimit(10);
|
|
1546
|
+
};
|
|
1547
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1548
|
+
const getItemList = (data) => {
|
|
1549
|
+
return data.map((item) => {
|
|
1550
|
+
return {
|
|
1551
|
+
label: item[display_column],
|
|
1552
|
+
key: item[column_ref],
|
|
1553
|
+
value: item[column_ref],
|
|
1554
|
+
};
|
|
1555
|
+
});
|
|
1556
|
+
};
|
|
1557
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1558
|
+
const getIdMap = (data) => {
|
|
1559
|
+
return Object.fromEntries(data.map((item) => {
|
|
1560
|
+
return [
|
|
1561
|
+
item[column_ref],
|
|
1562
|
+
{
|
|
1563
|
+
...item,
|
|
1564
|
+
},
|
|
1565
|
+
];
|
|
1566
|
+
}));
|
|
1567
|
+
};
|
|
1568
|
+
const getSelectedName = () => {
|
|
1569
|
+
const selectedItem = getIdMap(dataList)[selectedId ?? ""];
|
|
1570
|
+
if (selectedItem == undefined) {
|
|
1571
|
+
return "";
|
|
1572
|
+
}
|
|
1573
|
+
return selectedItem[display_column];
|
|
1574
|
+
};
|
|
1575
|
+
if (selectedId != undefined) {
|
|
1576
|
+
return (jsxRuntime.jsx(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn,
|
|
1577
|
+
gridRow, children: jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
1578
|
+
setSelectedId(undefined);
|
|
1579
|
+
setValue(column, "");
|
|
1580
|
+
}, children: getSelectedName() }) }));
|
|
1581
|
+
}
|
|
1582
|
+
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1583
|
+
gridRow, children: [jsxRuntime.jsx(react.Input, { placeholder: "Type to search", onChange: (event) => {
|
|
1584
|
+
onSearchChange(event);
|
|
1585
|
+
setOpenSearchResult(true);
|
|
1586
|
+
}, autoComplete: "off", ref: ref }), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsxs(RadioCardRoot, { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), jsxRuntime.jsx(react.Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsxRuntime.jsx(Button, { onClick: async () => {
|
|
1587
|
+
setOpenSearchResult(false);
|
|
1588
|
+
}, children: "close" }),
|
|
1589
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1590
|
+
getItemList(dataList).map((item) => (jsxRuntime.jsx(RadioCardItem, { label: item.label, description: item.description, value: item.value, onClick: () => {
|
|
1591
|
+
setSelectedId(item.key);
|
|
1592
|
+
setValue(column, item.key);
|
|
1593
|
+
setOpenSearchResult(false);
|
|
1594
|
+
}, indicator: false }, item.key))), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Empty Search Result" }), " ", count > dataList.length && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(Button, { onClick: async () => {
|
|
1595
|
+
setLimit((limit) => limit + 10);
|
|
1596
|
+
await getTableData({
|
|
1597
|
+
serverUrl,
|
|
1598
|
+
searching: searchText ?? "",
|
|
1599
|
+
in_table: in_table,
|
|
1600
|
+
limit: limit + 10,
|
|
1601
|
+
});
|
|
1602
|
+
}, children: "show more" }) }))] }))] })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
1606
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
1607
|
+
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] }) }) })] }));
|
|
1608
|
+
});
|
|
1609
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
1610
|
+
const { children, ...rest } = props;
|
|
1611
|
+
return (jsxRuntime.jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "gray", children: jsxRuntime.jsx(hi.HiOutlineInformationCircle, {}) }) }));
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
const DataListRoot = react.DataList.Root;
|
|
1615
|
+
const DataListItem = React__namespace.forwardRef(function DataListItem(props, ref) {
|
|
1616
|
+
const { label, info, value, children, grow, ...rest } = props;
|
|
1617
|
+
return (jsxRuntime.jsxs(react.DataList.Item, { ref: ref, ...rest, children: [jsxRuntime.jsxs(react.DataList.ItemLabel, { flex: grow ? "1" : undefined, children: [label, info && jsxRuntime.jsx(InfoTip, { children: info })] }), jsxRuntime.jsx(react.DataList.ItemValue, { flex: grow ? "1" : undefined, children: value }), children] }));
|
|
1618
|
+
});
|
|
1619
|
+
|
|
1620
|
+
const IdViewer = ({ value, in_table, column_ref, display_column, column, }) => {
|
|
1621
|
+
const { schema, serverUrl } = useSchemaContext();
|
|
1622
|
+
if (schema.properties == undefined) {
|
|
1623
|
+
throw new Error("schema properties when using DatePicker");
|
|
1624
|
+
}
|
|
1625
|
+
const { title } = schema.properties[column];
|
|
1626
|
+
const query = reactQuery.useQuery({
|
|
1627
|
+
queryKey: [`idpicker`, in_table, value],
|
|
1628
|
+
queryFn: async () => {
|
|
1629
|
+
return await getTableData({
|
|
1630
|
+
serverUrl,
|
|
1631
|
+
in_table: in_table,
|
|
1632
|
+
where: [
|
|
1633
|
+
{
|
|
1634
|
+
id: column_ref,
|
|
1635
|
+
value: value,
|
|
1636
|
+
},
|
|
1637
|
+
],
|
|
1638
|
+
});
|
|
1639
|
+
},
|
|
1640
|
+
staleTime: 10000,
|
|
1641
|
+
});
|
|
1642
|
+
const getDataListProps = (value) => {
|
|
1643
|
+
if (value == undefined || value.length <= 0) {
|
|
1644
|
+
return {
|
|
1645
|
+
value: "<empty>",
|
|
1646
|
+
color: "gray.400",
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
return {
|
|
1650
|
+
value: value,
|
|
1651
|
+
};
|
|
1652
|
+
};
|
|
1653
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(DataListItem, { label: `${title ?? snakeToLabel(column)}`, ...getDataListProps((query.data?.data[0] ?? {})[display_column]) }) }));
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
1657
|
+
const { children, ...rest } = props;
|
|
1658
|
+
return (jsxRuntime.jsxs(react.NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxRuntime.jsxs(react.NumberInput.Control, { children: [jsxRuntime.jsx(react.NumberInput.IncrementTrigger, {}), jsxRuntime.jsx(react.NumberInput.DecrementTrigger, {})] })] }));
|
|
1659
|
+
});
|
|
1660
|
+
const NumberInputField$1 = react.NumberInput.Input;
|
|
1661
|
+
react.NumberInput.Scrubber;
|
|
1662
|
+
react.NumberInput.Label;
|
|
1663
|
+
|
|
1664
|
+
const NumberInputField = ({ column }) => {
|
|
1665
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
1666
|
+
const { schema, displayText } = useSchemaContext();
|
|
1667
|
+
const { fieldRequired } = displayText;
|
|
1668
|
+
const { required } = schema;
|
|
1669
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1670
|
+
if (schema.properties == undefined) {
|
|
1671
|
+
throw new Error("schema properties when using String Input Field");
|
|
1672
|
+
}
|
|
1673
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1674
|
+
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(NumberInputRoot, { children: jsxRuntime.jsx(NumberInputField$1, { ...register(column, { required: isRequired }) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
const StringInputField = ({ column }) => {
|
|
1678
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
1679
|
+
const { schema, displayText } = useSchemaContext();
|
|
1680
|
+
const { fieldRequired } = displayText;
|
|
1681
|
+
const { required } = schema;
|
|
1682
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1683
|
+
if (schema.properties == undefined) {
|
|
1684
|
+
throw new Error("schema properties when using String Input Field");
|
|
1685
|
+
}
|
|
1686
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1687
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Input, { ...register(column, { required: isRequired }), autoComplete: "off" }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }) }));
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
const clearEmptyString = (object) => {
|
|
1691
|
+
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
const AccordionItemTrigger = React__namespace.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
1695
|
+
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
1696
|
+
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, {}) }))] }));
|
|
1697
|
+
});
|
|
1698
|
+
const AccordionItemContent = React__namespace.forwardRef(function AccordionItemContent(props, ref) {
|
|
1699
|
+
return (jsxRuntime.jsx(react.Accordion.ItemContent, { children: jsxRuntime.jsx(react.Accordion.ItemBody, { ...props, ref: ref }) }));
|
|
1700
|
+
});
|
|
1701
|
+
const AccordionRoot = react.Accordion.Root;
|
|
1702
|
+
const AccordionItem = react.Accordion.Item;
|
|
1703
|
+
|
|
1704
|
+
const CheckboxCard = React__namespace.forwardRef(function CheckboxCard(props, ref) {
|
|
1705
|
+
const { inputProps, label, description, icon, addon, indicator = jsxRuntime.jsx(react.CheckboxCard.Indicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
1706
|
+
const hasContent = label || description || icon;
|
|
1707
|
+
const ContentWrapper = indicator ? react.CheckboxCard.Content : React__namespace.Fragment;
|
|
1708
|
+
return (jsxRuntime.jsxs(react.CheckboxCard.Root, { ...rest, children: [jsxRuntime.jsx(react.CheckboxCard.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsxs(react.CheckboxCard.Control, { children: [indicatorPlacement === "start" && indicator, hasContent && (jsxRuntime.jsxs(ContentWrapper, { children: [icon, label && (jsxRuntime.jsx(react.CheckboxCard.Label, { children: label })), description && (jsxRuntime.jsx(react.CheckboxCard.Description, { children: description })), indicatorPlacement === "inside" && indicator] })), indicatorPlacement === "end" && indicator] }), addon && jsxRuntime.jsx(react.CheckboxCard.Addon, { children: addon })] }));
|
|
1709
|
+
});
|
|
1710
|
+
react.CheckboxCard.Indicator;
|
|
1711
|
+
|
|
1712
|
+
const BooleanPicker = ({ column }) => {
|
|
1713
|
+
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
1714
|
+
const { schema, displayText } = useSchemaContext();
|
|
1715
|
+
const { fieldRequired } = displayText;
|
|
1716
|
+
const { required } = schema;
|
|
1717
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1718
|
+
if (schema.properties == undefined) {
|
|
1719
|
+
throw new Error("schema properties when using BooleanPicker");
|
|
1720
|
+
}
|
|
1721
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1722
|
+
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1723
|
+
gridRow, children: [jsxRuntime.jsx(CheckboxCard
|
|
1724
|
+
// label={snakeToLabel(column)}
|
|
1725
|
+
, {
|
|
1726
|
+
// label={snakeToLabel(column)}
|
|
1727
|
+
value: getValues(column), variant: "surface", onSelect: () => {
|
|
1728
|
+
setValue(column, !getValues(column));
|
|
1729
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1730
|
+
};
|
|
1731
|
+
|
|
1732
|
+
const monthNamesShort = [
|
|
1733
|
+
"Jan",
|
|
1734
|
+
"Feb",
|
|
1735
|
+
"Mar",
|
|
1736
|
+
"Apr",
|
|
1737
|
+
"May",
|
|
1738
|
+
"Jun",
|
|
1739
|
+
"Jul",
|
|
1740
|
+
"Aug",
|
|
1741
|
+
"Sep",
|
|
1742
|
+
"Oct",
|
|
1743
|
+
"Nov",
|
|
1744
|
+
"Dec",
|
|
1745
|
+
];
|
|
1746
|
+
const weekdayNamesShort$1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
1747
|
+
const Calendar$1 = ({ calendars, getBackProps, getForwardProps, getDateProps, firstDayOfWeek = 0, }) => {
|
|
1748
|
+
if (calendars.length) {
|
|
1749
|
+
return (jsxRuntime.jsxs(react.Grid, { children: [jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({
|
|
1750
|
+
calendars,
|
|
1751
|
+
offset: 12,
|
|
1752
|
+
}), children: "<<" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({
|
|
1753
|
+
calendars,
|
|
1754
|
+
offset: 12,
|
|
1755
|
+
}), children: ">>" })] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", children: calendars.map((calendar) => (jsxRuntime.jsxs(react.Grid, { gap: 4, children: [jsxRuntime.jsxs(react.Grid, { justifyContent: "center", children: [monthNamesShort[calendar.month], " ", calendar.year] }), jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [[0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
|
|
1756
|
+
const weekday = (weekdayNum + firstDayOfWeek) % 7;
|
|
1757
|
+
return (jsxRuntime.jsx(react.Text, { textAlign: "center", children: weekdayNamesShort$1[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
|
|
1758
|
+
}), calendar.weeks.map((week, weekIndex) => week.map((dateObj, index) => {
|
|
1759
|
+
const key = `${calendar.month}${calendar.year}${weekIndex}${index}`;
|
|
1760
|
+
if (!dateObj) {
|
|
1761
|
+
return jsxRuntime.jsx(react.Grid, {}, key);
|
|
1762
|
+
}
|
|
1763
|
+
const { date, selected, selectable, today } = dateObj;
|
|
1764
|
+
const getDateColor = ({ today, selected, selectable, }) => {
|
|
1765
|
+
if (!selectable) {
|
|
1766
|
+
return "gray";
|
|
1767
|
+
}
|
|
1768
|
+
if (selected) {
|
|
1769
|
+
return "blue";
|
|
1770
|
+
}
|
|
1771
|
+
if (today) {
|
|
1772
|
+
return "green";
|
|
1773
|
+
}
|
|
1774
|
+
return "";
|
|
1775
|
+
};
|
|
1776
|
+
const getVariant = ({ today, selected, selectable, }) => {
|
|
1777
|
+
if (!selectable) {
|
|
1778
|
+
return "solid";
|
|
1779
|
+
}
|
|
1780
|
+
if (selected) {
|
|
1781
|
+
return "solid";
|
|
1782
|
+
}
|
|
1783
|
+
if (today) {
|
|
1784
|
+
return "solid";
|
|
1785
|
+
}
|
|
1786
|
+
return "ghost";
|
|
1787
|
+
};
|
|
1788
|
+
const color = getDateColor({ today, selected, selectable });
|
|
1789
|
+
const variant = getVariant({ today, selected, selectable });
|
|
1790
|
+
return (jsxRuntime.jsx(react.Button, { variant: variant, colorPalette: color, ...getDateProps({ dateObj }), children: selectable ? date.getDate() : "X" }, key));
|
|
1791
|
+
}))] })] }, `${calendar.month}${calendar.year}`))) })] }));
|
|
1792
|
+
}
|
|
1793
|
+
return null;
|
|
1794
|
+
};
|
|
1795
|
+
let DatePicker$1 = class DatePicker extends React.Component {
|
|
1796
|
+
render() {
|
|
1797
|
+
return (jsxRuntime.jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsxRuntime.jsx(Calendar$1, { ...dayzedData, firstDayOfWeek: this.props.firstDayOfWeek })) }));
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
|
|
1801
|
+
const DatePicker = ({ column }) => {
|
|
1802
|
+
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
1803
|
+
const { schema, displayText } = useSchemaContext();
|
|
1804
|
+
const { fieldRequired } = displayText;
|
|
1805
|
+
const { required } = schema;
|
|
1806
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1807
|
+
const [open, setOpen] = React.useState(false);
|
|
1808
|
+
if (schema.properties == undefined) {
|
|
1809
|
+
throw new Error("schema properties when using DatePicker");
|
|
1810
|
+
}
|
|
1811
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1812
|
+
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1813
|
+
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, positioning: { sameWidth: true }, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
1814
|
+
setOpen(true);
|
|
1815
|
+
}, children: getValues(column) !== undefined
|
|
1816
|
+
? dayjs(getValues(column)).format("YYYY-MM-DD")
|
|
1817
|
+
: "" }) }), jsxRuntime.jsx(PopoverContent, { width: "auto", children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1, { selected: new Date(getValues(column)), onDateSelected: ({ selected, selectable, date }) => {
|
|
1818
|
+
console.log(date, selected, selectable, "jasdio");
|
|
1819
|
+
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
1820
|
+
setOpen(false);
|
|
1821
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
const ObjectInput = ({ column }) => {
|
|
1825
|
+
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
1826
|
+
const { schema, displayText } = useSchemaContext();
|
|
1827
|
+
const { addNew, fieldRequired, save } = displayText;
|
|
1828
|
+
const { required } = schema;
|
|
1829
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
1830
|
+
const entries = Object.entries(getValues(column) ?? {});
|
|
1831
|
+
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
1832
|
+
const [newKey, setNewKey] = React.useState();
|
|
1833
|
+
const [newValue, setNewValue] = React.useState();
|
|
1834
|
+
if (schema.properties == undefined) {
|
|
1835
|
+
throw new Error("schema properties when using DatePicker");
|
|
1836
|
+
}
|
|
1837
|
+
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1838
|
+
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
1839
|
+
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
1840
|
+
const filtered = entries.filter(([target]) => {
|
|
1841
|
+
return target !== key;
|
|
1842
|
+
});
|
|
1843
|
+
setValue(column, Object.fromEntries([...filtered, [e.target.value, value]]));
|
|
1844
|
+
}, autoComplete: "off" }), jsxRuntime.jsx(react.Input, { value: value, onChange: (e) => {
|
|
1845
|
+
setValue(column, {
|
|
1846
|
+
...getValues(column),
|
|
1847
|
+
[key]: e.target.value,
|
|
1848
|
+
});
|
|
1849
|
+
}, autoComplete: "off" }), jsxRuntime.jsx(react.IconButton, { variant: "ghost", onClick: () => {
|
|
1850
|
+
const filtered = entries.filter(([target]) => {
|
|
1851
|
+
return target !== key;
|
|
1852
|
+
});
|
|
1853
|
+
setValue(column, Object.fromEntries([...filtered]));
|
|
1854
|
+
}, children: jsxRuntime.jsx(cg.CgClose, {}) })] }));
|
|
1855
|
+
}), jsxRuntime.jsx(react.Show, { when: showNewEntries, children: jsxRuntime.jsxs(react.Card.Root, { children: [jsxRuntime.jsx(react.Card.Body, { gap: "2", children: jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: newKey, onChange: (e) => {
|
|
1856
|
+
setNewKey(e.target.value);
|
|
1857
|
+
}, autoComplete: "off" }), jsxRuntime.jsx(react.Input, { value: newValue, onChange: (e) => {
|
|
1858
|
+
setNewValue(e.target.value);
|
|
1859
|
+
}, autoComplete: "off" })] }) }), jsxRuntime.jsxs(react.Card.Footer, { justifyContent: "flex-end", children: [jsxRuntime.jsx(react.IconButton, { variant: "subtle", onClick: () => {
|
|
1860
|
+
setShowNewEntries(false);
|
|
1861
|
+
setNewKey(undefined);
|
|
1862
|
+
setNewValue(undefined);
|
|
1863
|
+
}, children: jsxRuntime.jsx(cg.CgClose, {}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
1864
|
+
if (!!newKey === false) {
|
|
1865
|
+
setShowNewEntries(false);
|
|
1866
|
+
setNewKey(undefined);
|
|
1867
|
+
setNewValue(undefined);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
setValue(column, Object.fromEntries([...entries, [newKey, newValue]]));
|
|
1871
|
+
setShowNewEntries(false);
|
|
1872
|
+
setNewKey(undefined);
|
|
1873
|
+
setNewValue(undefined);
|
|
1874
|
+
}, children: save ?? "Save" })] })] }) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
1875
|
+
setShowNewEntries(true);
|
|
1876
|
+
setNewKey(undefined);
|
|
1877
|
+
setNewValue(undefined);
|
|
1878
|
+
}, children: addNew ?? "Add New" }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
const idPickerSanityCheck = (column, in_table, column_ref, display_column) => {
|
|
1882
|
+
console.log(!!in_table, "okgsd");
|
|
1883
|
+
if (!!in_table == false) {
|
|
1884
|
+
throw new Error(`The key in_table does not exist in properties of column ${column}.`);
|
|
1885
|
+
}
|
|
1886
|
+
if (!!column_ref == false) {
|
|
1887
|
+
throw new Error(`The key column_ref does not exist in properties of column ${column}.`);
|
|
1888
|
+
}
|
|
1889
|
+
if (!!display_column == false) {
|
|
1890
|
+
throw new Error(`The key display_column does not exist in properties of column ${column}.`);
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
const FormInternal = () => {
|
|
1894
|
+
const { schema, serverUrl, displayText, order, ignore, onSubmit, preLoadedValues, rowNumber, } = useSchemaContext();
|
|
1895
|
+
const { title, submit, empty, cancel, submitSuccess, submitAgain, confirm } = displayText;
|
|
1896
|
+
const methods = reactHookForm.useFormContext();
|
|
1897
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
1898
|
+
const [isError, setIsError] = React.useState(false);
|
|
1899
|
+
const [isSubmiting, setIsSubmiting] = React.useState(false);
|
|
1900
|
+
const [isConfirming, setIsConfirming] = React.useState(false);
|
|
1901
|
+
const [validatedData, setValidatedData] = React.useState();
|
|
1902
|
+
const [error, setError] = React.useState();
|
|
1903
|
+
const { properties } = schema;
|
|
1904
|
+
const onBeforeSubmit = () => {
|
|
1905
|
+
setIsSubmiting(true);
|
|
1906
|
+
};
|
|
1907
|
+
const onAfterSubmit = () => {
|
|
1908
|
+
setIsSubmiting(false);
|
|
1909
|
+
};
|
|
1910
|
+
const onSubmitError = () => {
|
|
1911
|
+
setIsError(true);
|
|
1912
|
+
};
|
|
1913
|
+
const onSubmitSuccess = () => {
|
|
1914
|
+
setIsSuccess(true);
|
|
1915
|
+
};
|
|
1916
|
+
const defaultOnSubmit = async (data) => {
|
|
1917
|
+
const options = {
|
|
1918
|
+
method: "POST",
|
|
1919
|
+
url: `${serverUrl}/api/g/${schema.title}`,
|
|
1920
|
+
headers: {
|
|
1921
|
+
Apikey: "YOUR_SECRET_TOKEN",
|
|
1922
|
+
"Content-Type": "application/json",
|
|
1923
|
+
},
|
|
1924
|
+
data: clearEmptyString(data),
|
|
1925
|
+
};
|
|
1926
|
+
try {
|
|
1927
|
+
onBeforeSubmit();
|
|
1928
|
+
await axios.request(options);
|
|
1929
|
+
onSubmitSuccess();
|
|
1930
|
+
}
|
|
1931
|
+
catch (error) {
|
|
1932
|
+
setIsError(true);
|
|
1933
|
+
setError(error);
|
|
1934
|
+
onSubmitError();
|
|
1935
|
+
}
|
|
1936
|
+
finally {
|
|
1937
|
+
onAfterSubmit();
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1941
|
+
const onFormSubmit = async (data) => {
|
|
1942
|
+
if (onSubmit === undefined) {
|
|
1943
|
+
defaultOnSubmit(data);
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
onSubmit(data);
|
|
1947
|
+
};
|
|
1948
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1949
|
+
const onValid = (data) => {
|
|
1950
|
+
setValidatedData(data);
|
|
1951
|
+
setIsError(false);
|
|
1952
|
+
setIsConfirming(true);
|
|
1953
|
+
};
|
|
1954
|
+
const renderOrder = (order, origin_list) => {
|
|
1955
|
+
const not_exist = origin_list.filter((columnA) => !order.some((columnB) => columnA === columnB));
|
|
1956
|
+
return [...order, ...not_exist];
|
|
1957
|
+
};
|
|
1958
|
+
const ordered = renderOrder(order, Object.keys(properties));
|
|
1959
|
+
const getDataListProps = (value) => {
|
|
1960
|
+
if (value == undefined || value.length <= 0) {
|
|
1961
|
+
return {
|
|
1962
|
+
value: `<${empty ?? "Empty"}>`,
|
|
1963
|
+
color: "gray.400",
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
return {
|
|
1967
|
+
value: value,
|
|
1968
|
+
};
|
|
1969
|
+
};
|
|
1970
|
+
React.useEffect(() => {
|
|
1971
|
+
const loadData = () => {
|
|
1972
|
+
Object.entries(preLoadedValues).map(([column, value]) => {
|
|
1973
|
+
methods.setValue(column, value);
|
|
1974
|
+
});
|
|
1975
|
+
};
|
|
1976
|
+
loadData();
|
|
1977
|
+
}, [preLoadedValues, methods]);
|
|
1978
|
+
if (isSuccess) {
|
|
1979
|
+
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children: title ?? snakeToLabel(schema.title ?? "") }), jsxRuntime.jsxs(react.Alert.Root, { status: "success", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsx(react.Alert.Title, { children: submitSuccess ?? "Data uploaded to the server. Fire on!" })] }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
1980
|
+
setIsError(false);
|
|
1981
|
+
setIsSubmiting(false);
|
|
1982
|
+
setIsSuccess(false);
|
|
1983
|
+
setIsConfirming(false);
|
|
1984
|
+
setValidatedData(undefined);
|
|
1985
|
+
methods.reset();
|
|
1986
|
+
}, formNoValidate: true, children: submitAgain ?? "Submit Again" })] }));
|
|
1987
|
+
}
|
|
1988
|
+
if (isConfirming) {
|
|
1989
|
+
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children: title ?? snakeToLabel(schema.title ?? "") }), jsxRuntime.jsx(DataListRoot, { orientation: "horizontal", gap: 4, display: "grid", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
1990
|
+
if (properties === undefined) {
|
|
1991
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
1992
|
+
}
|
|
1993
|
+
const key = column;
|
|
1994
|
+
const values = properties[column];
|
|
1995
|
+
const shouldIgnore = ignore.some((column) => {
|
|
1996
|
+
return column == key;
|
|
1997
|
+
});
|
|
1998
|
+
if (shouldIgnore) {
|
|
1999
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
2000
|
+
}
|
|
2001
|
+
const { type, variant, in_table, column_ref, display_column, gridColumn, gridRow, } = values;
|
|
2002
|
+
if (type === "string") {
|
|
2003
|
+
if (variant === "id-picker") {
|
|
2004
|
+
idPickerSanityCheck(column, in_table, column_ref, display_column);
|
|
2005
|
+
return (jsxRuntime.jsx(IdViewer, { value: (validatedData ?? {})[column], in_table,
|
|
2006
|
+
column_ref,
|
|
2007
|
+
display_column,
|
|
2008
|
+
column,
|
|
2009
|
+
gridColumn,
|
|
2010
|
+
gridRow }, `form-${key}`));
|
|
2011
|
+
}
|
|
2012
|
+
if (variant === "date-picker") {
|
|
2013
|
+
const value = (validatedData ?? {})[column];
|
|
2014
|
+
if (!!value === false) {
|
|
2015
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${snakeToLabel(column)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
2016
|
+
}
|
|
2017
|
+
const date = dayjs(value).format("YYYY-MM-DD");
|
|
2018
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${snakeToLabel(column)}`, ...getDataListProps(date) }, `form-${key}`));
|
|
2019
|
+
}
|
|
2020
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
2021
|
+
}
|
|
2022
|
+
if (type === "object") {
|
|
2023
|
+
const value = (validatedData ?? {})[column];
|
|
2024
|
+
if (!!value === false) {
|
|
2025
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${snakeToLabel(column)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
2026
|
+
}
|
|
2027
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children: snakeToLabel(column) }), jsxRuntime.jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
|
|
2028
|
+
return (jsxRuntime.jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
2029
|
+
}) })] }));
|
|
2030
|
+
}
|
|
2031
|
+
if (type === "boolean") {
|
|
2032
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
2033
|
+
}
|
|
2034
|
+
if (type === "number" || type === "integer") {
|
|
2035
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
2036
|
+
}
|
|
2037
|
+
if (type === "array") {
|
|
2038
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `array ${column}` });
|
|
2039
|
+
}
|
|
2040
|
+
if (type === "null") {
|
|
2041
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `null ${column}` });
|
|
2042
|
+
}
|
|
2043
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `unknown type ${column}` });
|
|
2044
|
+
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
2045
|
+
onFormSubmit(validatedData);
|
|
2046
|
+
}, children: confirm ?? "Confirm" }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
2047
|
+
setIsConfirming(false);
|
|
2048
|
+
}, variant: "subtle", children: cancel ?? "Cancel" }), 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: ["b"], children: jsxRuntime.jsxs(AccordionItem, { value: "b", children: [jsxRuntime.jsxs(AccordionItemTrigger, { children: [jsxRuntime.jsx(react.Alert.Indicator, {}), `${error}`] }), jsxRuntime.jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
|
|
2049
|
+
}
|
|
2050
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children: title ?? snakeToLabel(schema.title ?? "") }), jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
2051
|
+
if (properties === undefined) {
|
|
2052
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
2053
|
+
}
|
|
2054
|
+
const key = column;
|
|
2055
|
+
const values = properties[column];
|
|
2056
|
+
const shouldIgnore = ignore.some((column) => {
|
|
2057
|
+
return column == key;
|
|
2058
|
+
});
|
|
2059
|
+
if (shouldIgnore) {
|
|
2060
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
2061
|
+
}
|
|
2062
|
+
//@ts-expect-error TODO: add more fields to support form-creation
|
|
2063
|
+
const { type, variant, in_table, column_ref, display_column } = values;
|
|
2064
|
+
if (type === "string") {
|
|
2065
|
+
if (variant === "id-picker") {
|
|
2066
|
+
idPickerSanityCheck(column, in_table, column_ref, display_column);
|
|
2067
|
+
return (jsxRuntime.jsx(IdPicker, { column: key, in_table: in_table, column_ref: column_ref, display_column: display_column }, `form-${key}`));
|
|
2068
|
+
}
|
|
2069
|
+
if (variant === "date-picker") {
|
|
2070
|
+
return jsxRuntime.jsx(DatePicker, { column: key }, `form-${key}`);
|
|
2071
|
+
}
|
|
2072
|
+
return jsxRuntime.jsx(StringInputField, { column: key }, `form-${key}`);
|
|
2073
|
+
}
|
|
2074
|
+
if (type === "number" || type === "integer") {
|
|
2075
|
+
return jsxRuntime.jsx(NumberInputField, { column: key }, `form-${key}`);
|
|
2076
|
+
}
|
|
2077
|
+
if (type === "boolean") {
|
|
2078
|
+
return jsxRuntime.jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
2079
|
+
}
|
|
2080
|
+
if (type === "object") {
|
|
2081
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ObjectInput, { column: key }, `form-${key}`) }));
|
|
2082
|
+
}
|
|
2083
|
+
if (type === "array") {
|
|
2084
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `array ${column}` });
|
|
2085
|
+
}
|
|
2086
|
+
if (type === "null") {
|
|
2087
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `null ${column}` });
|
|
2088
|
+
}
|
|
2089
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "missing type" });
|
|
2090
|
+
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
2091
|
+
methods.handleSubmit(onValid)();
|
|
2092
|
+
}, formNoValidate: true, children: submit ?? "Submit" })] }), isError && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["isError", jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
2093
|
+
};
|
|
2094
|
+
const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, displayText = {}, }) => {
|
|
2095
|
+
const queryClient = new reactQuery.QueryClient();
|
|
2096
|
+
const methods = reactHookForm.useForm();
|
|
2097
|
+
const { properties } = schema;
|
|
2098
|
+
idListSanityCheck("order", order, properties);
|
|
2099
|
+
idListSanityCheck("ignore", ignore, properties);
|
|
2100
|
+
idListSanityCheck("preLoadedValues", Object.keys(preLoadedValues), properties);
|
|
2101
|
+
return (jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: queryClient, children: jsxRuntime.jsx(SchemaFormContext.Provider, { value: {
|
|
2102
|
+
schema,
|
|
2103
|
+
serverUrl,
|
|
2104
|
+
displayText,
|
|
2105
|
+
order,
|
|
2106
|
+
ignore,
|
|
2107
|
+
// @ts-expect-error TODO: find appropriate types
|
|
2108
|
+
onSubmit,
|
|
2109
|
+
preLoadedValues,
|
|
2110
|
+
rowNumber,
|
|
2111
|
+
}, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: jsxRuntime.jsx(FormInternal, {}) }) }) }));
|
|
2112
|
+
};
|
|
2113
|
+
|
|
2114
|
+
const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) => {
|
|
2115
|
+
if (!selectable) {
|
|
2116
|
+
return [...selectedDates];
|
|
2117
|
+
}
|
|
2118
|
+
if (selected) {
|
|
2119
|
+
// Remove
|
|
2120
|
+
return selectedDates.filter((time) => {
|
|
2121
|
+
return selectedDate.getTime() !== time.getTime();
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
// Add
|
|
2126
|
+
return [...selectedDates, selectedDate];
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2129
|
+
|
|
2130
|
+
const getRangeDates = ({ selectable, date, selectedDates, }) => {
|
|
2131
|
+
if (!selectable) {
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
const dateTime = date.getTime();
|
|
2135
|
+
const newDates = [...selectedDates];
|
|
2136
|
+
if (selectedDates.length) {
|
|
2137
|
+
if (selectedDates.length === 1) {
|
|
2138
|
+
const firstTime = selectedDates[0].getTime();
|
|
2139
|
+
if (firstTime < dateTime) {
|
|
2140
|
+
newDates.push(date);
|
|
2141
|
+
}
|
|
2142
|
+
else {
|
|
2143
|
+
newDates.unshift(date);
|
|
2144
|
+
}
|
|
2145
|
+
return newDates;
|
|
2146
|
+
}
|
|
2147
|
+
else if (newDates.length === 2) {
|
|
2148
|
+
return [date];
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
else {
|
|
2152
|
+
newDates.push(date);
|
|
2153
|
+
return newDates;
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
|
|
2157
|
+
const monthNamesFull = [
|
|
2158
|
+
"January",
|
|
2159
|
+
"February",
|
|
2160
|
+
"March",
|
|
2161
|
+
"April",
|
|
2162
|
+
"May",
|
|
2163
|
+
"June",
|
|
2164
|
+
"July",
|
|
2165
|
+
"August",
|
|
2166
|
+
"September",
|
|
2167
|
+
"October",
|
|
2168
|
+
"November",
|
|
2169
|
+
"December",
|
|
2170
|
+
];
|
|
2171
|
+
const weekdayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
2172
|
+
function Calendar({ calendars, getBackProps, getForwardProps, getDateProps, selected = [], firstDayOfWeek = 0, }) {
|
|
2173
|
+
const [hoveredDate, setHoveredDate] = React.useState();
|
|
2174
|
+
const onMouseLeave = () => {
|
|
2175
|
+
setHoveredDate(undefined);
|
|
2176
|
+
};
|
|
2177
|
+
const onMouseEnter = (date) => {
|
|
2178
|
+
setHoveredDate(date);
|
|
2179
|
+
};
|
|
2180
|
+
const isInRange = (date) => {
|
|
2181
|
+
if (selected.length) {
|
|
2182
|
+
const firstSelected = selected[0].getTime();
|
|
2183
|
+
if (selected.length === 2) {
|
|
2184
|
+
const secondSelected = selected[1].getTime();
|
|
2185
|
+
return (firstSelected < date.getTime() && secondSelected > date.getTime());
|
|
2186
|
+
}
|
|
2187
|
+
else {
|
|
2188
|
+
return !!(hoveredDate &&
|
|
2189
|
+
((firstSelected < date.getTime() &&
|
|
2190
|
+
hoveredDate.getTime() >= date.getTime()) ||
|
|
2191
|
+
(date.getTime() < firstSelected &&
|
|
2192
|
+
date.getTime() >= hoveredDate.getTime())));
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return false;
|
|
2196
|
+
};
|
|
2197
|
+
if (calendars.length) {
|
|
2198
|
+
return (jsxRuntime.jsxs(react.Grid, { onMouseLeave: onMouseLeave, children: [jsxRuntime.jsxs(react.Grid, { templateColumns: "repeat(4, auto)", justifyContent: "center", children: [jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({
|
|
2199
|
+
calendars,
|
|
2200
|
+
offset: 12,
|
|
2201
|
+
}), children: "<<" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getBackProps({ calendars }), children: "Back" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({ calendars }), children: "Next" }), jsxRuntime.jsx(react.Button, { variant: "ghost", ...getForwardProps({
|
|
2202
|
+
calendars,
|
|
2203
|
+
offset: 12,
|
|
2204
|
+
}), children: ">>" })] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(2, auto)", justifyContent: "center", gap: 4, children: calendars.map((calendar) => (jsxRuntime.jsxs(react.Grid, { gap: 4, children: [jsxRuntime.jsxs(react.Grid, { justifyContent: "center", children: [monthNamesFull[calendar.month], " ", calendar.year] }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: [0, 1, 2, 3, 4, 5, 6].map((weekdayNum) => {
|
|
2205
|
+
const weekday = (weekdayNum + firstDayOfWeek) % 7;
|
|
2206
|
+
return (jsxRuntime.jsx(react.Box, { minWidth: "48px", textAlign: 'center', children: weekdayNamesShort[weekday] }, `${calendar.month}${calendar.year}${weekday}`));
|
|
2207
|
+
}) }), jsxRuntime.jsx(react.Grid, { templateColumns: "repeat(7, auto)", justifyContent: "center", children: calendar.weeks.map((week, windex) => week.map((dateObj, index) => {
|
|
2208
|
+
const key = `${calendar.month}${calendar.year}${windex}${index}`;
|
|
2209
|
+
if (!dateObj) {
|
|
2210
|
+
return jsxRuntime.jsx(react.Box, {}, key);
|
|
2211
|
+
}
|
|
2212
|
+
const { date, selected, selectable, today } = dateObj;
|
|
2213
|
+
const getStyle = ({ selected, unavailable, today, isInRange, }) => {
|
|
2214
|
+
if (unavailable) {
|
|
2215
|
+
return {
|
|
2216
|
+
colorPalette: "gray",
|
|
2217
|
+
variant: "solid",
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
if (selected) {
|
|
2221
|
+
return {
|
|
2222
|
+
colorPalette: "blue",
|
|
2223
|
+
variant: "solid",
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
if (isInRange) {
|
|
2227
|
+
return {
|
|
2228
|
+
colorPalette: "blue",
|
|
2229
|
+
variant: "subtle",
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
if (today) {
|
|
2233
|
+
return {
|
|
2234
|
+
colorPalette: "green",
|
|
2235
|
+
variant: "solid",
|
|
2236
|
+
};
|
|
2237
|
+
}
|
|
2238
|
+
return { variant: "ghost" };
|
|
2239
|
+
};
|
|
2240
|
+
return (jsxRuntime.jsx(react.Button, { ...getDateProps({
|
|
2241
|
+
dateObj,
|
|
2242
|
+
onMouseEnter: () => {
|
|
2243
|
+
onMouseEnter(date);
|
|
2244
|
+
},
|
|
2245
|
+
}), ...getStyle({
|
|
2246
|
+
selected,
|
|
2247
|
+
unavailable: !selectable,
|
|
2248
|
+
today,
|
|
2249
|
+
isInRange: isInRange(date),
|
|
2250
|
+
}), children: selectable ? date.getDate() : "X" }, key));
|
|
2251
|
+
})) })] }, `${calendar.month}${calendar.year}`))) })] }));
|
|
2252
|
+
}
|
|
2253
|
+
return null;
|
|
2254
|
+
}
|
|
2255
|
+
class RangeDatePicker extends React.Component {
|
|
2256
|
+
render() {
|
|
2257
|
+
return (jsxRuntime.jsx(Dayzed, { onDateSelected: this.props.onDateSelected, selected: this.props.selected, firstDayOfWeek: this.props.firstDayOfWeek, showOutsideDays: this.props.showOutsideDays, date: this.props.date, minDate: this.props.minDate, maxDate: this.props.maxDate, monthsToDisplay: this.props.monthsToDisplay, render: (dayzedData) => (jsxRuntime.jsx(Calendar, { ...dayzedData,
|
|
2258
|
+
firstDayOfWeek: this.props.firstDayOfWeek,
|
|
2259
|
+
selected: this.props.selected })) }));
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
exports.CardHeader = CardHeader;
|
|
2264
|
+
exports.DataDisplay = DataDisplay;
|
|
1272
2265
|
exports.DataTable = DataTable;
|
|
1273
2266
|
exports.DataTableServer = DataTableServer;
|
|
1274
|
-
exports.DefaultCard = DefaultCard;
|
|
1275
2267
|
exports.DefaultCardTitle = DefaultCardTitle;
|
|
1276
2268
|
exports.DefaultTable = DefaultTable;
|
|
1277
2269
|
exports.DensityToggleButton = DensityToggleButton;
|
|
@@ -1280,6 +2272,7 @@ exports.EditOrderButton = EditOrderButton;
|
|
|
1280
2272
|
exports.EditSortingButton = EditSortingButton;
|
|
1281
2273
|
exports.EditViewButton = EditViewButton;
|
|
1282
2274
|
exports.FilterOptions = FilterOptions;
|
|
2275
|
+
exports.Form = Form;
|
|
1283
2276
|
exports.GlobalFilter = GlobalFilter;
|
|
1284
2277
|
exports.PageSizeControl = PageSizeControl;
|
|
1285
2278
|
exports.ReloadButton = ReloadButton;
|
|
@@ -1304,7 +2297,11 @@ exports.TableSelector = TableSelector;
|
|
|
1304
2297
|
exports.TableSorter = TableSorter;
|
|
1305
2298
|
exports.TableViewer = TableViewer;
|
|
1306
2299
|
exports.TextCell = TextCell;
|
|
2300
|
+
exports.getColumns = getColumns;
|
|
2301
|
+
exports.getMultiDates = getMultiDates;
|
|
2302
|
+
exports.getRangeDates = getRangeDates;
|
|
1307
2303
|
exports.useDataFromUrl = useDataFromUrl;
|
|
1308
2304
|
exports.useDataTable = useDataTable;
|
|
1309
2305
|
exports.useDataTableContext = useDataTableContext;
|
|
1310
2306
|
exports.useDataTableServer = useDataTableServer;
|
|
2307
|
+
exports.widthSanityCheck = widthSanityCheck;
|