@bsol-oss/react-datatable5 11.0.0-beta.5 → 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 +425 -59
- package/dist/index.mjs +426 -60
- package/dist/types/components/Form/Form.d.ts +1 -1
- 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
|
@@ -27,7 +27,7 @@ import { GrAscend, GrDescend } from 'react-icons/gr';
|
|
|
27
27
|
import { HiColorSwatch } from 'react-icons/hi';
|
|
28
28
|
import { useTranslation } from 'react-i18next';
|
|
29
29
|
import axios from 'axios';
|
|
30
|
-
import { useFormContext,
|
|
30
|
+
import { useFormContext, FormProvider, useForm as useForm$1 } from 'react-hook-form';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
32
|
import { TiDeleteOutline } from 'react-icons/ti';
|
|
33
33
|
|
|
@@ -3578,23 +3578,40 @@ const AccordionItemContent = React.forwardRef(function AccordionItemContent(prop
|
|
|
3578
3578
|
const AccordionRoot = Accordion.Root;
|
|
3579
3579
|
const AccordionItem = Accordion.Item;
|
|
3580
3580
|
|
|
3581
|
+
function removeIndex(str) {
|
|
3582
|
+
return str.replace(/\.\d+\./g, '.');
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3581
3585
|
const ArrayRenderer = ({ schema, column, prefix, }) => {
|
|
3582
3586
|
const { gridRow, gridColumn = "1/span 12", required, items } = schema;
|
|
3587
|
+
// @ts-expect-error TODO: find suitable types
|
|
3588
|
+
const { type } = items;
|
|
3583
3589
|
const { translate } = useSchemaContext();
|
|
3584
3590
|
const colLabel = `${prefix}${column}`;
|
|
3585
3591
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3586
|
-
const { formState: { errors },
|
|
3587
|
-
const
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
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`)) }))] }));
|
|
3598
3615
|
};
|
|
3599
3616
|
|
|
3600
3617
|
const Field = React.forwardRef(function Field(props, ref) {
|
|
@@ -3609,10 +3626,10 @@ const BooleanPicker = ({ schema, column, prefix }) => {
|
|
|
3609
3626
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3610
3627
|
const colLabel = `${prefix}${column}`;
|
|
3611
3628
|
const value = watch(colLabel);
|
|
3612
|
-
return (jsxs(Field, { label: `${translate.t(`${colLabel}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3613
|
-
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: () => {
|
|
3614
3631
|
setValue(colLabel, !value);
|
|
3615
|
-
} }), 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`)) }))] }));
|
|
3616
3633
|
};
|
|
3617
3634
|
|
|
3618
3635
|
const monthNamesShort = [
|
|
@@ -3710,7 +3727,7 @@ const DatePicker = ({ column, schema, prefix }) => {
|
|
|
3710
3727
|
const colLabel = `${prefix}${column}`;
|
|
3711
3728
|
const [open, setOpen] = useState(false);
|
|
3712
3729
|
const selectedDate = watch(colLabel);
|
|
3713
|
-
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,
|
|
3714
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: () => {
|
|
3715
3732
|
setOpen(true);
|
|
3716
3733
|
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
@@ -3720,9 +3737,9 @@ const DatePicker = ({ column, schema, prefix }) => {
|
|
|
3720
3737
|
selected: new Date(selectedDate),
|
|
3721
3738
|
// @ts-expect-error TODO: find appropriate types
|
|
3722
3739
|
onDateSelected: ({ date }) => {
|
|
3723
|
-
setValue(
|
|
3740
|
+
setValue(colLabel, dayjs(date).format("YYYY-MM-DD"));
|
|
3724
3741
|
setOpen(false);
|
|
3725
|
-
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${
|
|
3742
|
+
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
3726
3743
|
};
|
|
3727
3744
|
|
|
3728
3745
|
function filterArray(array, searchTerm) {
|
|
@@ -3745,8 +3762,9 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3745
3762
|
const [limit, setLimit] = useState(10);
|
|
3746
3763
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
3747
3764
|
const ref = useRef(null);
|
|
3748
|
-
const
|
|
3749
|
-
const
|
|
3765
|
+
const colLabel = `${prefix}${column}`;
|
|
3766
|
+
const watchEnum = watch(colLabel);
|
|
3767
|
+
const watchEnums = (watch(colLabel) ?? []);
|
|
3750
3768
|
const dataList = schema.enum ?? [];
|
|
3751
3769
|
const count = schema.enum?.length ?? 0;
|
|
3752
3770
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
@@ -3754,8 +3772,7 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3754
3772
|
setSearchText(event.target.value);
|
|
3755
3773
|
setLimit(10);
|
|
3756
3774
|
};
|
|
3757
|
-
|
|
3758
|
-
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,
|
|
3759
3776
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3760
3777
|
const item = enumValue;
|
|
3761
3778
|
if (item === undefined) {
|
|
@@ -3764,12 +3781,16 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3764
3781
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
3765
3782
|
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3766
3783
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3767
|
-
}, children: !!renderDisplay === true
|
|
3784
|
+
}, children: !!renderDisplay === true
|
|
3785
|
+
? renderDisplay(item)
|
|
3786
|
+
: translate.t(removeIndex(`${colLabel}.${item}`)) }));
|
|
3768
3787
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3769
3788
|
setOpenSearchResult(true);
|
|
3770
|
-
}, children:
|
|
3789
|
+
}, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
3771
3790
|
setOpenSearchResult(true);
|
|
3772
|
-
}, 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) => {
|
|
3773
3794
|
onSearchChange(event);
|
|
3774
3795
|
setOpenSearchResult(true);
|
|
3775
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) => {
|
|
@@ -3779,15 +3800,15 @@ const EnumPicker = ({ column, isMultiple = false, schema, prefix, }) => {
|
|
|
3779
3800
|
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
3780
3801
|
if (!isMultiple) {
|
|
3781
3802
|
setOpenSearchResult(false);
|
|
3782
|
-
setValue(
|
|
3803
|
+
setValue(colLabel, item);
|
|
3783
3804
|
return;
|
|
3784
3805
|
}
|
|
3785
3806
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3786
|
-
setValue(
|
|
3807
|
+
setValue(colLabel, [...newSet]);
|
|
3787
3808
|
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3788
3809
|
? renderDisplay(item)
|
|
3789
|
-
: translate.t(`${
|
|
3790
|
-
}) }), 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`)) }))] }));
|
|
3791
3812
|
};
|
|
3792
3813
|
|
|
3793
3814
|
function isEnteringWindow(_ref) {
|
|
@@ -4148,17 +4169,17 @@ const FilePicker = ({ column, schema, prefix }) => {
|
|
|
4148
4169
|
const { required, gridColumn, gridRow } = schema;
|
|
4149
4170
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4150
4171
|
const currentFiles = (watch(column) ?? []);
|
|
4151
|
-
const
|
|
4152
|
-
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 }) => {
|
|
4153
4174
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4154
|
-
setValue(
|
|
4155
|
-
}, 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) => {
|
|
4156
4177
|
return (jsx(Card.Root, { variant: "subtle", children: jsxs(Card.Body, { gap: "2", cursor: "pointer", onClick: () => {
|
|
4157
4178
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4158
4179
|
return name !== file.name;
|
|
4159
4180
|
}));
|
|
4160
4181
|
}, display: "flex", flexFlow: "row", alignItems: "center", padding: "2", children: [jsx(Box, { children: file.name }), jsx(TiDeleteOutline, {})] }) }, file.name));
|
|
4161
|
-
}) }), errors[`${
|
|
4182
|
+
}) }), errors[`${colLabel}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4162
4183
|
};
|
|
4163
4184
|
|
|
4164
4185
|
const getTableData = async ({ serverUrl, in_table, searching = "", where = [], limit = 10, offset = 0, }) => {
|
|
@@ -4200,7 +4221,6 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4200
4221
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
4201
4222
|
const [page, setPage] = useState(0);
|
|
4202
4223
|
const ref = useRef(null);
|
|
4203
|
-
const selectedIds = watch(column) ?? [];
|
|
4204
4224
|
const colLabel = `${prefix}${column}`;
|
|
4205
4225
|
const query = useQuery({
|
|
4206
4226
|
queryKey: [`idpicker`, { column, searchText, limit, page }],
|
|
@@ -4237,8 +4257,8 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4237
4257
|
setPage(0);
|
|
4238
4258
|
setLimit(10);
|
|
4239
4259
|
};
|
|
4240
|
-
const watchId = watch(
|
|
4241
|
-
const watchIds = (watch(
|
|
4260
|
+
const watchId = watch(colLabel);
|
|
4261
|
+
const watchIds = (watch(colLabel) ?? []);
|
|
4242
4262
|
const getPickedValue = () => {
|
|
4243
4263
|
if (Object.keys(idMap).length <= 0) {
|
|
4244
4264
|
return "";
|
|
@@ -4249,11 +4269,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4249
4269
|
}
|
|
4250
4270
|
return record[display_column];
|
|
4251
4271
|
};
|
|
4252
|
-
return (jsxs(Field, { label: `${translate.t(`${
|
|
4253
|
-
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) => {
|
|
4254
4274
|
const item = idMap[id];
|
|
4255
4275
|
if (item === undefined) {
|
|
4256
|
-
return (
|
|
4276
|
+
return (jsx(Text, { children: translate.t(removeIndex(`${colLabel}.undefined`)) }, id));
|
|
4257
4277
|
}
|
|
4258
4278
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
4259
4279
|
setValue(column, watchIds.filter((id) => id != item[column_ref]));
|
|
@@ -4262,12 +4282,12 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4262
4282
|
: item[display_column] }, id));
|
|
4263
4283
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4264
4284
|
setOpenSearchResult(true);
|
|
4265
|
-
}, children: translate.t(`${colLabel}.addMore`) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4285
|
+
}, children: translate.t(removeIndex(`${colLabel}.addMore`)) })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
4266
4286
|
setOpenSearchResult(true);
|
|
4267
|
-
}, 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) => {
|
|
4268
4288
|
onSearchChange(event);
|
|
4269
4289
|
setOpenSearchResult(true);
|
|
4270
|
-
}, 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:
|
|
4271
4291
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4272
4292
|
dataList.map((item) => {
|
|
4273
4293
|
const selected = isMultiple
|
|
@@ -4283,11 +4303,11 @@ const IdPicker = ({ column, schema, prefix, isMultiple = false, }) => {
|
|
|
4283
4303
|
...(watchIds ?? []),
|
|
4284
4304
|
item[column_ref],
|
|
4285
4305
|
]);
|
|
4286
|
-
setValue(
|
|
4306
|
+
setValue(colLabel, [...newSet]);
|
|
4287
4307
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
4288
4308
|
? renderDisplay(item)
|
|
4289
4309
|
: item[display_column] }, item[column_ref]));
|
|
4290
|
-
}) }), 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`)) }))] }));
|
|
4291
4311
|
};
|
|
4292
4312
|
|
|
4293
4313
|
const NumberInputRoot = React.forwardRef(function NumberInput$1(props, ref) {
|
|
@@ -4299,12 +4319,12 @@ NumberInput.Scrubber;
|
|
|
4299
4319
|
NumberInput.Label;
|
|
4300
4320
|
|
|
4301
4321
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4302
|
-
const { register, formState: { errors }, } = useFormContext();
|
|
4322
|
+
const { register, formState: { errors }, watch } = useFormContext();
|
|
4303
4323
|
const { translate } = useSchemaContext();
|
|
4304
4324
|
const { required, gridColumn, gridRow } = schema;
|
|
4305
4325
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4306
4326
|
const colLabel = `${prefix}${column}`;
|
|
4307
|
-
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`)) }))] }));
|
|
4308
4328
|
};
|
|
4309
4329
|
|
|
4310
4330
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
@@ -4312,20 +4332,20 @@ const ObjectInput = ({ schema, column, prefix }) => {
|
|
|
4312
4332
|
const { translate } = useSchemaContext();
|
|
4313
4333
|
const colLabel = `${prefix}${column}`;
|
|
4314
4334
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4315
|
-
const {
|
|
4335
|
+
const { formState: { errors }, } = useFormContext();
|
|
4316
4336
|
if (properties === undefined) {
|
|
4317
4337
|
throw new Error(`properties is undefined when using ObjectInput`);
|
|
4318
4338
|
}
|
|
4319
|
-
return (jsxs(Box, { gridRow, gridColumn, children: [jsxs(Box, { as: "label", gridColumn: "1/span12", children: [`${translate.t(`${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) => {
|
|
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) => {
|
|
4320
4340
|
return (
|
|
4321
4341
|
// @ts-expect-error find suitable types
|
|
4322
4342
|
jsx(ColumnRenderer, { column: `${key}`,
|
|
4323
4343
|
prefix: `${prefix}${column}.`,
|
|
4324
|
-
properties }, `form-${
|
|
4325
|
-
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${colLabel}.fieldRequired`) }))] }));
|
|
4344
|
+
properties }, `form-${colLabel}-${key}`));
|
|
4345
|
+
}) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4326
4346
|
};
|
|
4327
4347
|
|
|
4328
|
-
const RecordInput = ({ column, schema, prefix }) => {
|
|
4348
|
+
const RecordInput$1 = ({ column, schema, prefix }) => {
|
|
4329
4349
|
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
4330
4350
|
const { translate } = useSchemaContext();
|
|
4331
4351
|
const { required, gridColumn, gridRow } = schema;
|
|
@@ -4383,7 +4403,7 @@ const StringInputField = ({ column, schema, prefix, }) => {
|
|
|
4383
4403
|
const { required, gridColumn, gridRow } = schema;
|
|
4384
4404
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4385
4405
|
const colLabel = `${prefix}${column}`;
|
|
4386
|
-
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`)) }))] }) }));
|
|
4387
4407
|
};
|
|
4388
4408
|
|
|
4389
4409
|
const RadioCardItem = React.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4507,7 +4527,7 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4507
4527
|
if (innerProperties) {
|
|
4508
4528
|
return jsx(ObjectInput, { schema: colSchema, prefix, column });
|
|
4509
4529
|
}
|
|
4510
|
-
return jsx(RecordInput, { schema: colSchema, prefix, column });
|
|
4530
|
+
return jsx(RecordInput$1, { schema: colSchema, prefix, column });
|
|
4511
4531
|
}
|
|
4512
4532
|
if (type === "array") {
|
|
4513
4533
|
if (variant === "id-picker") {
|
|
@@ -4532,15 +4552,355 @@ const SchemaRenderer = ({ schema, prefix, column, }) => {
|
|
|
4532
4552
|
};
|
|
4533
4553
|
|
|
4534
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, }) => {
|
|
4535
4896
|
if (properties === undefined) {
|
|
4536
4897
|
return jsx(Fragment, {});
|
|
4537
4898
|
}
|
|
4538
|
-
console.log(`${column} does not exist when using ColumnRenderer`, { properties, column, prefix }, "fdpok");
|
|
4539
4899
|
const colSchema = properties[column];
|
|
4540
4900
|
if (colSchema === undefined) {
|
|
4541
4901
|
throw new Error(`${column} does not exist when using ColumnRenderer`);
|
|
4542
4902
|
}
|
|
4543
|
-
return jsx(
|
|
4903
|
+
return jsx(SchemaViewer, { schema: colSchema, prefix, column });
|
|
4544
4904
|
};
|
|
4545
4905
|
|
|
4546
4906
|
const idPickerSanityCheck = (column, foreign_key) => {
|
|
@@ -4559,7 +4919,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4559
4919
|
}
|
|
4560
4920
|
};
|
|
4561
4921
|
const FormInternal = () => {
|
|
4562
|
-
const { schema, requestUrl, order,
|
|
4922
|
+
const { schema, requestUrl, order, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4563
4923
|
const methods = useFormContext();
|
|
4564
4924
|
const [isSuccess, setIsSuccess] = useState(false);
|
|
4565
4925
|
const [isError, setIsError] = useState(false);
|
|
@@ -4634,7 +4994,13 @@ const FormInternal = () => {
|
|
|
4634
4994
|
}, formNoValidate: true, children: translate.t("submitAgain") }) })] }));
|
|
4635
4995
|
}
|
|
4636
4996
|
if (isConfirming) {
|
|
4637
|
-
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:
|
|
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}`));
|
|
5003
|
+
}) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
|
|
4638
5004
|
setIsConfirming(false);
|
|
4639
5005
|
}, variant: "subtle", children: translate.t("cancel") }), jsx(Button, { onClick: () => {
|
|
4640
5006
|
onFormSubmit(validatedData);
|
|
@@ -4645,7 +5011,7 @@ const FormInternal = () => {
|
|
|
4645
5011
|
// @ts-expect-error find suitable types
|
|
4646
5012
|
, {
|
|
4647
5013
|
// @ts-expect-error find suitable types
|
|
4648
|
-
properties: properties, prefix: ``, column }, `form-${column}`));
|
|
5014
|
+
properties: properties, prefix: ``, column }, `form-input-${column}`));
|
|
4649
5015
|
}) }), jsxs(Flex, { justifyContent: "end", gap: "2", children: [jsx(Button, { onClick: () => {
|
|
4650
5016
|
methods.reset();
|
|
4651
5017
|
}, variant: "subtle", children: translate.t("reset") }), jsx(Button, { onClick: () => {
|