@bsol-oss/react-datatable5 8.1.2 → 9.0.1
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 +22 -22
- package/dist/index.js +122 -116
- package/dist/index.mjs +125 -120
- package/dist/types/components/Form/Form.d.ts +8 -20
- package/dist/types/components/Form/SchemaFormContext.d.ts +2 -2
- package/dist/types/components/Form/components/IdViewer.d.ts +1 -3
- package/dist/types/components/Form/useForm.d.ts +12 -0
- package/dist/types/components/Form/useSchemaContext.d.ts +1 -1
- package/dist/types/components/ui/hover-card.d.ts +11 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var hi = require('react-icons/hi');
|
|
|
29
29
|
var axios = require('axios');
|
|
30
30
|
var reactHookForm = require('react-hook-form');
|
|
31
31
|
var dayjs = require('dayjs');
|
|
32
|
+
var reactI18next = require('react-i18next');
|
|
32
33
|
|
|
33
34
|
function _interopNamespaceDefault(e) {
|
|
34
35
|
var n = Object.create(null);
|
|
@@ -3559,7 +3560,7 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
|
3559
3560
|
});
|
|
3560
3561
|
|
|
3561
3562
|
const useSchemaContext = () => {
|
|
3562
|
-
const { schema, serverUrl, order, ignore, onSubmit, rowNumber,
|
|
3563
|
+
const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, } = React.useContext(SchemaFormContext);
|
|
3563
3564
|
return {
|
|
3564
3565
|
schema,
|
|
3565
3566
|
serverUrl,
|
|
@@ -3567,9 +3568,9 @@ const useSchemaContext = () => {
|
|
|
3567
3568
|
ignore,
|
|
3568
3569
|
onSubmit,
|
|
3569
3570
|
rowNumber,
|
|
3570
|
-
displayText,
|
|
3571
3571
|
idMap,
|
|
3572
3572
|
setIdMap,
|
|
3573
|
+
translate,
|
|
3573
3574
|
};
|
|
3574
3575
|
};
|
|
3575
3576
|
|
|
@@ -3607,16 +3608,13 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
3607
3608
|
|
|
3608
3609
|
const IdPicker = ({ column, isMultiple = false }) => {
|
|
3609
3610
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3610
|
-
const { schema, serverUrl,
|
|
3611
|
-
const { fieldRequired } = displayText;
|
|
3611
|
+
const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
3612
3612
|
const { required } = schema;
|
|
3613
3613
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3614
3614
|
if (schema.properties == undefined) {
|
|
3615
|
-
throw new Error("schema properties when using DatePicker");
|
|
3615
|
+
throw new Error("schema properties is undefined when using DatePicker");
|
|
3616
3616
|
}
|
|
3617
|
-
const {
|
|
3618
|
-
const { gridColumn, gridRow, title, renderDisplay, foreign_key } = schema
|
|
3619
|
-
.properties[column];
|
|
3617
|
+
const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
|
|
3620
3618
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
3621
3619
|
const [searchText, setSearchText] = React.useState();
|
|
3622
3620
|
const [limit, setLimit] = React.useState(10);
|
|
@@ -3671,7 +3669,7 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3671
3669
|
}
|
|
3672
3670
|
return record[display_column];
|
|
3673
3671
|
};
|
|
3674
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3672
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3675
3673
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
3676
3674
|
const item = idMap[id];
|
|
3677
3675
|
if (item === undefined) {
|
|
@@ -3686,10 +3684,10 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3686
3684
|
setOpenSearchResult(true);
|
|
3687
3685
|
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3688
3686
|
setOpenSearchResult(true);
|
|
3689
|
-
}, children: getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: typeToSearch
|
|
3687
|
+
}, children: getPickedValue() })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start", strategy: "fixed" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
|
|
3690
3688
|
onSearchChange(event);
|
|
3691
3689
|
setOpenSearchResult(true);
|
|
3692
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), jsxRuntime.jsx(react.Text, { justifySelf: "center", children: `${total
|
|
3690
|
+
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), (searchText?.length ?? 0) > 0 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isFetching && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isFetching" }), isLoading && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isLoading" }), isPending && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isPending" }), isError && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "isError" }), jsxRuntime.jsx(react.Text, { justifySelf: "center", children: `${translate.t(`${column}.total`)} ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children:
|
|
3693
3691
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3694
3692
|
dataList.map((item) => {
|
|
3695
3693
|
const selected = isMultiple
|
|
@@ -3709,49 +3707,33 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3709
3707
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3710
3708
|
? renderDisplay(item)
|
|
3711
3709
|
: item[display_column] }, item[column_ref]));
|
|
3712
|
-
}) }), isDirty && (jsxRuntime.
|
|
3710
|
+
}) }), isDirty && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: dataList.length <= 0 && (jsxRuntime.jsx(react.Text, { children: translate.t(`${column}.emptySearchResult`) })) }))] }), jsxRuntime.jsx(PaginationRoot, { justifySelf: "center", count: query?.data?.count ?? 0, pageSize: 10, defaultPage: 1, page: page + 1, onPageChange: (e) => setPage(e.page - 1), children: jsxRuntime.jsxs(react.HStack, { gap: "4", children: [jsxRuntime.jsx(PaginationPrevTrigger, {}), jsxRuntime.jsx(PaginationPageText, {}), jsxRuntime.jsx(PaginationNextTrigger, {})] }) })] }))] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3713
3711
|
};
|
|
3714
3712
|
|
|
3715
|
-
const
|
|
3716
|
-
const {
|
|
3717
|
-
return (jsxRuntime.
|
|
3718
|
-
});
|
|
3719
|
-
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
3720
|
-
const { children, ...rest } = props;
|
|
3721
|
-
return (jsxRuntime.jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "gray", children: jsxRuntime.jsx(hi.HiOutlineInformationCircle, {}) }) }));
|
|
3713
|
+
const HoverCardContent = React__namespace.forwardRef(function HoverCardContent(props, ref) {
|
|
3714
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
3715
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.HoverCard.Positioner, { children: jsxRuntime.jsx(react.HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3722
3716
|
});
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
const DataListItem = React__namespace.forwardRef(function DataListItem(props, ref) {
|
|
3726
|
-
const { label, info, value, children, grow, ...rest } = props;
|
|
3727
|
-
return (jsxRuntime.jsxs(react.DataList.Item, { ref: ref, ...rest, children: [jsxRuntime.jsxs(react.DataList.ItemLabel, { flex: grow ? "1" : undefined, children: [label, info && jsxRuntime.jsx(InfoTip, { children: info })] }), jsxRuntime.jsx(react.DataList.ItemValue, { flex: grow ? "1" : undefined, children: value }), children] }));
|
|
3717
|
+
const HoverCardArrow = React__namespace.forwardRef(function HoverCardArrow(props, ref) {
|
|
3718
|
+
return (jsxRuntime.jsx(react.HoverCard.Arrow, { ref: ref, ...props, children: jsxRuntime.jsx(react.HoverCard.ArrowTip, {}) }));
|
|
3728
3719
|
});
|
|
3720
|
+
const HoverCardRoot = react.HoverCard.Root;
|
|
3721
|
+
const HoverCardTrigger = react.HoverCard.Trigger;
|
|
3729
3722
|
|
|
3730
|
-
const IdViewer = ({ value, column
|
|
3731
|
-
const { schema, idMap } = useSchemaContext();
|
|
3723
|
+
const IdViewer = ({ value, column }) => {
|
|
3724
|
+
const { schema, idMap, translate } = useSchemaContext();
|
|
3732
3725
|
if (schema.properties == undefined) {
|
|
3733
3726
|
throw new Error("schema properties when using DatePicker");
|
|
3734
3727
|
}
|
|
3735
|
-
const {
|
|
3728
|
+
const { foreign_key } = schema.properties[column];
|
|
3736
3729
|
if (foreign_key === undefined) {
|
|
3737
3730
|
throw new Error("foreign_key when variant is id-picker");
|
|
3738
3731
|
}
|
|
3739
3732
|
const { display_column } = foreign_key;
|
|
3740
|
-
const getDataListProps = (value) => {
|
|
3741
|
-
if (value == undefined || value.length <= 0) {
|
|
3742
|
-
return {
|
|
3743
|
-
value: "<empty>",
|
|
3744
|
-
color: "gray.400",
|
|
3745
|
-
};
|
|
3746
|
-
}
|
|
3747
|
-
return {
|
|
3748
|
-
value: value,
|
|
3749
|
-
};
|
|
3750
|
-
};
|
|
3751
3733
|
if (value === undefined) {
|
|
3752
|
-
return jsxRuntime.jsx(jsxRuntime.
|
|
3734
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", children: [jsxRuntime.jsx(react.Text, { children: translate.t(`${column}.fieldLabel`) }), jsxRuntime.jsx(react.Text, { children: translate.t(`empty`) })] }));
|
|
3753
3735
|
}
|
|
3754
|
-
return (jsxRuntime.
|
|
3736
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", children: [jsxRuntime.jsx(react.Text, { children: translate.t(`${column}.fieldLabel`) }), jsxRuntime.jsxs(HoverCardRoot, { children: [jsxRuntime.jsx(HoverCardTrigger, { asChild: true, children: jsxRuntime.jsx(react.Text, { cursor: 'pointer', children: idMap[value][display_column] }) }), jsxRuntime.jsxs(HoverCardContent, { children: [jsxRuntime.jsx(HoverCardArrow, {}), jsxRuntime.jsx(RecordDisplay, { object: idMap[value] })] })] })] }));
|
|
3755
3737
|
};
|
|
3756
3738
|
|
|
3757
3739
|
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
@@ -3764,28 +3746,26 @@ react.NumberInput.Label;
|
|
|
3764
3746
|
|
|
3765
3747
|
const NumberInputField = ({ column }) => {
|
|
3766
3748
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3767
|
-
const { schema,
|
|
3768
|
-
const { fieldRequired } = displayText;
|
|
3749
|
+
const { schema, translate } = useSchemaContext();
|
|
3769
3750
|
const { required } = schema;
|
|
3770
3751
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3771
3752
|
if (schema.properties == undefined) {
|
|
3772
3753
|
throw new Error("schema properties when using String Input Field");
|
|
3773
3754
|
}
|
|
3774
|
-
const { gridColumn, gridRow
|
|
3775
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3755
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3756
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(NumberInputRoot, { children: jsxRuntime.jsx(NumberInputField$1, { ...register(column, { required: isRequired }) }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3776
3757
|
};
|
|
3777
3758
|
|
|
3778
3759
|
const StringInputField = ({ column }) => {
|
|
3779
3760
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3780
|
-
const { schema,
|
|
3781
|
-
const { fieldRequired } = displayText;
|
|
3761
|
+
const { schema, translate } = useSchemaContext();
|
|
3782
3762
|
const { required } = schema;
|
|
3783
3763
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3784
3764
|
if (schema.properties == undefined) {
|
|
3785
3765
|
throw new Error("schema properties when using String Input Field");
|
|
3786
3766
|
}
|
|
3787
|
-
const { gridColumn, gridRow
|
|
3788
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${
|
|
3767
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3768
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Input, { ...register(column, { required: isRequired }), autoComplete: "off" }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }) }));
|
|
3789
3769
|
};
|
|
3790
3770
|
|
|
3791
3771
|
const clearEmptyString = (object) => {
|
|
@@ -3802,21 +3782,35 @@ const AccordionItemContent = React__namespace.forwardRef(function AccordionItemC
|
|
|
3802
3782
|
const AccordionRoot = react.Accordion.Root;
|
|
3803
3783
|
const AccordionItem = react.Accordion.Item;
|
|
3804
3784
|
|
|
3785
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
3786
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
3787
|
+
return (jsxRuntime.jsxs(react.Popover.Root, { ...rest, positioning: { ...rest.positioning, gutter: 4 }, children: [jsxRuntime.jsx(react.Popover.Trigger, { asChild: true, children: children }), jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Popover.Positioner, { children: jsxRuntime.jsxs(react.Popover.Content, { width: "auto", px: "2", py: "1", textStyle: "xs", rounded: "sm", ref: ref, children: [showArrow && (jsxRuntime.jsx(react.Popover.Arrow, { children: jsxRuntime.jsx(react.Popover.ArrowTip, {}) })), content] }) }) })] }));
|
|
3788
|
+
});
|
|
3789
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
3790
|
+
const { children, ...rest } = props;
|
|
3791
|
+
return (jsxRuntime.jsx(ToggleTip, { content: children, ...rest, ref: ref, children: jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "info", size: "2xs", colorPalette: "gray", children: jsxRuntime.jsx(hi.HiOutlineInformationCircle, {}) }) }));
|
|
3792
|
+
});
|
|
3793
|
+
|
|
3794
|
+
const DataListRoot = react.DataList.Root;
|
|
3795
|
+
const DataListItem = React__namespace.forwardRef(function DataListItem(props, ref) {
|
|
3796
|
+
const { label, info, value, children, grow, ...rest } = props;
|
|
3797
|
+
return (jsxRuntime.jsxs(react.DataList.Item, { ref: ref, ...rest, children: [jsxRuntime.jsxs(react.DataList.ItemLabel, { flex: grow ? "1" : undefined, children: [label, info && jsxRuntime.jsx(InfoTip, { children: info })] }), jsxRuntime.jsx(react.DataList.ItemValue, { flex: grow ? "1" : undefined, children: value }), children] }));
|
|
3798
|
+
});
|
|
3799
|
+
|
|
3805
3800
|
const BooleanPicker = ({ column }) => {
|
|
3806
|
-
const { watch, formState: { errors }, setValue,
|
|
3807
|
-
const { schema,
|
|
3808
|
-
const { fieldRequired } = displayText;
|
|
3801
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3802
|
+
const { schema, translate } = useSchemaContext();
|
|
3809
3803
|
const { required } = schema;
|
|
3810
3804
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3811
3805
|
const value = watch(column);
|
|
3812
3806
|
if (schema.properties == undefined) {
|
|
3813
3807
|
throw new Error("schema properties when using BooleanPicker");
|
|
3814
3808
|
}
|
|
3815
|
-
const { gridColumn, gridRow
|
|
3816
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3809
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3810
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3817
3811
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
3818
3812
|
setValue(column, !value);
|
|
3819
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
3813
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3820
3814
|
};
|
|
3821
3815
|
|
|
3822
3816
|
const monthNamesShort = [
|
|
@@ -3890,8 +3884,7 @@ let DatePicker$1 = class DatePicker extends React.Component {
|
|
|
3890
3884
|
|
|
3891
3885
|
const DatePicker = ({ column }) => {
|
|
3892
3886
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3893
|
-
const { schema,
|
|
3894
|
-
const { fieldRequired } = displayText;
|
|
3887
|
+
const { schema, translate } = useSchemaContext();
|
|
3895
3888
|
const { required } = schema;
|
|
3896
3889
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3897
3890
|
const [open, setOpen] = React.useState(false);
|
|
@@ -3899,14 +3892,20 @@ const DatePicker = ({ column }) => {
|
|
|
3899
3892
|
if (schema.properties == undefined) {
|
|
3900
3893
|
throw new Error("schema properties when using DatePicker");
|
|
3901
3894
|
}
|
|
3902
|
-
const { gridColumn, gridRow
|
|
3903
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3895
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3896
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3904
3897
|
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3905
3898
|
setOpen(true);
|
|
3906
|
-
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3899
|
+
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3900
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3901
|
+
, {
|
|
3902
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3903
|
+
selected: new Date(selectedDate),
|
|
3904
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3905
|
+
onDateSelected: ({ selected, selectable, date }) => {
|
|
3907
3906
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
3908
3907
|
setOpen(false);
|
|
3909
|
-
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
3908
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3910
3909
|
};
|
|
3911
3910
|
|
|
3912
3911
|
function filterArray(array, searchTerm) {
|
|
@@ -3921,14 +3920,13 @@ function filterArray(array, searchTerm) {
|
|
|
3921
3920
|
|
|
3922
3921
|
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
3923
3922
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3924
|
-
const { schema,
|
|
3925
|
-
const { fieldRequired, total, showing, typeToSearch } = displayText;
|
|
3923
|
+
const { schema, translate } = useSchemaContext();
|
|
3926
3924
|
const { required } = schema;
|
|
3927
3925
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3928
3926
|
if (schema.properties == undefined) {
|
|
3929
3927
|
throw new Error("schema properties when using DatePicker");
|
|
3930
3928
|
}
|
|
3931
|
-
const { gridColumn, gridRow,
|
|
3929
|
+
const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
|
|
3932
3930
|
const [searchText, setSearchText] = React.useState();
|
|
3933
3931
|
const [limit, setLimit] = React.useState(10);
|
|
3934
3932
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -3943,24 +3941,24 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3943
3941
|
setSearchText(event.target.value);
|
|
3944
3942
|
setLimit(10);
|
|
3945
3943
|
};
|
|
3946
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3944
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3947
3945
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3948
3946
|
const item = enumValue;
|
|
3949
3947
|
if (item === undefined) {
|
|
3950
3948
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
3951
3949
|
}
|
|
3952
3950
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3953
|
-
setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3951
|
+
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3954
3952
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3955
3953
|
}, children: !!renderDisplay === true ? renderDisplay(item) : item }));
|
|
3956
3954
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3957
3955
|
setOpenSearchResult(true);
|
|
3958
3956
|
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3959
3957
|
setOpenSearchResult(true);
|
|
3960
|
-
}, children: watchEnum })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: typeToSearch
|
|
3958
|
+
}, children: watchEnum })), jsxRuntime.jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsxRuntime.jsx(PopoverTrigger, {}), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { display: "grid", gap: 1, children: [jsxRuntime.jsx(react.Input, { placeholder: translate.t(`${column}.typeToSearch`), onChange: (event) => {
|
|
3961
3959
|
onSearchChange(event);
|
|
3962
3960
|
setOpenSearchResult(true);
|
|
3963
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${total
|
|
3961
|
+
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${translate.t(`${column}.total`)}: ${count}, ${translate.t(`${column}.showing`)} ${limit}` }), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsxRuntime.jsx(react.Flex, { flexFlow: "column wrap", children: filterArray(dataList, searchText ?? "").map((item) => {
|
|
3964
3962
|
const selected = isMultiple
|
|
3965
3963
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3966
3964
|
: watchEnum == item;
|
|
@@ -3973,7 +3971,7 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3973
3971
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3974
3972
|
setValue(column, [...newSet]);
|
|
3975
3973
|
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true ? renderDisplay(item) : item }, `${column}-${item}`));
|
|
3976
|
-
}) }), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Empty Search Result" }), " "] }))] })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
3974
|
+
}) }), isDirty && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [dataList.length <= 0 && jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Empty Search Result" }), " "] }))] })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3977
3975
|
};
|
|
3978
3976
|
|
|
3979
3977
|
function isEnteringWindow(_ref) {
|
|
@@ -4330,8 +4328,8 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4330
4328
|
|
|
4331
4329
|
const FilePicker = ({ column }) => {
|
|
4332
4330
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4333
|
-
const { schema,
|
|
4334
|
-
|
|
4331
|
+
const { schema, translate } = useSchemaContext();
|
|
4332
|
+
displayText;
|
|
4335
4333
|
const { required } = schema;
|
|
4336
4334
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4337
4335
|
if (schema.properties == undefined) {
|
|
@@ -4339,22 +4337,21 @@ const FilePicker = ({ column }) => {
|
|
|
4339
4337
|
}
|
|
4340
4338
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
4341
4339
|
const currentFiles = (watch(column) ?? []);
|
|
4342
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
4340
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", display: "grid", gridTemplateRows: "auto 1fr auto", alignItems: "stretch", children: [jsxRuntime.jsx(FileDropzone, { onDrop: ({ files }) => {
|
|
4343
4341
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4344
4342
|
setValue(column, [...currentFiles, ...newFiles]);
|
|
4345
|
-
} }), jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
|
|
4343
|
+
}, placeholder: translate.t(`${column}.fileDropzone`) }), jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
|
|
4346
4344
|
return (jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4347
4345
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4348
4346
|
return name !== file.name;
|
|
4349
4347
|
}));
|
|
4350
4348
|
}, children: file.name }));
|
|
4351
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
4349
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4352
4350
|
};
|
|
4353
4351
|
|
|
4354
4352
|
const ObjectInput = ({ column }) => {
|
|
4355
4353
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4356
|
-
const { schema,
|
|
4357
|
-
const { addNew, fieldRequired, save } = displayText;
|
|
4354
|
+
const { schema, translate } = useSchemaContext();
|
|
4358
4355
|
const { required } = schema;
|
|
4359
4356
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4360
4357
|
const entries = Object.entries(getValues(column) ?? {});
|
|
@@ -4364,8 +4361,8 @@ const ObjectInput = ({ column }) => {
|
|
|
4364
4361
|
if (schema.properties == undefined) {
|
|
4365
4362
|
throw new Error("schema properties when using DatePicker");
|
|
4366
4363
|
}
|
|
4367
|
-
const { gridColumn, gridRow
|
|
4368
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
4364
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
4365
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4369
4366
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4370
4367
|
const filtered = entries.filter(([target]) => {
|
|
4371
4368
|
return target !== key;
|
|
@@ -4401,11 +4398,11 @@ const ObjectInput = ({ column }) => {
|
|
|
4401
4398
|
setShowNewEntries(false);
|
|
4402
4399
|
setNewKey(undefined);
|
|
4403
4400
|
setNewValue(undefined);
|
|
4404
|
-
}, children: save
|
|
4401
|
+
}, children: translate.t(`${column}.save`) })] })] }) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4405
4402
|
setShowNewEntries(true);
|
|
4406
4403
|
setNewKey(undefined);
|
|
4407
4404
|
setNewValue(undefined);
|
|
4408
|
-
}, children: addNew
|
|
4405
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4409
4406
|
};
|
|
4410
4407
|
|
|
4411
4408
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4519,8 +4516,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4519
4516
|
}
|
|
4520
4517
|
};
|
|
4521
4518
|
const FormInternal = () => {
|
|
4522
|
-
const { schema, serverUrl,
|
|
4523
|
-
const { title, submit, empty, cancel, submitSuccess, submitAgain, confirm } = displayText;
|
|
4519
|
+
const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, translate, } = useSchemaContext();
|
|
4524
4520
|
const methods = reactHookForm.useFormContext();
|
|
4525
4521
|
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
4526
4522
|
const [isError, setIsError] = React.useState(false);
|
|
@@ -4590,7 +4586,7 @@ const FormInternal = () => {
|
|
|
4590
4586
|
const getDataListProps = (value) => {
|
|
4591
4587
|
if (value == undefined || value.length <= 0) {
|
|
4592
4588
|
return {
|
|
4593
|
-
value: `<${empty ?? "Empty"}>`,
|
|
4589
|
+
value: `<${translate.t("empty") ?? "Empty"}>`,
|
|
4594
4590
|
color: "gray.400",
|
|
4595
4591
|
};
|
|
4596
4592
|
}
|
|
@@ -4599,17 +4595,17 @@ const FormInternal = () => {
|
|
|
4599
4595
|
};
|
|
4600
4596
|
};
|
|
4601
4597
|
if (isSuccess) {
|
|
4602
|
-
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children:
|
|
4598
|
+
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children: translate.t("title") }), jsxRuntime.jsxs(react.Alert.Root, { status: "success", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsx(react.Alert.Title, { children: translate.t("submitSuccess") })] }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4603
4599
|
setIsError(false);
|
|
4604
4600
|
setIsSubmiting(false);
|
|
4605
4601
|
setIsSuccess(false);
|
|
4606
4602
|
setIsConfirming(false);
|
|
4607
4603
|
setValidatedData(undefined);
|
|
4608
4604
|
methods.reset();
|
|
4609
|
-
}, formNoValidate: true, children: submitAgain
|
|
4605
|
+
}, formNoValidate: true, children: translate.t("submitAgain") })] }));
|
|
4610
4606
|
}
|
|
4611
4607
|
if (isConfirming) {
|
|
4612
|
-
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.
|
|
4608
|
+
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsxs(react.Heading, { children: [" ", translate.t("title")] }), jsxRuntime.jsx(DataListRoot, { orientation: "horizontal", gap: 4, display: "grid", gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
4613
4609
|
if (properties === undefined) {
|
|
4614
4610
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4615
4611
|
}
|
|
@@ -4631,38 +4627,38 @@ const FormInternal = () => {
|
|
|
4631
4627
|
if (variant === "date-picker") {
|
|
4632
4628
|
const value = (validatedData ?? {})[column];
|
|
4633
4629
|
if (!!value === false) {
|
|
4634
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4630
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4635
4631
|
}
|
|
4636
4632
|
const date = dayjs(value).format("YYYY-MM-DD");
|
|
4637
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4633
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(date) }, `form-${key}`));
|
|
4638
4634
|
}
|
|
4639
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4635
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4640
4636
|
}
|
|
4641
4637
|
if (type === "object") {
|
|
4642
4638
|
const value = (validatedData ?? {})[column];
|
|
4643
4639
|
if (!!value === false) {
|
|
4644
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4640
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4645
4641
|
}
|
|
4646
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children:
|
|
4642
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children: translate.t(`input.${column}`) }), jsxRuntime.jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
|
|
4647
4643
|
return (jsxRuntime.jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
4648
4644
|
}) })] }, `form-${key}`));
|
|
4649
4645
|
}
|
|
4650
4646
|
if (type === "boolean") {
|
|
4651
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4647
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4652
4648
|
}
|
|
4653
4649
|
if (type === "number" || type === "integer") {
|
|
4654
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4650
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4655
4651
|
}
|
|
4656
4652
|
if (type === "array") {
|
|
4657
4653
|
if (variant === "tag-picker") {
|
|
4658
4654
|
const value = (validatedData ?? {})[column];
|
|
4659
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4655
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
|
|
4660
4656
|
}
|
|
4661
4657
|
if (variant === "file-picker") {
|
|
4662
4658
|
const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
|
|
4663
4659
|
return file.name;
|
|
4664
4660
|
});
|
|
4665
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4661
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
|
|
4666
4662
|
}
|
|
4667
4663
|
if (variant === "id-picker") {
|
|
4668
4664
|
const value = (validatedData ?? {})[column];
|
|
@@ -4678,10 +4674,10 @@ const FormInternal = () => {
|
|
|
4678
4674
|
return idMap[item][display_column];
|
|
4679
4675
|
});
|
|
4680
4676
|
return (jsxRuntime.jsxs(react.Grid, { flexFlow: "column", gridColumn,
|
|
4681
|
-
gridRow, children: [jsxRuntime.jsx(react.Text, { children:
|
|
4677
|
+
gridRow, children: [jsxRuntime.jsx(react.Text, { children: translate.t(`input.${column}`) }), jsxRuntime.jsx(RecordDisplay, { object: mapped })] }, `form-${key}`));
|
|
4682
4678
|
}
|
|
4683
4679
|
const objectString = JSON.stringify((validatedData ?? {})[column]);
|
|
4684
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4680
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(objectString) }, `form-${key}`));
|
|
4685
4681
|
}
|
|
4686
4682
|
if (type === "null") {
|
|
4687
4683
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `null ${column}` });
|
|
@@ -4689,11 +4685,11 @@ const FormInternal = () => {
|
|
|
4689
4685
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `unknown type ${column}` });
|
|
4690
4686
|
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4691
4687
|
onFormSubmit(validatedData);
|
|
4692
|
-
}, children: confirm
|
|
4688
|
+
}, children: translate.t("confirm") }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4693
4689
|
setIsConfirming(false);
|
|
4694
|
-
}, variant: "subtle", children: cancel
|
|
4690
|
+
}, variant: "subtle", children: translate.t("cancel") }), isSubmiting && (jsxRuntime.jsx(react.Box, { pos: "absolute", inset: "0", bg: "bg/80", children: jsxRuntime.jsx(react.Center, { h: "full", children: jsxRuntime.jsx(react.Spinner, { color: "teal.500" }) }) })), isError && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react.Alert.Root, { status: "error", children: jsxRuntime.jsx(react.Alert.Title, { children: jsxRuntime.jsx(AccordionRoot, { collapsible: true, defaultValue: ["b"], children: jsxRuntime.jsxs(AccordionItem, { value: "b", children: [jsxRuntime.jsxs(AccordionItemTrigger, { children: [jsxRuntime.jsx(react.Alert.Indicator, {}), `${error}`] }), jsxRuntime.jsx(AccordionItemContent, { children: `${JSON.stringify(error)}` })] }) }) }) }) }))] }));
|
|
4695
4691
|
}
|
|
4696
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.
|
|
4692
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsxs(react.Heading, { children: [" ", translate.t("title")] }), jsxRuntime.jsx(react.Grid, { gap: 4, gridTemplateColumns: "repeat(12, 1fr)", gridTemplateRows: `repeat(${rowNumber ?? "auto-fit"}, auto)`, children: ordered.map((column) => {
|
|
4697
4693
|
if (properties === undefined) {
|
|
4698
4694
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4699
4695
|
}
|
|
@@ -4749,28 +4745,37 @@ const FormInternal = () => {
|
|
|
4749
4745
|
return jsxRuntime.jsx(react.Text, { children: "missing type" }, `form-${key}`);
|
|
4750
4746
|
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4751
4747
|
methods.handleSubmit(onValid)();
|
|
4752
|
-
}, formNoValidate: true, children: submit
|
|
4748
|
+
}, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["isError", jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
4753
4749
|
};
|
|
4754
|
-
const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined,
|
|
4755
|
-
const queryClient = new reactQuery.QueryClient();
|
|
4756
|
-
const methods = reactHookForm.useForm({ values: preLoadedValues });
|
|
4757
|
-
const [idMap, setIdMap] = React.useState({});
|
|
4750
|
+
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, }) => {
|
|
4758
4751
|
const { properties } = schema;
|
|
4759
4752
|
idListSanityCheck("order", order, properties);
|
|
4760
4753
|
idListSanityCheck("ignore", ignore, properties);
|
|
4761
4754
|
idListSanityCheck("preLoadedValues", Object.keys(preLoadedValues), properties);
|
|
4762
|
-
return (jsxRuntime.jsx(
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4755
|
+
return (jsxRuntime.jsx(SchemaFormContext.Provider, { value: {
|
|
4756
|
+
schema,
|
|
4757
|
+
serverUrl,
|
|
4758
|
+
order,
|
|
4759
|
+
ignore,
|
|
4760
|
+
// @ts-expect-error TODO: find appropriate types
|
|
4761
|
+
onSubmit,
|
|
4762
|
+
rowNumber,
|
|
4763
|
+
idMap,
|
|
4764
|
+
setIdMap,
|
|
4765
|
+
translate,
|
|
4766
|
+
}, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(FormInternal, {}) }) }));
|
|
4767
|
+
};
|
|
4768
|
+
|
|
4769
|
+
const useForm = ({ preLoadedValues, keyPrefix }) => {
|
|
4770
|
+
const form = reactHookForm.useForm({ values: preLoadedValues });
|
|
4771
|
+
const [idMap, setIdMap] = React.useState({});
|
|
4772
|
+
const translate = reactI18next.useTranslation("", { keyPrefix });
|
|
4773
|
+
return {
|
|
4774
|
+
form,
|
|
4775
|
+
idMap,
|
|
4776
|
+
setIdMap,
|
|
4777
|
+
translate,
|
|
4778
|
+
};
|
|
4774
4779
|
};
|
|
4775
4780
|
|
|
4776
4781
|
const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) => {
|
|
@@ -4835,4 +4840,5 @@ exports.getRangeDates = getRangeDates;
|
|
|
4835
4840
|
exports.useDataTable = useDataTable;
|
|
4836
4841
|
exports.useDataTableContext = useDataTableContext;
|
|
4837
4842
|
exports.useDataTableServer = useDataTableServer;
|
|
4843
|
+
exports.useForm = useForm;
|
|
4838
4844
|
exports.widthSanityCheck = widthSanityCheck;
|