@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, Popover, Field as Field$1,
|
|
2
|
+
import { Button as Button$1, AbsoluteCenter, Spinner, Span, IconButton, Portal, Dialog, RadioGroup as RadioGroup$1, Grid, Box, Slider as Slider$1, HStack, For, Flex, Text, Tag as Tag$1, Input, useDisclosure, DialogBackdrop, CheckboxCard as CheckboxCard$1, Menu, createRecipeContext, createContext as createContext$1, Pagination as Pagination$1, usePaginationContext, Image, Card, DataList, Checkbox as Checkbox$1, Table as Table$1, Tooltip as Tooltip$1, Group, InputElement, Icon, MenuRoot as MenuRoot$1, MenuTrigger as MenuTrigger$1, EmptyState as EmptyState$2, VStack, List, Alert, HoverCard, Accordion, Popover, Field as Field$1, NumberInput, Show, RadioCard, CheckboxGroup, Heading, Center } from '@chakra-ui/react';
|
|
3
3
|
import { AiOutlineColumnWidth } from 'react-icons/ai';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { createContext, useContext, useState, useEffect, useRef } from 'react';
|
|
@@ -27,8 +27,8 @@ import { GrAscend, GrDescend } from 'react-icons/gr';
|
|
|
27
27
|
import { HiColorSwatch, HiOutlineInformationCircle } from 'react-icons/hi';
|
|
28
28
|
import { useTranslation } from 'react-i18next';
|
|
29
29
|
import axios from 'axios';
|
|
30
|
-
import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
|
|
31
30
|
import dayjs from 'dayjs';
|
|
31
|
+
import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
|
|
32
32
|
import { TiDeleteOutline } from 'react-icons/ti';
|
|
33
33
|
|
|
34
34
|
const DataTableContext = createContext({
|
|
@@ -2360,7 +2360,7 @@ function ColumnCard({ columnId }) {
|
|
|
2360
2360
|
onDrop: () => setDragging(false), // NEW
|
|
2361
2361
|
});
|
|
2362
2362
|
}, [columnId, table]);
|
|
2363
|
-
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2363
|
+
return (jsxs(Grid, { ref: ref, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", style: dragging ? { opacity: 0.4 } : {}, children: [jsx(Flex, { alignItems: "center", padding: "0", cursor: 'grab', children: jsx(FaGripLinesVertical, { color: "gray.400" }) }), jsx(Flex, { justifyContent: "space-between", alignItems: "center", children: jsx(CheckboxCard, { variant: "surface", label: displayName, checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }) })] }));
|
|
2364
2364
|
}
|
|
2365
2365
|
function CardContainer({ location, children }) {
|
|
2366
2366
|
const ref = useRef(null);
|
|
@@ -2398,9 +2398,11 @@ function CardContainer({ location, children }) {
|
|
|
2398
2398
|
}
|
|
2399
2399
|
const TableViewer = () => {
|
|
2400
2400
|
const { table } = useDataTableContext();
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
|
|
2401
|
+
const order = table.getState().columnOrder.length > 0
|
|
2402
|
+
? table.getState().columnOrder
|
|
2403
|
+
: table.getAllLeafColumns().map(({ id }) => {
|
|
2404
|
+
return id;
|
|
2405
|
+
});
|
|
2404
2406
|
useEffect(() => {
|
|
2405
2407
|
return monitorForElements({
|
|
2406
2408
|
onDrop({ source, location }) {
|
|
@@ -2425,11 +2427,10 @@ const TableViewer = () => {
|
|
|
2425
2427
|
...columnAfter,
|
|
2426
2428
|
].filter((id) => id != "<marker>");
|
|
2427
2429
|
table.setColumnOrder(newOrder);
|
|
2428
|
-
setOrder(newOrder);
|
|
2429
2430
|
},
|
|
2430
2431
|
});
|
|
2431
|
-
}, [
|
|
2432
|
-
return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children:
|
|
2432
|
+
}, [table]);
|
|
2433
|
+
return (jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: order.map((columnId, index) => {
|
|
2433
2434
|
return (jsx(CardContainer, { location: index, children: jsx(ColumnCard, { columnId: columnId }) }));
|
|
2434
2435
|
}) }));
|
|
2435
2436
|
};
|
|
@@ -2604,21 +2605,6 @@ const RecordDisplay = ({ object, boxProps, translate, prefix = "", }) => {
|
|
|
2604
2605
|
}) }));
|
|
2605
2606
|
};
|
|
2606
2607
|
|
|
2607
|
-
const formatValue = (value) => {
|
|
2608
|
-
if (typeof value === "object") {
|
|
2609
|
-
return JSON.stringify(value);
|
|
2610
|
-
}
|
|
2611
|
-
if (typeof value === "string") {
|
|
2612
|
-
return value;
|
|
2613
|
-
}
|
|
2614
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
2615
|
-
return `${value}`;
|
|
2616
|
-
}
|
|
2617
|
-
if (value === undefined) {
|
|
2618
|
-
return `undefined`;
|
|
2619
|
-
}
|
|
2620
|
-
throw new Error(`value is unknown, ${typeof value}`);
|
|
2621
|
-
};
|
|
2622
2608
|
const DataDisplay = ({ variant = "", translate }) => {
|
|
2623
2609
|
const { table } = useDataTableContext();
|
|
2624
2610
|
const getLabel = ({ columnId }) => {
|
|
@@ -2627,6 +2613,24 @@ const DataDisplay = ({ variant = "", translate }) => {
|
|
|
2627
2613
|
}
|
|
2628
2614
|
return snakeToLabel(columnId);
|
|
2629
2615
|
};
|
|
2616
|
+
const formatValue = (value) => {
|
|
2617
|
+
if (typeof value === "object") {
|
|
2618
|
+
return JSON.stringify(value);
|
|
2619
|
+
}
|
|
2620
|
+
if (typeof value === "string") {
|
|
2621
|
+
return value;
|
|
2622
|
+
}
|
|
2623
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
2624
|
+
return `${value}`;
|
|
2625
|
+
}
|
|
2626
|
+
if (value === undefined) {
|
|
2627
|
+
if (translate !== undefined) {
|
|
2628
|
+
return translate.t(`undefined`);
|
|
2629
|
+
}
|
|
2630
|
+
return `undefined`;
|
|
2631
|
+
}
|
|
2632
|
+
throw new Error(`value is unknown, ${typeof value}`);
|
|
2633
|
+
};
|
|
2630
2634
|
if (variant == "horizontal") {
|
|
2631
2635
|
return (jsx(Flex, { flexFlow: "column", gap: "1", children: table.getRowModel().rows.map((row) => {
|
|
2632
2636
|
return (jsx(Card.Root, { children: jsx(Card.Body, { children: jsx(DataList.Root, { gap: 4, padding: 4, display: "grid", variant: "subtle", orientation: "horizontal", overflow: "auto", children: row.getVisibleCells().map((cell) => {
|
|
@@ -3543,28 +3547,15 @@ const SchemaFormContext = createContext({
|
|
|
3543
3547
|
requestOptions: {},
|
|
3544
3548
|
});
|
|
3545
3549
|
|
|
3546
|
-
const
|
|
3550
|
+
const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
|
|
3547
3551
|
const { portalled = true, portalRef, ...rest } = props;
|
|
3548
|
-
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(
|
|
3549
|
-
});
|
|
3550
|
-
React.forwardRef(function PopoverArrow(props, ref) {
|
|
3551
|
-
return (jsx(Popover.Arrow, { ...props, ref: ref, children: jsx(Popover.ArrowTip, {}) }));
|
|
3552
|
-
});
|
|
3553
|
-
React.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
3554
|
-
return (jsx(Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsx(CloseButton, { size: "sm" }) }));
|
|
3552
|
+
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(HoverCard.Positioner, { children: jsx(HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3555
3553
|
});
|
|
3556
|
-
const
|
|
3557
|
-
|
|
3558
|
-
Popover.Footer;
|
|
3559
|
-
Popover.Header;
|
|
3560
|
-
const PopoverRoot = Popover.Root;
|
|
3561
|
-
const PopoverBody = Popover.Body;
|
|
3562
|
-
const PopoverTrigger = Popover.Trigger;
|
|
3563
|
-
|
|
3564
|
-
const Field = React.forwardRef(function Field(props, ref) {
|
|
3565
|
-
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
3566
|
-
return (jsxs(Field$1.Root, { ref: ref, ...rest, children: [label && (jsxs(Field$1.Label, { children: [label, jsx(Field$1.RequiredIndicator, { fallback: optionalText })] })), children, helperText && (jsx(Field$1.HelperText, { children: helperText })), errorText && (jsx(Field$1.ErrorText, { children: errorText }))] }));
|
|
3554
|
+
const HoverCardArrow = React.forwardRef(function HoverCardArrow(props, ref) {
|
|
3555
|
+
return (jsx(HoverCard.Arrow, { ref: ref, ...props, children: jsx(HoverCard.ArrowTip, {}) }));
|
|
3567
3556
|
});
|
|
3557
|
+
const HoverCardRoot = HoverCard.Root;
|
|
3558
|
+
const HoverCardTrigger = HoverCard.Trigger;
|
|
3568
3559
|
|
|
3569
3560
|
const useSchemaContext = () => {
|
|
3570
3561
|
const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = useContext(SchemaFormContext);
|
|
@@ -3583,148 +3574,6 @@ const useSchemaContext = () => {
|
|
|
3583
3574
|
};
|
|
3584
3575
|
};
|
|
3585
3576
|
|
|
3586
|
-
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
3587
|
-
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
3588
|
-
throw new Error("The serverUrl is missing");
|
|
3589
|
-
}
|
|
3590
|
-
if (in_table === undefined || in_table.length == 0) {
|
|
3591
|
-
throw new Error("The in_table is missing");
|
|
3592
|
-
}
|
|
3593
|
-
const options = {
|
|
3594
|
-
method: "GET",
|
|
3595
|
-
url: `${serverUrl}/api/g/${in_table}`,
|
|
3596
|
-
params: {
|
|
3597
|
-
searching,
|
|
3598
|
-
where,
|
|
3599
|
-
limit,
|
|
3600
|
-
offset
|
|
3601
|
-
},
|
|
3602
|
-
};
|
|
3603
|
-
try {
|
|
3604
|
-
const { data } = await axios.request(options);
|
|
3605
|
-
console.log(data);
|
|
3606
|
-
return data;
|
|
3607
|
-
}
|
|
3608
|
-
catch (error) {
|
|
3609
|
-
console.error(error);
|
|
3610
|
-
throw error;
|
|
3611
|
-
}
|
|
3612
|
-
};
|
|
3613
|
-
|
|
3614
|
-
const IdPicker = ({ column, isMultiple = false }) => {
|
|
3615
|
-
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3616
|
-
const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
3617
|
-
const { required } = schema;
|
|
3618
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3619
|
-
if (schema.properties == undefined) {
|
|
3620
|
-
throw new Error("schema properties is undefined when using DatePicker");
|
|
3621
|
-
}
|
|
3622
|
-
const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
|
|
3623
|
-
const { table, column: column_ref, display_column, } = foreign_key;
|
|
3624
|
-
const [searchText, setSearchText] = useState();
|
|
3625
|
-
const [limit, setLimit] = useState(10);
|
|
3626
|
-
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3627
|
-
const [page, setPage] = useState(0);
|
|
3628
|
-
const ref = useRef(null);
|
|
3629
|
-
const selectedIds = watch(column) ?? [];
|
|
3630
|
-
const query = useQuery({
|
|
3631
|
-
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
3632
|
-
queryFn: async () => {
|
|
3633
|
-
const data = await getTableData({
|
|
3634
|
-
serverUrl,
|
|
3635
|
-
searching: searchText ?? "",
|
|
3636
|
-
in_table: table,
|
|
3637
|
-
limit: limit,
|
|
3638
|
-
offset: page * 10,
|
|
3639
|
-
});
|
|
3640
|
-
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
3641
|
-
return [
|
|
3642
|
-
item[column_ref],
|
|
3643
|
-
{
|
|
3644
|
-
...item,
|
|
3645
|
-
},
|
|
3646
|
-
];
|
|
3647
|
-
}));
|
|
3648
|
-
setIdMap((state) => {
|
|
3649
|
-
return { ...state, ...newMap };
|
|
3650
|
-
});
|
|
3651
|
-
return data;
|
|
3652
|
-
},
|
|
3653
|
-
enabled: (searchText ?? "")?.length > 0,
|
|
3654
|
-
staleTime: 300000,
|
|
3655
|
-
});
|
|
3656
|
-
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
3657
|
-
const dataList = data?.data ?? [];
|
|
3658
|
-
const count = data?.count ?? 0;
|
|
3659
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3660
|
-
const onSearchChange = async (event) => {
|
|
3661
|
-
setSearchText(event.target.value);
|
|
3662
|
-
setPage(0);
|
|
3663
|
-
setLimit(10);
|
|
3664
|
-
};
|
|
3665
|
-
const watchId = watch(column);
|
|
3666
|
-
const watchIds = (watch(column) ?? []);
|
|
3667
|
-
const getPickedValue = () => {
|
|
3668
|
-
if (Object.keys(idMap).length <= 0) {
|
|
3669
|
-
return "";
|
|
3670
|
-
}
|
|
3671
|
-
const record = idMap[watchId];
|
|
3672
|
-
if (record === undefined) {
|
|
3673
|
-
return "";
|
|
3674
|
-
}
|
|
3675
|
-
return record[display_column];
|
|
3676
|
-
};
|
|
3677
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3678
|
-
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
3679
|
-
const item = idMap[id];
|
|
3680
|
-
if (item === undefined) {
|
|
3681
|
-
return jsx(Text, { children: "undefined" }, id);
|
|
3682
|
-
}
|
|
3683
|
-
return (jsx(Tag, { closable: true, onClick: () => {
|
|
3684
|
-
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
3685
|
-
}, children: !!renderDisplay === true
|
|
3686
|
-
? renderDisplay(item)
|
|
3687
|
-
: item[display_column] }, id));
|
|
3688
|
-
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3689
|
-
setOpenSearchResult(true);
|
|
3690
|
-
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
3691
|
-
setOpenSearchResult(true);
|
|
3692
|
-
}, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
|
|
3693
|
-
onSearchChange(event);
|
|
3694
|
-
setOpenSearchResult(true);
|
|
3695
|
-
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxs(Fragment, { children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { justifySelf: "center", children: `${translate.t(`${column}.total`)} ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
|
|
3696
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3697
|
-
dataList.map((item) => {
|
|
3698
|
-
const selected = isMultiple
|
|
3699
|
-
? watchIds.some((id) => item[column_ref] === id)
|
|
3700
|
-
: watchId === item[column_ref];
|
|
3701
|
-
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
3702
|
-
if (!isMultiple) {
|
|
3703
|
-
setOpenSearchResult(false);
|
|
3704
|
-
setValue(column, item[column_ref]);
|
|
3705
|
-
return;
|
|
3706
|
-
}
|
|
3707
|
-
const newSet = new Set([
|
|
3708
|
-
...(watchIds ?? []),
|
|
3709
|
-
item[column_ref],
|
|
3710
|
-
]);
|
|
3711
|
-
setValue(column, [...newSet]);
|
|
3712
|
-
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3713
|
-
? renderDisplay(item)
|
|
3714
|
-
: item[display_column] }, item[column_ref]));
|
|
3715
|
-
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(`${column}.emptySearchResult`) })) }))] }), jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3716
|
-
};
|
|
3717
|
-
|
|
3718
|
-
const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
|
|
3719
|
-
const { portalled = true, portalRef, ...rest } = props;
|
|
3720
|
-
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(HoverCard.Positioner, { children: jsx(HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3721
|
-
});
|
|
3722
|
-
const HoverCardArrow = React.forwardRef(function HoverCardArrow(props, ref) {
|
|
3723
|
-
return (jsx(HoverCard.Arrow, { ref: ref, ...props, children: jsx(HoverCard.ArrowTip, {}) }));
|
|
3724
|
-
});
|
|
3725
|
-
const HoverCardRoot = HoverCard.Root;
|
|
3726
|
-
const HoverCardTrigger = HoverCard.Trigger;
|
|
3727
|
-
|
|
3728
3577
|
const IdViewer = ({ value, column }) => {
|
|
3729
3578
|
const { schema, idMap, translate } = useSchemaContext();
|
|
3730
3579
|
if (schema.properties == undefined) {
|
|
@@ -3741,38 +3590,6 @@ const IdViewer = ({ value, column }) => {
|
|
|
3741
3590
|
return (jsxs(Flex, { flexFlow: "column", children: [jsx(Text, { children: translate.t(`${column}.fieldLabel`) }), jsxs(HoverCardRoot, { children: [jsx(HoverCardTrigger, { asChild: true, children: jsx(Text, { cursor: 'pointer', children: idMap[value][display_column] }) }), jsxs(HoverCardContent, { children: [jsx(HoverCardArrow, {}), jsx(RecordDisplay, { object: idMap[value] })] })] })] }));
|
|
3742
3591
|
};
|
|
3743
3592
|
|
|
3744
|
-
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
3745
|
-
const { children, ...rest } = props;
|
|
3746
|
-
return (jsxs(NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxs(NumberInput.Control, { children: [jsx(NumberInput.IncrementTrigger, {}), jsx(NumberInput.DecrementTrigger, {})] })] }));
|
|
3747
|
-
});
|
|
3748
|
-
const NumberInputField$1 = NumberInput.Input;
|
|
3749
|
-
NumberInput.Scrubber;
|
|
3750
|
-
NumberInput.Label;
|
|
3751
|
-
|
|
3752
|
-
const NumberInputField = ({ column }) => {
|
|
3753
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
3754
|
-
const { schema, translate } = useSchemaContext();
|
|
3755
|
-
const { required } = schema;
|
|
3756
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3757
|
-
if (schema.properties == undefined) {
|
|
3758
|
-
throw new Error("schema properties when using String Input Field");
|
|
3759
|
-
}
|
|
3760
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3761
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { ...register(column, { required: isRequired }) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3762
|
-
};
|
|
3763
|
-
|
|
3764
|
-
const StringInputField = ({ column }) => {
|
|
3765
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
3766
|
-
const { schema, translate } = useSchemaContext();
|
|
3767
|
-
const { required } = schema;
|
|
3768
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3769
|
-
if (schema.properties == undefined) {
|
|
3770
|
-
throw new Error("schema properties when using String Input Field");
|
|
3771
|
-
}
|
|
3772
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3773
|
-
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Input, { ...register(column, { required: isRequired }), autoComplete: "off" }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }) }));
|
|
3774
|
-
};
|
|
3775
|
-
|
|
3776
3593
|
const clearEmptyString = (object) => {
|
|
3777
3594
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
3778
3595
|
};
|
|
@@ -3802,20 +3619,22 @@ const DataListItem = React.forwardRef(function DataListItem(props, ref) {
|
|
|
3802
3619
|
return (jsxs(DataList.Item, { ref: ref, ...rest, children: [jsxs(DataList.ItemLabel, { flex: grow ? "1" : undefined, children: [label, info && jsx(InfoTip, { children: info })] }), jsx(DataList.ItemValue, { flex: grow ? "1" : undefined, children: value }), children] }));
|
|
3803
3620
|
});
|
|
3804
3621
|
|
|
3805
|
-
const
|
|
3622
|
+
const Field = React.forwardRef(function Field(props, ref) {
|
|
3623
|
+
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
3624
|
+
return (jsxs(Field$1.Root, { ref: ref, ...rest, children: [label && (jsxs(Field$1.Label, { children: [label, jsx(Field$1.RequiredIndicator, { fallback: optionalText })] })), children, helperText && (jsx(Field$1.HelperText, { children: helperText })), errorText && (jsx(Field$1.ErrorText, { children: errorText }))] }));
|
|
3625
|
+
});
|
|
3626
|
+
|
|
3627
|
+
const BooleanPicker = ({ schema, column, prefix }) => {
|
|
3806
3628
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3807
|
-
const {
|
|
3808
|
-
const { required } = schema;
|
|
3629
|
+
const { translate } = useSchemaContext();
|
|
3630
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3809
3631
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3810
|
-
const
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
}
|
|
3814
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3815
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3632
|
+
const colLabel = `${prefix}${column}`;
|
|
3633
|
+
const value = watch(colLabel);
|
|
3634
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3816
3635
|
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
3817
|
-
setValue(
|
|
3818
|
-
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${
|
|
3636
|
+
setValue(colLabel, !value);
|
|
3637
|
+
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
3819
3638
|
};
|
|
3820
3639
|
|
|
3821
3640
|
const monthNamesShort = [
|
|
@@ -3887,18 +3706,33 @@ let DatePicker$1 = class DatePicker extends React__default.Component {
|
|
|
3887
3706
|
}
|
|
3888
3707
|
};
|
|
3889
3708
|
|
|
3890
|
-
const
|
|
3709
|
+
const PopoverContent = React.forwardRef(function PopoverContent(props, ref) {
|
|
3710
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
3711
|
+
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(Popover.Positioner, { children: jsx(Popover.Content, { ref: ref, ...rest }) }) }));
|
|
3712
|
+
});
|
|
3713
|
+
React.forwardRef(function PopoverArrow(props, ref) {
|
|
3714
|
+
return (jsx(Popover.Arrow, { ...props, ref: ref, children: jsx(Popover.ArrowTip, {}) }));
|
|
3715
|
+
});
|
|
3716
|
+
React.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
3717
|
+
return (jsx(Popover.CloseTrigger, { position: "absolute", top: "1", insetEnd: "1", ...props, asChild: true, ref: ref, children: jsx(CloseButton, { size: "sm" }) }));
|
|
3718
|
+
});
|
|
3719
|
+
const PopoverTitle = Popover.Title;
|
|
3720
|
+
Popover.Description;
|
|
3721
|
+
Popover.Footer;
|
|
3722
|
+
Popover.Header;
|
|
3723
|
+
const PopoverRoot = Popover.Root;
|
|
3724
|
+
const PopoverBody = Popover.Body;
|
|
3725
|
+
const PopoverTrigger = Popover.Trigger;
|
|
3726
|
+
|
|
3727
|
+
const DatePicker = ({ column, schema, prefix }) => {
|
|
3891
3728
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3892
|
-
const {
|
|
3893
|
-
const { required } = schema;
|
|
3729
|
+
const { translate } = useSchemaContext();
|
|
3730
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3894
3731
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3732
|
+
const colLabel = `${prefix}${column}`;
|
|
3895
3733
|
const [open, setOpen] = useState(false);
|
|
3896
|
-
const selectedDate = watch(
|
|
3897
|
-
|
|
3898
|
-
throw new Error("schema properties when using DatePicker");
|
|
3899
|
-
}
|
|
3900
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3901
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3734
|
+
const selectedDate = watch(colLabel);
|
|
3735
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3902
3736
|
gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3903
3737
|
setOpen(true);
|
|
3904
3738
|
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
@@ -3907,7 +3741,7 @@ const DatePicker = ({ column }) => {
|
|
|
3907
3741
|
// @ts-expect-error TODO: find appropriate types
|
|
3908
3742
|
selected: new Date(selectedDate),
|
|
3909
3743
|
// @ts-expect-error TODO: find appropriate types
|
|
3910
|
-
onDateSelected: ({
|
|
3744
|
+
onDateSelected: ({ date }) => {
|
|
3911
3745
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
3912
3746
|
setOpen(false);
|
|
3913
3747
|
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
@@ -3923,29 +3757,26 @@ function filterArray(array, searchTerm) {
|
|
|
3923
3757
|
});
|
|
3924
3758
|
}
|
|
3925
3759
|
|
|
3926
|
-
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
3760
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3927
3761
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3928
|
-
const {
|
|
3762
|
+
const { translate } = useSchemaContext();
|
|
3929
3763
|
const { required } = schema;
|
|
3930
3764
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3931
|
-
|
|
3932
|
-
throw new Error("schema properties when using DatePicker");
|
|
3933
|
-
}
|
|
3934
|
-
const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
|
|
3765
|
+
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3935
3766
|
const [searchText, setSearchText] = useState();
|
|
3936
3767
|
const [limit, setLimit] = useState(10);
|
|
3937
3768
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3938
3769
|
const ref = useRef(null);
|
|
3939
3770
|
const watchEnum = watch(column);
|
|
3940
3771
|
const watchEnums = (watch(column) ?? []);
|
|
3941
|
-
const
|
|
3942
|
-
const
|
|
3943
|
-
const count = properties.enum?.length ?? 0;
|
|
3772
|
+
const dataList = schema.enum ?? [];
|
|
3773
|
+
const count = schema.enum?.length ?? 0;
|
|
3944
3774
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3945
3775
|
const onSearchChange = async (event) => {
|
|
3946
3776
|
setSearchText(event.target.value);
|
|
3947
3777
|
setLimit(10);
|
|
3948
3778
|
};
|
|
3779
|
+
const col = `${prefix}${column}`;
|
|
3949
3780
|
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3950
3781
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3951
3782
|
const item = enumValue;
|
|
@@ -3975,8 +3806,10 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3975
3806
|
}
|
|
3976
3807
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3977
3808
|
setValue(column, [...newSet]);
|
|
3978
|
-
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3979
|
-
|
|
3809
|
+
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3810
|
+
? renderDisplay(item)
|
|
3811
|
+
: translate.t(`${col}.${item}`) }, `${column}-${item}`));
|
|
3812
|
+
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(`${col}.emptySearchResult`) })) }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
|
|
3980
3813
|
};
|
|
3981
3814
|
|
|
3982
3815
|
function isEnteringWindow(_ref) {
|
|
@@ -4331,41 +4164,193 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4331
4164
|
return (jsxs(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 && (jsxs(Fragment, { children: [jsx(Flex, { children: placeholder }), jsx(Input, { type: "file", multiple: true, style: { display: "none" }, ref: fileInput, onChange: handleChange })] }))] }));
|
|
4332
4165
|
};
|
|
4333
4166
|
|
|
4334
|
-
const FilePicker = ({ column }) => {
|
|
4167
|
+
const FilePicker = ({ column, schema, prefix }) => {
|
|
4335
4168
|
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4336
|
-
const {
|
|
4337
|
-
const { required } = schema;
|
|
4169
|
+
const { translate } = useSchemaContext();
|
|
4170
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4338
4171
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4339
|
-
if (schema.properties == undefined) {
|
|
4340
|
-
throw new Error("schema properties when using String Input Field");
|
|
4341
|
-
}
|
|
4342
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4343
4172
|
const currentFiles = (watch(column) ?? []);
|
|
4344
|
-
|
|
4173
|
+
const col = `${prefix}${column}`;
|
|
4174
|
+
return (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: [jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4345
4175
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4346
|
-
setValue(
|
|
4347
|
-
}, placeholder: translate.t(`${
|
|
4176
|
+
setValue(col, [...currentFiles, ...newFiles]);
|
|
4177
|
+
}, placeholder: translate.t(`${col}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4348
4178
|
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4349
4179
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4350
4180
|
return name !== file.name;
|
|
4351
4181
|
}));
|
|
4352
|
-
}, display: "flex", flexFlow:
|
|
4353
|
-
}) }), errors[`${
|
|
4182
|
+
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4183
|
+
}) }), errors[`${col}`] && (jsx(Text, { color: "red.400", children: translate.t(`${col}.fieldRequired`) }))] }));
|
|
4354
4184
|
};
|
|
4355
4185
|
|
|
4356
|
-
const
|
|
4186
|
+
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
4187
|
+
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
4188
|
+
throw new Error("The serverUrl is missing");
|
|
4189
|
+
}
|
|
4190
|
+
if (in_table === undefined || in_table.length == 0) {
|
|
4191
|
+
throw new Error("The in_table is missing");
|
|
4192
|
+
}
|
|
4193
|
+
const options = {
|
|
4194
|
+
method: "GET",
|
|
4195
|
+
url: `${serverUrl}/api/g/${in_table}`,
|
|
4196
|
+
params: {
|
|
4197
|
+
searching,
|
|
4198
|
+
where,
|
|
4199
|
+
limit,
|
|
4200
|
+
offset
|
|
4201
|
+
},
|
|
4202
|
+
};
|
|
4203
|
+
try {
|
|
4204
|
+
const { data } = await axios.request(options);
|
|
4205
|
+
console.log(data);
|
|
4206
|
+
return data;
|
|
4207
|
+
}
|
|
4208
|
+
catch (error) {
|
|
4209
|
+
console.error(error);
|
|
4210
|
+
throw error;
|
|
4211
|
+
}
|
|
4212
|
+
};
|
|
4213
|
+
|
|
4214
|
+
const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4215
|
+
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
4216
|
+
const { serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
4217
|
+
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4218
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4219
|
+
const { table, column: column_ref, display_column, } = foreign_key;
|
|
4220
|
+
const [searchText, setSearchText] = useState();
|
|
4221
|
+
const [limit, setLimit] = useState(10);
|
|
4222
|
+
const [openSearchResult, setOpenSearchResult] = useState();
|
|
4223
|
+
const [page, setPage] = useState(0);
|
|
4224
|
+
const ref = useRef(null);
|
|
4225
|
+
const selectedIds = watch(column) ?? [];
|
|
4226
|
+
const colLabel = `${prefix}${column}`;
|
|
4227
|
+
const query = useQuery({
|
|
4228
|
+
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
4229
|
+
queryFn: async () => {
|
|
4230
|
+
const data = await getTableData({
|
|
4231
|
+
serverUrl,
|
|
4232
|
+
searching: searchText ?? "",
|
|
4233
|
+
in_table: table,
|
|
4234
|
+
limit: limit,
|
|
4235
|
+
offset: page * 10,
|
|
4236
|
+
});
|
|
4237
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
4238
|
+
return [
|
|
4239
|
+
item[column_ref],
|
|
4240
|
+
{
|
|
4241
|
+
...item,
|
|
4242
|
+
},
|
|
4243
|
+
];
|
|
4244
|
+
}));
|
|
4245
|
+
setIdMap((state) => {
|
|
4246
|
+
return { ...state, ...newMap };
|
|
4247
|
+
});
|
|
4248
|
+
return data;
|
|
4249
|
+
},
|
|
4250
|
+
enabled: (searchText ?? "")?.length > 0,
|
|
4251
|
+
staleTime: 300000,
|
|
4252
|
+
});
|
|
4253
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4254
|
+
const dataList = data?.data ?? [];
|
|
4255
|
+
const count = data?.count ?? 0;
|
|
4256
|
+
const isDirty = (searchText?.length ?? 0) > 0;
|
|
4257
|
+
const onSearchChange = async (event) => {
|
|
4258
|
+
setSearchText(event.target.value);
|
|
4259
|
+
setPage(0);
|
|
4260
|
+
setLimit(10);
|
|
4261
|
+
};
|
|
4262
|
+
const watchId = watch(column);
|
|
4263
|
+
const watchIds = (watch(column) ?? []);
|
|
4264
|
+
const getPickedValue = () => {
|
|
4265
|
+
if (Object.keys(idMap).length <= 0) {
|
|
4266
|
+
return "";
|
|
4267
|
+
}
|
|
4268
|
+
const record = idMap[watchId];
|
|
4269
|
+
if (record === undefined) {
|
|
4270
|
+
return "";
|
|
4271
|
+
}
|
|
4272
|
+
return record[display_column];
|
|
4273
|
+
};
|
|
4274
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4275
|
+
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
4276
|
+
const item = idMap[id];
|
|
4277
|
+
if (item === undefined) {
|
|
4278
|
+
return (jsxs(Text, { children: [" ", translate.t(`${colLabel}.undefined`)] }, id));
|
|
4279
|
+
}
|
|
4280
|
+
return (jsx(Tag, { closable: true, onClick: () => {
|
|
4281
|
+
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
4282
|
+
}, children: !!renderDisplay === true
|
|
4283
|
+
? renderDisplay(item)
|
|
4284
|
+
: item[display_column] }, id));
|
|
4285
|
+
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4286
|
+
setOpenSearchResult(true);
|
|
4287
|
+
}, children: translate.t(`${colLabel}.addMore`) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4288
|
+
setOpenSearchResult(true);
|
|
4289
|
+
}, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${colLabel}.typeToSearch`), onChange: (event) => {
|
|
4290
|
+
onSearchChange(event);
|
|
4291
|
+
setOpenSearchResult(true);
|
|
4292
|
+
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxs(Fragment, { children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { justifySelf: "center", children: `${translate.t(`${colLabel}.total`)} ${count}, ${translate.t(`${colLabel}.showing`)} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
|
|
4293
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4294
|
+
dataList.map((item) => {
|
|
4295
|
+
const selected = isMultiple
|
|
4296
|
+
? watchIds.some((id) => item[column_ref] === id)
|
|
4297
|
+
: watchId === item[column_ref];
|
|
4298
|
+
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
4299
|
+
if (!isMultiple) {
|
|
4300
|
+
setOpenSearchResult(false);
|
|
4301
|
+
setValue(colLabel, item[column_ref]);
|
|
4302
|
+
return;
|
|
4303
|
+
}
|
|
4304
|
+
const newSet = new Set([
|
|
4305
|
+
...(watchIds ?? []),
|
|
4306
|
+
item[column_ref],
|
|
4307
|
+
]);
|
|
4308
|
+
setValue(column, [...newSet]);
|
|
4309
|
+
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
4310
|
+
? renderDisplay(item)
|
|
4311
|
+
: item[display_column] }, item[column_ref]));
|
|
4312
|
+
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(`${colLabel}.emptySearchResult`) })) }))] }), jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxs(HStack, { gap: "4", children: [jsx(PaginationPrevTrigger, {}), jsx(PaginationPageText, {}), jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
4313
|
+
};
|
|
4314
|
+
|
|
4315
|
+
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
4316
|
+
const { children, ...rest } = props;
|
|
4317
|
+
return (jsxs(NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxs(NumberInput.Control, { children: [jsx(NumberInput.IncrementTrigger, {}), jsx(NumberInput.DecrementTrigger, {})] })] }));
|
|
4318
|
+
});
|
|
4319
|
+
const NumberInputField$1 = NumberInput.Input;
|
|
4320
|
+
NumberInput.Scrubber;
|
|
4321
|
+
NumberInput.Label;
|
|
4322
|
+
|
|
4323
|
+
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4324
|
+
const { register, formState: { errors }, } = useFormContext();
|
|
4325
|
+
const { translate } = useSchemaContext();
|
|
4326
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4327
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4328
|
+
const colLabel = `${prefix}${column}`;
|
|
4329
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { ...register(`${colLabel}`, { required: isRequired }) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
4330
|
+
};
|
|
4331
|
+
|
|
4332
|
+
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4333
|
+
const { properties } = schema;
|
|
4334
|
+
if (properties === undefined) {
|
|
4335
|
+
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4336
|
+
}
|
|
4337
|
+
return (jsx(Fragment, { children: Object.keys(properties ?? {}).map((key) => {
|
|
4338
|
+
console.log(properties, key, "gkor");
|
|
4339
|
+
return (jsx(ColumnRenderer, { column: `${key}`,
|
|
4340
|
+
prefix: `${prefix}${column}.`,
|
|
4341
|
+
properties }, `form-${column}`));
|
|
4342
|
+
}) }));
|
|
4343
|
+
};
|
|
4344
|
+
|
|
4345
|
+
const RecordInput = ({ column, schema, prefix }) => {
|
|
4357
4346
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4358
|
-
const {
|
|
4359
|
-
const { required } = schema;
|
|
4347
|
+
const { translate } = useSchemaContext();
|
|
4348
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4360
4349
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4361
4350
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4362
4351
|
const [showNewEntries, setShowNewEntries] = useState(false);
|
|
4363
4352
|
const [newKey, setNewKey] = useState();
|
|
4364
4353
|
const [newValue, setNewValue] = useState();
|
|
4365
|
-
if (schema.properties == undefined) {
|
|
4366
|
-
throw new Error("schema properties when using DatePicker");
|
|
4367
|
-
}
|
|
4368
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4369
4354
|
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4370
4355
|
return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
|
|
4371
4356
|
const filtered = entries.filter(([target]) => {
|
|
@@ -4409,6 +4394,15 @@ const ObjectInput = ({ column }) => {
|
|
|
4409
4394
|
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4410
4395
|
};
|
|
4411
4396
|
|
|
4397
|
+
const StringInputField = ({ column, schema, prefix, }) => {
|
|
4398
|
+
const { register, formState: { errors }, } = useFormContext();
|
|
4399
|
+
const { translate } = useSchemaContext();
|
|
4400
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4401
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4402
|
+
const colLabel = `${prefix}${column}`;
|
|
4403
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Input, { ...register(`${colLabel}`, { required: isRequired }), autoComplete: "off" }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }) }));
|
|
4404
|
+
};
|
|
4405
|
+
|
|
4412
4406
|
const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
|
|
4413
4407
|
const { inputProps, label, description, addon, icon, indicator = jsx(RadioCard.ItemIndicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
4414
4408
|
const hasContent = label || description || icon;
|
|
@@ -4504,6 +4498,62 @@ const TagPicker = ({ column }) => {
|
|
|
4504
4498
|
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4505
4499
|
};
|
|
4506
4500
|
|
|
4501
|
+
const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
4502
|
+
if (properties === undefined) {
|
|
4503
|
+
return jsx(Fragment, {});
|
|
4504
|
+
}
|
|
4505
|
+
console.log(`${column} does not exist when using ColumnRenderer`, { properties,
|
|
4506
|
+
column,
|
|
4507
|
+
prefix, }, "fdpok");
|
|
4508
|
+
const colSchema = properties[column];
|
|
4509
|
+
if (colSchema === undefined) {
|
|
4510
|
+
throw new Error(`${column} does not exist when using ColumnRenderer`);
|
|
4511
|
+
}
|
|
4512
|
+
const { type, variant, foreign_key, properties: innerProperties } = colSchema;
|
|
4513
|
+
if (type === "string") {
|
|
4514
|
+
if ((properties[column].enum ?? []).length > 0) {
|
|
4515
|
+
return jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
4516
|
+
}
|
|
4517
|
+
if (variant === "id-picker") {
|
|
4518
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4519
|
+
return jsx(IdPicker, { schema: colSchema, prefix, column });
|
|
4520
|
+
}
|
|
4521
|
+
if (variant === "date-picker") {
|
|
4522
|
+
return jsx(DatePicker, { schema: colSchema, prefix, column });
|
|
4523
|
+
}
|
|
4524
|
+
return jsx(StringInputField, { schema: colSchema, prefix, column });
|
|
4525
|
+
}
|
|
4526
|
+
if (type === "number" || type === "integer") {
|
|
4527
|
+
return jsx(NumberInputField, { schema: colSchema, prefix, column });
|
|
4528
|
+
}
|
|
4529
|
+
if (type === "boolean") {
|
|
4530
|
+
return jsx(BooleanPicker, { schema: colSchema, prefix, column });
|
|
4531
|
+
}
|
|
4532
|
+
if (type === "object") {
|
|
4533
|
+
if (innerProperties) {
|
|
4534
|
+
return jsx(ObjectInput, { schema: colSchema, prefix, column });
|
|
4535
|
+
}
|
|
4536
|
+
return jsx(RecordInput, { schema: colSchema, prefix, column });
|
|
4537
|
+
}
|
|
4538
|
+
if (type === "array") {
|
|
4539
|
+
if (variant === "id-picker") {
|
|
4540
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4541
|
+
return (jsx(IdPicker, { schema: colSchema, prefix, column, isMultiple: true }));
|
|
4542
|
+
}
|
|
4543
|
+
if (variant === "tag-picker") {
|
|
4544
|
+
return jsx(TagPicker, { schema: colSchema, prefix, column });
|
|
4545
|
+
}
|
|
4546
|
+
if (variant === "file-picker") {
|
|
4547
|
+
return jsx(FilePicker, { schema: colSchema, prefix, column });
|
|
4548
|
+
}
|
|
4549
|
+
return jsx(Text, { children: `array ${column}` });
|
|
4550
|
+
}
|
|
4551
|
+
if (type === "null") {
|
|
4552
|
+
return jsx(Text, { children: `null ${column}` });
|
|
4553
|
+
}
|
|
4554
|
+
return jsx(Text, { children: "missing type" });
|
|
4555
|
+
};
|
|
4556
|
+
|
|
4507
4557
|
const idPickerSanityCheck = (column, foreign_key) => {
|
|
4508
4558
|
if (!!foreign_key == false) {
|
|
4509
4559
|
throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
|
|
@@ -4691,59 +4741,11 @@ const FormInternal = () => {
|
|
|
4691
4741
|
}, variant: "subtle", children: translate.t("cancel") }), isSubmiting && (jsx(Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsx(Center, { h: "full", children: jsx(Spinner, { color: "teal.500" }) }) })), isError && (jsx(Fragment, { children: jsx(Alert.Root, { status: "error", children: jsx(Alert.Title, { children: jsx(AccordionRoot, { collapsible: true, defaultValue: ["b"], children: jsxs(AccordionItem, { value: "b", children: [jsxs(AccordionItemTrigger, { children: [jsx(Alert.Indicator, {}), `${error}`] }), jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
|
|
4692
4742
|
}
|
|
4693
4743
|
return (jsxs(Fragment, { children: [jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
const shouldIgnore = ignore.some((column) => {
|
|
4700
|
-
return column == key;
|
|
4701
|
-
});
|
|
4702
|
-
if (shouldIgnore) {
|
|
4703
|
-
return jsx(Fragment, {});
|
|
4704
|
-
}
|
|
4705
|
-
//@ts-expect-error TODO: add more fields to support form-creation
|
|
4706
|
-
const { type, variant, foreign_key } = values;
|
|
4707
|
-
if (type === "string") {
|
|
4708
|
-
// @ts-expect-error enum should exists
|
|
4709
|
-
if ((values.enum ?? []).length > 0) {
|
|
4710
|
-
return jsx(EnumPicker, { column: key }, `form-${key}`);
|
|
4711
|
-
}
|
|
4712
|
-
if (variant === "id-picker") {
|
|
4713
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4714
|
-
return jsx(IdPicker, { column: key }, `form-${key}`);
|
|
4715
|
-
}
|
|
4716
|
-
if (variant === "date-picker") {
|
|
4717
|
-
return jsx(DatePicker, { column: key }, `form-${key}`);
|
|
4718
|
-
}
|
|
4719
|
-
return jsx(StringInputField, { column: key }, `form-${key}`);
|
|
4720
|
-
}
|
|
4721
|
-
if (type === "number" || type === "integer") {
|
|
4722
|
-
return jsx(NumberInputField, { column: key }, `form-${key}`);
|
|
4723
|
-
}
|
|
4724
|
-
if (type === "boolean") {
|
|
4725
|
-
return jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
4726
|
-
}
|
|
4727
|
-
if (type === "object") {
|
|
4728
|
-
return jsx(ObjectInput, { column: key }, `form-${key}`);
|
|
4729
|
-
}
|
|
4730
|
-
if (type === "array") {
|
|
4731
|
-
if (variant === "id-picker") {
|
|
4732
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4733
|
-
return jsx(IdPicker, { column: key, isMultiple: true }, `form-${key}`);
|
|
4734
|
-
}
|
|
4735
|
-
if (variant === "tag-picker") {
|
|
4736
|
-
return jsx(TagPicker, { column: key }, `form-${key}`);
|
|
4737
|
-
}
|
|
4738
|
-
if (variant === "file-picker") {
|
|
4739
|
-
return jsx(FilePicker, { column: key }, `form-${key}`);
|
|
4740
|
-
}
|
|
4741
|
-
return jsx(Text, { children: `array ${column}` }, `form-${key}`);
|
|
4742
|
-
}
|
|
4743
|
-
if (type === "null") {
|
|
4744
|
-
return jsx(Text, { children: `null ${column}` }, `form-${key}`);
|
|
4745
|
-
}
|
|
4746
|
-
return jsx(Text, { children: "missing type" }, `form-${key}`);
|
|
4744
|
+
return (jsx(ColumnRenderer
|
|
4745
|
+
// @ts-expect-error find suitable types
|
|
4746
|
+
, {
|
|
4747
|
+
// @ts-expect-error find suitable types
|
|
4748
|
+
properties: properties, prefix: ``, column }, `form-${column}`));
|
|
4747
4749
|
}) }), jsx(Button, { onClick: () => {
|
|
4748
4750
|
methods.handleSubmit(onValid)();
|
|
4749
4751
|
}, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxs(Fragment, { children: ["isError", jsxs(Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
@@ -4795,4 +4797,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
|
|
|
4795
4797
|
}
|
|
4796
4798
|
};
|
|
4797
4799
|
|
|
4798
|
-
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditOrderButton, EditSortingButton, EmptyState, ErrorAlert, FilterDialog, FilterOptions, Form, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
|
|
4800
|
+
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditOrderButton, EditSortingButton, EmptyState, ErrorAlert, FilterDialog, FilterOptions, Form, GlobalFilter, PageSizeControl, Pagination, RecordDisplay, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TableSelector, TableSorter, TableViewer, TextCell, ViewDialog, getColumns, getMultiDates, getRangeDates, idPickerSanityCheck, useDataTable, useDataTableContext, useDataTableServer, useForm, widthSanityCheck };
|