@bsol-oss/react-datatable5 11.0.0-beta.2 → 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 +297 -298
- package/dist/index.mjs +298 -300
- 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({
|
|
@@ -3547,28 +3547,15 @@ const SchemaFormContext = createContext({
|
|
|
3547
3547
|
requestOptions: {},
|
|
3548
3548
|
});
|
|
3549
3549
|
|
|
3550
|
-
const
|
|
3550
|
+
const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
|
|
3551
3551
|
const { portalled = true, portalRef, ...rest } = props;
|
|
3552
|
-
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(
|
|
3553
|
-
});
|
|
3554
|
-
React.forwardRef(function PopoverArrow(props, ref) {
|
|
3555
|
-
return (jsx(Popover.Arrow, { ...props, ref: ref, children: jsx(Popover.ArrowTip, {}) }));
|
|
3556
|
-
});
|
|
3557
|
-
React.forwardRef(function PopoverCloseTrigger(props, ref) {
|
|
3558
|
-
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 }) }) }));
|
|
3559
3553
|
});
|
|
3560
|
-
const
|
|
3561
|
-
|
|
3562
|
-
Popover.Footer;
|
|
3563
|
-
Popover.Header;
|
|
3564
|
-
const PopoverRoot = Popover.Root;
|
|
3565
|
-
const PopoverBody = Popover.Body;
|
|
3566
|
-
const PopoverTrigger = Popover.Trigger;
|
|
3567
|
-
|
|
3568
|
-
const Field = React.forwardRef(function Field(props, ref) {
|
|
3569
|
-
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
3570
|
-
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, {}) }));
|
|
3571
3556
|
});
|
|
3557
|
+
const HoverCardRoot = HoverCard.Root;
|
|
3558
|
+
const HoverCardTrigger = HoverCard.Trigger;
|
|
3572
3559
|
|
|
3573
3560
|
const useSchemaContext = () => {
|
|
3574
3561
|
const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = useContext(SchemaFormContext);
|
|
@@ -3587,148 +3574,6 @@ const useSchemaContext = () => {
|
|
|
3587
3574
|
};
|
|
3588
3575
|
};
|
|
3589
3576
|
|
|
3590
|
-
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
3591
|
-
if (serverUrl === undefined || serverUrl.length == 0) {
|
|
3592
|
-
throw new Error("The serverUrl is missing");
|
|
3593
|
-
}
|
|
3594
|
-
if (in_table === undefined || in_table.length == 0) {
|
|
3595
|
-
throw new Error("The in_table is missing");
|
|
3596
|
-
}
|
|
3597
|
-
const options = {
|
|
3598
|
-
method: "GET",
|
|
3599
|
-
url: `${serverUrl}/api/g/${in_table}`,
|
|
3600
|
-
params: {
|
|
3601
|
-
searching,
|
|
3602
|
-
where,
|
|
3603
|
-
limit,
|
|
3604
|
-
offset
|
|
3605
|
-
},
|
|
3606
|
-
};
|
|
3607
|
-
try {
|
|
3608
|
-
const { data } = await axios.request(options);
|
|
3609
|
-
console.log(data);
|
|
3610
|
-
return data;
|
|
3611
|
-
}
|
|
3612
|
-
catch (error) {
|
|
3613
|
-
console.error(error);
|
|
3614
|
-
throw error;
|
|
3615
|
-
}
|
|
3616
|
-
};
|
|
3617
|
-
|
|
3618
|
-
const IdPicker = ({ column, isMultiple = false }) => {
|
|
3619
|
-
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3620
|
-
const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
3621
|
-
const { required } = schema;
|
|
3622
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3623
|
-
if (schema.properties == undefined) {
|
|
3624
|
-
throw new Error("schema properties is undefined when using DatePicker");
|
|
3625
|
-
}
|
|
3626
|
-
const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
|
|
3627
|
-
const { table, column: column_ref, display_column, } = foreign_key;
|
|
3628
|
-
const [searchText, setSearchText] = useState();
|
|
3629
|
-
const [limit, setLimit] = useState(10);
|
|
3630
|
-
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3631
|
-
const [page, setPage] = useState(0);
|
|
3632
|
-
const ref = useRef(null);
|
|
3633
|
-
const selectedIds = watch(column) ?? [];
|
|
3634
|
-
const query = useQuery({
|
|
3635
|
-
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
3636
|
-
queryFn: async () => {
|
|
3637
|
-
const data = await getTableData({
|
|
3638
|
-
serverUrl,
|
|
3639
|
-
searching: searchText ?? "",
|
|
3640
|
-
in_table: table,
|
|
3641
|
-
limit: limit,
|
|
3642
|
-
offset: page * 10,
|
|
3643
|
-
});
|
|
3644
|
-
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
3645
|
-
return [
|
|
3646
|
-
item[column_ref],
|
|
3647
|
-
{
|
|
3648
|
-
...item,
|
|
3649
|
-
},
|
|
3650
|
-
];
|
|
3651
|
-
}));
|
|
3652
|
-
setIdMap((state) => {
|
|
3653
|
-
return { ...state, ...newMap };
|
|
3654
|
-
});
|
|
3655
|
-
return data;
|
|
3656
|
-
},
|
|
3657
|
-
enabled: (searchText ?? "")?.length > 0,
|
|
3658
|
-
staleTime: 300000,
|
|
3659
|
-
});
|
|
3660
|
-
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
3661
|
-
const dataList = data?.data ?? [];
|
|
3662
|
-
const count = data?.count ?? 0;
|
|
3663
|
-
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3664
|
-
const onSearchChange = async (event) => {
|
|
3665
|
-
setSearchText(event.target.value);
|
|
3666
|
-
setPage(0);
|
|
3667
|
-
setLimit(10);
|
|
3668
|
-
};
|
|
3669
|
-
const watchId = watch(column);
|
|
3670
|
-
const watchIds = (watch(column) ?? []);
|
|
3671
|
-
const getPickedValue = () => {
|
|
3672
|
-
if (Object.keys(idMap).length <= 0) {
|
|
3673
|
-
return "";
|
|
3674
|
-
}
|
|
3675
|
-
const record = idMap[watchId];
|
|
3676
|
-
if (record === undefined) {
|
|
3677
|
-
return "";
|
|
3678
|
-
}
|
|
3679
|
-
return record[display_column];
|
|
3680
|
-
};
|
|
3681
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3682
|
-
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
3683
|
-
const item = idMap[id];
|
|
3684
|
-
if (item === undefined) {
|
|
3685
|
-
return jsx(Text, { children: "undefined" }, id);
|
|
3686
|
-
}
|
|
3687
|
-
return (jsx(Tag, { closable: true, onClick: () => {
|
|
3688
|
-
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
3689
|
-
}, children: !!renderDisplay === true
|
|
3690
|
-
? renderDisplay(item)
|
|
3691
|
-
: item[display_column] }, id));
|
|
3692
|
-
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3693
|
-
setOpenSearchResult(true);
|
|
3694
|
-
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
3695
|
-
setOpenSearchResult(true);
|
|
3696
|
-
}, 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) => {
|
|
3697
|
-
onSearchChange(event);
|
|
3698
|
-
setOpenSearchResult(true);
|
|
3699
|
-
}, 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:
|
|
3700
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3701
|
-
dataList.map((item) => {
|
|
3702
|
-
const selected = isMultiple
|
|
3703
|
-
? watchIds.some((id) => item[column_ref] === id)
|
|
3704
|
-
: watchId === item[column_ref];
|
|
3705
|
-
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
3706
|
-
if (!isMultiple) {
|
|
3707
|
-
setOpenSearchResult(false);
|
|
3708
|
-
setValue(column, item[column_ref]);
|
|
3709
|
-
return;
|
|
3710
|
-
}
|
|
3711
|
-
const newSet = new Set([
|
|
3712
|
-
...(watchIds ?? []),
|
|
3713
|
-
item[column_ref],
|
|
3714
|
-
]);
|
|
3715
|
-
setValue(column, [...newSet]);
|
|
3716
|
-
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3717
|
-
? renderDisplay(item)
|
|
3718
|
-
: item[display_column] }, item[column_ref]));
|
|
3719
|
-
}) }), 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`) }))] }));
|
|
3720
|
-
};
|
|
3721
|
-
|
|
3722
|
-
const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
|
|
3723
|
-
const { portalled = true, portalRef, ...rest } = props;
|
|
3724
|
-
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(HoverCard.Positioner, { children: jsx(HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3725
|
-
});
|
|
3726
|
-
const HoverCardArrow = React.forwardRef(function HoverCardArrow(props, ref) {
|
|
3727
|
-
return (jsx(HoverCard.Arrow, { ref: ref, ...props, children: jsx(HoverCard.ArrowTip, {}) }));
|
|
3728
|
-
});
|
|
3729
|
-
const HoverCardRoot = HoverCard.Root;
|
|
3730
|
-
const HoverCardTrigger = HoverCard.Trigger;
|
|
3731
|
-
|
|
3732
3577
|
const IdViewer = ({ value, column }) => {
|
|
3733
3578
|
const { schema, idMap, translate } = useSchemaContext();
|
|
3734
3579
|
if (schema.properties == undefined) {
|
|
@@ -3745,38 +3590,6 @@ const IdViewer = ({ value, column }) => {
|
|
|
3745
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] })] })] })] }));
|
|
3746
3591
|
};
|
|
3747
3592
|
|
|
3748
|
-
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
3749
|
-
const { children, ...rest } = props;
|
|
3750
|
-
return (jsxs(NumberInput.Root, { ref: ref, variant: "outline", ...rest, children: [children, jsxs(NumberInput.Control, { children: [jsx(NumberInput.IncrementTrigger, {}), jsx(NumberInput.DecrementTrigger, {})] })] }));
|
|
3751
|
-
});
|
|
3752
|
-
const NumberInputField$1 = NumberInput.Input;
|
|
3753
|
-
NumberInput.Scrubber;
|
|
3754
|
-
NumberInput.Label;
|
|
3755
|
-
|
|
3756
|
-
const NumberInputField = ({ column }) => {
|
|
3757
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
3758
|
-
const { schema, translate } = useSchemaContext();
|
|
3759
|
-
const { required } = schema;
|
|
3760
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3761
|
-
if (schema.properties == undefined) {
|
|
3762
|
-
throw new Error("schema properties when using String Input Field");
|
|
3763
|
-
}
|
|
3764
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3765
|
-
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`) }))] }));
|
|
3766
|
-
};
|
|
3767
|
-
|
|
3768
|
-
const StringInputField = ({ column }) => {
|
|
3769
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
3770
|
-
const { schema, translate } = useSchemaContext();
|
|
3771
|
-
const { required } = schema;
|
|
3772
|
-
const isRequired = required?.some((columnId) => columnId === column);
|
|
3773
|
-
if (schema.properties == undefined) {
|
|
3774
|
-
throw new Error("schema properties when using String Input Field");
|
|
3775
|
-
}
|
|
3776
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3777
|
-
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`) }))] }) }));
|
|
3778
|
-
};
|
|
3779
|
-
|
|
3780
3593
|
const clearEmptyString = (object) => {
|
|
3781
3594
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
3782
3595
|
};
|
|
@@ -3806,20 +3619,22 @@ const DataListItem = React.forwardRef(function DataListItem(props, ref) {
|
|
|
3806
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] }));
|
|
3807
3620
|
});
|
|
3808
3621
|
|
|
3809
|
-
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 }) => {
|
|
3810
3628
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3811
|
-
const {
|
|
3812
|
-
const { required } = schema;
|
|
3629
|
+
const { translate } = useSchemaContext();
|
|
3630
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3813
3631
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3814
|
-
const
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
}
|
|
3818
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3819
|
-
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,
|
|
3820
3635
|
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
3821
|
-
setValue(
|
|
3822
|
-
} }), 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`) }))] }));
|
|
3823
3638
|
};
|
|
3824
3639
|
|
|
3825
3640
|
const monthNamesShort = [
|
|
@@ -3891,18 +3706,33 @@ let DatePicker$1 = class DatePicker extends React__default.Component {
|
|
|
3891
3706
|
}
|
|
3892
3707
|
};
|
|
3893
3708
|
|
|
3894
|
-
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 }) => {
|
|
3895
3728
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3896
|
-
const {
|
|
3897
|
-
const { required } = schema;
|
|
3729
|
+
const { translate } = useSchemaContext();
|
|
3730
|
+
const { required, gridColumn, gridRow } = schema;
|
|
3898
3731
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3732
|
+
const colLabel = `${prefix}${column}`;
|
|
3899
3733
|
const [open, setOpen] = useState(false);
|
|
3900
|
-
const selectedDate = watch(
|
|
3901
|
-
|
|
3902
|
-
throw new Error("schema properties when using DatePicker");
|
|
3903
|
-
}
|
|
3904
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
3905
|
-
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,
|
|
3906
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: () => {
|
|
3907
3737
|
setOpen(true);
|
|
3908
3738
|
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
@@ -3911,7 +3741,7 @@ const DatePicker = ({ column }) => {
|
|
|
3911
3741
|
// @ts-expect-error TODO: find appropriate types
|
|
3912
3742
|
selected: new Date(selectedDate),
|
|
3913
3743
|
// @ts-expect-error TODO: find appropriate types
|
|
3914
|
-
onDateSelected: ({
|
|
3744
|
+
onDateSelected: ({ date }) => {
|
|
3915
3745
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
3916
3746
|
setOpen(false);
|
|
3917
3747
|
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
@@ -3927,29 +3757,26 @@ function filterArray(array, searchTerm) {
|
|
|
3927
3757
|
});
|
|
3928
3758
|
}
|
|
3929
3759
|
|
|
3930
|
-
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
3760
|
+
const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
3931
3761
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3932
|
-
const {
|
|
3762
|
+
const { translate } = useSchemaContext();
|
|
3933
3763
|
const { required } = schema;
|
|
3934
3764
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3935
|
-
|
|
3936
|
-
throw new Error("schema properties when using DatePicker");
|
|
3937
|
-
}
|
|
3938
|
-
const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
|
|
3765
|
+
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
3939
3766
|
const [searchText, setSearchText] = useState();
|
|
3940
3767
|
const [limit, setLimit] = useState(10);
|
|
3941
3768
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3942
3769
|
const ref = useRef(null);
|
|
3943
3770
|
const watchEnum = watch(column);
|
|
3944
3771
|
const watchEnums = (watch(column) ?? []);
|
|
3945
|
-
const
|
|
3946
|
-
const
|
|
3947
|
-
const count = properties.enum?.length ?? 0;
|
|
3772
|
+
const dataList = schema.enum ?? [];
|
|
3773
|
+
const count = schema.enum?.length ?? 0;
|
|
3948
3774
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
3949
3775
|
const onSearchChange = async (event) => {
|
|
3950
3776
|
setSearchText(event.target.value);
|
|
3951
3777
|
setLimit(10);
|
|
3952
3778
|
};
|
|
3779
|
+
const col = `${prefix}${column}`;
|
|
3953
3780
|
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3954
3781
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3955
3782
|
const item = enumValue;
|
|
@@ -3979,8 +3806,10 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3979
3806
|
}
|
|
3980
3807
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3981
3808
|
setValue(column, [...newSet]);
|
|
3982
|
-
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3983
|
-
|
|
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`) }))] }));
|
|
3984
3813
|
};
|
|
3985
3814
|
|
|
3986
3815
|
function isEnteringWindow(_ref) {
|
|
@@ -4335,41 +4164,193 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4335
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 })] }))] }));
|
|
4336
4165
|
};
|
|
4337
4166
|
|
|
4338
|
-
const FilePicker = ({ column }) => {
|
|
4167
|
+
const FilePicker = ({ column, schema, prefix }) => {
|
|
4339
4168
|
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4340
|
-
const {
|
|
4341
|
-
const { required } = schema;
|
|
4169
|
+
const { translate } = useSchemaContext();
|
|
4170
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4342
4171
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4343
|
-
if (schema.properties == undefined) {
|
|
4344
|
-
throw new Error("schema properties when using String Input Field");
|
|
4345
|
-
}
|
|
4346
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4347
4172
|
const currentFiles = (watch(column) ?? []);
|
|
4348
|
-
|
|
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 }) => {
|
|
4349
4175
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4350
|
-
setValue(
|
|
4351
|
-
}, placeholder: translate.t(`${
|
|
4176
|
+
setValue(col, [...currentFiles, ...newFiles]);
|
|
4177
|
+
}, placeholder: translate.t(`${col}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4352
4178
|
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4353
4179
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4354
4180
|
return name !== file.name;
|
|
4355
4181
|
}));
|
|
4356
|
-
}, display: "flex", flexFlow:
|
|
4357
|
-
}) }), 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`) }))] }));
|
|
4184
|
+
};
|
|
4185
|
+
|
|
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`) }))] }));
|
|
4358
4313
|
};
|
|
4359
4314
|
|
|
4360
|
-
const
|
|
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 }) => {
|
|
4361
4346
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4362
|
-
const {
|
|
4363
|
-
const { required } = schema;
|
|
4347
|
+
const { translate } = useSchemaContext();
|
|
4348
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4364
4349
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4365
4350
|
const entries = Object.entries(getValues(column) ?? {});
|
|
4366
4351
|
const [showNewEntries, setShowNewEntries] = useState(false);
|
|
4367
4352
|
const [newKey, setNewKey] = useState();
|
|
4368
4353
|
const [newValue, setNewValue] = useState();
|
|
4369
|
-
if (schema.properties == undefined) {
|
|
4370
|
-
throw new Error("schema properties when using DatePicker");
|
|
4371
|
-
}
|
|
4372
|
-
const { gridColumn, gridRow } = schema.properties[column];
|
|
4373
4354
|
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4374
4355
|
return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
|
|
4375
4356
|
const filtered = entries.filter(([target]) => {
|
|
@@ -4413,6 +4394,15 @@ const ObjectInput = ({ column }) => {
|
|
|
4413
4394
|
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4414
4395
|
};
|
|
4415
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
|
+
|
|
4416
4406
|
const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
|
|
4417
4407
|
const { inputProps, label, description, addon, icon, indicator = jsx(RadioCard.ItemIndicator, {}), indicatorPlacement = "end", ...rest } = props;
|
|
4418
4408
|
const hasContent = label || description || icon;
|
|
@@ -4508,6 +4498,62 @@ const TagPicker = ({ column }) => {
|
|
|
4508
4498
|
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4509
4499
|
};
|
|
4510
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
|
+
|
|
4511
4557
|
const idPickerSanityCheck = (column, foreign_key) => {
|
|
4512
4558
|
if (!!foreign_key == false) {
|
|
4513
4559
|
throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
|
|
@@ -4695,59 +4741,11 @@ const FormInternal = () => {
|
|
|
4695
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)}` })] }) }) }) }) }))] }));
|
|
4696
4742
|
}
|
|
4697
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) => {
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
const shouldIgnore = ignore.some((column) => {
|
|
4704
|
-
return column == key;
|
|
4705
|
-
});
|
|
4706
|
-
if (shouldIgnore) {
|
|
4707
|
-
return jsx(Fragment, {});
|
|
4708
|
-
}
|
|
4709
|
-
//@ts-expect-error TODO: add more fields to support form-creation
|
|
4710
|
-
const { type, variant, foreign_key } = values;
|
|
4711
|
-
if (type === "string") {
|
|
4712
|
-
// @ts-expect-error enum should exists
|
|
4713
|
-
if ((values.enum ?? []).length > 0) {
|
|
4714
|
-
return jsx(EnumPicker, { column: key }, `form-${key}`);
|
|
4715
|
-
}
|
|
4716
|
-
if (variant === "id-picker") {
|
|
4717
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4718
|
-
return jsx(IdPicker, { column: key }, `form-${key}`);
|
|
4719
|
-
}
|
|
4720
|
-
if (variant === "date-picker") {
|
|
4721
|
-
return jsx(DatePicker, { column: key }, `form-${key}`);
|
|
4722
|
-
}
|
|
4723
|
-
return jsx(StringInputField, { column: key }, `form-${key}`);
|
|
4724
|
-
}
|
|
4725
|
-
if (type === "number" || type === "integer") {
|
|
4726
|
-
return jsx(NumberInputField, { column: key }, `form-${key}`);
|
|
4727
|
-
}
|
|
4728
|
-
if (type === "boolean") {
|
|
4729
|
-
return jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
4730
|
-
}
|
|
4731
|
-
if (type === "object") {
|
|
4732
|
-
return jsx(ObjectInput, { column: key }, `form-${key}`);
|
|
4733
|
-
}
|
|
4734
|
-
if (type === "array") {
|
|
4735
|
-
if (variant === "id-picker") {
|
|
4736
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4737
|
-
return jsx(IdPicker, { column: key, isMultiple: true }, `form-${key}`);
|
|
4738
|
-
}
|
|
4739
|
-
if (variant === "tag-picker") {
|
|
4740
|
-
return jsx(TagPicker, { column: key }, `form-${key}`);
|
|
4741
|
-
}
|
|
4742
|
-
if (variant === "file-picker") {
|
|
4743
|
-
return jsx(FilePicker, { column: key }, `form-${key}`);
|
|
4744
|
-
}
|
|
4745
|
-
return jsx(Text, { children: `array ${column}` }, `form-${key}`);
|
|
4746
|
-
}
|
|
4747
|
-
if (type === "null") {
|
|
4748
|
-
return jsx(Text, { children: `null ${column}` }, `form-${key}`);
|
|
4749
|
-
}
|
|
4750
|
-
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}`));
|
|
4751
4749
|
}) }), jsx(Button, { onClick: () => {
|
|
4752
4750
|
methods.handleSubmit(onValid)();
|
|
4753
4751
|
}, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxs(Fragment, { children: ["isError", jsxs(Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
@@ -4799,4 +4797,4 @@ const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) =
|
|
|
4799
4797
|
}
|
|
4800
4798
|
};
|
|
4801
4799
|
|
|
4802
|
-
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 };
|