@bsol-oss/react-datatable5 11.0.0-beta.8 → 12.0.0-beta.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
CHANGED
|
@@ -467,6 +467,7 @@ interface FormProps<TData extends FieldValues> {
|
|
|
467
467
|
translate: UseTranslationResponse<any, any>;
|
|
468
468
|
order?: string[];
|
|
469
469
|
ignore?: string[];
|
|
470
|
+
include?: string[];
|
|
470
471
|
onSubmit?: SubmitHandler<TData>;
|
|
471
472
|
rowNumber?: number | string;
|
|
472
473
|
requestOptions?: AxiosRequestConfig;
|
|
@@ -485,7 +486,7 @@ declare const idPickerSanityCheck: (column: string, foreign_key?: {
|
|
|
485
486
|
column?: string | undefined;
|
|
486
487
|
display_column?: string | undefined;
|
|
487
488
|
} | undefined) => void;
|
|
488
|
-
declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, rowNumber, requestOptions, }: FormProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
489
|
+
declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, include, onSubmit, rowNumber, requestOptions, }: FormProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
489
490
|
|
|
490
491
|
interface UseFormProps {
|
|
491
492
|
preLoadedValues?: FieldValues | undefined;
|
package/dist/index.js
CHANGED
|
@@ -3548,26 +3548,14 @@ const SchemaFormContext = React.createContext({
|
|
|
3548
3548
|
requestUrl: "",
|
|
3549
3549
|
order: [],
|
|
3550
3550
|
ignore: [],
|
|
3551
|
+
include: [],
|
|
3551
3552
|
onSubmit: async () => { },
|
|
3552
3553
|
rowNumber: 0,
|
|
3553
3554
|
requestOptions: {},
|
|
3554
3555
|
});
|
|
3555
3556
|
|
|
3556
3557
|
const useSchemaContext = () => {
|
|
3557
|
-
|
|
3558
|
-
return {
|
|
3559
|
-
schema,
|
|
3560
|
-
serverUrl,
|
|
3561
|
-
requestUrl,
|
|
3562
|
-
order,
|
|
3563
|
-
ignore,
|
|
3564
|
-
onSubmit,
|
|
3565
|
-
rowNumber,
|
|
3566
|
-
idMap,
|
|
3567
|
-
setIdMap,
|
|
3568
|
-
translate,
|
|
3569
|
-
requestOptions,
|
|
3570
|
-
};
|
|
3558
|
+
return React.useContext(SchemaFormContext);
|
|
3571
3559
|
};
|
|
3572
3560
|
|
|
3573
3561
|
const clearEmptyString = (object) => {
|
|
@@ -4350,12 +4338,15 @@ react.NumberInput.Scrubber;
|
|
|
4350
4338
|
react.NumberInput.Label;
|
|
4351
4339
|
|
|
4352
4340
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4353
|
-
const {
|
|
4341
|
+
const { setValue, formState: { errors }, watch, } = reactHookForm.useFormContext();
|
|
4354
4342
|
const { translate } = useSchemaContext();
|
|
4355
4343
|
const { required, gridColumn, gridRow } = schema;
|
|
4356
4344
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4357
4345
|
const colLabel = `${prefix}${column}`;
|
|
4358
|
-
|
|
4346
|
+
const value = watch(`${colLabel}`);
|
|
4347
|
+
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn, gridRow, children: [jsxRuntime.jsx(NumberInputRoot, { children: jsxRuntime.jsx(NumberInputField$1, { required: isRequired, value: value, onChange: (event) => {
|
|
4348
|
+
setValue(`${colLabel}`, Number(event.target.value));
|
|
4349
|
+
} }) }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4359
4350
|
};
|
|
4360
4351
|
|
|
4361
4352
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
@@ -4950,7 +4941,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4950
4941
|
}
|
|
4951
4942
|
};
|
|
4952
4943
|
const FormInternal = () => {
|
|
4953
|
-
const { schema, requestUrl, order, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4944
|
+
const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4954
4945
|
const methods = reactHookForm.useFormContext();
|
|
4955
4946
|
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
4956
4947
|
const [isError, setIsError] = React.useState(false);
|
|
@@ -5009,11 +5000,19 @@ const FormInternal = () => {
|
|
|
5009
5000
|
setIsError(false);
|
|
5010
5001
|
setIsConfirming(true);
|
|
5011
5002
|
};
|
|
5012
|
-
const
|
|
5013
|
-
const
|
|
5014
|
-
|
|
5003
|
+
const renderColumns = ({ order, keys, ignore, include, }) => {
|
|
5004
|
+
const included = include.length > 0 ? include : keys;
|
|
5005
|
+
const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
|
|
5006
|
+
const ordered = [...order, ...not_exist];
|
|
5007
|
+
const ignored = ordered.filter((column) => !ignore.some((shouldIgnore) => column === shouldIgnore));
|
|
5008
|
+
return ignored;
|
|
5015
5009
|
};
|
|
5016
|
-
const ordered =
|
|
5010
|
+
const ordered = renderColumns({
|
|
5011
|
+
order,
|
|
5012
|
+
keys: Object.keys(properties),
|
|
5013
|
+
ignore,
|
|
5014
|
+
include,
|
|
5015
|
+
});
|
|
5017
5016
|
if (isSuccess) {
|
|
5018
5017
|
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(react.Flex, { justifyContent: "end", children: jsxRuntime.jsx(Button, { onClick: () => {
|
|
5019
5018
|
setIsError(false);
|
|
@@ -5049,15 +5048,16 @@ const FormInternal = () => {
|
|
|
5049
5048
|
methods.handleSubmit(onValid)();
|
|
5050
5049
|
}, formNoValidate: true, children: translate.t("submit") })] })] }) }));
|
|
5051
5050
|
};
|
|
5052
|
-
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
|
|
5053
|
-
const { properties } = schema;
|
|
5054
|
-
idListSanityCheck("order", order, properties);
|
|
5055
|
-
idListSanityCheck("ignore", ignore, properties);
|
|
5051
|
+
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
|
|
5052
|
+
// const { properties } = schema;
|
|
5053
|
+
// idListSanityCheck("order", order, properties as object);
|
|
5054
|
+
// idListSanityCheck("ignore", ignore, properties as object);
|
|
5056
5055
|
return (jsxRuntime.jsx(SchemaFormContext.Provider, { value: {
|
|
5057
5056
|
schema,
|
|
5058
5057
|
serverUrl,
|
|
5059
5058
|
order,
|
|
5060
5059
|
ignore,
|
|
5060
|
+
include,
|
|
5061
5061
|
// @ts-expect-error TODO: find appropriate types
|
|
5062
5062
|
onSubmit,
|
|
5063
5063
|
rowNumber,
|
package/dist/index.mjs
CHANGED
|
@@ -3528,26 +3528,14 @@ const SchemaFormContext = createContext({
|
|
|
3528
3528
|
requestUrl: "",
|
|
3529
3529
|
order: [],
|
|
3530
3530
|
ignore: [],
|
|
3531
|
+
include: [],
|
|
3531
3532
|
onSubmit: async () => { },
|
|
3532
3533
|
rowNumber: 0,
|
|
3533
3534
|
requestOptions: {},
|
|
3534
3535
|
});
|
|
3535
3536
|
|
|
3536
3537
|
const useSchemaContext = () => {
|
|
3537
|
-
|
|
3538
|
-
return {
|
|
3539
|
-
schema,
|
|
3540
|
-
serverUrl,
|
|
3541
|
-
requestUrl,
|
|
3542
|
-
order,
|
|
3543
|
-
ignore,
|
|
3544
|
-
onSubmit,
|
|
3545
|
-
rowNumber,
|
|
3546
|
-
idMap,
|
|
3547
|
-
setIdMap,
|
|
3548
|
-
translate,
|
|
3549
|
-
requestOptions,
|
|
3550
|
-
};
|
|
3538
|
+
return useContext(SchemaFormContext);
|
|
3551
3539
|
};
|
|
3552
3540
|
|
|
3553
3541
|
const clearEmptyString = (object) => {
|
|
@@ -4330,12 +4318,15 @@ NumberInput.Scrubber;
|
|
|
4330
4318
|
NumberInput.Label;
|
|
4331
4319
|
|
|
4332
4320
|
const NumberInputField = ({ schema, column, prefix, }) => {
|
|
4333
|
-
const {
|
|
4321
|
+
const { setValue, formState: { errors }, watch, } = useFormContext();
|
|
4334
4322
|
const { translate } = useSchemaContext();
|
|
4335
4323
|
const { required, gridColumn, gridRow } = schema;
|
|
4336
4324
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4337
4325
|
const colLabel = `${prefix}${column}`;
|
|
4338
|
-
|
|
4326
|
+
const value = watch(`${colLabel}`);
|
|
4327
|
+
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.fieldLabel`))}`, required: isRequired, gridColumn, gridRow, children: [jsx(NumberInputRoot, { children: jsx(NumberInputField$1, { required: isRequired, value: value, onChange: (event) => {
|
|
4328
|
+
setValue(`${colLabel}`, Number(event.target.value));
|
|
4329
|
+
} }) }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(removeIndex(`${colLabel}.fieldRequired`)) }))] }));
|
|
4339
4330
|
};
|
|
4340
4331
|
|
|
4341
4332
|
const ObjectInput = ({ schema, column, prefix }) => {
|
|
@@ -4930,7 +4921,7 @@ const idPickerSanityCheck = (column, foreign_key) => {
|
|
|
4930
4921
|
}
|
|
4931
4922
|
};
|
|
4932
4923
|
const FormInternal = () => {
|
|
4933
|
-
const { schema, requestUrl, order, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4924
|
+
const { schema, requestUrl, order, ignore, include, onSubmit, rowNumber, translate, requestOptions, } = useSchemaContext();
|
|
4934
4925
|
const methods = useFormContext();
|
|
4935
4926
|
const [isSuccess, setIsSuccess] = useState(false);
|
|
4936
4927
|
const [isError, setIsError] = useState(false);
|
|
@@ -4989,11 +4980,19 @@ const FormInternal = () => {
|
|
|
4989
4980
|
setIsError(false);
|
|
4990
4981
|
setIsConfirming(true);
|
|
4991
4982
|
};
|
|
4992
|
-
const
|
|
4993
|
-
const
|
|
4994
|
-
|
|
4983
|
+
const renderColumns = ({ order, keys, ignore, include, }) => {
|
|
4984
|
+
const included = include.length > 0 ? include : keys;
|
|
4985
|
+
const not_exist = included.filter((columnA) => !order.some((columnB) => columnA === columnB));
|
|
4986
|
+
const ordered = [...order, ...not_exist];
|
|
4987
|
+
const ignored = ordered.filter((column) => !ignore.some((shouldIgnore) => column === shouldIgnore));
|
|
4988
|
+
return ignored;
|
|
4995
4989
|
};
|
|
4996
|
-
const ordered =
|
|
4990
|
+
const ordered = renderColumns({
|
|
4991
|
+
order,
|
|
4992
|
+
keys: Object.keys(properties),
|
|
4993
|
+
ignore,
|
|
4994
|
+
include,
|
|
4995
|
+
});
|
|
4997
4996
|
if (isSuccess) {
|
|
4998
4997
|
return (jsxs(Grid, { gap: 2, children: [jsx(Heading, { children: translate.t("title") }), jsxs(Alert.Root, { status: "success", children: [jsx(Alert.Indicator, {}), jsx(Alert.Title, { children: translate.t("submitSuccess") })] }), jsx(Flex, { justifyContent: "end", children: jsx(Button, { onClick: () => {
|
|
4999
4998
|
setIsError(false);
|
|
@@ -5029,15 +5028,16 @@ const FormInternal = () => {
|
|
|
5029
5028
|
methods.handleSubmit(onValid)();
|
|
5030
5029
|
}, formNoValidate: true, children: translate.t("submit") })] })] }) }));
|
|
5031
5030
|
};
|
|
5032
|
-
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
|
|
5033
|
-
const { properties } = schema;
|
|
5034
|
-
idListSanityCheck("order", order, properties);
|
|
5035
|
-
idListSanityCheck("ignore", ignore, properties);
|
|
5031
|
+
const Form = ({ schema, idMap, setIdMap, form, serverUrl, translate, order = [], ignore = [], include = [], onSubmit = undefined, rowNumber = undefined, requestOptions = {}, }) => {
|
|
5032
|
+
// const { properties } = schema;
|
|
5033
|
+
// idListSanityCheck("order", order, properties as object);
|
|
5034
|
+
// idListSanityCheck("ignore", ignore, properties as object);
|
|
5036
5035
|
return (jsx(SchemaFormContext.Provider, { value: {
|
|
5037
5036
|
schema,
|
|
5038
5037
|
serverUrl,
|
|
5039
5038
|
order,
|
|
5040
5039
|
ignore,
|
|
5040
|
+
include,
|
|
5041
5041
|
// @ts-expect-error TODO: find appropriate types
|
|
5042
5042
|
onSubmit,
|
|
5043
5043
|
rowNumber,
|
|
@@ -14,6 +14,7 @@ export interface FormProps<TData extends FieldValues> {
|
|
|
14
14
|
translate: UseTranslationResponse<any, any>;
|
|
15
15
|
order?: string[];
|
|
16
16
|
ignore?: string[];
|
|
17
|
+
include?: string[];
|
|
17
18
|
onSubmit?: SubmitHandler<TData>;
|
|
18
19
|
rowNumber?: number | string;
|
|
19
20
|
requestOptions?: AxiosRequestConfig;
|
|
@@ -32,4 +33,4 @@ export declare const idPickerSanityCheck: (column: string, foreign_key?: {
|
|
|
32
33
|
column?: string | undefined;
|
|
33
34
|
display_column?: string | undefined;
|
|
34
35
|
} | undefined) => void;
|
|
35
|
-
export declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, onSubmit, rowNumber, requestOptions, }: FormProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
export declare const Form: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, order, ignore, include, onSubmit, rowNumber, requestOptions, }: FormProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const useSchemaContext: () =>
|
|
3
|
-
schema: import("json-schema").JSONSchema7;
|
|
4
|
-
serverUrl: string;
|
|
5
|
-
requestUrl: string;
|
|
6
|
-
order: string[];
|
|
7
|
-
ignore: string[];
|
|
8
|
-
onSubmit: ((data: unknown) => Promise<void>) | undefined;
|
|
9
|
-
rowNumber: string | number | undefined;
|
|
10
|
-
idMap: Record<string, object>;
|
|
11
|
-
setIdMap: import("react").Dispatch<import("react").SetStateAction<Record<string, object>>>;
|
|
12
|
-
translate: import("react-i18next").UseTranslationResponse<any, any>;
|
|
13
|
-
requestOptions: import("axios").AxiosRequestConfig<any>;
|
|
14
|
-
};
|
|
1
|
+
import { SchemaFormContext } from "./SchemaFormContext";
|
|
2
|
+
export declare const useSchemaContext: () => SchemaFormContext<unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsol-oss/react-datatable5",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -49,12 +49,11 @@
|
|
|
49
49
|
"react": "^19.0.0",
|
|
50
50
|
"react-dom": "^19.0.0",
|
|
51
51
|
"react-hook-form": "^7.54.2",
|
|
52
|
+
"react-i18next": "^15.4.1",
|
|
52
53
|
"react-icons": "^5.4.0",
|
|
53
|
-
"tiny-invariant": "^1.3.3"
|
|
54
|
-
"react-i18next": "^15.4.1"
|
|
54
|
+
"tiny-invariant": "^1.3.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@chromatic-com/storybook": "^3.2.3",
|
|
58
57
|
"@rollup/plugin-alias": "^5.1.1",
|
|
59
58
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
60
59
|
"@storybook/addon-essentials": "^8.4.7",
|