@bsol-oss/react-datatable5 11.0.0-beta.1 → 11.0.0-beta.3
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 +6 -1
- package/dist/index.js +323 -320
- package/dist/index.mjs +324 -322
- package/dist/types/components/Form/Form.d.ts +5 -0
- package/dist/types/components/Form/components/BooleanPicker.d.ts +4 -1
- package/dist/types/components/Form/components/ColumnRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/DatePicker.d.ts +4 -1
- package/dist/types/components/Form/components/EnumPicker.d.ts +4 -1
- package/dist/types/components/Form/components/FilePicker.d.ts +3 -1
- package/dist/types/components/Form/components/IdPicker.d.ts +4 -1
- package/dist/types/components/Form/components/NumberInputField.d.ts +4 -1
- package/dist/types/components/Form/components/ObjectInput.d.ts +5 -2
- package/dist/types/components/Form/components/RecordInput.d.ts +7 -0
- package/dist/types/components/Form/components/StringInputField.d.ts +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,8 +28,8 @@ var gr = require('react-icons/gr');
|
|
|
28
28
|
var hi = require('react-icons/hi');
|
|
29
29
|
var reactI18next = require('react-i18next');
|
|
30
30
|
var axios = require('axios');
|
|
31
|
-
var reactHookForm = require('react-hook-form');
|
|
32
31
|
var dayjs = require('dayjs');
|
|
32
|
+
var reactHookForm = require('react-hook-form');
|
|
33
33
|
var ti = require('react-icons/ti');
|
|
34
34
|
|
|
35
35
|
function _interopNamespaceDefault(e) {
|
|
@@ -2380,7 +2380,7 @@ function ColumnCard({ columnId }) {
|
|
|
2380
2380
|
onDrop: () => setDragging(false), // NEW
|
|
2381
2381
|
});
|
|
2382
2382
|
}, [columnId, table]);
|
|
2383
|
-
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "gray.400" }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "space-between", alignItems: "center", children: jsxRuntime.jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2383
|
+
return (jsxRuntime.jsxs(react.Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsxRuntime.jsx(react.Flex, { alignItems: "center", padding: "0", cursor: 'grab', children: jsxRuntime.jsx(fa6.FaGripLinesVertical, { color: "gray.400" }) }), jsxRuntime.jsx(react.Flex, { justifyContent: "space-between", alignItems: "center", children: jsxRuntime.jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2384
2384
|
}
|
|
2385
2385
|
function CardContainer({ location, children }) {
|
|
2386
2386
|
const ref = React.useRef(null);
|
|
@@ -2418,9 +2418,11 @@ function CardContainer({ location, children }) {
|
|
|
2418
2418
|
}
|
|
2419
2419
|
const TableViewer = () => {
|
|
2420
2420
|
const { table } = useDataTableContext();
|
|
2421
|
-
const
|
|
2422
|
-
|
|
2423
|
-
|
|
2421
|
+
const order = table.getState().columnOrder.length > 0
|
|
2422
|
+
? table.getState().columnOrder
|
|
2423
|
+
: table.getAllLeafColumns().map(({ id }) => {
|
|
2424
|
+
return id;
|
|
2425
|
+
});
|
|
2424
2426
|
React.useEffect(() => {
|
|
2425
2427
|
return monitorForElements({
|
|
2426
2428
|
onDrop({ source, location }) {
|
|
@@ -2445,11 +2447,10 @@ const TableViewer = () => {
|
|
|
2445
2447
|
...columnAfter,
|
|
2446
2448
|
].filter((id) => id != "<marker>");
|
|
2447
2449
|
table.setColumnOrder(newOrder);
|
|
2448
|
-
setOrder(newOrder);
|
|
2449
2450
|
},
|
|
2450
2451
|
});
|
|
2451
|
-
}, [
|
|
2452
|
-
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children:
|
|
2452
|
+
}, [table]);
|
|
2453
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: order.map((columnId, index) => {
|
|
2453
2454
|
return (jsxRuntime.jsx(CardContainer, { location: index, children: jsxRuntime.jsx(ColumnCard, { columnId: columnId }) }));
|
|
2454
2455
|
}) }));
|
|
2455
2456
|
};
|
|
@@ -2624,21 +2625,6 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
|
|
|
2624
2625
|
}) }));
|
|
2625
2626
|
};
|
|
2626
2627
|
|
|
2627
|
-
const formatValue = (value) => {
|
|
2628
|
-
if (typeof value === "object") {
|
|
2629
|
-
return JSON.stringify(value);
|
|
2630
|
-
}
|
|
2631
|
-
if (typeof value === "string") {
|
|
2632
|
-
return value;
|
|
2633
|
-
}
|
|
2634
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
2635
|
-
return `${value}`;
|
|
2636
|
-
}
|
|
2637
|
-
if (value === undefined) {
|
|
2638
|
-
return `undefined`;
|
|
2639
|
-
}
|
|
2640
|
-
throw new Error(`value is unknown, ${typeof value}`);
|
|
2641
|
-
};
|
|
2642
2628
|
const DataDisplay = ({ variant = "", translate }) => {
|
|
2643
2629
|
const { table } = useDataTableContext();
|
|
2644
2630
|
const getLabel = ({ columnId }) => {
|
|
@@ -2647,6 +2633,24 @@ const DataDisplay = ({ variant = "", translate }) => {
|
|
|
2647
2633
|
}
|
|
2648
2634
|
return snakeToLabel(columnId);
|
|
2649
2635
|
};
|
|
2636
|
+
const formatValue = (value) => {
|
|
2637
|
+
if (typeof value === "object") {
|
|
2638
|
+
return JSON.stringify(value);
|
|
2639
|
+
}
|
|
2640
|
+
if (typeof value === "string") {
|
|
2641
|
+
return value;
|
|
2642
|
+
}
|
|
2643
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
2644
|
+
return `${value}`;
|
|
2645
|
+
}
|
|
2646
|
+
if (value === undefined) {
|
|
2647
|
+
if (translate !== undefined) {
|
|
2648
|
+
return translate.t(`undefined`);
|
|
2649
|
+
}
|
|
2650
|
+
return `undefined`;
|
|
2651
|
+
}
|
|
2652
|
+
throw new Error(`value is unknown, ${typeof value}`);
|
|
2653
|
+
};
|
|
2650
2654
|
if (variant == "horizontal") {
|
|
2651
2655
|
return (jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
|
|
2652
2656
|
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) => {
|
|
@@ -3563,28 +3567,15 @@ const SchemaFormContext = React.createContext({
|
|
|
3563
3567
|
requestOptions: {},
|
|
3564
3568
|
});
|
|
3565
3569
|
|
|
3566
|
-
const
|
|
3570
|
+
const HoverCardContent = React__namespace.forwardRef(function HoverCardContent(props, ref) {
|
|
3567
3571
|
const { portalled = true, portalRef, ...rest } = props;
|
|
3568
|
-
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.
|
|
3569
|
-
});
|
|
3570
|
-
React__namespace.forwardRef(function PopoverArrow(props, ref) {
|
|
3571
|
-
return (jsxRuntime.jsx(react.Popover.Arrow, { ...props, ref: ref, children: jsxRuntime.jsx(react.Popover.ArrowTip, {}) }));
|
|
3572
|
-
});
|
|
3573
|
-
React__namespace.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
3574
|
-
return (jsxRuntime.jsx(react.Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsxRuntime.jsx(CloseButton, { size: "sm" }) }));
|
|
3572
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.HoverCard.Positioner, { children: jsxRuntime.jsx(react.HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3575
3573
|
});
|
|
3576
|
-
const
|
|
3577
|
-
react.
|
|
3578
|
-
react.Popover.Footer;
|
|
3579
|
-
react.Popover.Header;
|
|
3580
|
-
const PopoverRoot = react.Popover.Root;
|
|
3581
|
-
const PopoverBody = react.Popover.Body;
|
|
3582
|
-
const PopoverTrigger = react.Popover.Trigger;
|
|
3583
|
-
|
|
3584
|
-
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
3585
|
-
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
3586
|
-
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 }))] }));
|
|
3574
|
+
const HoverCardArrow = React__namespace.forwardRef(function HoverCardArrow(props, ref) {
|
|
3575
|
+
return (jsxRuntime.jsx(react.HoverCard.Arrow, { ref: ref, ...props, children: jsxRuntime.jsx(react.HoverCard.ArrowTip, {}) }));
|
|
3587
3576
|
});
|
|
3577
|
+
const HoverCardRoot = react.HoverCard.Root;
|
|
3578
|
+
const HoverCardTrigger = react.HoverCard.Trigger;
|
|
3588
3579
|
|
|
3589
3580
|
const useSchemaContext = () => {
|
|
3590
3581
|
const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = React.useContext(SchemaFormContext);
|
|
@@ -3603,148 +3594,6 @@ const useSchemaContext = () => {
|
|
|
3603
3594
|
};
|
|
3604
3595
|
};
|
|
3605
3596
|
|
|
3606
|
-
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
3607
|
-
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
3608
|
-
throw new Error("The serverUrl is missing");
|
|
3609
|
-
}
|
|
3610
|
-
if (in_table === undefined || in_table.length == 0) {
|
|
3611
|
-
throw new Error("The in_table is missing");
|
|
3612
|
-
}
|
|
3613
|
-
const options = {
|
|
3614
|
-
method: "GET",
|
|
3615
|
-
url: `${serverUrl}/api/g/${in_table}`,
|
|
3616
|
-
params: {
|
|
3617
|
-
searching,
|
|
3618
|
-
where,
|
|
3619
|
-
limit,
|
|
3620
|
-
offset
|
|
3621
|
-
},
|
|
3622
|
-
};
|
|
3623
|
-
try {
|
|
3624
|
-
const { data } = await axios.request(options);
|
|
3625
|
-
console.log(data);
|
|
3626
|
-
return data;
|
|
3627
|
-
}
|
|
3628
|
-
catch (error) {
|
|
3629
|
-
console.error(error);
|
|
3630
|
-
throw error;
|
|
3631
|
-
}
|
|
3632
|
-
};
|
|
3633
|
-
|
|
3634
|
-
const IdPicker = ({ column, isMultiple = false }) => {
|
|
3635
|
-
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3636
|
-
const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
3637
|
-
const { required } = schema;
|
|
3638
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3639
|
-
if (schema.properties == undefined) {
|
|
3640
|
-
throw new Error("schema properties is undefined when using DatePicker");
|
|
3641
|
-
}
|
|
3642
|
-
const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
|
|
3643
|
-
const { table, column: column_ref, display_column, } = foreign_key;
|
|
3644
|
-
const [searchText, setSearchText] = React.useState();
|
|
3645
|
-
const [limit, setLimit] = React.useState(10);
|
|
3646
|
-
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
3647
|
-
const [page, setPage] = React.useState(0);
|
|
3648
|
-
const ref = React.useRef(null);
|
|
3649
|
-
const selectedIds = watch(column) ?? [];
|
|
3650
|
-
const query = reactQuery.useQuery({
|
|
3651
|
-
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
3652
|
-
queryFn: async () => {
|
|
3653
|
-
const data = await getTableData({
|
|
3654
|
-
serverUrl,
|
|
3655
|
-
searching: searchText ?? "",
|
|
3656
|
-
in_table: table,
|
|
3657
|
-
limit: limit,
|
|
3658
|
-
offset: page * 10,
|
|
3659
|
-
});
|
|
3660
|
-
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
3661
|
-
return [
|
|
3662
|
-
item[column_ref],
|
|
3663
|
-
{
|
|
3664
|
-
...item,
|
|
3665
|
-
},
|
|
3666
|
-
];
|
|
3667
|
-
}));
|
|
3668
|
-
setIdMap((state) => {
|
|
3669
|
-
return { ...state, ...newMap };
|
|
3670
|
-
});
|
|
3671
|
-
return data;
|
|
3672
|
-
},
|
|
3673
|
-
enabled: (searchText ?? "")?.length > 0,
|
|
3674
|
-
staleTime: 300000,
|
|
3675
|
-
});
|
|
3676
|
-
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
3677
|
-
const dataList = data?.data ?? [];
|
|
3678
|
-
const count = data?.count ?? 0;
|
|
3679
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3680
|
-
const onSearchChange = async (event) => {
|
|
3681
|
-
setSearchText(event.target.value);
|
|
3682
|
-
setPage(0);
|
|
3683
|
-
setLimit(10);
|
|
3684
|
-
};
|
|
3685
|
-
const watchId = watch(column);
|
|
3686
|
-
const watchIds = (watch(column) ?? []);
|
|
3687
|
-
const getPickedValue = () => {
|
|
3688
|
-
if (Object.keys(idMap).length <= 0) {
|
|
3689
|
-
return "";
|
|
3690
|
-
}
|
|
3691
|
-
const record = idMap[watchId];
|
|
3692
|
-
if (record === undefined) {
|
|
3693
|
-
return "";
|
|
3694
|
-
}
|
|
3695
|
-
return record[display_column];
|
|
3696
|
-
};
|
|
3697
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3698
|
-
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
3699
|
-
const item = idMap[id];
|
|
3700
|
-
if (item === undefined) {
|
|
3701
|
-
return jsxRuntime.jsx(react.Text, { children: "undefined" }, id);
|
|
3702
|
-
}
|
|
3703
|
-
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3704
|
-
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
3705
|
-
}, children: !!renderDisplay === true
|
|
3706
|
-
? renderDisplay(item)
|
|
3707
|
-
: item[display_column] }, id));
|
|
3708
|
-
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3709
|
-
setOpenSearchResult(true);
|
|
3710
|
-
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3711
|
-
setOpenSearchResult(true);
|
|
3712
|
-
}, children: getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
|
|
3713
|
-
onSearchChange(event);
|
|
3714
|
-
setOpenSearchResult(true);
|
|
3715
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { 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, { justifySelf: "center", children: `${translate.t(`${column}.total`)} ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children:
|
|
3716
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3717
|
-
dataList.map((item) => {
|
|
3718
|
-
const selected = isMultiple
|
|
3719
|
-
? watchIds.some((id) => item[column_ref] === id)
|
|
3720
|
-
: watchId === item[column_ref];
|
|
3721
|
-
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
3722
|
-
if (!isMultiple) {
|
|
3723
|
-
setOpenSearchResult(false);
|
|
3724
|
-
setValue(column, item[column_ref]);
|
|
3725
|
-
return;
|
|
3726
|
-
}
|
|
3727
|
-
const newSet = new Set([
|
|
3728
|
-
...(watchIds ?? []),
|
|
3729
|
-
item[column_ref],
|
|
3730
|
-
]);
|
|
3731
|
-
setValue(column, [...newSet]);
|
|
3732
|
-
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3733
|
-
? renderDisplay(item)
|
|
3734
|
-
: item[display_column] }, item[column_ref]));
|
|
3735
|
-
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(react.Text, { children: translate.t(`${column}.emptySearchResult`) })) }))] }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3736
|
-
};
|
|
3737
|
-
|
|
3738
|
-
const HoverCardContent = React__namespace.forwardRef(function HoverCardContent(props, ref) {
|
|
3739
|
-
const { portalled = true, portalRef, ...rest } = props;
|
|
3740
|
-
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.HoverCard.Positioner, { children: jsxRuntime.jsx(react.HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3741
|
-
});
|
|
3742
|
-
const HoverCardArrow = React__namespace.forwardRef(function HoverCardArrow(props, ref) {
|
|
3743
|
-
return (jsxRuntime.jsx(react.HoverCard.Arrow, { ref: ref, ...props, children: jsxRuntime.jsx(react.HoverCard.ArrowTip, {}) }));
|
|
3744
|
-
});
|
|
3745
|
-
const HoverCardRoot = react.HoverCard.Root;
|
|
3746
|
-
const HoverCardTrigger = react.HoverCard.Trigger;
|
|
3747
|
-
|
|
3748
3597
|
const IdViewer = ({ value, column }) => {
|
|
3749
3598
|
const { schema, idMap, translate } = useSchemaContext();
|
|
3750
3599
|
if (schema.properties == undefined) {
|
|
@@ -3761,38 +3610,6 @@ const IdViewer = ({ value, column }) => {
|
|
|
3761
3610
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", children: [jsxRuntime.jsx(react.Text, { children: translate.t(`${column}.fieldLabel`) }), jsxRuntime.jsxs(HoverCardRoot, { children: [jsxRuntime.jsx(HoverCardTrigger, { asChild: true, children: jsxRuntime.jsx(react.Text, { cursor: 'pointer', children: idMap[value][display_column] }) }), jsxRuntime.jsxs(HoverCardContent, { children: [jsxRuntime.jsx(HoverCardArrow, {}), jsxRuntime.jsx(RecordDisplay, { object: idMap[value] })] })] })] }));
|
|
3762
3611
|
};
|
|
3763
3612
|
|
|
3764
|
-
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
3765
|
-
const { children, ...rest } = props;
|
|
3766
|
-
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, {})] })] }));
|
|
3767
|
-
});
|
|
3768
|
-
const NumberInputField$1 = react.NumberInput.Input;
|
|
3769
|
-
react.NumberInput.Scrubber;
|
|
3770
|
-
react.NumberInput.Label;
|
|
3771
|
-
|
|
3772
|
-
const NumberInputField = ({ column }) => {
|
|
3773
|
-
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3774
|
-
const { schema, translate } = useSchemaContext();
|
|
3775
|
-
const { required } = schema;
|
|
3776
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3777
|
-
if (schema.properties == undefined) {
|
|
3778
|
-
throw new Error("schema properties when using String Input Field");
|
|
3779
|
-
}
|
|
3780
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3781
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, 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: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3782
|
-
};
|
|
3783
|
-
|
|
3784
|
-
const StringInputField = ({ column }) => {
|
|
3785
|
-
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3786
|
-
const { schema, translate } = useSchemaContext();
|
|
3787
|
-
const { required } = schema;
|
|
3788
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3789
|
-
if (schema.properties == undefined) {
|
|
3790
|
-
throw new Error("schema properties when using String Input Field");
|
|
3791
|
-
}
|
|
3792
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3793
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, 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: translate.t(`${column}.fieldRequired`) }))] }) }));
|
|
3794
|
-
};
|
|
3795
|
-
|
|
3796
3613
|
const clearEmptyString = (object) => {
|
|
3797
3614
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
3798
3615
|
};
|
|
@@ -3822,20 +3639,22 @@ const DataListItem = React__namespace.forwardRef(function DataListItem(props, re
|
|
|
3822
3639
|
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] }));
|
|
3823
3640
|
});
|
|
3824
3641
|
|
|
3825
|
-
const
|
|
3642
|
+
const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
3643
|
+
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
3644
|
+
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 }))] }));
|
|
3645
|
+
});
|
|
3646
|
+
|
|
3647
|
+
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3826
3648
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3827
|
-
const {
|
|
3828
|
-
const { required } = schema;
|
|
3649
|
+
const { translate } = useSchemaContext();
|
|
3650
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3829
3651
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3830
|
-
const
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
}
|
|
3834
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3835
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3652
|
+
const colLabel = `${prefix}${column}`;
|
|
3653
|
+
const value = watch(colLabel);
|
|
3654
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3836
3655
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
3837
|
-
setValue(
|
|
3838
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${
|
|
3656
|
+
setValue(colLabel, !value);
|
|
3657
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
3839
3658
|
};
|
|
3840
3659
|
|
|
3841
3660
|
const monthNamesShort = [
|
|
@@ -3907,18 +3726,33 @@ let DatePicker$1 = class DatePicker extends React.Component {
|
|
|
3907
3726
|
}
|
|
3908
3727
|
};
|
|
3909
3728
|
|
|
3910
|
-
const
|
|
3729
|
+
const PopoverContent = React__namespace.forwardRef(function PopoverContent(props, ref) {
|
|
3730
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
3731
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Popover.Positioner, { children: jsxRuntime.jsx(react.Popover.Content, { ref: ref, ...rest }) }) }));
|
|
3732
|
+
});
|
|
3733
|
+
React__namespace.forwardRef(function PopoverArrow(props, ref) {
|
|
3734
|
+
return (jsxRuntime.jsx(react.Popover.Arrow, { ...props, ref: ref, children: jsxRuntime.jsx(react.Popover.ArrowTip, {}) }));
|
|
3735
|
+
});
|
|
3736
|
+
React__namespace.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
3737
|
+
return (jsxRuntime.jsx(react.Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsxRuntime.jsx(CloseButton, { size: "sm" }) }));
|
|
3738
|
+
});
|
|
3739
|
+
const PopoverTitle = react.Popover.Title;
|
|
3740
|
+
react.Popover.Description;
|
|
3741
|
+
react.Popover.Footer;
|
|
3742
|
+
react.Popover.Header;
|
|
3743
|
+
const PopoverRoot = react.Popover.Root;
|
|
3744
|
+
const PopoverBody = react.Popover.Body;
|
|
3745
|
+
const PopoverTrigger = react.Popover.Trigger;
|
|
3746
|
+
|
|
3747
|
+
const DatePicker = ({ column, schema, prefix }) => {
|
|
3911
3748
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3912
|
-
const {
|
|
3913
|
-
const { required } = schema;
|
|
3749
|
+
const { translate } = useSchemaContext();
|
|
3750
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3914
3751
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3752
|
+
const colLabel = `${prefix}${column}`;
|
|
3915
3753
|
const [open, setOpen] = React.useState(false);
|
|
3916
|
-
const selectedDate = watch(
|
|
3917
|
-
|
|
3918
|
-
throw new Error("schema properties when using DatePicker");
|
|
3919
|
-
}
|
|
3920
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3921
|
-
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3754
|
+
const selectedDate = watch(colLabel);
|
|
3755
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3922
3756
|
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3923
3757
|
setOpen(true);
|
|
3924
3758
|
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
@@ -3927,7 +3761,7 @@ const DatePicker = ({ column }) => {
|
|
|
3927
3761
|
// @ts-expect-error TODO: find appropriate types
|
|
3928
3762
|
selected: new Date(selectedDate),
|
|
3929
3763
|
// @ts-expect-error TODO: find appropriate types
|
|
3930
|
-
onDateSelected: ({
|
|
3764
|
+
onDateSelected: ({ date }) => {
|
|
3931
3765
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
3932
3766
|
setOpen(false);
|
|
3933
3767
|
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
@@ -3943,29 +3777,26 @@ function filterArray(array, searchTerm) {
|
|
|
3943
3777
|
});
|
|
3944
3778
|
}
|
|
3945
3779
|
|
|
3946
|
-
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
3780
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3947
3781
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3948
|
-
const {
|
|
3782
|
+
const { translate } = useSchemaContext();
|
|
3949
3783
|
const { required } = schema;
|
|
3950
3784
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3951
|
-
|
|
3952
|
-
throw new Error("schema properties when using DatePicker");
|
|
3953
|
-
}
|
|
3954
|
-
const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
|
|
3785
|
+
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3955
3786
|
const [searchText, setSearchText] = React.useState();
|
|
3956
3787
|
const [limit, setLimit] = React.useState(10);
|
|
3957
3788
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
3958
3789
|
const ref = React.useRef(null);
|
|
3959
3790
|
const watchEnum = watch(column);
|
|
3960
3791
|
const watchEnums = (watch(column) ?? []);
|
|
3961
|
-
const
|
|
3962
|
-
const
|
|
3963
|
-
const count = properties.enum?.length ?? 0;
|
|
3792
|
+
const dataList = schema.enum ?? [];
|
|
3793
|
+
const count = schema.enum?.length ?? 0;
|
|
3964
3794
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3965
3795
|
const onSearchChange = async (event) => {
|
|
3966
3796
|
setSearchText(event.target.value);
|
|
3967
3797
|
setLimit(10);
|
|
3968
3798
|
};
|
|
3799
|
+
const col = `${prefix}${column}`;
|
|
3969
3800
|
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3970
3801
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3971
3802
|
const item = enumValue;
|
|
@@ -3995,8 +3826,10 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3995
3826
|
}
|
|
3996
3827
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3997
3828
|
setValue(column, [...newSet]);
|
|
3998
|
-
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3999
|
-
|
|
3829
|
+
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3830
|
+
? renderDisplay(item)
|
|
3831
|
+
: translate.t(`${col}.${item}`) }, `${column}-${item}`));
|
|
3832
|
+
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: translate.t(`${col}.emptySearchResult`) })) }))] })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
|
|
4000
3833
|
};
|
|
4001
3834
|
|
|
4002
3835
|
function isEnteringWindow(_ref) {
|
|
@@ -4351,41 +4184,193 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4351
4184
|
return (jsxRuntime.jsxs(react.Grid, { ...getColor(isDraggedOver), ref: ref, cursor: "pointer", onClick: handleClick, borderStyle: "dashed", borderColor: "gray.400", alignContent: "center", justifyContent: "center", borderWidth: 1, borderRadius: 4, ...gridProps, children: [children, !!children === false && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Flex, { children: placeholder }), jsxRuntime.jsx(react.Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
|
|
4352
4185
|
};
|
|
4353
4186
|
|
|
4354
|
-
const FilePicker = ({ column }) => {
|
|
4187
|
+
const FilePicker = ({ column, schema, prefix }) => {
|
|
4355
4188
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4356
|
-
const {
|
|
4357
|
-
const { required } = schema;
|
|
4189
|
+
const { translate } = useSchemaContext();
|
|
4190
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4358
4191
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4359
|
-
if (schema.properties == undefined) {
|
|
4360
|
-
throw new Error("schema properties when using String Input Field");
|
|
4361
|
-
}
|
|
4362
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4363
4192
|
const currentFiles = (watch(column) ?? []);
|
|
4364
|
-
|
|
4193
|
+
const col = `${prefix}${column}`;
|
|
4194
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${col}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsxRuntime.jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4365
4195
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4366
|
-
setValue(
|
|
4367
|
-
}, placeholder: translate.t(`${
|
|
4196
|
+
setValue(col, [...currentFiles, ...newFiles]);
|
|
4197
|
+
}, placeholder: translate.t(`${col}.fileDropzone`) }), jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4368
4198
|
return (jsxRuntime.jsx(react.Card.Root, { variant: "subtle", children: jsxRuntime.jsxs(react.Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4369
4199
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4370
4200
|
return name !== file.name;
|
|
4371
4201
|
}));
|
|
4372
|
-
}, display: "flex", flexFlow:
|
|
4373
|
-
}) }), errors[`${
|
|
4202
|
+
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsxRuntime.jsx(react.Box, { children: file.name }), jsxRuntime.jsx(ti.TiDeleteOutline, {})] }) }, file.name));
|
|
4203
|
+
}) }), errors[`${col}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
|
|
4374
4204
|
};
|
|
4375
4205
|
|
|
4376
|
-
const
|
|
4206
|
+
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4207
|
+
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4208
|
+
throw new Error("The serverUrl is missing");
|
|
4209
|
+
}
|
|
4210
|
+
if (in_table === undefined || in_table.length == 0) {
|
|
4211
|
+
throw new Error("The in_table is missing");
|
|
4212
|
+
}
|
|
4213
|
+
const options = {
|
|
4214
|
+
method: "GET",
|
|
4215
|
+
url: `${serverUrl}/api/g/${in_table}`,
|
|
4216
|
+
params: {
|
|
4217
|
+
searching,
|
|
4218
|
+
where,
|
|
4219
|
+
limit,
|
|
4220
|
+
offset
|
|
4221
|
+
},
|
|
4222
|
+
};
|
|
4223
|
+
try {
|
|
4224
|
+
const { data } = await axios.request(options);
|
|
4225
|
+
console.log(data);
|
|
4226
|
+
return data;
|
|
4227
|
+
}
|
|
4228
|
+
catch (error) {
|
|
4229
|
+
console.error(error);
|
|
4230
|
+
throw error;
|
|
4231
|
+
}
|
|
4232
|
+
};
|
|
4233
|
+
|
|
4234
|
+
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4235
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
4236
|
+
const { serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
4237
|
+
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4238
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4239
|
+
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4240
|
+
const [searchText, setSearchText] = React.useState();
|
|
4241
|
+
const [limit, setLimit] = React.useState(10);
|
|
4242
|
+
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
4243
|
+
const [page, setPage] = React.useState(0);
|
|
4244
|
+
const ref = React.useRef(null);
|
|
4245
|
+
const selectedIds = watch(column) ?? [];
|
|
4246
|
+
const colLabel = `${prefix}${column}`;
|
|
4247
|
+
const query = reactQuery.useQuery({
|
|
4248
|
+
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4249
|
+
queryFn: async () => {
|
|
4250
|
+
const data = await getTableData({
|
|
4251
|
+
serverUrl,
|
|
4252
|
+
searching: searchText ?? "",
|
|
4253
|
+
in_table: table,
|
|
4254
|
+
limit: limit,
|
|
4255
|
+
offset: page * 10,
|
|
4256
|
+
});
|
|
4257
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4258
|
+
return [
|
|
4259
|
+
item[column_ref],
|
|
4260
|
+
{
|
|
4261
|
+
...item,
|
|
4262
|
+
},
|
|
4263
|
+
];
|
|
4264
|
+
}));
|
|
4265
|
+
setIdMap((state) => {
|
|
4266
|
+
return { ...state, ...newMap };
|
|
4267
|
+
});
|
|
4268
|
+
return data;
|
|
4269
|
+
},
|
|
4270
|
+
enabled: (searchText ?? "")?.length > 0,
|
|
4271
|
+
staleTime: 300000,
|
|
4272
|
+
});
|
|
4273
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4274
|
+
const dataList = data?.data ?? [];
|
|
4275
|
+
const count = data?.count ?? 0;
|
|
4276
|
+
const isDirty = (searchText?.length ?? 0) > 0;
|
|
4277
|
+
const onSearchChange = async (event) => {
|
|
4278
|
+
setSearchText(event.target.value);
|
|
4279
|
+
setPage(0);
|
|
4280
|
+
setLimit(10);
|
|
4281
|
+
};
|
|
4282
|
+
const watchId = watch(column);
|
|
4283
|
+
const watchIds = (watch(column) ?? []);
|
|
4284
|
+
const getPickedValue = () => {
|
|
4285
|
+
if (Object.keys(idMap).length <= 0) {
|
|
4286
|
+
return "";
|
|
4287
|
+
}
|
|
4288
|
+
const record = idMap[watchId];
|
|
4289
|
+
if (record === undefined) {
|
|
4290
|
+
return "";
|
|
4291
|
+
}
|
|
4292
|
+
return record[display_column];
|
|
4293
|
+
};
|
|
4294
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4295
|
+
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
4296
|
+
const item = idMap[id];
|
|
4297
|
+
if (item === undefined) {
|
|
4298
|
+
return (jsxRuntime.jsxs(react.Text, { children: [" ", translate.t(`${colLabel}.undefined`)] }, id));
|
|
4299
|
+
}
|
|
4300
|
+
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
4301
|
+
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
4302
|
+
}, children: !!renderDisplay === true
|
|
4303
|
+
? renderDisplay(item)
|
|
4304
|
+
: item[display_column] }, id));
|
|
4305
|
+
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4306
|
+
setOpenSearchResult(true);
|
|
4307
|
+
}, children: translate.t(`${colLabel}.addMore`) })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
4308
|
+
setOpenSearchResult(true);
|
|
4309
|
+
}, children: getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${colLabel}.typeToSearch`), onChange: (event) => {
|
|
4310
|
+
onSearchChange(event);
|
|
4311
|
+
setOpenSearchResult(true);
|
|
4312
|
+
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { 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, { justifySelf: "center", children: `${translate.t(`${colLabel}.total`)} ${count}, ${translate.t(`${colLabel}.showing`)} ${limit}` }), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children:
|
|
4313
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4314
|
+
dataList.map((item) => {
|
|
4315
|
+
const selected = isMultiple
|
|
4316
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4317
|
+
: watchId === item[column_ref];
|
|
4318
|
+
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
4319
|
+
if (!isMultiple) {
|
|
4320
|
+
setOpenSearchResult(false);
|
|
4321
|
+
setValue(colLabel, item[column_ref]);
|
|
4322
|
+
return;
|
|
4323
|
+
}
|
|
4324
|
+
const newSet = new Set([
|
|
4325
|
+
...(watchIds ?? []),
|
|
4326
|
+
item[column_ref],
|
|
4327
|
+
]);
|
|
4328
|
+
setValue(column, [...newSet]);
|
|
4329
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
4330
|
+
? renderDisplay(item)
|
|
4331
|
+
: item[display_column] }, item[column_ref]));
|
|
4332
|
+
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(react.Text, { children: translate.t(`${colLabel}.emptySearchResult`) })) }))] }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${colLabel}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
4333
|
+
};
|
|
4334
|
+
|
|
4335
|
+
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
4336
|
+
const { children, ...rest } = props;
|
|
4337
|
+
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, {})] })] }));
|
|
4338
|
+
});
|
|
4339
|
+
const NumberInputField$1 = react.NumberInput.Input;
|
|
4340
|
+
react.NumberInput.Scrubber;
|
|
4341
|
+
react.NumberInput.Label;
|
|
4342
|
+
|
|
4343
|
+
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4344
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4345
|
+
const { translate } = useSchemaContext();
|
|
4346
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4347
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4348
|
+
const colLabel = `${prefix}${column}`;
|
|
4349
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(NumberInputRoot, { children: jsxRuntime.jsx(NumberInputField$1, { ...register(`${colLabel}`, { required: isRequired }) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
4350
|
+
};
|
|
4351
|
+
|
|
4352
|
+
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4353
|
+
const { properties } = schema;
|
|
4354
|
+
if (properties === undefined) {
|
|
4355
|
+
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4356
|
+
}
|
|
4357
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: Object.keys(properties ?? {}).map((key) => {
|
|
4358
|
+
console.log(properties, key, "gkor");
|
|
4359
|
+
return (jsxRuntime.jsx(ColumnRenderer, { column: `${key}`,
|
|
4360
|
+
prefix: `${prefix}${column}.`,
|
|
4361
|
+
properties }, `form-${column}`));
|
|
4362
|
+
}) }));
|
|
4363
|
+
};
|
|
4364
|
+
|
|
4365
|
+
const RecordInput = ({ column, schema, prefix }) => {
|
|
4377
4366
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4378
|
-
const {
|
|
4379
|
-
const { required } = schema;
|
|
4367
|
+
const { translate } = useSchemaContext();
|
|
4368
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4380
4369
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4381
4370
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4382
4371
|
const [showNewEntries, setShowNewEntries] = React.useState(false);
|
|
4383
4372
|
const [newKey, setNewKey] = React.useState();
|
|
4384
4373
|
const [newValue, setNewValue] = React.useState();
|
|
4385
|
-
if (schema.properties == undefined) {
|
|
4386
|
-
throw new Error("schema properties when using DatePicker");
|
|
4387
|
-
}
|
|
4388
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4389
4374
|
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4390
4375
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4391
4376
|
const filtered = entries.filter(([target]) => {
|
|
@@ -4429,6 +4414,15 @@ const ObjectInput = ({ column }) => {
|
|
|
4429
4414
|
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4430
4415
|
};
|
|
4431
4416
|
|
|
4417
|
+
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4418
|
+
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4419
|
+
const { translate } = useSchemaContext();
|
|
4420
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4421
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4422
|
+
const colLabel = `${prefix}${column}`;
|
|
4423
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Input, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }) }));
|
|
4424
|
+
};
|
|
4425
|
+
|
|
4432
4426
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
4433
4427
|
const { inputProps, label, description, addon, icon, indicator = jsxRuntime.jsx(react.RadioCard.ItemIndicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
4434
4428
|
const hasContent = label || description || icon;
|
|
@@ -4524,6 +4518,62 @@ const TagPicker = ({ column }) => {
|
|
|
4524
4518
|
}), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4525
4519
|
};
|
|
4526
4520
|
|
|
4521
|
+
const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
4522
|
+
if (properties === undefined) {
|
|
4523
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4524
|
+
}
|
|
4525
|
+
console.log(`${column} does not exist when using ColumnRenderer`, { properties,
|
|
4526
|
+
column,
|
|
4527
|
+
prefix, }, "fdpok");
|
|
4528
|
+
const colSchema = properties[column];
|
|
4529
|
+
if (colSchema === undefined) {
|
|
4530
|
+
throw new Error(`${column} does not exist when using ColumnRenderer`);
|
|
4531
|
+
}
|
|
4532
|
+
const { type, variant, foreign_key, properties: innerProperties } = colSchema;
|
|
4533
|
+
if (type === "string") {
|
|
4534
|
+
if ((properties[column].enum ?? []).length > 0) {
|
|
4535
|
+
return jsxRuntime.jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
4536
|
+
}
|
|
4537
|
+
if (variant === "id-picker") {
|
|
4538
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4539
|
+
return jsxRuntime.jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4540
|
+
}
|
|
4541
|
+
if (variant === "date-picker") {
|
|
4542
|
+
return jsxRuntime.jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4543
|
+
}
|
|
4544
|
+
return jsxRuntime.jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4545
|
+
}
|
|
4546
|
+
if (type === "number" || type === "integer") {
|
|
4547
|
+
return jsxRuntime.jsx(NumberInputField, { schema: colSchema, prefix, column });
|
|
4548
|
+
}
|
|
4549
|
+
if (type === "boolean") {
|
|
4550
|
+
return jsxRuntime.jsx(BooleanPicker, { schema: colSchema, prefix, column });
|
|
4551
|
+
}
|
|
4552
|
+
if (type === "object") {
|
|
4553
|
+
if (innerProperties) {
|
|
4554
|
+
return jsxRuntime.jsx(ObjectInput, { schema: colSchema, prefix, column });
|
|
4555
|
+
}
|
|
4556
|
+
return jsxRuntime.jsx(RecordInput, { schema: colSchema, prefix, column });
|
|
4557
|
+
}
|
|
4558
|
+
if (type === "array") {
|
|
4559
|
+
if (variant === "id-picker") {
|
|
4560
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4561
|
+
return (jsxRuntime.jsx(IdPicker, { schema: colSchema, prefix, column, isMultiple: true }));
|
|
4562
|
+
}
|
|
4563
|
+
if (variant === "tag-picker") {
|
|
4564
|
+
return jsxRuntime.jsx(TagPicker, { schema: colSchema, prefix, column });
|
|
4565
|
+
}
|
|
4566
|
+
if (variant === "file-picker") {
|
|
4567
|
+
return jsxRuntime.jsx(FilePicker, { schema: colSchema, prefix, column });
|
|
4568
|
+
}
|
|
4569
|
+
return jsxRuntime.jsx(react.Text, { children: `array ${column}` });
|
|
4570
|
+
}
|
|
4571
|
+
if (type === "null") {
|
|
4572
|
+
return jsxRuntime.jsx(react.Text, { children: `null ${column}` });
|
|
4573
|
+
}
|
|
4574
|
+
return jsxRuntime.jsx(react.Text, { children: "missing type" });
|
|
4575
|
+
};
|
|
4576
|
+
|
|
4527
4577
|
const idPickerSanityCheck = (column, foreign_key) => {
|
|
4528
4578
|
if (!!foreign_key == false) {
|
|
4529
4579
|
throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
|
|
@@ -4711,59 +4761,11 @@ const FormInternal = () => {
|
|
|
4711
4761
|
}, variant: "subtle", children: translate.t("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)}` })] }) }) }) }) }))] }));
|
|
4712
4762
|
}
|
|
4713
4763
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsxs(react.Heading, { children: [" ", translate.t("title")] }), jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
const shouldIgnore = ignore.some((column) => {
|
|
4720
|
-
return column == key;
|
|
4721
|
-
});
|
|
4722
|
-
if (shouldIgnore) {
|
|
4723
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4724
|
-
}
|
|
4725
|
-
//@ts-expect-error TODO: add more fields to support form-creation
|
|
4726
|
-
const { type, variant, foreign_key } = values;
|
|
4727
|
-
if (type === "string") {
|
|
4728
|
-
// @ts-expect-error enum should exists
|
|
4729
|
-
if ((values.enum ?? []).length > 0) {
|
|
4730
|
-
return jsxRuntime.jsx(EnumPicker, { column: key }, `form-${key}`);
|
|
4731
|
-
}
|
|
4732
|
-
if (variant === "id-picker") {
|
|
4733
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4734
|
-
return jsxRuntime.jsx(IdPicker, { column: key }, `form-${key}`);
|
|
4735
|
-
}
|
|
4736
|
-
if (variant === "date-picker") {
|
|
4737
|
-
return jsxRuntime.jsx(DatePicker, { column: key }, `form-${key}`);
|
|
4738
|
-
}
|
|
4739
|
-
return jsxRuntime.jsx(StringInputField, { column: key }, `form-${key}`);
|
|
4740
|
-
}
|
|
4741
|
-
if (type === "number" || type === "integer") {
|
|
4742
|
-
return jsxRuntime.jsx(NumberInputField, { column: key }, `form-${key}`);
|
|
4743
|
-
}
|
|
4744
|
-
if (type === "boolean") {
|
|
4745
|
-
return jsxRuntime.jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
4746
|
-
}
|
|
4747
|
-
if (type === "object") {
|
|
4748
|
-
return jsxRuntime.jsx(ObjectInput, { column: key }, `form-${key}`);
|
|
4749
|
-
}
|
|
4750
|
-
if (type === "array") {
|
|
4751
|
-
if (variant === "id-picker") {
|
|
4752
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4753
|
-
return jsxRuntime.jsx(IdPicker, { column: key, isMultiple: true }, `form-${key}`);
|
|
4754
|
-
}
|
|
4755
|
-
if (variant === "tag-picker") {
|
|
4756
|
-
return jsxRuntime.jsx(TagPicker, { column: key }, `form-${key}`);
|
|
4757
|
-
}
|
|
4758
|
-
if (variant === "file-picker") {
|
|
4759
|
-
return jsxRuntime.jsx(FilePicker, { column: key }, `form-${key}`);
|
|
4760
|
-
}
|
|
4761
|
-
return jsxRuntime.jsx(react.Text, { children: `array ${column}` }, `form-${key}`);
|
|
4762
|
-
}
|
|
4763
|
-
if (type === "null") {
|
|
4764
|
-
return jsxRuntime.jsx(react.Text, { children: `null ${column}` }, `form-${key}`);
|
|
4765
|
-
}
|
|
4766
|
-
return jsxRuntime.jsx(react.Text, { children: "missing type" }, `form-${key}`);
|
|
4764
|
+
return (jsxRuntime.jsx(ColumnRenderer
|
|
4765
|
+
// @ts-expect-error find suitable types
|
|
4766
|
+
, {
|
|
4767
|
+
// @ts-expect-error find suitable types
|
|
4768
|
+
properties: properties, prefix: ``, column }, `form-${column}`));
|
|
4767
4769
|
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4768
4770
|
methods.handleSubmit(onValid)();
|
|
4769
4771
|
}, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["isError", jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
@@ -4858,6 +4860,7 @@ exports.ViewDialog = ViewDialog;
|
|
|
4858
4860
|
exports.getColumns = getColumns;
|
|
4859
4861
|
exports.getMultiDates = getMultiDates;
|
|
4860
4862
|
exports.getRangeDates = getRangeDates;
|
|
4863
|
+
exports.idPickerSanityCheck = idPickerSanityCheck;
|
|
4861
4864
|
exports.useDataTable = useDataTable;
|
|
4862
4865
|
exports.useDataTableContext = useDataTableContext;
|
|
4863
4866
|
exports.useDataTableServer = useDataTableServer;
|