@bsol-oss/react-datatable5 8.1.2 → 9.0.0
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 +9 -22
- package/dist/index.js +108 -116
- package/dist/index.mjs +111 -119
- 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/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Row, RowData, OnChangeFn, Updater, FilterFn, ColumnDef, RowSelectionState, ColumnOrderState, ColumnFiltersState, PaginationState, SortingState, VisibilityState, Table as Table$1, Column } from '@tanstack/react-table';
|
|
3
3
|
import * as React$1 from 'react';
|
|
4
|
-
import React__default, { ReactNode } from 'react';
|
|
4
|
+
import React__default, { ReactNode, Dispatch, SetStateAction } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { ImageProps, TableHeaderProps as TableHeaderProps$1, TableRootProps, GridProps, CardBodyProps, FlexProps, TextProps, BoxProps } from '@chakra-ui/react';
|
|
7
7
|
import { IconType } from 'react-icons';
|
|
@@ -9,7 +9,8 @@ import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
|
9
9
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
10
10
|
import { JSONSchema7 } from 'json-schema';
|
|
11
11
|
import { ForeignKeyProps } from '@/components/Form/components/StringInputField';
|
|
12
|
-
import { FieldValues, SubmitHandler } from 'react-hook-form';
|
|
12
|
+
import { FieldValues, UseFormReturn, SubmitHandler } from 'react-hook-form';
|
|
13
|
+
import { UseTranslationResponse } from 'react-i18next';
|
|
13
14
|
import { RenderProps, Props } from '@bsol-oss/dayzed-react19';
|
|
14
15
|
|
|
15
16
|
interface DensityToggleButtonProps {
|
|
@@ -451,32 +452,18 @@ declare const FilterOptions: ({ column }: FilterOptionsProps) => react_jsx_runti
|
|
|
451
452
|
|
|
452
453
|
declare const GlobalFilter: () => react_jsx_runtime.JSX.Element;
|
|
453
454
|
|
|
454
|
-
interface DisplayTextProps {
|
|
455
|
-
title?: string;
|
|
456
|
-
addNew?: string;
|
|
457
|
-
submit?: string;
|
|
458
|
-
confirm?: string;
|
|
459
|
-
save?: string;
|
|
460
|
-
empty?: string;
|
|
461
|
-
cancel?: string;
|
|
462
|
-
submitSuccess?: string;
|
|
463
|
-
submitAgain?: string;
|
|
464
|
-
fieldRequired?: string;
|
|
465
|
-
total: string;
|
|
466
|
-
showing: string;
|
|
467
|
-
close: string;
|
|
468
|
-
typeToSearch: string;
|
|
469
|
-
showMore: string;
|
|
470
|
-
}
|
|
471
455
|
interface FormProps<TData extends FieldValues> {
|
|
472
456
|
schema: JSONSchema7;
|
|
473
457
|
serverUrl: string;
|
|
458
|
+
idMap: Record<string, object>;
|
|
459
|
+
setIdMap: Dispatch<SetStateAction<Record<string, object>>>;
|
|
460
|
+
form: UseFormReturn;
|
|
461
|
+
translate: UseTranslationResponse<any, any>;
|
|
474
462
|
order?: string[];
|
|
475
463
|
ignore?: string[];
|
|
476
464
|
onSubmit?: SubmitHandler<TData>;
|
|
477
465
|
preLoadedValues?: object;
|
|
478
466
|
rowNumber?: number | string;
|
|
479
|
-
displayText?: Partial<DisplayTextProps>;
|
|
480
467
|
}
|
|
481
468
|
interface CustomJSONSchema7Definition extends JSONSchema7 {
|
|
482
469
|
variant: string;
|
|
@@ -487,7 +474,7 @@ interface CustomJSONSchema7Definition extends JSONSchema7 {
|
|
|
487
474
|
gridRow: string;
|
|
488
475
|
foreign_key: ForeignKeyProps;
|
|
489
476
|
}
|
|
490
|
-
declare const Form: <TData extends FieldValues>({ schema, serverUrl, order, ignore, onSubmit, preLoadedValues, rowNumber,
|
|
477
|
+
declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, preLoadedValues, rowNumber, }: FormProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
491
478
|
|
|
492
479
|
interface CalendarProps extends RenderProps {
|
|
493
480
|
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
@@ -597,4 +584,4 @@ declare module "@tanstack/react-table" {
|
|
|
597
584
|
}
|
|
598
585
|
}
|
|
599
586
|
|
|
600
|
-
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerProps, DefaultCardTitle, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps,
|
|
587
|
+
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerProps, DefaultCardTitle, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, EditFilterButton, type EditFilterButtonProps, EditOrderButton, type EditOrderButtonProps, EditSortingButton, type EditSortingButtonProps, EditViewButton, type EditViewButtonProps, EmptyState, type EmptyStateProps, ErrorAlert, type ErrorAlertProps, FilterOptions, type FilterOptionsProps, Form, type FormProps, type GetColumnsConfigs, type GetDateColorProps, type GetMultiDatesProps, type GetRangeDatesProps, type GetStyleProps, type GetVariantProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, type RangeCalendarProps, type RangeDatePickerProps, RecordDisplay, type RecordDisplayProps, ReloadButton, type ReloadButtonProps, ResetFilteringButton, type ResetFilteringButtonProps, ResetSelectionButton, type ResetSelectionButtonProps, ResetSortingButton, type ResetSortingButtonProps, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableLoadingComponent, type TableLoadingComponentProps, TableOrderer, TablePagination, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataTableProps, type UseDataTableReturn, type UseDataTableServerProps, type UseDataTableServerReturn, getColumns, getMultiDates, getRangeDates, useDataTable, useDataTableContext, useDataTableServer, widthSanityCheck };
|
package/dist/index.js
CHANGED
|
@@ -3559,7 +3559,7 @@ const Field = React__namespace.forwardRef(function Field(props, ref) {
|
|
|
3559
3559
|
});
|
|
3560
3560
|
|
|
3561
3561
|
const useSchemaContext = () => {
|
|
3562
|
-
const { schema, serverUrl, order, ignore, onSubmit, rowNumber,
|
|
3562
|
+
const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, setIdMap, translate, } = React.useContext(SchemaFormContext);
|
|
3563
3563
|
return {
|
|
3564
3564
|
schema,
|
|
3565
3565
|
serverUrl,
|
|
@@ -3567,9 +3567,9 @@ const useSchemaContext = () => {
|
|
|
3567
3567
|
ignore,
|
|
3568
3568
|
onSubmit,
|
|
3569
3569
|
rowNumber,
|
|
3570
|
-
displayText,
|
|
3571
3570
|
idMap,
|
|
3572
3571
|
setIdMap,
|
|
3572
|
+
translate,
|
|
3573
3573
|
};
|
|
3574
3574
|
};
|
|
3575
3575
|
|
|
@@ -3607,16 +3607,13 @@ const getTableData = async ({ serverUrl, in_table, searching = "", where = [], l
|
|
|
3607
3607
|
|
|
3608
3608
|
const IdPicker = ({ column, isMultiple = false }) => {
|
|
3609
3609
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3610
|
-
const { schema, serverUrl,
|
|
3611
|
-
const { fieldRequired } = displayText;
|
|
3610
|
+
const { schema, serverUrl, idMap, setIdMap, translate } = useSchemaContext();
|
|
3612
3611
|
const { required } = schema;
|
|
3613
3612
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3614
3613
|
if (schema.properties == undefined) {
|
|
3615
|
-
throw new Error("schema properties when using DatePicker");
|
|
3614
|
+
throw new Error("schema properties is undefined when using DatePicker");
|
|
3616
3615
|
}
|
|
3617
|
-
const {
|
|
3618
|
-
const { gridColumn, gridRow, title, renderDisplay, foreign_key } = schema
|
|
3619
|
-
.properties[column];
|
|
3616
|
+
const { gridColumn, gridRow, renderDisplay, foreign_key } = schema.properties[column];
|
|
3620
3617
|
const { table, column: column_ref, display_column, } = foreign_key;
|
|
3621
3618
|
const [searchText, setSearchText] = React.useState();
|
|
3622
3619
|
const [limit, setLimit] = React.useState(10);
|
|
@@ -3671,7 +3668,7 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3671
3668
|
}
|
|
3672
3669
|
return record[display_column];
|
|
3673
3670
|
};
|
|
3674
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3671
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3675
3672
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
3676
3673
|
const item = idMap[id];
|
|
3677
3674
|
if (item === undefined) {
|
|
@@ -3686,10 +3683,10 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3686
3683
|
setOpenSearchResult(true);
|
|
3687
3684
|
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3688
3685
|
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
|
|
3686
|
+
}, 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
3687
|
onSearchChange(event);
|
|
3691
3688
|
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
|
|
3689
|
+
}, 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
3690
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3694
3691
|
dataList.map((item) => {
|
|
3695
3692
|
const selected = isMultiple
|
|
@@ -3709,49 +3706,33 @@ const IdPicker = ({ column, isMultiple = false }) => {
|
|
|
3709
3706
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
3710
3707
|
? renderDisplay(item)
|
|
3711
3708
|
: item[display_column] }, item[column_ref]));
|
|
3712
|
-
}) }), isDirty && (jsxRuntime.
|
|
3709
|
+
}) }), 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
3710
|
};
|
|
3714
3711
|
|
|
3715
|
-
const
|
|
3716
|
-
const {
|
|
3717
|
-
return (jsxRuntime.
|
|
3712
|
+
const HoverCardContent = React__namespace.forwardRef(function HoverCardContent(props, ref) {
|
|
3713
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
3714
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.HoverCard.Positioner, { children: jsxRuntime.jsx(react.HoverCard.Content, { ref: ref, ...rest }) }) }));
|
|
3718
3715
|
});
|
|
3719
|
-
const
|
|
3720
|
-
|
|
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, {}) }) }));
|
|
3716
|
+
const HoverCardArrow = React__namespace.forwardRef(function HoverCardArrow(props, ref) {
|
|
3717
|
+
return (jsxRuntime.jsx(react.HoverCard.Arrow, { ref: ref, ...props, children: jsxRuntime.jsx(react.HoverCard.ArrowTip, {}) }));
|
|
3722
3718
|
});
|
|
3719
|
+
const HoverCardRoot = react.HoverCard.Root;
|
|
3720
|
+
const HoverCardTrigger = react.HoverCard.Trigger;
|
|
3723
3721
|
|
|
3724
|
-
const
|
|
3725
|
-
const
|
|
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] }));
|
|
3728
|
-
});
|
|
3729
|
-
|
|
3730
|
-
const IdViewer = ({ value, column, dataListItemProps, }) => {
|
|
3731
|
-
const { schema, idMap } = useSchemaContext();
|
|
3722
|
+
const IdViewer = ({ value, column }) => {
|
|
3723
|
+
const { schema, idMap, translate } = useSchemaContext();
|
|
3732
3724
|
if (schema.properties == undefined) {
|
|
3733
3725
|
throw new Error("schema properties when using DatePicker");
|
|
3734
3726
|
}
|
|
3735
|
-
const {
|
|
3727
|
+
const { foreign_key } = schema.properties[column];
|
|
3736
3728
|
if (foreign_key === undefined) {
|
|
3737
3729
|
throw new Error("foreign_key when variant is id-picker");
|
|
3738
3730
|
}
|
|
3739
3731
|
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
3732
|
if (value === undefined) {
|
|
3752
|
-
return jsxRuntime.jsx(jsxRuntime.
|
|
3733
|
+
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
3734
|
}
|
|
3754
|
-
return (jsxRuntime.
|
|
3735
|
+
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
3736
|
};
|
|
3756
3737
|
|
|
3757
3738
|
const NumberInputRoot = React__namespace.forwardRef(function NumberInput(props, ref) {
|
|
@@ -3764,28 +3745,26 @@ react.NumberInput.Label;
|
|
|
3764
3745
|
|
|
3765
3746
|
const NumberInputField = ({ column }) => {
|
|
3766
3747
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3767
|
-
const { schema,
|
|
3768
|
-
const { fieldRequired } = displayText;
|
|
3748
|
+
const { schema, translate } = useSchemaContext();
|
|
3769
3749
|
const { required } = schema;
|
|
3770
3750
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3771
3751
|
if (schema.properties == undefined) {
|
|
3772
3752
|
throw new Error("schema properties when using String Input Field");
|
|
3773
3753
|
}
|
|
3774
|
-
const { gridColumn, gridRow
|
|
3775
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3754
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3755
|
+
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
3756
|
};
|
|
3777
3757
|
|
|
3778
3758
|
const StringInputField = ({ column }) => {
|
|
3779
3759
|
const { register, formState: { errors }, } = reactHookForm.useFormContext();
|
|
3780
|
-
const { schema,
|
|
3781
|
-
const { fieldRequired } = displayText;
|
|
3760
|
+
const { schema, translate } = useSchemaContext();
|
|
3782
3761
|
const { required } = schema;
|
|
3783
3762
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3784
3763
|
if (schema.properties == undefined) {
|
|
3785
3764
|
throw new Error("schema properties when using String Input Field");
|
|
3786
3765
|
}
|
|
3787
|
-
const { gridColumn, gridRow
|
|
3788
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(Field, { label: `${
|
|
3766
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3767
|
+
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
3768
|
};
|
|
3790
3769
|
|
|
3791
3770
|
const clearEmptyString = (object) => {
|
|
@@ -3802,21 +3781,35 @@ const AccordionItemContent = React__namespace.forwardRef(function AccordionItemC
|
|
|
3802
3781
|
const AccordionRoot = react.Accordion.Root;
|
|
3803
3782
|
const AccordionItem = react.Accordion.Item;
|
|
3804
3783
|
|
|
3784
|
+
const ToggleTip = React__namespace.forwardRef(function ToggleTip(props, ref) {
|
|
3785
|
+
const { showArrow, children, portalled = true, content, portalRef, ...rest } = props;
|
|
3786
|
+
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] }) }) })] }));
|
|
3787
|
+
});
|
|
3788
|
+
const InfoTip = React__namespace.forwardRef(function InfoTip(props, ref) {
|
|
3789
|
+
const { children, ...rest } = props;
|
|
3790
|
+
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, {}) }) }));
|
|
3791
|
+
});
|
|
3792
|
+
|
|
3793
|
+
const DataListRoot = react.DataList.Root;
|
|
3794
|
+
const DataListItem = React__namespace.forwardRef(function DataListItem(props, ref) {
|
|
3795
|
+
const { label, info, value, children, grow, ...rest } = props;
|
|
3796
|
+
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] }));
|
|
3797
|
+
});
|
|
3798
|
+
|
|
3805
3799
|
const BooleanPicker = ({ column }) => {
|
|
3806
|
-
const { watch, formState: { errors }, setValue,
|
|
3807
|
-
const { schema,
|
|
3808
|
-
const { fieldRequired } = displayText;
|
|
3800
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3801
|
+
const { schema, translate } = useSchemaContext();
|
|
3809
3802
|
const { required } = schema;
|
|
3810
3803
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3811
3804
|
const value = watch(column);
|
|
3812
3805
|
if (schema.properties == undefined) {
|
|
3813
3806
|
throw new Error("schema properties when using BooleanPicker");
|
|
3814
3807
|
}
|
|
3815
|
-
const { gridColumn, gridRow
|
|
3816
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3808
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3809
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3817
3810
|
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
3818
3811
|
setValue(column, !value);
|
|
3819
|
-
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
3812
|
+
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3820
3813
|
};
|
|
3821
3814
|
|
|
3822
3815
|
const monthNamesShort = [
|
|
@@ -3890,8 +3883,7 @@ let DatePicker$1 = class DatePicker extends React.Component {
|
|
|
3890
3883
|
|
|
3891
3884
|
const DatePicker = ({ column }) => {
|
|
3892
3885
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3893
|
-
const { schema,
|
|
3894
|
-
const { fieldRequired } = displayText;
|
|
3886
|
+
const { schema, translate } = useSchemaContext();
|
|
3895
3887
|
const { required } = schema;
|
|
3896
3888
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3897
3889
|
const [open, setOpen] = React.useState(false);
|
|
@@ -3899,14 +3891,20 @@ const DatePicker = ({ column }) => {
|
|
|
3899
3891
|
if (schema.properties == undefined) {
|
|
3900
3892
|
throw new Error("schema properties when using DatePicker");
|
|
3901
3893
|
}
|
|
3902
|
-
const { gridColumn, gridRow
|
|
3903
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3894
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
3895
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3904
3896
|
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
3897
|
setOpen(true);
|
|
3906
|
-
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3898
|
+
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3899
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3900
|
+
, {
|
|
3901
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3902
|
+
selected: new Date(selectedDate),
|
|
3903
|
+
// @ts-expect-error TODO: find appropriate types
|
|
3904
|
+
onDateSelected: ({ selected, selectable, date }) => {
|
|
3907
3905
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
3908
3906
|
setOpen(false);
|
|
3909
|
-
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
3907
|
+
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
3910
3908
|
};
|
|
3911
3909
|
|
|
3912
3910
|
function filterArray(array, searchTerm) {
|
|
@@ -3921,14 +3919,13 @@ function filterArray(array, searchTerm) {
|
|
|
3921
3919
|
|
|
3922
3920
|
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
3923
3921
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3924
|
-
const { schema,
|
|
3925
|
-
const { fieldRequired, total, showing, typeToSearch } = displayText;
|
|
3922
|
+
const { schema, translate } = useSchemaContext();
|
|
3926
3923
|
const { required } = schema;
|
|
3927
3924
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3928
3925
|
if (schema.properties == undefined) {
|
|
3929
3926
|
throw new Error("schema properties when using DatePicker");
|
|
3930
3927
|
}
|
|
3931
|
-
const { gridColumn, gridRow,
|
|
3928
|
+
const { gridColumn, gridRow, renderDisplay } = schema.properties[column];
|
|
3932
3929
|
const [searchText, setSearchText] = React.useState();
|
|
3933
3930
|
const [limit, setLimit] = React.useState(10);
|
|
3934
3931
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -3943,24 +3940,24 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3943
3940
|
setSearchText(event.target.value);
|
|
3944
3941
|
setLimit(10);
|
|
3945
3942
|
};
|
|
3946
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
3943
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3947
3944
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
3948
3945
|
const item = enumValue;
|
|
3949
3946
|
if (item === undefined) {
|
|
3950
3947
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
3951
3948
|
}
|
|
3952
3949
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
3953
|
-
setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3950
|
+
// setSelectedEnums((state) => state.filter((id) => id != item));
|
|
3954
3951
|
setValue(column, watchEnums.filter((id) => id != item));
|
|
3955
3952
|
}, children: !!renderDisplay === true ? renderDisplay(item) : item }));
|
|
3956
3953
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
3957
3954
|
setOpenSearchResult(true);
|
|
3958
3955
|
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
3959
3956
|
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
|
|
3957
|
+
}, 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
3958
|
onSearchChange(event);
|
|
3962
3959
|
setOpenSearchResult(true);
|
|
3963
|
-
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(react.Text, { children: `${total
|
|
3960
|
+
}, 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
3961
|
const selected = isMultiple
|
|
3965
3962
|
? watchEnums.some((enumValue) => item === enumValue)
|
|
3966
3963
|
: watchEnum == item;
|
|
@@ -3973,7 +3970,7 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
3973
3970
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
3974
3971
|
setValue(column, [...newSet]);
|
|
3975
3972
|
}, ...(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
|
|
3973
|
+
}) }), 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
3974
|
};
|
|
3978
3975
|
|
|
3979
3976
|
function isEnteringWindow(_ref) {
|
|
@@ -4330,8 +4327,8 @@ const FileDropzone = ({ children = undefined, gridProps = {}, onDrop = () => { }
|
|
|
4330
4327
|
|
|
4331
4328
|
const FilePicker = ({ column }) => {
|
|
4332
4329
|
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4333
|
-
const { schema,
|
|
4334
|
-
|
|
4330
|
+
const { schema, translate } = useSchemaContext();
|
|
4331
|
+
displayText;
|
|
4335
4332
|
const { required } = schema;
|
|
4336
4333
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4337
4334
|
if (schema.properties == undefined) {
|
|
@@ -4339,22 +4336,21 @@ const FilePicker = ({ column }) => {
|
|
|
4339
4336
|
}
|
|
4340
4337
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
4341
4338
|
const currentFiles = (watch(column) ?? []);
|
|
4342
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
4339
|
+
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
4340
|
const newFiles = files.filter(({ name }) => !currentFiles.some((cur) => cur.name === name));
|
|
4344
4341
|
setValue(column, [...currentFiles, ...newFiles]);
|
|
4345
|
-
} }), jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
|
|
4342
|
+
}, placeholder: translate.t(`${column}.fileDropzone`) }), jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", alignItems: "start", gap: 1, children: currentFiles.map((file) => {
|
|
4346
4343
|
return (jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
4347
4344
|
setValue(column, currentFiles.filter(({ name }) => {
|
|
4348
4345
|
return name !== file.name;
|
|
4349
4346
|
}));
|
|
4350
4347
|
}, children: file.name }));
|
|
4351
|
-
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired
|
|
4348
|
+
}) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4352
4349
|
};
|
|
4353
4350
|
|
|
4354
4351
|
const ObjectInput = ({ column }) => {
|
|
4355
4352
|
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
4356
|
-
const { schema,
|
|
4357
|
-
const { addNew, fieldRequired, save } = displayText;
|
|
4353
|
+
const { schema, translate } = useSchemaContext();
|
|
4358
4354
|
const { required } = schema;
|
|
4359
4355
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4360
4356
|
const entries = Object.entries(getValues(column) ?? {});
|
|
@@ -4364,8 +4360,8 @@ const ObjectInput = ({ column }) => {
|
|
|
4364
4360
|
if (schema.properties == undefined) {
|
|
4365
4361
|
throw new Error("schema properties when using DatePicker");
|
|
4366
4362
|
}
|
|
4367
|
-
const { gridColumn, gridRow
|
|
4368
|
-
return (jsxRuntime.jsxs(Field, { label: `${
|
|
4363
|
+
const { gridColumn, gridRow } = schema.properties[column];
|
|
4364
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(`${column}.fieldLabel`)}`, required: isRequired, alignItems: "stretch", gridColumn, gridRow, children: [entries.map(([key, value]) => {
|
|
4369
4365
|
return (jsxRuntime.jsxs(react.Grid, { templateColumns: "1fr 1fr auto", gap: 1, children: [jsxRuntime.jsx(react.Input, { value: key, onChange: (e) => {
|
|
4370
4366
|
const filtered = entries.filter(([target]) => {
|
|
4371
4367
|
return target !== key;
|
|
@@ -4401,11 +4397,11 @@ const ObjectInput = ({ column }) => {
|
|
|
4401
4397
|
setShowNewEntries(false);
|
|
4402
4398
|
setNewKey(undefined);
|
|
4403
4399
|
setNewValue(undefined);
|
|
4404
|
-
}, children: save
|
|
4400
|
+
}, children: translate.t(`${column}.save`) })] })] }) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4405
4401
|
setShowNewEntries(true);
|
|
4406
4402
|
setNewKey(undefined);
|
|
4407
4403
|
setNewValue(undefined);
|
|
4408
|
-
}, children: addNew
|
|
4404
|
+
}, children: translate.t(`${column}.addNew`) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.fieldRequired`) }))] }));
|
|
4409
4405
|
};
|
|
4410
4406
|
|
|
4411
4407
|
const RadioCardItem = React__namespace.forwardRef(function RadioCardItem(props, ref) {
|
|
@@ -4519,8 +4515,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4519
4515
|
}
|
|
4520
4516
|
};
|
|
4521
4517
|
const FormInternal = () => {
|
|
4522
|
-
const { schema, serverUrl,
|
|
4523
|
-
const { title, submit, empty, cancel, submitSuccess, submitAgain, confirm } = displayText;
|
|
4518
|
+
const { schema, serverUrl, order, ignore, onSubmit, rowNumber, idMap, translate, } = useSchemaContext();
|
|
4524
4519
|
const methods = reactHookForm.useFormContext();
|
|
4525
4520
|
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
4526
4521
|
const [isError, setIsError] = React.useState(false);
|
|
@@ -4590,7 +4585,7 @@ const FormInternal = () => {
|
|
|
4590
4585
|
const getDataListProps = (value) => {
|
|
4591
4586
|
if (value == undefined || value.length <= 0) {
|
|
4592
4587
|
return {
|
|
4593
|
-
value: `<${empty ?? "Empty"}>`,
|
|
4588
|
+
value: `<${translate.t("empty") ?? "Empty"}>`,
|
|
4594
4589
|
color: "gray.400",
|
|
4595
4590
|
};
|
|
4596
4591
|
}
|
|
@@ -4599,17 +4594,17 @@ const FormInternal = () => {
|
|
|
4599
4594
|
};
|
|
4600
4595
|
};
|
|
4601
4596
|
if (isSuccess) {
|
|
4602
|
-
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children:
|
|
4597
|
+
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
4598
|
setIsError(false);
|
|
4604
4599
|
setIsSubmiting(false);
|
|
4605
4600
|
setIsSuccess(false);
|
|
4606
4601
|
setIsConfirming(false);
|
|
4607
4602
|
setValidatedData(undefined);
|
|
4608
4603
|
methods.reset();
|
|
4609
|
-
}, formNoValidate: true, children: submitAgain
|
|
4604
|
+
}, formNoValidate: true, children: translate.t("submitAgain") })] }));
|
|
4610
4605
|
}
|
|
4611
4606
|
if (isConfirming) {
|
|
4612
|
-
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.
|
|
4607
|
+
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
4608
|
if (properties === undefined) {
|
|
4614
4609
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4615
4610
|
}
|
|
@@ -4631,38 +4626,38 @@ const FormInternal = () => {
|
|
|
4631
4626
|
if (variant === "date-picker") {
|
|
4632
4627
|
const value = (validatedData ?? {})[column];
|
|
4633
4628
|
if (!!value === false) {
|
|
4634
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4629
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4635
4630
|
}
|
|
4636
4631
|
const date = dayjs(value).format("YYYY-MM-DD");
|
|
4637
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4632
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(date) }, `form-${key}`));
|
|
4638
4633
|
}
|
|
4639
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4634
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4640
4635
|
}
|
|
4641
4636
|
if (type === "object") {
|
|
4642
4637
|
const value = (validatedData ?? {})[column];
|
|
4643
4638
|
if (!!value === false) {
|
|
4644
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4639
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(undefined) }, `form-${key}`));
|
|
4645
4640
|
}
|
|
4646
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children:
|
|
4641
|
+
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
4642
|
return (jsxRuntime.jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
4648
4643
|
}) })] }, `form-${key}`));
|
|
4649
4644
|
}
|
|
4650
4645
|
if (type === "boolean") {
|
|
4651
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4646
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4652
4647
|
}
|
|
4653
4648
|
if (type === "number" || type === "integer") {
|
|
4654
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4649
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
4655
4650
|
}
|
|
4656
4651
|
if (type === "array") {
|
|
4657
4652
|
if (variant === "tag-picker") {
|
|
4658
4653
|
const value = (validatedData ?? {})[column];
|
|
4659
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${
|
|
4654
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(value)) }, `form-${key}`));
|
|
4660
4655
|
}
|
|
4661
4656
|
if (variant === "file-picker") {
|
|
4662
4657
|
const fileNames = ((validatedData ?? {})[column] ?? []).map((file) => {
|
|
4663
4658
|
return file.name;
|
|
4664
4659
|
});
|
|
4665
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4660
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(JSON.stringify(fileNames)) }, `form-${key}`));
|
|
4666
4661
|
}
|
|
4667
4662
|
if (variant === "id-picker") {
|
|
4668
4663
|
const value = (validatedData ?? {})[column];
|
|
@@ -4678,10 +4673,10 @@ const FormInternal = () => {
|
|
|
4678
4673
|
return idMap[item][display_column];
|
|
4679
4674
|
});
|
|
4680
4675
|
return (jsxRuntime.jsxs(react.Grid, { flexFlow: "column", gridColumn,
|
|
4681
|
-
gridRow, children: [jsxRuntime.jsx(react.Text, { children:
|
|
4676
|
+
gridRow, children: [jsxRuntime.jsx(react.Text, { children: translate.t(`input.${column}`) }), jsxRuntime.jsx(RecordDisplay, { object: mapped })] }, `form-${key}`));
|
|
4682
4677
|
}
|
|
4683
4678
|
const objectString = JSON.stringify((validatedData ?? {})[column]);
|
|
4684
|
-
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${
|
|
4679
|
+
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${translate.t(`${column}.fieldLabel`)}`, ...getDataListProps(objectString) }, `form-${key}`));
|
|
4685
4680
|
}
|
|
4686
4681
|
if (type === "null") {
|
|
4687
4682
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `null ${column}` });
|
|
@@ -4689,11 +4684,11 @@ const FormInternal = () => {
|
|
|
4689
4684
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: `unknown type ${column}` });
|
|
4690
4685
|
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4691
4686
|
onFormSubmit(validatedData);
|
|
4692
|
-
}, children: confirm
|
|
4687
|
+
}, children: translate.t("confirm") }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4693
4688
|
setIsConfirming(false);
|
|
4694
|
-
}, variant: "subtle", children: cancel
|
|
4689
|
+
}, 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
4690
|
}
|
|
4696
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.
|
|
4691
|
+
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
4692
|
if (properties === undefined) {
|
|
4698
4693
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
4699
4694
|
}
|
|
@@ -4749,28 +4744,25 @@ const FormInternal = () => {
|
|
|
4749
4744
|
return jsxRuntime.jsx(react.Text, { children: "missing type" }, `form-${key}`);
|
|
4750
4745
|
}) }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
4751
4746
|
methods.handleSubmit(onValid)();
|
|
4752
|
-
}, formNoValidate: true, children: submit
|
|
4747
|
+
}, formNoValidate: true, children: translate.t("submit") })] }), isError && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["isError", jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", `${error}`] })] }))] }));
|
|
4753
4748
|
};
|
|
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({});
|
|
4749
|
+
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, }) => {
|
|
4758
4750
|
const { properties } = schema;
|
|
4759
4751
|
idListSanityCheck("order", order, properties);
|
|
4760
4752
|
idListSanityCheck("ignore", ignore, properties);
|
|
4761
4753
|
idListSanityCheck("preLoadedValues", Object.keys(preLoadedValues), properties);
|
|
4762
|
-
return (jsxRuntime.jsx(
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4754
|
+
return (jsxRuntime.jsx(SchemaFormContext.Provider, { value: {
|
|
4755
|
+
schema,
|
|
4756
|
+
serverUrl,
|
|
4757
|
+
order,
|
|
4758
|
+
ignore,
|
|
4759
|
+
// @ts-expect-error TODO: find appropriate types
|
|
4760
|
+
onSubmit,
|
|
4761
|
+
rowNumber,
|
|
4762
|
+
idMap,
|
|
4763
|
+
setIdMap,
|
|
4764
|
+
translate,
|
|
4765
|
+
}, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(FormInternal, {}) }) }));
|
|
4774
4766
|
};
|
|
4775
4767
|
|
|
4776
4768
|
const getMultiDates = ({ selected, selectedDate, selectedDates, selectable, }) => {
|