@bsol-oss/react-datatable5 11.0.0-beta.4 → 11.0.0-beta.6
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 +1 -1
- package/dist/index.js +465 -197
- package/dist/index.mjs +467 -199
- package/dist/types/components/Form/Form.d.ts +1 -1
- package/dist/types/components/Form/components/ArrayRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/SchemaRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/fields/ArrayRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/fields/BooleanPicker.d.ts +7 -0
- package/dist/types/components/Form/components/fields/ColumnRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/fields/DatePicker.d.ts +7 -0
- package/dist/types/components/Form/components/fields/EnumPicker.d.ts +8 -0
- package/dist/types/components/Form/components/fields/FilePicker.d.ts +5 -0
- package/dist/types/components/Form/components/fields/IdPicker.d.ts +8 -0
- package/dist/types/components/Form/components/fields/NumberInputField.d.ts +7 -0
- package/dist/types/components/Form/components/fields/ObjectInput.d.ts +7 -0
- package/dist/types/components/Form/components/fields/RecordInput.d.ts +7 -0
- package/dist/types/components/Form/components/fields/SchemaRenderer.d.ts +7 -0
- package/dist/types/components/Form/components/fields/StringInputField.d.ts +12 -0
- package/dist/types/components/Form/components/fields/TagPicker.d.ts +25 -0
- package/dist/types/components/Form/components/types/CustomJSONSchema7.d.ts +15 -0
- package/dist/types/components/Form/components/viewers/ArrayViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/BooleanViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/ColumnViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/DateViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/EnumViewer.d.ts +8 -0
- package/dist/types/components/Form/components/viewers/FileViewer.d.ts +5 -0
- package/dist/types/components/Form/components/viewers/IdViewer.d.ts +8 -0
- package/dist/types/components/Form/components/viewers/NumberViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/ObjectViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/RecordViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/SchemaViewer.d.ts +7 -0
- package/dist/types/components/Form/components/viewers/StringViewer.d.ts +12 -0
- package/dist/types/components/Form/components/viewers/TagViewer.d.ts +30 -0
- package/dist/types/components/Form/utils/removeIndex.d.ts +1 -0
- 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,
|
|
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, Accordion, Field as Field$1, Popover, 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';
|
|
@@ -24,11 +24,11 @@ import { useDebounce } from '@uidotdev/usehooks';
|
|
|
24
24
|
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
25
25
|
import { IoReload } from 'react-icons/io5';
|
|
26
26
|
import { GrAscend, GrDescend } from 'react-icons/gr';
|
|
27
|
-
import { HiColorSwatch
|
|
27
|
+
import { HiColorSwatch } from 'react-icons/hi';
|
|
28
28
|
import { useTranslation } from 'react-i18next';
|
|
29
29
|
import axios from 'axios';
|
|
30
|
-
import dayjs from 'dayjs';
|
|
31
30
|
import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
|
|
31
|
+
import dayjs from 'dayjs';
|
|
32
32
|
import { TiDeleteOutline } from 'react-icons/ti';
|
|
33
33
|
|
|
34
34
|
const DataTableContext = createContext({
|
|
@@ -3547,16 +3547,6 @@ const SchemaFormContext = createContext({
|
|
|
3547
3547
|
requestOptions: {},
|
|
3548
3548
|
});
|
|
3549
3549
|
|
|
3550
|
-
const HoverCardContent = React.forwardRef(function HoverCardContent(props, ref) {
|
|
3551
|
-
const { portalled = true, portalRef, ...rest } = props;
|
|
3552
|
-
return (jsx(Portal, { disabled: !portalled, container: portalRef, children: jsx(HoverCard.Positioner, { children: jsx(HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3553
|
-
});
|
|
3554
|
-
const HoverCardArrow = React.forwardRef(function HoverCardArrow(props, ref) {
|
|
3555
|
-
return (jsx(HoverCard.Arrow, { ref: ref, ...props, children: jsx(HoverCard.ArrowTip, {}) }));
|
|
3556
|
-
});
|
|
3557
|
-
const HoverCardRoot = HoverCard.Root;
|
|
3558
|
-
const HoverCardTrigger = HoverCard.Trigger;
|
|
3559
|
-
|
|
3560
3550
|
const useSchemaContext = () => {
|
|
3561
3551
|
const { schema, serverUrl, requestUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, requestOptions, } = useContext(SchemaFormContext);
|
|
3562
3552
|
return {
|
|
@@ -3574,22 +3564,6 @@ const useSchemaContext = () => {
|
|
|
3574
3564
|
};
|
|
3575
3565
|
};
|
|
3576
3566
|
|
|
3577
|
-
const IdViewer = ({ value, column }) => {
|
|
3578
|
-
const { schema, idMap, translate } = useSchemaContext();
|
|
3579
|
-
if (schema.properties == undefined) {
|
|
3580
|
-
throw new Error("schema properties when using DatePicker");
|
|
3581
|
-
}
|
|
3582
|
-
const { foreign_key } = schema.properties[column];
|
|
3583
|
-
if (foreign_key === undefined) {
|
|
3584
|
-
throw new Error("foreign_key when variant is id-picker");
|
|
3585
|
-
}
|
|
3586
|
-
const { display_column } = foreign_key;
|
|
3587
|
-
if (value === undefined) {
|
|
3588
|
-
return (jsxs(Flex, { flexFlow: "column", children: [jsx(Text, { children: translate.t(`${column}.fieldLabel`) }), jsx(Text, { children: translate.t(`empty`) })] }));
|
|
3589
|
-
}
|
|
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] })] })] })] }));
|
|
3591
|
-
};
|
|
3592
|
-
|
|
3593
3567
|
const clearEmptyString = (object) => {
|
|
3594
3568
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
3595
3569
|
};
|
|
@@ -3604,20 +3578,41 @@ const AccordionItemContent = React.forwardRef(function AccordionItemContent(prop
|
|
|
3604
3578
|
const AccordionRoot = Accordion.Root;
|
|
3605
3579
|
const AccordionItem = Accordion.Item;
|
|
3606
3580
|
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
});
|
|
3611
|
-
const InfoTip = React.forwardRef(function InfoTip(props, ref) {
|
|
3612
|
-
const { children, ...rest } = props;
|
|
3613
|
-
return (jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsx(IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "gray", children: jsx(HiOutlineInformationCircle, {}) }) }));
|
|
3614
|
-
});
|
|
3581
|
+
function removeIndex(str) {
|
|
3582
|
+
return str.replace(/\.\d+\./g, '.');
|
|
3583
|
+
}
|
|
3615
3584
|
|
|
3616
|
-
const
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
});
|
|
3585
|
+
const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
3586
|
+
const { gridRow, gridColumn = "1/span 12", required, items } = schema;
|
|
3587
|
+
// @ts-expect-error TODO: find suitable types
|
|
3588
|
+
const { type } = items;
|
|
3589
|
+
const { translate } = useSchemaContext();
|
|
3590
|
+
const colLabel = `${prefix}${column}`;
|
|
3591
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
3592
|
+
const { formState: { errors }, setValue, watch, } = useFormContext();
|
|
3593
|
+
const fields = (watch(colLabel) ?? []);
|
|
3594
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), fields.map((field, index) => (jsxs(Flex, { flexFlow: "column", children: [jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: jsx(SchemaRenderer, { column: `${index}`,
|
|
3595
|
+
prefix: `${colLabel}.`,
|
|
3596
|
+
schema: items }) }), jsx(Flex, { justifyContent: "end", children: jsx(Button$1, { variant: "ghost", onClick: () => {
|
|
3597
|
+
setValue(colLabel, fields.filter((_, curIndex) => {
|
|
3598
|
+
return curIndex === index;
|
|
3599
|
+
}));
|
|
3600
|
+
}, children: translate.t(removeIndex(`${colLabel}.remove`)) }) })] }, `${colLabel}.${index}`))), jsx(Flex, { children: jsx(Button$1, { onClick: () => {
|
|
3601
|
+
if (type === "number") {
|
|
3602
|
+
setValue(colLabel, [...fields, 0]);
|
|
3603
|
+
return;
|
|
3604
|
+
}
|
|
3605
|
+
if (type === "string") {
|
|
3606
|
+
setValue(colLabel, [...fields, ""]);
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3609
|
+
if (type === "boolean") {
|
|
3610
|
+
setValue(colLabel, [...fields, false]);
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
setValue(colLabel, [...fields, {}]);
|
|
3614
|
+
}, children: translate.t(removeIndex(`${colLabel}.add`)) }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
3615
|
+
};
|
|
3621
3616
|
|
|
3622
3617
|
const Field = React.forwardRef(function Field(props, ref) {
|
|
3623
3618
|
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
@@ -3631,10 +3626,10 @@ const BooleanPicker = ({ schema, column, prefix }) => {
|
|
|
3631
3626
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3632
3627
|
const colLabel = `${prefix}${column}`;
|
|
3633
3628
|
const value = watch(colLabel);
|
|
3634
|
-
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3635
|
-
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface",
|
|
3629
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3630
|
+
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onChange: () => {
|
|
3636
3631
|
setValue(colLabel, !value);
|
|
3637
|
-
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
3632
|
+
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
3638
3633
|
};
|
|
3639
3634
|
|
|
3640
3635
|
const monthNamesShort = [
|
|
@@ -3732,7 +3727,7 @@ const DatePicker = ({ column, schema, prefix }) => {
|
|
|
3732
3727
|
const colLabel = `${prefix}${column}`;
|
|
3733
3728
|
const [open, setOpen] = useState(false);
|
|
3734
3729
|
const selectedDate = watch(colLabel);
|
|
3735
|
-
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3730
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3736
3731
|
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: () => {
|
|
3737
3732
|
setOpen(true);
|
|
3738
3733
|
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
@@ -3742,9 +3737,9 @@ const DatePicker = ({ column, schema, prefix }) => {
|
|
|
3742
3737
|
selected: new Date(selectedDate),
|
|
3743
3738
|
// @ts-expect-error TODO: find appropriate types
|
|
3744
3739
|
onDateSelected: ({ date }) => {
|
|
3745
|
-
setValue(
|
|
3740
|
+
setValue(colLabel, dayjs(date).format("YYYY-MM-DD"));
|
|
3746
3741
|
setOpen(false);
|
|
3747
|
-
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${
|
|
3742
|
+
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
3748
3743
|
};
|
|
3749
3744
|
|
|
3750
3745
|
function filterArray(array, searchTerm) {
|
|
@@ -3767,8 +3762,9 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3767
3762
|
const [limit, setLimit] = useState(10);
|
|
3768
3763
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3769
3764
|
const ref = useRef(null);
|
|
3770
|
-
const
|
|
3771
|
-
const
|
|
3765
|
+
const colLabel = `${prefix}${column}`;
|
|
3766
|
+
const watchEnum = watch(colLabel);
|
|
3767
|
+
const watchEnums = (watch(colLabel) ?? []);
|
|
3772
3768
|
const dataList = schema.enum ?? [];
|
|
3773
3769
|
const count = schema.enum?.length ?? 0;
|
|
3774
3770
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
@@ -3776,8 +3772,7 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3776
3772
|
setSearchText(event.target.value);
|
|
3777
3773
|
setLimit(10);
|
|
3778
3774
|
};
|
|
3779
|
-
|
|
3780
|
-
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3775
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3781
3776
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3782
3777
|
const item = enumValue;
|
|
3783
3778
|
if (item === undefined) {
|
|
@@ -3786,12 +3781,16 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3786
3781
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
3787
3782
|
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3788
3783
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3789
|
-
}, children: !!renderDisplay === true
|
|
3784
|
+
}, children: !!renderDisplay === true
|
|
3785
|
+
? renderDisplay(item)
|
|
3786
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3790
3787
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3791
3788
|
setOpenSearchResult(true);
|
|
3792
|
-
}, children:
|
|
3789
|
+
}, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
3793
3790
|
setOpenSearchResult(true);
|
|
3794
|
-
}, children: watchEnum
|
|
3791
|
+
}, children: watchEnum === undefined
|
|
3792
|
+
? ""
|
|
3793
|
+
: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsx(Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
|
|
3795
3794
|
onSearchChange(event);
|
|
3796
3795
|
setOpenSearchResult(true);
|
|
3797
3796
|
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), jsx(Text, { 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: filterArray(dataList, searchText ?? "").map((item) => {
|
|
@@ -3801,15 +3800,15 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3801
3800
|
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
3802
3801
|
if (!isMultiple) {
|
|
3803
3802
|
setOpenSearchResult(false);
|
|
3804
|
-
setValue(
|
|
3803
|
+
setValue(colLabel, item);
|
|
3805
3804
|
return;
|
|
3806
3805
|
}
|
|
3807
3806
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3808
|
-
setValue(
|
|
3807
|
+
setValue(colLabel, [...newSet]);
|
|
3809
3808
|
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3810
3809
|
? renderDisplay(item)
|
|
3811
|
-
: translate.t(`${
|
|
3812
|
-
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(`${
|
|
3810
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) }, `${colLabel}-${item}`));
|
|
3811
|
+
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Fragment, { children: translate.t(removeIndex(`${colLabel}.emptySearchResult`)) })) }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
3813
3812
|
};
|
|
3814
3813
|
|
|
3815
3814
|
function isEnteringWindow(_ref) {
|
|
@@ -4170,17 +4169,17 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4170
4169
|
const { required, gridColumn, gridRow } = schema;
|
|
4171
4170
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4172
4171
|
const currentFiles = (watch(column) ?? []);
|
|
4173
|
-
const
|
|
4174
|
-
return (jsxs(Field, { label: `${translate.t(`${
|
|
4172
|
+
const colLabel = `${prefix}${column}`;
|
|
4173
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4175
4174
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4176
|
-
setValue(
|
|
4177
|
-
}, placeholder: translate.t(`${
|
|
4175
|
+
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4176
|
+
}, placeholder: translate.t(removeIndex(`${colLabel}.fileDropzone`)) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4178
4177
|
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4179
4178
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4180
4179
|
return name !== file.name;
|
|
4181
4180
|
}));
|
|
4182
4181
|
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4183
|
-
}) }), errors[`${
|
|
4182
|
+
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4184
4183
|
};
|
|
4185
4184
|
|
|
4186
4185
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
@@ -4222,7 +4221,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4222
4221
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
4223
4222
|
const [page, setPage] = useState(0);
|
|
4224
4223
|
const ref = useRef(null);
|
|
4225
|
-
const selectedIds = watch(column) ?? [];
|
|
4226
4224
|
const colLabel = `${prefix}${column}`;
|
|
4227
4225
|
const query = useQuery({
|
|
4228
4226
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
@@ -4259,8 +4257,8 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4259
4257
|
setPage(0);
|
|
4260
4258
|
setLimit(10);
|
|
4261
4259
|
};
|
|
4262
|
-
const watchId = watch(
|
|
4263
|
-
const watchIds = (watch(
|
|
4260
|
+
const watchId = watch(colLabel);
|
|
4261
|
+
const watchIds = (watch(colLabel) ?? []);
|
|
4264
4262
|
const getPickedValue = () => {
|
|
4265
4263
|
if (Object.keys(idMap).length <= 0) {
|
|
4266
4264
|
return "";
|
|
@@ -4271,11 +4269,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4271
4269
|
}
|
|
4272
4270
|
return record[display_column];
|
|
4273
4271
|
};
|
|
4274
|
-
return (jsxs(Field, { label: `${translate.t(`${
|
|
4275
|
-
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [
|
|
4272
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(removeIndex(`${column}.fieldLabel`)))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4273
|
+
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchIds.map((id) => {
|
|
4276
4274
|
const item = idMap[id];
|
|
4277
4275
|
if (item === undefined) {
|
|
4278
|
-
return (
|
|
4276
|
+
return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4279
4277
|
}
|
|
4280
4278
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
4281
4279
|
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
@@ -4284,12 +4282,12 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4284
4282
|
: item[display_column] }, id));
|
|
4285
4283
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4286
4284
|
setOpenSearchResult(true);
|
|
4287
|
-
}, children: translate.t(`${colLabel}.addMore`) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4285
|
+
}, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4288
4286
|
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) => {
|
|
4287
|
+
}, 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(removeIndex(`${colLabel}.typeToSearch`)), onChange: (event) => {
|
|
4290
4288
|
onSearchChange(event);
|
|
4291
4289
|
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:
|
|
4290
|
+
}, 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(removeIndex(`${colLabel}.total`))} ${count}, ${translate.t(removeIndex(`${colLabel}.showing`))} ${limit}` }), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Flex, { flexFlow: "column wrap", children:
|
|
4293
4291
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4294
4292
|
dataList.map((item) => {
|
|
4295
4293
|
const selected = isMultiple
|
|
@@ -4305,11 +4303,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4305
4303
|
...(watchIds ?? []),
|
|
4306
4304
|
item[column_ref],
|
|
4307
4305
|
]);
|
|
4308
|
-
setValue(
|
|
4306
|
+
setValue(colLabel, [...newSet]);
|
|
4309
4307
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
4310
4308
|
? renderDisplay(item)
|
|
4311
4309
|
: 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`) }))] }));
|
|
4310
|
+
}) }), isDirty && (jsx(Fragment, { children: dataList.length <= 0 && (jsx(Text, { children: translate.t(removeIndex(`${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(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4313
4311
|
};
|
|
4314
4312
|
|
|
4315
4313
|
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
@@ -4321,28 +4319,33 @@ NumberInput.Scrubber;
|
|
|
4321
4319
|
NumberInput.Label;
|
|
4322
4320
|
|
|
4323
4321
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4324
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
4322
|
+
const { register, formState: { errors }, watch } = useFormContext();
|
|
4325
4323
|
const { translate } = useSchemaContext();
|
|
4326
4324
|
const { required, gridColumn, gridRow } = schema;
|
|
4327
4325
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4328
4326
|
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`) }))] }));
|
|
4327
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${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(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4330
4328
|
};
|
|
4331
4329
|
|
|
4332
4330
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
4333
|
-
const { properties } = schema;
|
|
4331
|
+
const { properties, gridRow, gridColumn = "1/span 12", required } = schema;
|
|
4332
|
+
const { translate } = useSchemaContext();
|
|
4333
|
+
const colLabel = `${prefix}${column}`;
|
|
4334
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4335
|
+
const { formState: { errors }, } = useFormContext();
|
|
4334
4336
|
if (properties === undefined) {
|
|
4335
4337
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4336
4338
|
}
|
|
4337
|
-
return (jsx(
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4339
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: Object.keys(properties ?? {}).map((key) => {
|
|
4340
|
+
return (
|
|
4341
|
+
// @ts-expect-error find suitable types
|
|
4342
|
+
jsx(ColumnRenderer, { column: `${key}`,
|
|
4343
|
+
prefix: `${prefix}${column}.`,
|
|
4344
|
+
properties }, `form-${colLabel}-${key}`));
|
|
4345
|
+
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4343
4346
|
};
|
|
4344
4347
|
|
|
4345
|
-
const RecordInput = ({ column, schema, prefix }) => {
|
|
4348
|
+
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4346
4349
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4347
4350
|
const { translate } = useSchemaContext();
|
|
4348
4351
|
const { required, gridColumn, gridRow } = schema;
|
|
@@ -4400,7 +4403,7 @@ const StringInputField = ({ column, schema, prefix, }) => {
|
|
|
4400
4403
|
const { required, gridColumn, gridRow } = schema;
|
|
4401
4404
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4402
4405
|
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`) }))] }) }));
|
|
4406
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${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(removeIndex(`${colLabel}.fieldRequired`)) }))] }) }));
|
|
4404
4407
|
};
|
|
4405
4408
|
|
|
4406
4409
|
const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4498,18 +4501,11 @@ const TagPicker = ({ column, schema, prefix }) => {
|
|
|
4498
4501
|
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4499
4502
|
};
|
|
4500
4503
|
|
|
4501
|
-
const
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
}
|
|
4505
|
-
console.log(`${column} does not exist when using ColumnRenderer`, { properties, column, prefix }, "fdpok");
|
|
4506
|
-
const colSchema = properties[column];
|
|
4507
|
-
if (colSchema === undefined) {
|
|
4508
|
-
throw new Error(`${column} does not exist when using ColumnRenderer`);
|
|
4509
|
-
}
|
|
4510
|
-
const { type, variant, foreign_key, properties: innerProperties } = colSchema;
|
|
4504
|
+
const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
4505
|
+
const colSchema = schema;
|
|
4506
|
+
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4511
4507
|
if (type === "string") {
|
|
4512
|
-
if ((
|
|
4508
|
+
if ((schema.enum ?? []).length > 0) {
|
|
4513
4509
|
return jsx(EnumPicker, { schema: colSchema, prefix, column });
|
|
4514
4510
|
}
|
|
4515
4511
|
if (variant === "id-picker") {
|
|
@@ -4531,7 +4527,7 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4531
4527
|
if (innerProperties) {
|
|
4532
4528
|
return jsx(ObjectInput, { schema: colSchema, prefix, column });
|
|
4533
4529
|
}
|
|
4534
|
-
return jsx(RecordInput, { schema: colSchema, prefix, column });
|
|
4530
|
+
return jsx(RecordInput$1, { schema: colSchema, prefix, column });
|
|
4535
4531
|
}
|
|
4536
4532
|
if (type === "array") {
|
|
4537
4533
|
if (variant === "id-picker") {
|
|
@@ -4544,6 +4540,9 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4544
4540
|
if (variant === "file-picker") {
|
|
4545
4541
|
return jsx(FilePicker, { schema: colSchema, prefix, column });
|
|
4546
4542
|
}
|
|
4543
|
+
if (items) {
|
|
4544
|
+
return jsx(ArrayRenderer, { schema: colSchema, prefix, column });
|
|
4545
|
+
}
|
|
4547
4546
|
return jsx(Text, { children: `array ${column}` });
|
|
4548
4547
|
}
|
|
4549
4548
|
if (type === "null") {
|
|
@@ -4552,6 +4551,358 @@ const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
|
4552
4551
|
return jsx(Text, { children: "missing type" });
|
|
4553
4552
|
};
|
|
4554
4553
|
|
|
4554
|
+
const ColumnRenderer = ({ column, properties, prefix, }) => {
|
|
4555
|
+
const colSchema = properties[column];
|
|
4556
|
+
const colLabel = `${prefix}${column}`;
|
|
4557
|
+
if (colSchema === undefined) {
|
|
4558
|
+
throw new Error(`${colLabel} does not exist when using ColumnRenderer`);
|
|
4559
|
+
}
|
|
4560
|
+
return jsx(SchemaRenderer, { schema: colSchema, prefix, column });
|
|
4561
|
+
};
|
|
4562
|
+
|
|
4563
|
+
const ArrayViewer = ({ schema, column, prefix }) => {
|
|
4564
|
+
const { gridRow, gridColumn = "1/span 12", required, items } = schema;
|
|
4565
|
+
const { translate } = useSchemaContext();
|
|
4566
|
+
const colLabel = `${prefix}${column}`;
|
|
4567
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4568
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4569
|
+
const values = watch(colLabel) ?? [];
|
|
4570
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), values.map((field, index) => (jsx(Flex, { flexFlow: "column", children: jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: jsx(SchemaViewer, { column: `${index}`,
|
|
4571
|
+
prefix: `${colLabel}.`,
|
|
4572
|
+
schema: items }) }) }, `form-${prefix}${column}.${index}`))), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4573
|
+
};
|
|
4574
|
+
|
|
4575
|
+
const BooleanViewer = ({ schema, column, prefix, }) => {
|
|
4576
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4577
|
+
const { translate } = useSchemaContext();
|
|
4578
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4579
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4580
|
+
const colLabel = `${prefix}${column}`;
|
|
4581
|
+
const value = watch(colLabel);
|
|
4582
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4583
|
+
gridRow, children: [jsx(Text, { children: value
|
|
4584
|
+
? translate.t(removeIndex(`${colLabel}.true`))
|
|
4585
|
+
: translate.t(removeIndex(`${colLabel}.false`)) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4586
|
+
};
|
|
4587
|
+
|
|
4588
|
+
const DateViewer = ({ column, schema, prefix }) => {
|
|
4589
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4590
|
+
const { translate } = useSchemaContext();
|
|
4591
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4592
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4593
|
+
const colLabel = `${prefix}${column}`;
|
|
4594
|
+
const selectedDate = watch(colLabel);
|
|
4595
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4596
|
+
gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ? selectedDate : ""] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4597
|
+
};
|
|
4598
|
+
|
|
4599
|
+
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
4600
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4601
|
+
const { translate } = useSchemaContext();
|
|
4602
|
+
const { required } = schema;
|
|
4603
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4604
|
+
const { gridColumn, gridRow, renderDisplay } = schema;
|
|
4605
|
+
const colLabel = `${prefix}${column}`;
|
|
4606
|
+
const watchEnum = watch(colLabel);
|
|
4607
|
+
const watchEnums = (watch(colLabel) ?? []);
|
|
4608
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4609
|
+
gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchEnums.map((enumValue) => {
|
|
4610
|
+
const item = enumValue;
|
|
4611
|
+
if (item === undefined) {
|
|
4612
|
+
return jsx(Fragment, { children: "undefined" });
|
|
4613
|
+
}
|
|
4614
|
+
return (jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4615
|
+
? renderDisplay(item)
|
|
4616
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
4617
|
+
}) })), !isMultiple && (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.${watchEnum}`)) })), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4618
|
+
};
|
|
4619
|
+
|
|
4620
|
+
const FileViewer = ({ column, schema, prefix }) => {
|
|
4621
|
+
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4622
|
+
const { translate } = useSchemaContext();
|
|
4623
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4624
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4625
|
+
const currentFiles = (watch(column) ?? []);
|
|
4626
|
+
const colLabel = `${prefix}${column}`;
|
|
4627
|
+
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4628
|
+
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4629
|
+
setValue(colLabel, [...currentFiles, ...newFiles]);
|
|
4630
|
+
}, placeholder: translate.t(`${colLabel}.fileDropzone`) }), jsx(Flex, { flexFlow: "column", gap: 1, children: currentFiles.map((file) => {
|
|
4631
|
+
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4632
|
+
setValue(column, currentFiles.filter(({ name }) => {
|
|
4633
|
+
return name !== file.name;
|
|
4634
|
+
}));
|
|
4635
|
+
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4636
|
+
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4637
|
+
};
|
|
4638
|
+
|
|
4639
|
+
const IdViewer = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
4640
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4641
|
+
const { idMap, translate } = useSchemaContext();
|
|
4642
|
+
const { required, gridColumn, gridRow, renderDisplay, foreign_key } = schema;
|
|
4643
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4644
|
+
const { display_column } = foreign_key;
|
|
4645
|
+
const colLabel = `${prefix}${column}`;
|
|
4646
|
+
const watchId = watch(colLabel);
|
|
4647
|
+
const watchIds = (watch(colLabel) ?? []);
|
|
4648
|
+
const getPickedValue = () => {
|
|
4649
|
+
if (Object.keys(idMap).length <= 0) {
|
|
4650
|
+
return "";
|
|
4651
|
+
}
|
|
4652
|
+
const record = idMap[watchId];
|
|
4653
|
+
if (record === undefined) {
|
|
4654
|
+
return "";
|
|
4655
|
+
}
|
|
4656
|
+
return record[display_column];
|
|
4657
|
+
};
|
|
4658
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.fieldLabel`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4659
|
+
gridRow, children: [isMultiple && (jsx(Flex, { flexFlow: "wrap", gap: 1, children: watchIds.map((id) => {
|
|
4660
|
+
const item = idMap[id];
|
|
4661
|
+
if (item === undefined) {
|
|
4662
|
+
return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4663
|
+
}
|
|
4664
|
+
return (jsx(Tag, { closable: true, children: !!renderDisplay === true
|
|
4665
|
+
? renderDisplay(item)
|
|
4666
|
+
: item[display_column] }, id));
|
|
4667
|
+
}) })), !isMultiple && jsx(Text, { children: getPickedValue() }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4668
|
+
};
|
|
4669
|
+
|
|
4670
|
+
const NumberViewer = ({ schema, column, prefix, }) => {
|
|
4671
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4672
|
+
const { translate } = useSchemaContext();
|
|
4673
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4674
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4675
|
+
const colLabel = `${prefix}${column}`;
|
|
4676
|
+
const value = watch(colLabel);
|
|
4677
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(Text, { children: value }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4678
|
+
};
|
|
4679
|
+
|
|
4680
|
+
const ObjectViewer = ({ schema, column, prefix }) => {
|
|
4681
|
+
const { properties, gridRow, gridColumn = "1/span 12", required } = schema;
|
|
4682
|
+
const { translate } = useSchemaContext();
|
|
4683
|
+
const colLabel = `${prefix}${column}`;
|
|
4684
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4685
|
+
const { formState: { errors }, } = useFormContext();
|
|
4686
|
+
if (properties === undefined) {
|
|
4687
|
+
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4688
|
+
}
|
|
4689
|
+
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, isRequired && jsx("span", { children: "*" })] }), jsx(Grid, { gap: "4", padding: "4", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat("auto-fit", auto)`, children: Object.keys(properties ?? {}).map((key) => {
|
|
4690
|
+
return (
|
|
4691
|
+
// @ts-expect-error find suitable types
|
|
4692
|
+
jsx(ColumnViewer, { column: `${key}`,
|
|
4693
|
+
prefix: `${prefix}${column}.`,
|
|
4694
|
+
properties }, `form-objectviewer-${colLabel}-${key}`));
|
|
4695
|
+
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4696
|
+
};
|
|
4697
|
+
|
|
4698
|
+
const RecordInput = ({ column, schema, prefix }) => {
|
|
4699
|
+
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4700
|
+
const { translate } = useSchemaContext();
|
|
4701
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4702
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4703
|
+
const entries = Object.entries(getValues(column) ?? {});
|
|
4704
|
+
const [showNewEntries, setShowNewEntries] = useState(false);
|
|
4705
|
+
const [newKey, setNewKey] = useState();
|
|
4706
|
+
const [newValue, setNewValue] = useState();
|
|
4707
|
+
return (jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4708
|
+
return (jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: key, onChange: (e) => {
|
|
4709
|
+
const filtered = entries.filter(([target]) => {
|
|
4710
|
+
return target !== key;
|
|
4711
|
+
});
|
|
4712
|
+
setValue(column, Object.fromEntries([...filtered, [e.target.value, value]]));
|
|
4713
|
+
}, autoComplete: "off" }), jsx(Input, { value: value, onChange: (e) => {
|
|
4714
|
+
setValue(column, {
|
|
4715
|
+
...getValues(column),
|
|
4716
|
+
[key]: e.target.value,
|
|
4717
|
+
});
|
|
4718
|
+
}, autoComplete: "off" }), jsx(IconButton, { variant: "ghost", onClick: () => {
|
|
4719
|
+
const filtered = entries.filter(([target]) => {
|
|
4720
|
+
return target !== key;
|
|
4721
|
+
});
|
|
4722
|
+
setValue(column, Object.fromEntries([...filtered]));
|
|
4723
|
+
}, children: jsx(CgClose, {}) })] }));
|
|
4724
|
+
}), jsx(Show, { when: showNewEntries, children: jsxs(Card.Root, { children: [jsx(Card.Body, { gap: "2", children: jsxs(Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsx(Input, { value: newKey, onChange: (e) => {
|
|
4725
|
+
setNewKey(e.target.value);
|
|
4726
|
+
}, autoComplete: "off" }), jsx(Input, { value: newValue, onChange: (e) => {
|
|
4727
|
+
setNewValue(e.target.value);
|
|
4728
|
+
}, autoComplete: "off" })] }) }), jsxs(Card.Footer, { justifyContent: "flex-end", children: [jsx(IconButton, { variant: "subtle", onClick: () => {
|
|
4729
|
+
setShowNewEntries(false);
|
|
4730
|
+
setNewKey(undefined);
|
|
4731
|
+
setNewValue(undefined);
|
|
4732
|
+
}, children: jsx(CgClose, {}) }), jsx(Button, { onClick: () => {
|
|
4733
|
+
if (!!newKey === false) {
|
|
4734
|
+
setShowNewEntries(false);
|
|
4735
|
+
setNewKey(undefined);
|
|
4736
|
+
setNewValue(undefined);
|
|
4737
|
+
return;
|
|
4738
|
+
}
|
|
4739
|
+
setValue(column, Object.fromEntries([...entries, [newKey, newValue]]));
|
|
4740
|
+
setShowNewEntries(false);
|
|
4741
|
+
setNewKey(undefined);
|
|
4742
|
+
setNewValue(undefined);
|
|
4743
|
+
}, children: translate.t(`${column}.save`) })] })] }) }), jsx(Button, { onClick: () => {
|
|
4744
|
+
setShowNewEntries(true);
|
|
4745
|
+
setNewKey(undefined);
|
|
4746
|
+
setNewValue(undefined);
|
|
4747
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4748
|
+
};
|
|
4749
|
+
|
|
4750
|
+
const TagViewer = ({ column, schema, prefix }) => {
|
|
4751
|
+
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
4752
|
+
const { serverUrl } = useSchemaContext();
|
|
4753
|
+
if (schema.properties == undefined) {
|
|
4754
|
+
throw new Error("schema properties undefined when using DatePicker");
|
|
4755
|
+
}
|
|
4756
|
+
const { gridColumn, gridRow, in_table, object_id_column } = schema;
|
|
4757
|
+
if (in_table === undefined) {
|
|
4758
|
+
throw new Error("in_table is undefined when using TagPicker");
|
|
4759
|
+
}
|
|
4760
|
+
if (object_id_column === undefined) {
|
|
4761
|
+
throw new Error("object_id_column is undefined when using TagPicker");
|
|
4762
|
+
}
|
|
4763
|
+
const query = useQuery({
|
|
4764
|
+
queryKey: [`tagpicker`, in_table],
|
|
4765
|
+
queryFn: async () => {
|
|
4766
|
+
return await getTableData({
|
|
4767
|
+
serverUrl,
|
|
4768
|
+
in_table: "tables_tags_view",
|
|
4769
|
+
where: [
|
|
4770
|
+
{
|
|
4771
|
+
id: "table_name",
|
|
4772
|
+
value: [in_table],
|
|
4773
|
+
},
|
|
4774
|
+
],
|
|
4775
|
+
limit: 100,
|
|
4776
|
+
});
|
|
4777
|
+
},
|
|
4778
|
+
staleTime: 10000,
|
|
4779
|
+
});
|
|
4780
|
+
const object_id = watch(object_id_column);
|
|
4781
|
+
const existingTagsQuery = useQuery({
|
|
4782
|
+
queryKey: [`existing`, { in_table, object_id_column }, object_id],
|
|
4783
|
+
queryFn: async () => {
|
|
4784
|
+
return await getTableData({
|
|
4785
|
+
serverUrl,
|
|
4786
|
+
in_table: in_table,
|
|
4787
|
+
where: [
|
|
4788
|
+
{
|
|
4789
|
+
id: object_id_column,
|
|
4790
|
+
value: object_id[0],
|
|
4791
|
+
},
|
|
4792
|
+
],
|
|
4793
|
+
limit: 100,
|
|
4794
|
+
});
|
|
4795
|
+
},
|
|
4796
|
+
enabled: object_id != undefined,
|
|
4797
|
+
staleTime: 10000,
|
|
4798
|
+
});
|
|
4799
|
+
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
4800
|
+
const dataList = data?.data ?? [];
|
|
4801
|
+
const existingTagList = existingTagsQuery.data?.data ?? [];
|
|
4802
|
+
if (!!object_id === false) {
|
|
4803
|
+
return jsx(Fragment, {});
|
|
4804
|
+
}
|
|
4805
|
+
return (jsxs(Flex, { flexFlow: "column", gap: 4, gridColumn,
|
|
4806
|
+
gridRow, children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), dataList.map(({ parent_tag_name, all_tags, is_mutually_exclusive }) => {
|
|
4807
|
+
return (jsxs(Flex, { flexFlow: "column", gap: 2, children: [jsx(Text, { children: parent_tag_name }), is_mutually_exclusive && (jsx(RadioCardRoot, { defaultValue: "next", variant: "surface", onValueChange: (tagIds) => {
|
|
4808
|
+
const existedTags = Object.values(all_tags)
|
|
4809
|
+
.filter(({ id }) => {
|
|
4810
|
+
return existingTagList.some(({ tag_id }) => tag_id === id);
|
|
4811
|
+
})
|
|
4812
|
+
.map(({ id }) => {
|
|
4813
|
+
return id;
|
|
4814
|
+
});
|
|
4815
|
+
setValue(`${column}.${parent_tag_name}.current`, [
|
|
4816
|
+
tagIds.value,
|
|
4817
|
+
]);
|
|
4818
|
+
setValue(`${column}.${parent_tag_name}.old`, existedTags);
|
|
4819
|
+
}, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
|
|
4820
|
+
if (existingTagList.some(({ tag_id }) => tag_id === id)) {
|
|
4821
|
+
return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", disabled: true }, `${tagName}-${id}`));
|
|
4822
|
+
}
|
|
4823
|
+
return (jsx(RadioCardItem, { label: tagName, value: id, flex: "0 0 0%", colorPalette: "blue" }, `${tagName}-${id}`));
|
|
4824
|
+
}) }) })), !is_mutually_exclusive && (jsx(CheckboxGroup, { onValueChange: (tagIds) => {
|
|
4825
|
+
setValue(`${column}.${parent_tag_name}.current`, tagIds);
|
|
4826
|
+
}, children: jsx(Flex, { flexFlow: "wrap", gap: 2, children: Object.entries(all_tags).map(([tagName, { id }]) => {
|
|
4827
|
+
if (existingTagList.some(({ tag_id }) => tag_id === id)) {
|
|
4828
|
+
return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%", disabled: true, colorPalette: "blue" }, `${tagName}-${id}`));
|
|
4829
|
+
}
|
|
4830
|
+
return (jsx(CheckboxCard, { label: tagName, value: id, flex: "0 0 0%" }, `${tagName}-${id}`));
|
|
4831
|
+
}) }) }))] }, `tag-${parent_tag_name}`));
|
|
4832
|
+
}), errors[`${column}`] && (jsx(Text, { color: "red.400", children: (errors[`${column}`]?.message ?? "No error message") }))] }));
|
|
4833
|
+
};
|
|
4834
|
+
|
|
4835
|
+
const StringViewer = ({ column, schema, prefix, }) => {
|
|
4836
|
+
const { watch, formState: { errors }, } = useFormContext();
|
|
4837
|
+
const { translate } = useSchemaContext();
|
|
4838
|
+
const { required, gridColumn, gridRow } = schema;
|
|
4839
|
+
const isRequired = required?.some((columnId) => columnId === column);
|
|
4840
|
+
const colLabel = `${prefix}${column}`;
|
|
4841
|
+
const value = watch(colLabel);
|
|
4842
|
+
return (jsx(Fragment, { children: jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: value }), errors[colLabel] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }) }));
|
|
4843
|
+
};
|
|
4844
|
+
|
|
4845
|
+
const SchemaViewer = ({ schema, prefix, column, }) => {
|
|
4846
|
+
const colSchema = schema;
|
|
4847
|
+
const { type, variant, properties: innerProperties, foreign_key, items, } = schema;
|
|
4848
|
+
if (type === "string") {
|
|
4849
|
+
if ((schema.enum ?? []).length > 0) {
|
|
4850
|
+
return jsx(EnumViewer, { schema: colSchema, prefix, column });
|
|
4851
|
+
}
|
|
4852
|
+
if (variant === "id-picker") {
|
|
4853
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4854
|
+
return jsx(IdViewer, { schema: colSchema, prefix, column });
|
|
4855
|
+
}
|
|
4856
|
+
if (variant === "date-picker") {
|
|
4857
|
+
return jsx(DateViewer, { schema: colSchema, prefix, column });
|
|
4858
|
+
}
|
|
4859
|
+
return jsx(StringViewer, { schema: colSchema, prefix, column });
|
|
4860
|
+
}
|
|
4861
|
+
if (type === "number" || type === "integer") {
|
|
4862
|
+
return jsx(NumberViewer, { schema: colSchema, prefix, column });
|
|
4863
|
+
}
|
|
4864
|
+
if (type === "boolean") {
|
|
4865
|
+
return jsx(BooleanViewer, { schema: colSchema, prefix, column });
|
|
4866
|
+
}
|
|
4867
|
+
if (type === "object") {
|
|
4868
|
+
if (innerProperties) {
|
|
4869
|
+
return jsx(ObjectViewer, { schema: colSchema, prefix, column });
|
|
4870
|
+
}
|
|
4871
|
+
return jsx(RecordInput, { schema: colSchema, prefix, column });
|
|
4872
|
+
}
|
|
4873
|
+
if (type === "array") {
|
|
4874
|
+
if (variant === "id-picker") {
|
|
4875
|
+
idPickerSanityCheck(column, foreign_key);
|
|
4876
|
+
return (jsx(IdViewer, { schema: colSchema, prefix, column, isMultiple: true }));
|
|
4877
|
+
}
|
|
4878
|
+
if (variant === "tag-picker") {
|
|
4879
|
+
return jsx(TagViewer, { schema: colSchema, prefix, column });
|
|
4880
|
+
}
|
|
4881
|
+
if (variant === "file-picker") {
|
|
4882
|
+
return jsx(FileViewer, { schema: colSchema, prefix, column });
|
|
4883
|
+
}
|
|
4884
|
+
if (items) {
|
|
4885
|
+
return jsx(ArrayViewer, { schema: colSchema, prefix, column });
|
|
4886
|
+
}
|
|
4887
|
+
return jsx(Text, { children: `array ${column}` });
|
|
4888
|
+
}
|
|
4889
|
+
if (type === "null") {
|
|
4890
|
+
return jsx(Text, { children: `null ${column}` });
|
|
4891
|
+
}
|
|
4892
|
+
return jsx(Text, { children: "missing type" });
|
|
4893
|
+
};
|
|
4894
|
+
|
|
4895
|
+
const ColumnViewer = ({ column, properties, prefix, }) => {
|
|
4896
|
+
if (properties === undefined) {
|
|
4897
|
+
return jsx(Fragment, {});
|
|
4898
|
+
}
|
|
4899
|
+
const colSchema = properties[column];
|
|
4900
|
+
if (colSchema === undefined) {
|
|
4901
|
+
throw new Error(`${column} does not exist when using ColumnRenderer`);
|
|
4902
|
+
}
|
|
4903
|
+
return jsx(SchemaViewer, { schema: colSchema, prefix, column });
|
|
4904
|
+
};
|
|
4905
|
+
|
|
4555
4906
|
const idPickerSanityCheck = (column, foreign_key) => {
|
|
4556
4907
|
if (!!foreign_key == false) {
|
|
4557
4908
|
throw new Error(`The key foreign_key does not exist in properties of column ${column} when using id-picker.`);
|
|
@@ -4568,7 +4919,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4568
4919
|
}
|
|
4569
4920
|
};
|
|
4570
4921
|
const FormInternal = () => {
|
|
4571
|
-
const { schema, requestUrl, order,
|
|
4922
|
+
const { schema, requestUrl, order, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4572
4923
|
const methods = useFormContext();
|
|
4573
4924
|
const [isSuccess, setIsSuccess] = useState(false);
|
|
4574
4925
|
const [isError, setIsError] = useState(false);
|
|
@@ -4632,19 +4983,8 @@ const FormInternal = () => {
|
|
|
4632
4983
|
return [...order, ...not_exist];
|
|
4633
4984
|
};
|
|
4634
4985
|
const ordered = renderOrder(order, Object.keys(properties));
|
|
4635
|
-
const getDataListProps = (value) => {
|
|
4636
|
-
if (value == undefined || value.length <= 0) {
|
|
4637
|
-
return {
|
|
4638
|
-
value: `<${translate.t("empty") ?? "Empty"}>`,
|
|
4639
|
-
color: "gray.400",
|
|
4640
|
-
};
|
|
4641
|
-
}
|
|
4642
|
-
return {
|
|
4643
|
-
value: value,
|
|
4644
|
-
};
|
|
4645
|
-
};
|
|
4646
4986
|
if (isSuccess) {
|
|
4647
|
-
return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent:
|
|
4987
|
+
return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button, { onClick: () => {
|
|
4648
4988
|
setIsError(false);
|
|
4649
4989
|
setIsSubmiting(false);
|
|
4650
4990
|
setIsSuccess(false);
|
|
@@ -4654,101 +4994,29 @@ const FormInternal = () => {
|
|
|
4654
4994
|
}, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
|
|
4655
4995
|
}
|
|
4656
4996
|
if (isConfirming) {
|
|
4657
|
-
return (jsxs(Grid, { gap: 2, children: [jsxs(Heading, { children: [" ", translate.t("title")] }), jsx(
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
const shouldIgnore = ignore.some((column) => {
|
|
4664
|
-
return column == key;
|
|
4665
|
-
});
|
|
4666
|
-
if (shouldIgnore) {
|
|
4667
|
-
return jsx(Fragment, {});
|
|
4668
|
-
}
|
|
4669
|
-
const { type, variant, gridColumn, gridRow, foreign_key } = values;
|
|
4670
|
-
if (type === "string") {
|
|
4671
|
-
if (variant === "id-picker") {
|
|
4672
|
-
idPickerSanityCheck(column, foreign_key);
|
|
4673
|
-
return (jsx(IdViewer, { value: (validatedData ?? {})[column], column,
|
|
4674
|
-
dataListItemProps: { gridColumn, gridRow } }, `form-${key}`));
|
|
4675
|
-
}
|
|
4676
|
-
if (variant === "date-picker") {
|
|
4677
|
-
const value = (validatedData ?? {})[column];
|
|
4678
|
-
if (!!value === false) {
|
|
4679
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4680
|
-
}
|
|
4681
|
-
const date = dayjs(value).format("YYYY-MM-DD");
|
|
4682
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(date) }, `form-${key}`));
|
|
4683
|
-
}
|
|
4684
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4685
|
-
}
|
|
4686
|
-
if (type === "object") {
|
|
4687
|
-
const value = (validatedData ?? {})[column];
|
|
4688
|
-
if (!!value === false) {
|
|
4689
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4690
|
-
}
|
|
4691
|
-
return (jsxs(Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: translate.t(`input.${column}`) }), jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
|
|
4692
|
-
return (jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
4693
|
-
}) })] }, `form-${key}`));
|
|
4694
|
-
}
|
|
4695
|
-
if (type === "boolean") {
|
|
4696
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4697
|
-
}
|
|
4698
|
-
if (type === "number" || type === "integer") {
|
|
4699
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4700
|
-
}
|
|
4701
|
-
if (type === "array") {
|
|
4702
|
-
if (variant === "tag-picker") {
|
|
4703
|
-
const value = (validatedData ?? {})[column];
|
|
4704
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
|
|
4705
|
-
}
|
|
4706
|
-
if (variant === "file-picker") {
|
|
4707
|
-
const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
|
|
4708
|
-
return file.name;
|
|
4709
|
-
});
|
|
4710
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
|
|
4711
|
-
}
|
|
4712
|
-
if (variant === "id-picker") {
|
|
4713
|
-
const value = (validatedData ?? {})[column];
|
|
4714
|
-
if (schema.properties == undefined) {
|
|
4715
|
-
throw new Error("schema properties when using DatePicker");
|
|
4716
|
-
}
|
|
4717
|
-
const { foreign_key } = schema.properties[column];
|
|
4718
|
-
if (foreign_key === undefined) {
|
|
4719
|
-
throw new Error("foreign_key when variant is id-picker");
|
|
4720
|
-
}
|
|
4721
|
-
const { display_column } = foreign_key;
|
|
4722
|
-
const mapped = value.map((item) => {
|
|
4723
|
-
return idMap[item][display_column];
|
|
4724
|
-
});
|
|
4725
|
-
return (jsxs(Grid, { flexFlow: "column", gridColumn,
|
|
4726
|
-
gridRow, children: [jsx(Text, { children: translate.t(`input.${column}`) }), jsx(RecordDisplay, { object: mapped })] }, `form-${key}`));
|
|
4727
|
-
}
|
|
4728
|
-
const objectString = JSON.stringify((validatedData ?? {})[column]);
|
|
4729
|
-
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(objectString) }, `form-${key}`));
|
|
4730
|
-
}
|
|
4731
|
-
if (type === "null") {
|
|
4732
|
-
return jsx(Fragment, { children: `null ${column}` });
|
|
4733
|
-
}
|
|
4734
|
-
return jsx(Fragment, { children: `unknown type ${column}` });
|
|
4997
|
+
return (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) => {
|
|
4998
|
+
return (jsx(ColumnViewer
|
|
4999
|
+
// @ts-expect-error find suitable types
|
|
5000
|
+
, {
|
|
5001
|
+
// @ts-expect-error find suitable types
|
|
5002
|
+
properties: properties, prefix: ``, column }, `form-viewer-${column}`));
|
|
4735
5003
|
}) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
|
|
4736
5004
|
setIsConfirming(false);
|
|
4737
5005
|
}, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
|
|
4738
5006
|
onFormSubmit(validatedData);
|
|
4739
5007
|
}, children: translate.t("confirm") })] }), 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)}` })] }) }) }) }) }))] }));
|
|
4740
5008
|
}
|
|
4741
|
-
return (
|
|
4742
|
-
|
|
5009
|
+
return (jsx(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) => {
|
|
5010
|
+
return (jsx(ColumnRenderer
|
|
5011
|
+
// @ts-expect-error find suitable types
|
|
5012
|
+
, {
|
|
4743
5013
|
// @ts-expect-error find suitable types
|
|
4744
|
-
, {
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
methods.handleSubmit(onValid)();
|
|
4751
|
-
}, formNoValidate: true, children: translate.t("submit") })] })] }), isError && (jsxs(Fragment, { children: ["isError", jsxs(Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
5014
|
+
properties: properties, prefix: ``, column }, `form-input-${column}`));
|
|
5015
|
+
}) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
|
|
5016
|
+
methods.reset();
|
|
5017
|
+
}, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {
|
|
5018
|
+
methods.handleSubmit(onValid)();
|
|
5019
|
+
}, formNoValidate: true, children: translate.t("submit") })] })] }) }));
|
|
4752
5020
|
};
|
|
4753
5021
|
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
|
|
4754
5022
|
const { properties } = schema;
|