drf-react-by-schema 0.24.6 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/index.d.ts +80 -64
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts +10 -12
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +2 -2
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +5 -5
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +5 -5
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +3 -6
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +13 -17
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +0 -1
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils.js +8 -1
- package/dist/components/DataGridBySchemaEditable.d.ts +5 -5
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable.js +4 -4
- package/dist/components/GenericModelList.d.ts +11 -11
- package/dist/components/GenericModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelList.d.ts +10 -10
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelListTable.d.ts +6 -6
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.d.ts +2 -2
- package/dist/components/details/DetailBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.js +30 -21
- package/dist/components/forms/DialogFormBySchema.d.ts +3 -3
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -1
- package/dist/components/forms/Form.d.ts +11 -8
- package/dist/components/forms/Form.d.ts.map +1 -1
- package/dist/components/forms/Form.js +18 -8
- package/dist/components/forms/FormActions.d.ts +3 -3
- package/dist/components/forms/FormActions.d.ts.map +1 -1
- package/dist/components/forms/FormActions.js +2 -2
- package/dist/components/forms/FormBySchema.d.ts +4 -4
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +27 -11
- package/dist/components/forms/FormWatcher.d.ts +7 -5
- package/dist/components/forms/FormWatcher.d.ts.map +1 -1
- package/dist/components/forms/FormWatcher.js +8 -4
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +2 -2
- package/dist/context/APIWrapper.d.ts +2 -1
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +1 -1
- package/dist/context/APIWrapperContext.d.ts +23 -23
- package/dist/context/APIWrapperContext.d.ts.map +1 -1
- package/dist/context/PrivateContext.d.ts +3 -2
- package/dist/context/PrivateContext.d.ts.map +1 -1
- package/dist/utils/utils.d.ts +2 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -62,25 +62,31 @@ const styles_1 = require("../../styles");
|
|
|
62
62
|
const utils_1 = require("../../utils");
|
|
63
63
|
const DetailFieldBySchema_1 = __importDefault(require("./DetailFieldBySchema"));
|
|
64
64
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return (react_1.default.createElement(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
65
|
+
function SectionContent({ sectionRows, item, schema, fieldsProps, SectionCustomElement, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
66
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
67
|
+
SectionCustomElement && react_1.default.createElement(react_1.default.Fragment, null, SectionCustomElement),
|
|
68
|
+
sectionRows && (react_1.default.createElement(react_1.default.Fragment, null, sectionRows.map((row, rowIdx) => {
|
|
69
|
+
if (typeof row === 'string') {
|
|
70
|
+
const field = row;
|
|
71
|
+
const fieldProps = fieldsProps && field in fieldsProps
|
|
72
|
+
? fieldsProps[field]
|
|
73
|
+
: {};
|
|
74
|
+
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
75
|
+
react_1.default.createElement(DetailFieldBySchema_1.default, Object.assign({ fieldKey: field, fieldSchema: field in schema ? schema[field] : undefined, value: item[field], sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps))));
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(row)) {
|
|
78
|
+
return (react_1.default.createElement(Box_1.default, { key: `row_${rowIdx}`, sx: sxRowMultiple }, row.map((field, fieldIdx) => {
|
|
79
|
+
const key = typeof field === 'string' ? field : field.key;
|
|
80
|
+
const fieldProps = fieldsProps && key in fieldsProps
|
|
81
|
+
? fieldsProps[key]
|
|
82
|
+
: {};
|
|
83
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIdx}_${fieldIdx}` }, typeof field === 'string' ? (react_1.default.createElement(DetailFieldBySchema_1.default, Object.assign({ fieldKey: field, fieldSchema: field in schema ? schema[field] : undefined, value: item[field], sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps))) : (react_1.default.createElement(field.CustomElement, Object.assign({ sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps)))));
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
const fieldProps = fieldsProps && row.key in fieldsProps ? fieldsProps[row.key] : {};
|
|
87
|
+
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `field_customElement_row_${rowIdx}`, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps)));
|
|
88
|
+
})))));
|
|
89
|
+
}
|
|
84
90
|
function DetailBySchema({ values, schema, columns, loading, editLink, editLabel, fieldsLayout: fieldsLayoutInitial, hiddenFields = ['id'], fieldsProps, elevation = 2, sxSection, sxSectionTitle, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
85
91
|
const { isMobile } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
86
92
|
const [preparedColumns, setPreparedColumns] = (0, react_1.useState)(null);
|
|
@@ -92,7 +98,7 @@ function DetailBySchema({ values, schema, columns, loading, editLink, editLabel,
|
|
|
92
98
|
for (const column of preparedColumns) {
|
|
93
99
|
const field = column.field;
|
|
94
100
|
if (field in values) {
|
|
95
|
-
newFormattedValues[field] = {
|
|
101
|
+
newFormattedValues[column.field] = {
|
|
96
102
|
title: column.headerName || '',
|
|
97
103
|
valueStr: !values[field] && typeof values[field] !== 'boolean'
|
|
98
104
|
? '-'
|
|
@@ -142,7 +148,10 @@ function DetailBySchema({ values, schema, columns, loading, editLink, editLabel,
|
|
|
142
148
|
}, [fieldsLayoutInitial, schema, hiddenFields]);
|
|
143
149
|
(0, react_1.useEffect)(() => {
|
|
144
150
|
const initColumns = () => __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const preparedColumns = yield (0, utils_1.initViewColumns)({
|
|
151
|
+
const preparedColumns = yield (0, utils_1.initViewColumns)({
|
|
152
|
+
columns: columns,
|
|
153
|
+
schema: schema,
|
|
154
|
+
});
|
|
146
155
|
setPreparedColumns(preparedColumns);
|
|
147
156
|
});
|
|
148
157
|
initColumns();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
3
|
import { AnyObjectSchema } from 'yup';
|
|
4
|
-
import { AutocompleteItem, FormFieldLayout, Item, OptionsAC, SchemaType } from '../../@types';
|
|
4
|
+
import { AutocompleteItem, FormFieldLayout, Item, OptionsAC, SchemaType, TField } from '../../@types';
|
|
5
5
|
import { DialogType } from '../../context/APIWrapperContext';
|
|
6
|
-
interface DialogFormBySchemaProps<T = void> {
|
|
6
|
+
interface DialogFormBySchemaProps<T extends TField = void> {
|
|
7
7
|
schema: SchemaType<T>;
|
|
8
8
|
validationSchema: AnyObjectSchema;
|
|
9
9
|
initialValues: Item<T>;
|
|
@@ -16,6 +16,6 @@ interface DialogFormBySchemaProps<T = void> {
|
|
|
16
16
|
optionsAC: OptionsAC<T> | null;
|
|
17
17
|
setOptionsAC: (x: Partial<OptionsAC<T>>) => void;
|
|
18
18
|
}
|
|
19
|
-
export default function DialogFormBySchema<T = void>({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, fieldsLayout, isCancelDisabled, forceSaveEnabled, }: DialogFormBySchemaProps<T>): React.JSX.Element;
|
|
19
|
+
export default function DialogFormBySchema<T extends TField = void>({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, fieldsLayout, isCancelDisabled, forceSaveEnabled, }: DialogFormBySchemaProps<T>): React.JSX.Element;
|
|
20
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=DialogFormBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogFormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/DialogFormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAKtC,OAAO,
|
|
1
|
+
{"version":3,"file":"DialogFormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/DialogFormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAKtC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,SAAS,EACT,UAAU,EACV,MAAM,EACP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,UAAU,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACvD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,gBAAgB,EAAE,eAAe,CAAC;IAClC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,eAAe,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,CAAC;IAC/D,SAAS,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC5C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,GAAG,UAAU,CAAC,CAAC;IAC7E,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC/B,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAClE,MAAM,EACN,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,SAAS,EACT,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,EAAE,uBAAuB,CAAC,CAAC,CAAC,qBAmE5B"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
3
|
import { UseFormRegister } from 'react-hook-form';
|
|
4
|
-
import { AutocompleteItem, CommonFieldProps, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldsProps, FormFieldLayout, FormSaveActions, Id, Item, OptionsAC, ExtraValidators, FieldKey } from '../../@types';
|
|
4
|
+
import { AutocompleteItem, CommonFieldProps, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldsProps, FormFieldLayout, FormSaveActions, Id, Item, OptionsAC, ExtraValidators, FieldKey, FormWatchObject, FieldList, TField, PartialItem } from '../../@types';
|
|
5
5
|
import { FormActionsProps } from './FormActions';
|
|
6
|
-
interface FormProps<T = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' | 'optionsAC'> {
|
|
6
|
+
interface FormProps<T extends TField = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' | 'optionsAC'> {
|
|
7
7
|
model: string;
|
|
8
8
|
objId?: Id;
|
|
9
|
-
defaults?:
|
|
9
|
+
defaults?: PartialItem<T>;
|
|
10
10
|
objTitleField?: FieldKey<T>;
|
|
11
11
|
/** Optional. If the dev wants to do something after saving. Gets the new Id */
|
|
12
12
|
onSave?: (currentId: Id, newId: Id | AxiosError, buttonType: FormSaveActions) => void;
|
|
@@ -14,7 +14,10 @@ interface FormProps<T = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' |
|
|
|
14
14
|
onDelete?: (removedId: Id) => void;
|
|
15
15
|
/** Optional. If the dev wants to do something after canceling the form editing. */
|
|
16
16
|
onCancel?: React.MouseEventHandler<HTMLButtonElement>;
|
|
17
|
-
navigate?:
|
|
17
|
+
navigate?: {
|
|
18
|
+
(to: string): void;
|
|
19
|
+
(delta: number): void;
|
|
20
|
+
};
|
|
18
21
|
/** Optional. Exit function. If not provided and also no exitPath provided,
|
|
19
22
|
* navigate(exitPath) or history.back() will be used.
|
|
20
23
|
*/
|
|
@@ -38,7 +41,7 @@ interface FormProps<T = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' |
|
|
|
38
41
|
labelRemove?: string;
|
|
39
42
|
fieldsLayout?: FormFieldLayout<T>[];
|
|
40
43
|
customFieldFormLayouts?: CustomFormFieldLayouts<T>;
|
|
41
|
-
hiddenFields?:
|
|
44
|
+
hiddenFields?: FieldList<T>;
|
|
42
45
|
register?: UseFormRegister<Item<T>>;
|
|
43
46
|
optionsAC?: OptionsAC<T>;
|
|
44
47
|
setOptionsAC?: (x: OptionsAC<T>) => void;
|
|
@@ -49,9 +52,9 @@ interface FormProps<T = void> extends Omit<CommonFieldProps<T>, 'fieldsLayout' |
|
|
|
49
52
|
elevation?: number;
|
|
50
53
|
CustomFormActions?: (props: FormActionsProps) => React.JSX.Element;
|
|
51
54
|
extraValidators?: ExtraValidators<T>;
|
|
55
|
+
watchValues?: FieldList<T>;
|
|
56
|
+
onWatchChange?: (values: FormWatchObject<T>) => void;
|
|
52
57
|
}
|
|
53
|
-
declare function Form<T = void>({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
54
|
-
children?: React.ReactNode;
|
|
55
|
-
}): React.JSX.Element;
|
|
58
|
+
declare function Form<T extends TField = void>({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle, watchValues, onWatchChange, }: FormProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
56
59
|
export default Form;
|
|
57
60
|
//# sourceMappingURL=Form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/forms/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,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AC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACnE,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAErC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACtD;AAED,iBAAS,IAAI,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EACrC,KAAK,EACL,KAAK,EACL,QAAQ,EACR,aAAa,EAEb,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,IAAI,EAAE,UAAU,EAChB,eAAe,EAEf,QAAQ,EACR,QAAQ,EAER,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,EAEX,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAY,EAEZ,YAAY,EACZ,sBAAsB,EAEtB,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAET,iBAAiB,EACjB,eAAe,EAEf,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,EAEd,WAAW,EACX,aAAa,GACd,EAAE,SAAS,CAAC,CAAC,CAAC,GACb,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBA8TF;AAED,eAAe,IAAI,CAAC"}
|
|
@@ -57,7 +57,8 @@ const FormActions_1 = __importDefault(require("./FormActions"));
|
|
|
57
57
|
const PrivateContext_1 = require("../../context/PrivateContext");
|
|
58
58
|
const useDeepMemo_1 = require("../../hooks/useDeepMemo");
|
|
59
59
|
const utils_2 = require("../DataGridBySchemaEditable/utils");
|
|
60
|
-
|
|
60
|
+
const FormWatcher_1 = __importDefault(require("./FormWatcher"));
|
|
61
|
+
function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCancel, navigate, exit: customExit, saveAndContinue, editPath, exitPath, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, multiline, fieldKey, labelKey, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout, customFieldFormLayouts, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, CustomFormActions, extraValidators, sxRow, sxRowMultiple, sxSection, sxSectionTitle, watchValues, onWatchChange, }) {
|
|
61
62
|
const { setFormTools } = (0, PrivateContext_1.usePrivateContext)();
|
|
62
63
|
const { pageForm, loadSinglePageData, onSubmit, formTools, resetPageForm } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
63
64
|
const formToolsRef = (0, react_1.useRef)(formTools);
|
|
@@ -118,22 +119,31 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
118
119
|
}), [loadSinglePageData, model, stableDefaults, objTitleField, stableExtraValidators, reset]);
|
|
119
120
|
const genericNavigate = (0, react_1.useCallback)((path) => {
|
|
120
121
|
if (navigate) {
|
|
122
|
+
if (typeof path === 'string') {
|
|
123
|
+
navigate(path);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
121
126
|
navigate(path);
|
|
122
127
|
return;
|
|
123
128
|
}
|
|
124
|
-
|
|
129
|
+
if (typeof path === 'string') {
|
|
130
|
+
window.location.href = path;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
window.history.back();
|
|
125
134
|
}, [navigate]);
|
|
126
|
-
const exit = (0, react_1.useCallback)(() => {
|
|
135
|
+
const exit = (0, react_1.useCallback)((id) => {
|
|
127
136
|
if (customExitRef.current) {
|
|
128
137
|
customExitRef.current();
|
|
129
138
|
return;
|
|
130
139
|
}
|
|
131
140
|
if (exitPath) {
|
|
132
|
-
genericNavigate(exitPath);
|
|
141
|
+
genericNavigate((0, utils_2.buildExitPath)(exitPath, id));
|
|
133
142
|
return;
|
|
134
143
|
}
|
|
135
|
-
const parentPath = window.location.pathname.replace(/\/[^\/]+\/?$/, '/');
|
|
136
|
-
genericNavigate(parentPath);
|
|
144
|
+
// const parentPath = window.location.pathname.replace(/\/[^\/]+\/?$/, '/');
|
|
145
|
+
// genericNavigate(parentPath);
|
|
146
|
+
genericNavigate(-1);
|
|
137
147
|
}, [exitPath, genericNavigate]);
|
|
138
148
|
const localOnSubmit = (0, react_1.useCallback)((data, event) => __awaiter(this, void 0, void 0, function* () {
|
|
139
149
|
const currentId = objId || (0, utils_1.getTmpId)();
|
|
@@ -175,7 +185,7 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
175
185
|
break;
|
|
176
186
|
case _types_1.FormSaveActions.EXIT_ON_SAVE:
|
|
177
187
|
default:
|
|
178
|
-
exit();
|
|
188
|
+
exit(newId);
|
|
179
189
|
break;
|
|
180
190
|
}
|
|
181
191
|
}
|
|
@@ -237,7 +247,7 @@ function Form({ model, objId, defaults, objTitleField, onSave, onDelete, onCance
|
|
|
237
247
|
react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
|
|
238
248
|
react_1.default.createElement(FinalFormActions, { formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }),
|
|
239
249
|
react_1.default.createElement(FormBySchema_1.default, { fieldsLayout: fieldsLayout, hiddenFields: hiddenFields, control: control, register: register, errors: errors, schema: pageForm.schema, getValues: getValues, setValue: setValue, multiline: multiline, fieldKey: fieldKey, labelKey: labelKey, optionsAC: optionsAC, setOptionsAC: setOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, customFieldFormLayouts: customFieldFormLayouts, fieldsProps: fieldsProps, isolatedGetAutoComplete: isolatedGetAutoComplete, relatedEditable: relatedEditable, autoFocusField: autoFocusField, elevation: elevation, sxRow: sxRow, sxRowMultiple: sxRowMultiple, sxSection: sxSection, sxSectionTitle: sxSectionTitle, conditionalVisible: conditionalVisible, watchedValues: watchedValues }),
|
|
240
|
-
|
|
250
|
+
watchValues && onWatchChange && (react_1.default.createElement(FormWatcher_1.default, { control: control, watch: watchValues, onChange: onWatchChange })),
|
|
241
251
|
react_1.default.createElement(FinalFormActions, { bottom: true, formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, exit: exit, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }))));
|
|
242
252
|
}
|
|
243
253
|
exports.default = Form;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Id } from '../../@types';
|
|
2
|
+
import { Id, TField } from '../../@types';
|
|
3
3
|
export type FormActionsProps = {
|
|
4
4
|
formDisabled?: boolean;
|
|
5
5
|
model: string;
|
|
6
6
|
objId?: Id;
|
|
7
7
|
onCancel?: React.MouseEventHandler<HTMLButtonElement>;
|
|
8
8
|
onDelete?: (removedId: Id) => void;
|
|
9
|
-
exit: () => void;
|
|
9
|
+
exit: (id?: Id) => void;
|
|
10
10
|
bottom?: boolean;
|
|
11
11
|
saveAndContinue?: boolean;
|
|
12
12
|
title?: string;
|
|
@@ -16,5 +16,5 @@ export type FormActionsProps = {
|
|
|
16
16
|
labelCancel?: string;
|
|
17
17
|
labelRemove?: string;
|
|
18
18
|
};
|
|
19
|
-
export default function FormActions<T = void>({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
|
|
19
|
+
export default function FormActions<T extends TField = void>({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
|
|
20
20
|
//# sourceMappingURL=FormActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormActions.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAmB,EAAE,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"FormActions.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormActions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,OAAO,EAAmB,EAAE,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC3D,YAAY,EACZ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,eAAe,EACf,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,GACZ,EAAE,gBAAgB,qBA+GlB"}
|
|
@@ -30,14 +30,14 @@ function FormActions({ formDisabled, model, objId, onCancel, onDelete, exit, bot
|
|
|
30
30
|
if (onDelete) {
|
|
31
31
|
onDelete(objId);
|
|
32
32
|
}
|
|
33
|
-
exit();
|
|
33
|
+
exit(objId);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
const handleCancel = (event) => {
|
|
37
37
|
if (onCancel) {
|
|
38
38
|
onCancel(event);
|
|
39
39
|
}
|
|
40
|
-
exit();
|
|
40
|
+
exit(objId);
|
|
41
41
|
};
|
|
42
42
|
return (react_1.default.createElement(Box_1.default, { sx: finalSx },
|
|
43
43
|
bottom ? (react_1.default.createElement(Button_1.default, { variant: "contained", type: "button", color: "error", size: "small", disabled: (0, utils_1.isTmpId)(objId) || !onDeleteModel, onClick: handleDelete }, labelRemove || 'Remove')) : title ? (react_1.default.createElement(Typography_1.default, { variant: "h5" }, title)) : (react_1.default.createElement(Box_1.default, null)),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
3
|
import { UseFormRegister } from 'react-hook-form';
|
|
4
|
-
import { AutocompleteItem, ConditionalVisible, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldBySchemaProps, FieldsProps, FormFieldLayout, GenericValue, Item, OptionsAC, FieldKey } from '../../@types';
|
|
5
|
-
type FormBySchemaProps<T = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
|
|
4
|
+
import { AutocompleteItem, ConditionalVisible, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldBySchemaProps, FieldsProps, FormFieldLayout, GenericValue, Item, OptionsAC, FieldKey, FieldList, TField } from '../../@types';
|
|
5
|
+
type FormBySchemaProps<T extends TField = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
|
|
6
6
|
fieldsLayout?: FormFieldLayout<T>[];
|
|
7
7
|
customFieldFormLayouts?: CustomFormFieldLayouts<T>;
|
|
8
|
-
hiddenFields?:
|
|
8
|
+
hiddenFields?: FieldList<T>;
|
|
9
9
|
register?: UseFormRegister<Item<T>>;
|
|
10
10
|
setOptionsAC?: (x: OptionsAC<T>) => void;
|
|
11
11
|
isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
|
|
@@ -16,6 +16,6 @@ type FormBySchemaProps<T = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
|
|
|
16
16
|
conditionalVisible?: ConditionalVisible[];
|
|
17
17
|
watchedValues?: GenericValue[];
|
|
18
18
|
};
|
|
19
|
-
export default function FormBySchema<T = void>({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, sxRow, sxRowMultiple, sxSection, sxSectionTitle, }: FormBySchemaProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
19
|
+
export default function FormBySchema<T extends TField = void>({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, sxRow, sxRowMultiple, sxSection, sxSectionTitle, }: FormBySchemaProps<T> & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
20
20
|
export {};
|
|
21
21
|
//# sourceMappingURL=FormBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;AAOtB,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAEtF,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,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,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBAkWF"}
|
|
@@ -57,7 +57,7 @@ const styles_1 = require("../../styles");
|
|
|
57
57
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
58
58
|
const utils_1 = require("../../utils");
|
|
59
59
|
const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
|
|
60
|
-
function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields
|
|
60
|
+
function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric, label, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, conditionalVisible, watchedValues, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation,
|
|
61
61
|
// sx,
|
|
62
62
|
// sxField,
|
|
63
63
|
// sxLabel,
|
|
@@ -139,14 +139,14 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
139
139
|
}
|
|
140
140
|
const rows = [];
|
|
141
141
|
for (const [key, field] of Object.entries(schema)) {
|
|
142
|
-
if (['field', 'nested object'].includes(field.type)) {
|
|
142
|
+
if (field && ['field', 'nested object'].includes(field.type)) {
|
|
143
143
|
rows.push(key);
|
|
144
144
|
if (!newOptionsACModels.includes(key)) {
|
|
145
145
|
newOptionsACModels.push(key);
|
|
146
146
|
}
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
-
if (!field.read_only) {
|
|
149
|
+
if (!(field === null || field === void 0 ? void 0 : field.read_only)) {
|
|
150
150
|
rows.push(key);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -188,7 +188,10 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
188
188
|
}
|
|
189
189
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
190
190
|
register &&
|
|
191
|
-
hiddenFields
|
|
191
|
+
(hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.map((hiddenField) => {
|
|
192
|
+
const typedHiddenField = hiddenField;
|
|
193
|
+
return (react_1.default.createElement("input", Object.assign({ hidden: true }, register(typedHiddenField), { value: getValues ? getValues(typedHiddenField) : undefined, key: hiddenField })));
|
|
194
|
+
})),
|
|
192
195
|
fieldsLayout.map((section, sectionIndex) => {
|
|
193
196
|
return (react_1.default.createElement(Card_1.default, { sx: sxSection ? Object.assign(Object.assign({}, styles_1.Layout.formCard), sxSection) : styles_1.Layout.formCard, key: `section_${sectionIndex}`, elevation: elevation },
|
|
194
197
|
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: sxSectionTitle }),
|
|
@@ -196,11 +199,13 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
196
199
|
section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
|
|
197
200
|
section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
|
|
198
201
|
if (typeof row === 'string') {
|
|
199
|
-
if (hiddenFields.includes(row)) {
|
|
202
|
+
if (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(row)) {
|
|
200
203
|
return null;
|
|
201
204
|
}
|
|
202
205
|
const field = row;
|
|
203
|
-
const fieldProps = fieldsProps && field in fieldsProps
|
|
206
|
+
const fieldProps = fieldsProps && field in fieldsProps
|
|
207
|
+
? fieldsProps[field]
|
|
208
|
+
: {};
|
|
204
209
|
if (fieldProps) {
|
|
205
210
|
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
206
211
|
}
|
|
@@ -211,7 +216,12 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
211
216
|
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
212
217
|
react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index,
|
|
213
218
|
// optionsAC={setOptionsAC ? optionsAC : localOptionsAC}
|
|
214
|
-
optionsAC: optionsAC && field in optionsAC
|
|
219
|
+
optionsAC: optionsAC && field in optionsAC
|
|
220
|
+
? optionsAC
|
|
221
|
+
: localOptionsAC,
|
|
222
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>>
|
|
223
|
+
// optionsAC: BaseOptionsAC | Partial<Record<FieldKey<T>, FieldOptionsAC>> | undefined
|
|
224
|
+
optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, fieldsLayout: customFieldFormLayouts && field in customFieldFormLayouts
|
|
215
225
|
? customFieldFormLayouts[field]
|
|
216
226
|
: undefined, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field || (sectionIndex === 0 && rowIndex === 0) }, fieldProps))));
|
|
217
227
|
}
|
|
@@ -220,12 +230,14 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
220
230
|
? Object.assign(Object.assign({}, styles_1.Layout.inLineForm), { sxRowMultiple })
|
|
221
231
|
: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
|
|
222
232
|
react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => {
|
|
223
|
-
if (typeof field === 'string' && hiddenFields.includes(field)) {
|
|
233
|
+
if (typeof field === 'string' && (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(field))) {
|
|
224
234
|
return null;
|
|
225
235
|
}
|
|
226
236
|
const mr = i + 1 === j.length ? 0 : 2;
|
|
227
237
|
const key = typeof field === 'string' ? field : field.key;
|
|
228
|
-
const fieldProps = fieldsProps && key in fieldsProps
|
|
238
|
+
const fieldProps = fieldsProps && key in fieldsProps
|
|
239
|
+
? fieldsProps[key]
|
|
240
|
+
: {};
|
|
229
241
|
if (fieldProps) {
|
|
230
242
|
fieldProps.sx =
|
|
231
243
|
'sx' in fieldProps
|
|
@@ -237,11 +249,15 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
237
249
|
if (!isVisible) {
|
|
238
250
|
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }));
|
|
239
251
|
}
|
|
240
|
-
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }, typeof field === 'string' ? (react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC && field in optionsAC
|
|
252
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }, typeof field === 'string' ? (react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC && field in optionsAC
|
|
253
|
+
? optionsAC
|
|
254
|
+
: localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field ||
|
|
241
255
|
(sectionIndex === 0 && rowIndex === 0 && i === 0) }, fieldProps))) : (react_1.default.createElement(field.CustomElement, Object.assign({}, fieldProps)))));
|
|
242
256
|
}))));
|
|
243
257
|
}
|
|
244
|
-
const fieldProps = fieldsProps && row.key in fieldsProps
|
|
258
|
+
const fieldProps = fieldsProps && row.key in fieldsProps
|
|
259
|
+
? fieldsProps[row.key]
|
|
260
|
+
: {};
|
|
245
261
|
if (fieldProps) {
|
|
246
262
|
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
247
263
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Control } from 'react-hook-form';
|
|
2
|
+
import { FieldList, FormWatchObject, GenericValue, TField } from '../../@types';
|
|
3
|
+
export interface FormWatcherProps<T extends TField = void> {
|
|
4
|
+
control: Control<GenericValue>;
|
|
5
|
+
watch: FieldList<T>;
|
|
6
|
+
onChange: (values: FormWatchObject<T>) => void;
|
|
5
7
|
}
|
|
6
|
-
declare function FormWatcher<T = void>({ watch, onChange }: FormWatcherProps<T>): null;
|
|
8
|
+
declare function FormWatcher<T extends TField = void>({ control, watch, onChange }: FormWatcherProps<T>): null;
|
|
7
9
|
export default FormWatcher;
|
|
8
10
|
//# sourceMappingURL=FormWatcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormWatcher.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormWatcher.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FormWatcher.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormWatcher.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAQ,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtF,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACvD,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAChD;AAGD,iBAAS,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC,QAqB9F;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const react_hook_form_1 = require("react-hook-form");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// Ensure K is constrained to the same type as the prop
|
|
7
|
+
function FormWatcher({ control, watch, onChange }) {
|
|
8
8
|
const values = (0, react_hook_form_1.useWatch)({
|
|
9
9
|
control,
|
|
10
10
|
name: watch,
|
|
@@ -13,9 +13,13 @@ function FormWatcher({ watch, onChange }) {
|
|
|
13
13
|
(0, react_1.useEffect)(() => {
|
|
14
14
|
if (!(0, utils_1.deepEqual)(values, previousValues.current)) {
|
|
15
15
|
previousValues.current = values;
|
|
16
|
-
|
|
16
|
+
const valuesObject = watch.reduce((acc, key, index) => {
|
|
17
|
+
acc[key] = values[index];
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
onChange(valuesObject);
|
|
17
21
|
}
|
|
18
|
-
}, [values, onChange]);
|
|
22
|
+
}, [values, watch, onChange]);
|
|
19
23
|
return null;
|
|
20
24
|
}
|
|
21
25
|
exports.default = FormWatcher;
|
|
@@ -2,12 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import { Controller } from 'react-hook-form';
|
|
3
3
|
import { Item } from '../../../@types';
|
|
4
4
|
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<Omit<import("../../../@types").CommonFieldProps<void>, "value" | "onEditModel"> & {
|
|
5
|
-
onEditModel?: <U =
|
|
5
|
+
onEditModel?: <U extends import("../../../@types").TField = void>(x: import("../../../@types").OnEditModelType<U>) => void;
|
|
6
6
|
name: string;
|
|
7
7
|
schema: {
|
|
8
8
|
[x: string]: import("../../../@types").Field;
|
|
9
9
|
};
|
|
10
|
-
control: Controller<Item<T>,
|
|
10
|
+
control: Controller<Item<T>, import("../../../@types").GenericValue, Item<T>>;
|
|
11
11
|
errors: Controller<Item<T>>;
|
|
12
12
|
autoFocus?: boolean;
|
|
13
13
|
} & React.RefAttributes<any>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { TField } from '../@types';
|
|
2
3
|
import { DialogType, FormTools, PageFormType, SnackBarType } from './APIWrapperContext';
|
|
3
|
-
interface APIWrapperProps<T = void> {
|
|
4
|
+
interface APIWrapperProps<T extends TField = void> {
|
|
4
5
|
handleLoading: (x: boolean) => void;
|
|
5
6
|
setSnackBar: (x: Partial<SnackBarType>) => void;
|
|
6
7
|
setDialog: (newState: Partial<DialogType> | null) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;AAM7F,OAAO,EAgBL,MAAM,EAEP,MAAM,WAAW,CAAC;AA6BnB,OAAO,EAEL,UAAU,EAEV,SAAS,EAMT,YAAY,EACZ,YAAY,EACb,MAAM,qBAAqB,CAAC;AAI7B,UAAU,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IAC/C,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;IAChD,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACzB,YAAY,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACxC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,iBAAS,UAAU,CAAC,EAClB,aAAa,EACb,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,aAAa,EACb,SAAS,EACT,YAAY,EACZ,QAAQ,GACT,EAAE,eAAe,qBAkrBjB;;AAED,wBAAsC"}
|
|
@@ -168,7 +168,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, pageForm, setPageFo
|
|
|
168
168
|
schema: newSchema,
|
|
169
169
|
columns: newColumns,
|
|
170
170
|
fieldsLayout: fieldsLayout,
|
|
171
|
-
defaults,
|
|
171
|
+
defaults: defaults,
|
|
172
172
|
extraValidators: extraValidators,
|
|
173
173
|
});
|
|
174
174
|
setPageForm({
|