@bsol-oss/react-datatable5 7.3.3 → 7.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -2
- package/dist/index.js +70 -53
- package/dist/index.mjs +70 -53
- package/dist/types/components/DataTable/components/EmptyState.d.ts +0 -2
- package/dist/types/components/DataTable/context/DataTableContext.d.ts +1 -1
- package/dist/types/components/Form/SchemaFormContext.d.ts +0 -1
- package/dist/types/components/Form/useSchemaContext.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -372,7 +372,7 @@ interface DataTableContext<TData> {
|
|
|
372
372
|
setGlobalFilter: OnChangeFn<string>;
|
|
373
373
|
type: "client" | "server";
|
|
374
374
|
}
|
|
375
|
-
declare const DataTableContext: React$1.Context<DataTableContext<
|
|
375
|
+
declare const DataTableContext: React$1.Context<DataTableContext<unknown>>;
|
|
376
376
|
|
|
377
377
|
declare const useDataTableContext: <TData>() => DataTableContext<TData>;
|
|
378
378
|
|
|
@@ -389,7 +389,6 @@ declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreL
|
|
|
389
389
|
declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
|
|
390
390
|
|
|
391
391
|
interface EmptyStateProps {
|
|
392
|
-
query: UseQueryResult;
|
|
393
392
|
title?: string;
|
|
394
393
|
description?: string;
|
|
395
394
|
}
|
package/dist/index.js
CHANGED
|
@@ -1568,7 +1568,6 @@ const SchemaFormContext = React.createContext({
|
|
|
1568
1568
|
order: [],
|
|
1569
1569
|
ignore: [],
|
|
1570
1570
|
onSubmit: async () => { },
|
|
1571
|
-
preLoadedValues: {},
|
|
1572
1571
|
rowNumber: 0,
|
|
1573
1572
|
displayText: {},
|
|
1574
1573
|
});
|
|
@@ -1652,26 +1651,63 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1652
1651
|
}
|
|
1653
1652
|
const { total, showing, close, typeToSearch, showMore } = displayText;
|
|
1654
1653
|
const { gridColumn, gridRow, title, renderDisplay } = schema.properties[column];
|
|
1655
|
-
const [selectedIds, setSelectedIds] = React.useState([]);
|
|
1656
1654
|
const [searchText, setSearchText] = React.useState();
|
|
1657
1655
|
const [limit, setLimit] = React.useState(10);
|
|
1658
1656
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
1659
1657
|
const [idMap, setIdMap] = React.useState({});
|
|
1660
1658
|
const ref = React.useRef(null);
|
|
1659
|
+
const selectedIds = watch(column) ?? [];
|
|
1661
1660
|
const query = reactQuery.useQuery({
|
|
1662
1661
|
queryKey: [`idpicker`, searchText, in_table, limit],
|
|
1663
1662
|
queryFn: async () => {
|
|
1664
|
-
|
|
1663
|
+
const data = await getTableData({
|
|
1665
1664
|
serverUrl,
|
|
1666
1665
|
searching: searchText ?? "",
|
|
1667
1666
|
in_table: in_table,
|
|
1668
1667
|
limit: limit,
|
|
1669
1668
|
});
|
|
1669
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
1670
|
+
return [
|
|
1671
|
+
item[column_ref],
|
|
1672
|
+
{
|
|
1673
|
+
...item,
|
|
1674
|
+
},
|
|
1675
|
+
];
|
|
1676
|
+
}));
|
|
1677
|
+
setIdMap((state) => {
|
|
1678
|
+
return { ...state, ...newMap };
|
|
1679
|
+
});
|
|
1680
|
+
return data;
|
|
1681
|
+
},
|
|
1682
|
+
enabled: (searchText ?? "")?.length > 0,
|
|
1683
|
+
staleTime: 10000,
|
|
1684
|
+
});
|
|
1685
|
+
reactQuery.useQuery({
|
|
1686
|
+
queryKey: [`idpicker`, ...selectedIds],
|
|
1687
|
+
queryFn: async () => {
|
|
1688
|
+
const data = await getTableData({
|
|
1689
|
+
serverUrl,
|
|
1690
|
+
in_table: in_table,
|
|
1691
|
+
limit: limit,
|
|
1692
|
+
});
|
|
1693
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
1694
|
+
return [
|
|
1695
|
+
item[column_ref],
|
|
1696
|
+
{
|
|
1697
|
+
...item,
|
|
1698
|
+
},
|
|
1699
|
+
];
|
|
1700
|
+
}));
|
|
1701
|
+
setIdMap((state) => {
|
|
1702
|
+
return { ...state, ...newMap };
|
|
1703
|
+
});
|
|
1704
|
+
return data;
|
|
1670
1705
|
},
|
|
1706
|
+
enabled: (selectedIds ?? []).length > 0,
|
|
1671
1707
|
staleTime: 10000,
|
|
1672
1708
|
});
|
|
1673
1709
|
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
1674
|
-
const dataList = data?.data ?? [];
|
|
1710
|
+
const dataList = React.useMemo(() => data?.data ?? [], [data]);
|
|
1675
1711
|
const count = data?.count ?? 0;
|
|
1676
1712
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
1677
1713
|
const onSearchChange = async (event) => {
|
|
@@ -1679,19 +1715,19 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1679
1715
|
setLimit(10);
|
|
1680
1716
|
};
|
|
1681
1717
|
const ids = (watch(column) ?? []);
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
}
|
|
1718
|
+
const getPickedValue = () => {
|
|
1719
|
+
if (selectedIds.length <= 0) {
|
|
1720
|
+
return "";
|
|
1721
|
+
}
|
|
1722
|
+
if (Object.keys(idMap).length <= 0) {
|
|
1723
|
+
return "";
|
|
1724
|
+
}
|
|
1725
|
+
const record = idMap[selectedIds[0]];
|
|
1726
|
+
if (record === undefined) {
|
|
1727
|
+
return "";
|
|
1728
|
+
}
|
|
1729
|
+
return record[display_column];
|
|
1730
|
+
};
|
|
1695
1731
|
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1696
1732
|
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
1697
1733
|
const item = idMap[id];
|
|
@@ -1699,16 +1735,15 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1699
1735
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
1700
1736
|
}
|
|
1701
1737
|
return (jsxRuntime.jsx(Tag, { closable: true, onClick: () => {
|
|
1702
|
-
setSelectedIds((state) => state.filter((id) => id != item[column_ref]));
|
|
1703
1738
|
setValue(column, ids.filter((id) => id != item[column_ref]));
|
|
1704
1739
|
}, children: !!renderDisplay === true
|
|
1705
1740
|
? renderDisplay(item)
|
|
1706
1741
|
: item[display_column] }));
|
|
1707
1742
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
1708
1743
|
setOpenSearchResult(true);
|
|
1709
|
-
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: (
|
|
1744
|
+
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
1710
1745
|
setOpenSearchResult(true);
|
|
1711
|
-
}, children:
|
|
1746
|
+
}, children: getPickedValue() })), 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, { children: [jsxRuntime.jsx(react.Input, { placeholder: typeToSearch, onChange: (event) => {
|
|
1712
1747
|
onSearchChange(event);
|
|
1713
1748
|
setOpenSearchResult(true);
|
|
1714
1749
|
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", 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, { children: `${total ?? "Total"} ${count}, ${showing ?? "Showing"} ${limit}` }), jsxRuntime.jsx(Button, { onClick: async () => {
|
|
@@ -1720,7 +1755,6 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1720
1755
|
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
1721
1756
|
if (!isMultiple) {
|
|
1722
1757
|
setOpenSearchResult(false);
|
|
1723
|
-
setSelectedIds(() => [item[column_ref]]);
|
|
1724
1758
|
setValue(column, [item[column_ref]]);
|
|
1725
1759
|
return;
|
|
1726
1760
|
}
|
|
@@ -1728,7 +1762,6 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1728
1762
|
...(ids ?? []),
|
|
1729
1763
|
item[column_ref],
|
|
1730
1764
|
]);
|
|
1731
|
-
setSelectedIds(() => [...newSet]);
|
|
1732
1765
|
setValue(column, [...newSet]);
|
|
1733
1766
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
1734
1767
|
? renderDisplay(item)
|
|
@@ -1844,21 +1877,18 @@ const AccordionRoot = react.Accordion.Root;
|
|
|
1844
1877
|
const AccordionItem = react.Accordion.Item;
|
|
1845
1878
|
|
|
1846
1879
|
const BooleanPicker = ({ column }) => {
|
|
1847
|
-
const { formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
1880
|
+
const { watch, formState: { errors }, setValue, getValues, } = reactHookForm.useFormContext();
|
|
1848
1881
|
const { schema, displayText } = useSchemaContext();
|
|
1849
1882
|
const { fieldRequired } = displayText;
|
|
1850
1883
|
const { required } = schema;
|
|
1851
1884
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
1885
|
+
const value = watch(column);
|
|
1852
1886
|
if (schema.properties == undefined) {
|
|
1853
1887
|
throw new Error("schema properties when using BooleanPicker");
|
|
1854
1888
|
}
|
|
1855
1889
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1856
1890
|
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1857
|
-
gridRow, children: [jsxRuntime.jsx(CheckboxCard
|
|
1858
|
-
// label={snakeToLabel(column)}
|
|
1859
|
-
, {
|
|
1860
|
-
// label={snakeToLabel(column)}
|
|
1861
|
-
value: getValues(column), variant: "surface", onSelect: () => {
|
|
1891
|
+
gridRow, children: [jsxRuntime.jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
1862
1892
|
setValue(column, !getValues(column));
|
|
1863
1893
|
} }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1864
1894
|
};
|
|
@@ -1933,22 +1963,21 @@ let DatePicker$1 = class DatePicker extends React.Component {
|
|
|
1933
1963
|
};
|
|
1934
1964
|
|
|
1935
1965
|
const DatePicker = ({ column }) => {
|
|
1936
|
-
const { formState: { errors }, setValue,
|
|
1966
|
+
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
1937
1967
|
const { schema, displayText } = useSchemaContext();
|
|
1938
1968
|
const { fieldRequired } = displayText;
|
|
1939
1969
|
const { required } = schema;
|
|
1940
1970
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
1941
1971
|
const [open, setOpen] = React.useState(false);
|
|
1972
|
+
const selectedDate = watch(column);
|
|
1942
1973
|
if (schema.properties == undefined) {
|
|
1943
1974
|
throw new Error("schema properties when using DatePicker");
|
|
1944
1975
|
}
|
|
1945
1976
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1946
1977
|
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1947
|
-
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true,
|
|
1978
|
+
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: () => {
|
|
1948
1979
|
setOpen(true);
|
|
1949
|
-
}, children:
|
|
1950
|
-
? dayjs(getValues(column)).format("YYYY-MM-DD")
|
|
1951
|
-
: "" }) }), jsxRuntime.jsx(PopoverContent, { width: "auto", children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1, { selected: new Date(getValues(column)), onDateSelected: ({ selected, selectable, date }) => {
|
|
1980
|
+
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1, { selected: new Date(selectedDate), onDateSelected: ({ selected, selectable, date }) => {
|
|
1952
1981
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
1953
1982
|
setOpen(false);
|
|
1954
1983
|
} })] }) })] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
@@ -2180,7 +2209,7 @@ const FilePicker = ({ column }) => {
|
|
|
2180
2209
|
|
|
2181
2210
|
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
2182
2211
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
2183
|
-
const { schema,
|
|
2212
|
+
const { schema, displayText } = useSchemaContext();
|
|
2184
2213
|
const { fieldRequired } = displayText;
|
|
2185
2214
|
const { required } = schema;
|
|
2186
2215
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -2188,7 +2217,6 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2188
2217
|
throw new Error("schema properties when using DatePicker");
|
|
2189
2218
|
}
|
|
2190
2219
|
const { gridColumn, gridRow, title, renderDisplay } = schema.properties[column];
|
|
2191
|
-
const [selectedEnums, setSelectedEnums] = React.useState([]);
|
|
2192
2220
|
const [searchText, setSearchText] = React.useState();
|
|
2193
2221
|
const [limit, setLimit] = React.useState(10);
|
|
2194
2222
|
const [openSearchResult, setOpenSearchResult] = React.useState();
|
|
@@ -2203,7 +2231,7 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2203
2231
|
setLimit(10);
|
|
2204
2232
|
};
|
|
2205
2233
|
return (jsxRuntime.jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
2206
|
-
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [
|
|
2234
|
+
gridRow, children: [isMultiple && (jsxRuntime.jsxs(react.Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
2207
2235
|
const item = enumValue;
|
|
2208
2236
|
if (item === undefined) {
|
|
2209
2237
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "undefined" });
|
|
@@ -2214,9 +2242,9 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2214
2242
|
}, children: !!renderDisplay === true ? renderDisplay(item) : item }));
|
|
2215
2243
|
}), jsxRuntime.jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
2216
2244
|
setOpenSearchResult(true);
|
|
2217
|
-
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: (
|
|
2245
|
+
}, children: "Add" })] })), !isMultiple && (jsxRuntime.jsx(Button, { variant: "outline", onClick: () => {
|
|
2218
2246
|
setOpenSearchResult(true);
|
|
2219
|
-
}, children:
|
|
2247
|
+
}, children: watchEnums[0] })), 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, { children: [jsxRuntime.jsx(react.Input, { placeholder: "Type to search", onChange: (event) => {
|
|
2220
2248
|
onSearchChange(event);
|
|
2221
2249
|
setOpenSearchResult(true);
|
|
2222
2250
|
}, autoComplete: "off", ref: ref }), jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsxs(react.Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsxRuntime.jsx(react.Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsxRuntime.jsx(Button, { onClick: async () => {
|
|
@@ -2226,12 +2254,10 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2226
2254
|
return (jsxRuntime.jsx(react.Box, { cursor: "pointer", onClick: () => {
|
|
2227
2255
|
if (!isMultiple) {
|
|
2228
2256
|
setOpenSearchResult(false);
|
|
2229
|
-
setSelectedEnums(() => [item]);
|
|
2230
2257
|
setValue(column, [item]);
|
|
2231
2258
|
return;
|
|
2232
2259
|
}
|
|
2233
2260
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
2234
|
-
setSelectedEnums(() => [...newSet]);
|
|
2235
2261
|
setValue(column, [...newSet]);
|
|
2236
2262
|
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true ? renderDisplay(item) : item }, `${column}-${item}`));
|
|
2237
2263
|
}) }), 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 ?? "The field is requried" }))] }));
|
|
@@ -2249,7 +2275,7 @@ const idPickerSanityCheck = (column, in_table, column_ref, display_column) => {
|
|
|
2249
2275
|
}
|
|
2250
2276
|
};
|
|
2251
2277
|
const FormInternal = () => {
|
|
2252
|
-
const { schema, serverUrl, displayText, order, ignore, onSubmit,
|
|
2278
|
+
const { schema, serverUrl, displayText, order, ignore, onSubmit, rowNumber } = useSchemaContext();
|
|
2253
2279
|
const { title, submit, empty, cancel, submitSuccess, submitAgain, confirm } = displayText;
|
|
2254
2280
|
const methods = reactHookForm.useFormContext();
|
|
2255
2281
|
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
@@ -2328,14 +2354,6 @@ const FormInternal = () => {
|
|
|
2328
2354
|
value: value,
|
|
2329
2355
|
};
|
|
2330
2356
|
};
|
|
2331
|
-
React.useEffect(() => {
|
|
2332
|
-
const loadData = () => {
|
|
2333
|
-
Object.entries(preLoadedValues).map(([column, value]) => {
|
|
2334
|
-
methods.setValue(column, value);
|
|
2335
|
-
});
|
|
2336
|
-
};
|
|
2337
|
-
loadData();
|
|
2338
|
-
}, [preLoadedValues, methods]);
|
|
2339
2357
|
if (isSuccess) {
|
|
2340
2358
|
return (jsxRuntime.jsxs(react.Grid, { gap: 2, children: [jsxRuntime.jsx(react.Heading, { children: title ?? snakeToLabel(schema.title ?? "") }), jsxRuntime.jsxs(react.Alert.Root, { status: "success", children: [jsxRuntime.jsx(react.Alert.Indicator, {}), jsxRuntime.jsx(react.Alert.Title, { children: submitSuccess ?? "Data uploaded to the server. Fire on!" })] }), jsxRuntime.jsx(Button, { onClick: () => {
|
|
2341
2359
|
setIsError(false);
|
|
@@ -2387,7 +2405,7 @@ const FormInternal = () => {
|
|
|
2387
2405
|
}
|
|
2388
2406
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsxRuntime.jsx(react.Text, { children: snakeToLabel(column) }), jsxRuntime.jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
|
|
2389
2407
|
return (jsxRuntime.jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
2390
|
-
}) })] }));
|
|
2408
|
+
}) })] }, `form-${key}`));
|
|
2391
2409
|
}
|
|
2392
2410
|
if (type === "boolean") {
|
|
2393
2411
|
return (jsxRuntime.jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
@@ -2453,7 +2471,7 @@ const FormInternal = () => {
|
|
|
2453
2471
|
return jsxRuntime.jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
2454
2472
|
}
|
|
2455
2473
|
if (type === "object") {
|
|
2456
|
-
return
|
|
2474
|
+
return jsxRuntime.jsx(ObjectInput, { column: key }, `form-${key}`);
|
|
2457
2475
|
}
|
|
2458
2476
|
if (type === "array") {
|
|
2459
2477
|
if (variant === "id-picker") {
|
|
@@ -2478,7 +2496,7 @@ const FormInternal = () => {
|
|
|
2478
2496
|
};
|
|
2479
2497
|
const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, displayText = {}, }) => {
|
|
2480
2498
|
const queryClient = new reactQuery.QueryClient();
|
|
2481
|
-
const methods = reactHookForm.useForm();
|
|
2499
|
+
const methods = reactHookForm.useForm({ values: preLoadedValues });
|
|
2482
2500
|
const { properties } = schema;
|
|
2483
2501
|
idListSanityCheck("order", order, properties);
|
|
2484
2502
|
idListSanityCheck("ignore", ignore, properties);
|
|
@@ -2491,7 +2509,6 @@ const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined
|
|
|
2491
2509
|
ignore,
|
|
2492
2510
|
// @ts-expect-error TODO: find appropriate types
|
|
2493
2511
|
onSubmit,
|
|
2494
|
-
preLoadedValues,
|
|
2495
2512
|
rowNumber,
|
|
2496
2513
|
}, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: jsxRuntime.jsx(FormInternal, {}) }) }) }));
|
|
2497
2514
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1548,7 +1548,6 @@ const SchemaFormContext = createContext({
|
|
|
1548
1548
|
order: [],
|
|
1549
1549
|
ignore: [],
|
|
1550
1550
|
onSubmit: async () => { },
|
|
1551
|
-
preLoadedValues: {},
|
|
1552
1551
|
rowNumber: 0,
|
|
1553
1552
|
displayText: {},
|
|
1554
1553
|
});
|
|
@@ -1632,26 +1631,63 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1632
1631
|
}
|
|
1633
1632
|
const { total, showing, close, typeToSearch, showMore } = displayText;
|
|
1634
1633
|
const { gridColumn, gridRow, title, renderDisplay } = schema.properties[column];
|
|
1635
|
-
const [selectedIds, setSelectedIds] = useState([]);
|
|
1636
1634
|
const [searchText, setSearchText] = useState();
|
|
1637
1635
|
const [limit, setLimit] = useState(10);
|
|
1638
1636
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
1639
1637
|
const [idMap, setIdMap] = useState({});
|
|
1640
1638
|
const ref = useRef(null);
|
|
1639
|
+
const selectedIds = watch(column) ?? [];
|
|
1641
1640
|
const query = useQuery({
|
|
1642
1641
|
queryKey: [`idpicker`, searchText, in_table, limit],
|
|
1643
1642
|
queryFn: async () => {
|
|
1644
|
-
|
|
1643
|
+
const data = await getTableData({
|
|
1645
1644
|
serverUrl,
|
|
1646
1645
|
searching: searchText ?? "",
|
|
1647
1646
|
in_table: in_table,
|
|
1648
1647
|
limit: limit,
|
|
1649
1648
|
});
|
|
1649
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
1650
|
+
return [
|
|
1651
|
+
item[column_ref],
|
|
1652
|
+
{
|
|
1653
|
+
...item,
|
|
1654
|
+
},
|
|
1655
|
+
];
|
|
1656
|
+
}));
|
|
1657
|
+
setIdMap((state) => {
|
|
1658
|
+
return { ...state, ...newMap };
|
|
1659
|
+
});
|
|
1660
|
+
return data;
|
|
1661
|
+
},
|
|
1662
|
+
enabled: (searchText ?? "")?.length > 0,
|
|
1663
|
+
staleTime: 10000,
|
|
1664
|
+
});
|
|
1665
|
+
useQuery({
|
|
1666
|
+
queryKey: [`idpicker`, ...selectedIds],
|
|
1667
|
+
queryFn: async () => {
|
|
1668
|
+
const data = await getTableData({
|
|
1669
|
+
serverUrl,
|
|
1670
|
+
in_table: in_table,
|
|
1671
|
+
limit: limit,
|
|
1672
|
+
});
|
|
1673
|
+
const newMap = Object.fromEntries((data ?? { data: [] }).data.map((item) => {
|
|
1674
|
+
return [
|
|
1675
|
+
item[column_ref],
|
|
1676
|
+
{
|
|
1677
|
+
...item,
|
|
1678
|
+
},
|
|
1679
|
+
];
|
|
1680
|
+
}));
|
|
1681
|
+
setIdMap((state) => {
|
|
1682
|
+
return { ...state, ...newMap };
|
|
1683
|
+
});
|
|
1684
|
+
return data;
|
|
1650
1685
|
},
|
|
1686
|
+
enabled: (selectedIds ?? []).length > 0,
|
|
1651
1687
|
staleTime: 10000,
|
|
1652
1688
|
});
|
|
1653
1689
|
const { isLoading, isFetching, data, isPending, isError } = query;
|
|
1654
|
-
const dataList = data?.data ?? [];
|
|
1690
|
+
const dataList = useMemo(() => data?.data ?? [], [data]);
|
|
1655
1691
|
const count = data?.count ?? 0;
|
|
1656
1692
|
const isDirty = (searchText?.length ?? 0) > 0;
|
|
1657
1693
|
const onSearchChange = async (event) => {
|
|
@@ -1659,19 +1695,19 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1659
1695
|
setLimit(10);
|
|
1660
1696
|
};
|
|
1661
1697
|
const ids = (watch(column) ?? []);
|
|
1662
|
-
const
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1698
|
+
const getPickedValue = () => {
|
|
1699
|
+
if (selectedIds.length <= 0) {
|
|
1700
|
+
return "";
|
|
1701
|
+
}
|
|
1702
|
+
if (Object.keys(idMap).length <= 0) {
|
|
1703
|
+
return "";
|
|
1704
|
+
}
|
|
1705
|
+
const record = idMap[selectedIds[0]];
|
|
1706
|
+
if (record === undefined) {
|
|
1707
|
+
return "";
|
|
1708
|
+
}
|
|
1709
|
+
return record[display_column];
|
|
1710
|
+
};
|
|
1675
1711
|
return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1676
1712
|
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [selectedIds.map((id) => {
|
|
1677
1713
|
const item = idMap[id];
|
|
@@ -1679,16 +1715,15 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1679
1715
|
return jsx(Fragment, { children: "undefined" });
|
|
1680
1716
|
}
|
|
1681
1717
|
return (jsx(Tag, { closable: true, onClick: () => {
|
|
1682
|
-
setSelectedIds((state) => state.filter((id) => id != item[column_ref]));
|
|
1683
1718
|
setValue(column, ids.filter((id) => id != item[column_ref]));
|
|
1684
1719
|
}, children: !!renderDisplay === true
|
|
1685
1720
|
? renderDisplay(item)
|
|
1686
1721
|
: item[display_column] }));
|
|
1687
1722
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
1688
1723
|
setOpenSearchResult(true);
|
|
1689
|
-
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: (
|
|
1724
|
+
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
1690
1725
|
setOpenSearchResult(true);
|
|
1691
|
-
}, children:
|
|
1726
|
+
}, children: getPickedValue() })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(Input, { placeholder: typeToSearch, onChange: (event) => {
|
|
1692
1727
|
onSearchChange(event);
|
|
1693
1728
|
setOpenSearchResult(true);
|
|
1694
1729
|
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [isFetching && jsx(Fragment, { children: "isFetching" }), isLoading && jsx(Fragment, { children: "isLoading" }), isPending && jsx(Fragment, { children: "isPending" }), isError && jsx(Fragment, { children: "isError" }), jsx(Text, { children: `${total ?? "Total"} ${count}, ${showing ?? "Showing"} ${limit}` }), jsx(Button, { onClick: async () => {
|
|
@@ -1700,7 +1735,6 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1700
1735
|
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
1701
1736
|
if (!isMultiple) {
|
|
1702
1737
|
setOpenSearchResult(false);
|
|
1703
|
-
setSelectedIds(() => [item[column_ref]]);
|
|
1704
1738
|
setValue(column, [item[column_ref]]);
|
|
1705
1739
|
return;
|
|
1706
1740
|
}
|
|
@@ -1708,7 +1742,6 @@ const IdPicker = ({ column, in_table, column_ref, display_column, isMultiple = f
|
|
|
1708
1742
|
...(ids ?? []),
|
|
1709
1743
|
item[column_ref],
|
|
1710
1744
|
]);
|
|
1711
|
-
setSelectedIds(() => [...newSet]);
|
|
1712
1745
|
setValue(column, [...newSet]);
|
|
1713
1746
|
}, opacity: 0.7, _hover: { opacity: 1 }, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true
|
|
1714
1747
|
? renderDisplay(item)
|
|
@@ -1824,21 +1857,18 @@ const AccordionRoot = Accordion.Root;
|
|
|
1824
1857
|
const AccordionItem = Accordion.Item;
|
|
1825
1858
|
|
|
1826
1859
|
const BooleanPicker = ({ column }) => {
|
|
1827
|
-
const { formState: { errors }, setValue, getValues, } = useFormContext();
|
|
1860
|
+
const { watch, formState: { errors }, setValue, getValues, } = useFormContext();
|
|
1828
1861
|
const { schema, displayText } = useSchemaContext();
|
|
1829
1862
|
const { fieldRequired } = displayText;
|
|
1830
1863
|
const { required } = schema;
|
|
1831
1864
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
1865
|
+
const value = watch(column);
|
|
1832
1866
|
if (schema.properties == undefined) {
|
|
1833
1867
|
throw new Error("schema properties when using BooleanPicker");
|
|
1834
1868
|
}
|
|
1835
1869
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1836
1870
|
return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1837
|
-
gridRow, children: [jsx(CheckboxCard
|
|
1838
|
-
// label={snakeToLabel(column)}
|
|
1839
|
-
, {
|
|
1840
|
-
// label={snakeToLabel(column)}
|
|
1841
|
-
value: getValues(column), variant: "surface", onSelect: () => {
|
|
1871
|
+
gridRow, children: [jsx(CheckboxCard, { checked: value, variant: "surface", onSelect: () => {
|
|
1842
1872
|
setValue(column, !getValues(column));
|
|
1843
1873
|
} }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
1844
1874
|
};
|
|
@@ -1913,22 +1943,21 @@ let DatePicker$1 = class DatePicker extends React__default.Component {
|
|
|
1913
1943
|
};
|
|
1914
1944
|
|
|
1915
1945
|
const DatePicker = ({ column }) => {
|
|
1916
|
-
const { formState: { errors }, setValue,
|
|
1946
|
+
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
1917
1947
|
const { schema, displayText } = useSchemaContext();
|
|
1918
1948
|
const { fieldRequired } = displayText;
|
|
1919
1949
|
const { required } = schema;
|
|
1920
1950
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
1921
1951
|
const [open, setOpen] = useState(false);
|
|
1952
|
+
const selectedDate = watch(column);
|
|
1922
1953
|
if (schema.properties == undefined) {
|
|
1923
1954
|
throw new Error("schema properties when using DatePicker");
|
|
1924
1955
|
}
|
|
1925
1956
|
const { gridColumn, gridRow, title } = schema.properties[column];
|
|
1926
1957
|
return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
1927
|
-
gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true,
|
|
1958
|
+
gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
1928
1959
|
setOpen(true);
|
|
1929
|
-
}, children:
|
|
1930
|
-
? dayjs(getValues(column)).format("YYYY-MM-DD")
|
|
1931
|
-
: "" }) }), jsx(PopoverContent, { width: "auto", children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1, { selected: new Date(getValues(column)), onDateSelected: ({ selected, selectable, date }) => {
|
|
1960
|
+
}, children: selectedDate !== undefined ? selectedDate : "" }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1, { selected: new Date(selectedDate), onDateSelected: ({ selected, selectable, date }) => {
|
|
1932
1961
|
setValue(column, dayjs(date).format("YYYY-MM-DD"));
|
|
1933
1962
|
setOpen(false);
|
|
1934
1963
|
} })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
@@ -2160,7 +2189,7 @@ const FilePicker = ({ column }) => {
|
|
|
2160
2189
|
|
|
2161
2190
|
const EnumPicker = ({ column, isMultiple = false }) => {
|
|
2162
2191
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
2163
|
-
const { schema,
|
|
2192
|
+
const { schema, displayText } = useSchemaContext();
|
|
2164
2193
|
const { fieldRequired } = displayText;
|
|
2165
2194
|
const { required } = schema;
|
|
2166
2195
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
@@ -2168,7 +2197,6 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2168
2197
|
throw new Error("schema properties when using DatePicker");
|
|
2169
2198
|
}
|
|
2170
2199
|
const { gridColumn, gridRow, title, renderDisplay } = schema.properties[column];
|
|
2171
|
-
const [selectedEnums, setSelectedEnums] = useState([]);
|
|
2172
2200
|
const [searchText, setSearchText] = useState();
|
|
2173
2201
|
const [limit, setLimit] = useState(10);
|
|
2174
2202
|
const [openSearchResult, setOpenSearchResult] = useState();
|
|
@@ -2183,7 +2211,7 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2183
2211
|
setLimit(10);
|
|
2184
2212
|
};
|
|
2185
2213
|
return (jsxs(Field, { label: `${title ?? snakeToLabel(column)}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
2186
|
-
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [
|
|
2214
|
+
gridRow, children: [isMultiple && (jsxs(Flex, { flexFlow: "wrap", gap: 1, children: [watchEnums.map((enumValue) => {
|
|
2187
2215
|
const item = enumValue;
|
|
2188
2216
|
if (item === undefined) {
|
|
2189
2217
|
return jsx(Fragment, { children: "undefined" });
|
|
@@ -2194,9 +2222,9 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2194
2222
|
}, children: !!renderDisplay === true ? renderDisplay(item) : item }));
|
|
2195
2223
|
}), jsx(Tag, { cursor: "pointer", onClick: () => {
|
|
2196
2224
|
setOpenSearchResult(true);
|
|
2197
|
-
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: (
|
|
2225
|
+
}, children: "Add" })] })), !isMultiple && (jsx(Button, { variant: "outline", onClick: () => {
|
|
2198
2226
|
setOpenSearchResult(true);
|
|
2199
|
-
}, children:
|
|
2227
|
+
}, children: watchEnums[0] })), jsxs(PopoverRoot, { open: openSearchResult, onOpenChange: (e) => setOpenSearchResult(e.open), closeOnInteractOutside: true, initialFocusEl: () => ref.current, positioning: { placement: "bottom-start" }, children: [jsx(PopoverTrigger, {}), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(Input, { placeholder: "Type to search", onChange: (event) => {
|
|
2200
2228
|
onSearchChange(event);
|
|
2201
2229
|
setOpenSearchResult(true);
|
|
2202
2230
|
}, autoComplete: "off", ref: ref }), jsx(PopoverTitle, {}), jsxs(Grid, { gridTemplateColumns: "repeat(auto-fit, minmax(15rem, 1fr))", overflow: "auto", maxHeight: "50vh", children: [jsx(Text, { children: `Search Result: ${count}, Showing ${limit}` }), jsx(Button, { onClick: async () => {
|
|
@@ -2206,12 +2234,10 @@ const EnumPicker = ({ column, isMultiple = false }) => {
|
|
|
2206
2234
|
return (jsx(Box, { cursor: "pointer", onClick: () => {
|
|
2207
2235
|
if (!isMultiple) {
|
|
2208
2236
|
setOpenSearchResult(false);
|
|
2209
|
-
setSelectedEnums(() => [item]);
|
|
2210
2237
|
setValue(column, [item]);
|
|
2211
2238
|
return;
|
|
2212
2239
|
}
|
|
2213
2240
|
const newSet = new Set([...(watchEnums ?? []), item]);
|
|
2214
|
-
setSelectedEnums(() => [...newSet]);
|
|
2215
2241
|
setValue(column, [...newSet]);
|
|
2216
2242
|
}, ...(selected ? { color: "gray.400/50" } : {}), children: !!renderDisplay === true ? renderDisplay(item) : item }, `${column}-${item}`));
|
|
2217
2243
|
}) }), isDirty && (jsxs(Fragment, { children: [dataList.length <= 0 && jsx(Fragment, { children: "Empty Search Result" }), " "] }))] })] }) })] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: fieldRequired ?? "The field is requried" }))] }));
|
|
@@ -2229,7 +2255,7 @@ const idPickerSanityCheck = (column, in_table, column_ref, display_column) => {
|
|
|
2229
2255
|
}
|
|
2230
2256
|
};
|
|
2231
2257
|
const FormInternal = () => {
|
|
2232
|
-
const { schema, serverUrl, displayText, order, ignore, onSubmit,
|
|
2258
|
+
const { schema, serverUrl, displayText, order, ignore, onSubmit, rowNumber } = useSchemaContext();
|
|
2233
2259
|
const { title, submit, empty, cancel, submitSuccess, submitAgain, confirm } = displayText;
|
|
2234
2260
|
const methods = useFormContext();
|
|
2235
2261
|
const [isSuccess, setIsSuccess] = useState(false);
|
|
@@ -2308,14 +2334,6 @@ const FormInternal = () => {
|
|
|
2308
2334
|
value: value,
|
|
2309
2335
|
};
|
|
2310
2336
|
};
|
|
2311
|
-
useEffect(() => {
|
|
2312
|
-
const loadData = () => {
|
|
2313
|
-
Object.entries(preLoadedValues).map(([column, value]) => {
|
|
2314
|
-
methods.setValue(column, value);
|
|
2315
|
-
});
|
|
2316
|
-
};
|
|
2317
|
-
loadData();
|
|
2318
|
-
}, [preLoadedValues, methods]);
|
|
2319
2337
|
if (isSuccess) {
|
|
2320
2338
|
return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: title ?? snakeToLabel(schema.title ?? "") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: submitSuccess ?? "Data uploaded to the server. Fire on!" })] }), jsx(Button, { onClick: () => {
|
|
2321
2339
|
setIsError(false);
|
|
@@ -2367,7 +2385,7 @@ const FormInternal = () => {
|
|
|
2367
2385
|
}
|
|
2368
2386
|
return (jsxs(Flex, { flexFlow: "column", gap: 2, gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 1", children: [jsx(Text, { children: snakeToLabel(column) }), jsx(DataListRoot, { orientation: "horizontal", padding: 4, borderColor: "gray.200", borderWidth: 1, borderRadius: 4, children: Object.entries(value).map(([key, value]) => {
|
|
2369
2387
|
return (jsx(DataListItem, { label: `${key}`, ...getDataListProps(value) }, `form-${column}-${key}`));
|
|
2370
|
-
}) })] }));
|
|
2388
|
+
}) })] }, `form-${key}`));
|
|
2371
2389
|
}
|
|
2372
2390
|
if (type === "boolean") {
|
|
2373
2391
|
return (jsx(DataListItem, { gridColumn: gridColumn ?? "span 4", gridRow: gridRow ?? "span 4", label: `${snakeToLabel(column)}`, ...getDataListProps((validatedData ?? {})[column]) }, `form-${key}`));
|
|
@@ -2433,7 +2451,7 @@ const FormInternal = () => {
|
|
|
2433
2451
|
return jsx(BooleanPicker, { column: key }, `form-${key}`);
|
|
2434
2452
|
}
|
|
2435
2453
|
if (type === "object") {
|
|
2436
|
-
return
|
|
2454
|
+
return jsx(ObjectInput, { column: key }, `form-${key}`);
|
|
2437
2455
|
}
|
|
2438
2456
|
if (type === "array") {
|
|
2439
2457
|
if (variant === "id-picker") {
|
|
@@ -2458,7 +2476,7 @@ const FormInternal = () => {
|
|
|
2458
2476
|
};
|
|
2459
2477
|
const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined, preLoadedValues = {}, rowNumber = undefined, displayText = {}, }) => {
|
|
2460
2478
|
const queryClient = new QueryClient();
|
|
2461
|
-
const methods = useForm();
|
|
2479
|
+
const methods = useForm({ values: preLoadedValues });
|
|
2462
2480
|
const { properties } = schema;
|
|
2463
2481
|
idListSanityCheck("order", order, properties);
|
|
2464
2482
|
idListSanityCheck("ignore", ignore, properties);
|
|
@@ -2471,7 +2489,6 @@ const Form = ({ schema, serverUrl, order = [], ignore = [], onSubmit = undefined
|
|
|
2471
2489
|
ignore,
|
|
2472
2490
|
// @ts-expect-error TODO: find appropriate types
|
|
2473
2491
|
onSubmit,
|
|
2474
|
-
preLoadedValues,
|
|
2475
2492
|
rowNumber,
|
|
2476
2493
|
}, children: jsx(FormProvider, { ...methods, children: jsx(FormInternal, {}) }) }) }));
|
|
2477
2494
|
};
|
|
@@ -6,4 +6,4 @@ export interface DataTableContext<TData> {
|
|
|
6
6
|
setGlobalFilter: OnChangeFn<string>;
|
|
7
7
|
type: "client" | "server";
|
|
8
8
|
}
|
|
9
|
-
export declare const DataTableContext: import("react").Context<DataTableContext<
|
|
9
|
+
export declare const DataTableContext: import("react").Context<DataTableContext<unknown>>;
|
|
@@ -9,7 +9,6 @@ export interface SchemaFormContext<TData extends FieldValues> {
|
|
|
9
9
|
ignore: string[];
|
|
10
10
|
displayText: DisplayTextProps;
|
|
11
11
|
onSubmit?: (data: TData) => Promise<void>;
|
|
12
|
-
preLoadedValues: object;
|
|
13
12
|
rowNumber?: number | string;
|
|
14
13
|
}
|
|
15
14
|
export declare const SchemaFormContext: import("react").Context<SchemaFormContext<unknown>>;
|
|
@@ -4,7 +4,7 @@ export declare const useSchemaContext: () => {
|
|
|
4
4
|
order: string[];
|
|
5
5
|
ignore: string[];
|
|
6
6
|
onSubmit: ((data: unknown) => Promise<void>) | undefined;
|
|
7
|
-
preLoadedValues:
|
|
7
|
+
preLoadedValues: any;
|
|
8
8
|
rowNumber: string | number | undefined;
|
|
9
9
|
displayText: import("./Form").DisplayTextProps;
|
|
10
10
|
};
|