drf-react-by-schema 0.24.4 → 0.24.6
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 +136 -87
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/@types/index.js +7 -0
- package/dist/api.d.ts +24 -17
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +612 -572
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +19 -19
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +7 -7
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +12 -12
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +8 -8
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +10 -5
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +4 -4
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +13 -13
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +156 -153
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +11 -12
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +150 -148
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils.js +4 -4
- package/dist/components/DataGridBySchemaEditable.d.ts +17 -17
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable.js +44 -24
- package/dist/components/DataTotals.d.ts.map +1 -1
- package/dist/components/DataTotalsServer.d.ts +1 -1
- package/dist/components/DataTotalsServer.d.ts.map +1 -1
- package/dist/components/DataTotalsServer.js +7 -10
- package/dist/components/GenericModelList.d.ts +16 -18
- package/dist/components/GenericModelList.d.ts.map +1 -1
- package/dist/components/GenericModelList.js +2 -1
- package/dist/components/GenericRelatedModelList.d.ts +15 -16
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelList.js +2 -2
- package/dist/components/GenericRelatedModelListTable.d.ts +14 -14
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelListTable.js +3 -2
- package/dist/components/details/DetailBySchema.d.ts +1 -1
- package/dist/components/details/DetailBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.js +1 -1
- package/dist/components/forms/DialogFormBySchema.d.ts +8 -8
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -1
- package/dist/components/forms/DialogFormBySchema.js +1 -1
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/FieldBySchema.js +4 -4
- package/dist/components/forms/Form.d.ts +35 -19
- package/dist/components/forms/Form.d.ts.map +1 -1
- package/dist/components/forms/Form.js +119 -60
- package/dist/components/forms/FormActions.d.ts +2 -1
- package/dist/components/forms/FormActions.d.ts.map +1 -1
- package/dist/components/forms/FormActions.js +14 -6
- package/dist/components/forms/FormBySchema.d.ts +11 -12
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +20 -13
- package/dist/components/forms/FormWatcher.d.ts +5 -4
- package/dist/components/forms/FormWatcher.d.ts.map +1 -1
- package/dist/components/forms/FormWatcher.js +2 -2
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +2 -1
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +2 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +12 -2
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +6 -5
- package/dist/components/forms/inputs/FileFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/PatternFieldBySchema.js +2 -1
- package/dist/components/forms/inputs/TextFieldBySchema.js +2 -1
- package/dist/context/APIWrapper.d.ts +9 -4
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +76 -104
- package/dist/context/APIWrapperContext.d.ts +53 -56
- package/dist/context/APIWrapperContext.d.ts.map +1 -1
- package/dist/context/APIWrapperContext.js +17 -19
- package/dist/context/DRFReactBySchemaContext.d.ts +2 -10
- package/dist/context/DRFReactBySchemaContext.d.ts.map +1 -1
- package/dist/context/DRFReactBySchemaContext.js +0 -5
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +1 -31
- package/dist/context/Overlays.d.ts.map +1 -1
- package/dist/context/Overlays.js +34 -16
- package/dist/context/PrivateContext.d.ts +9 -0
- package/dist/context/PrivateContext.d.ts.map +1 -0
- package/dist/context/PrivateContext.js +16 -0
- package/dist/hooks/useDeepMemo.d.ts +2 -0
- package/dist/hooks/useDeepMemo.d.ts.map +1 -0
- package/dist/hooks/useDeepMemo.js +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/{utils.d.ts → utils/utils.d.ts} +31 -5
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/{utils.js → utils/utils.js} +68 -76
- package/package.json +4 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts +0 -18
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts.map +0 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.js +0 -43
- package/dist/components/DialogJSONSchemaForm.d.ts +0 -13
- package/dist/components/DialogJSONSchemaForm.js +0 -20
- package/dist/components/FilteredButton.d.ts +0 -2
- package/dist/components/FilteredButton.js +0 -23
- package/dist/components/FilteredGridActionsCellItem.d.ts +0 -2
- package/dist/components/FilteredGridActionsCellItem.js +0 -29
- package/dist/components/FormButtons.d.ts +0 -23
- package/dist/components/FormButtons.d.ts.map +0 -1
- package/dist/components/FormButtons.js +0 -43
- package/dist/components/forms/inputs/PatternBySchema.d.ts +0 -4
- package/dist/components/forms/inputs/PatternBySchema.d.ts.map +0 -1
- package/dist/components/forms/inputs/PatternBySchema.js +0 -45
- package/dist/context/Form.d.ts +0 -21
- package/dist/context/Form.js +0 -95
- package/dist/context/FormContext.d.ts +0 -71
- package/dist/context/FormContext.js +0 -8
- package/dist/utils.d.ts.map +0 -1
|
@@ -45,31 +45,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.default = Form;
|
|
49
48
|
const react_1 = __importStar(require("react"));
|
|
50
49
|
const axios_1 = __importDefault(require("axios"));
|
|
51
50
|
const react_hook_form_1 = require("react-hook-form");
|
|
52
51
|
const yup_1 = require("@hookform/resolvers/yup");
|
|
52
|
+
const _types_1 = require("../../@types");
|
|
53
53
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
54
54
|
const utils_1 = require("../../utils");
|
|
55
55
|
const FormBySchema_1 = __importDefault(require("./FormBySchema"));
|
|
56
56
|
const FormActions_1 = __importDefault(require("./FormActions"));
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const PrivateContext_1 = require("../../context/PrivateContext");
|
|
58
|
+
const useDeepMemo_1 = require("../../hooks/useDeepMemo");
|
|
59
|
+
const utils_2 = require("../DataGridBySchemaEditable/utils");
|
|
60
|
+
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, children, }) {
|
|
61
|
+
const { setFormTools } = (0, PrivateContext_1.usePrivateContext)();
|
|
62
|
+
const { pageForm, loadSinglePageData, onSubmit, formTools, resetPageForm } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
63
|
+
const formToolsRef = (0, react_1.useRef)(formTools);
|
|
64
|
+
const onSaveRef = (0, react_1.useRef)(onSave);
|
|
65
|
+
const customExitRef = (0, react_1.useRef)(customExit);
|
|
61
66
|
const methods = (0, react_hook_form_1.useForm)({
|
|
62
67
|
mode: 'onBlur',
|
|
63
68
|
resolver: (pageForm === null || pageForm === void 0 ? void 0 : pageForm.validationSchema) ? (0, yup_1.yupResolver)(pageForm.validationSchema) : undefined,
|
|
64
69
|
});
|
|
65
70
|
const { control, handleSubmit, reset, getValues, setValue, formState: { errors, isDirty }, register, watch, } = methods;
|
|
71
|
+
const stableDefaults = (0, useDeepMemo_1.useDeepMemo)(defaults);
|
|
72
|
+
const stableExtraValidators = (0, useDeepMemo_1.useDeepMemo)(extraValidators);
|
|
73
|
+
const FinalFormActions = CustomFormActions || FormActions_1.default;
|
|
66
74
|
const conditionalVisible = (0, react_1.useMemo)(() => {
|
|
75
|
+
var _a;
|
|
67
76
|
const fields = [];
|
|
68
77
|
if (!(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema)) {
|
|
69
78
|
return fields;
|
|
70
79
|
}
|
|
71
80
|
for (const fieldKey of Object.keys(pageForm.schema)) {
|
|
72
|
-
const conditionalVisible = pageForm.schema[fieldKey].conditional_visible;
|
|
81
|
+
const conditionalVisible = (_a = pageForm.schema[fieldKey]) === null || _a === void 0 ? void 0 : _a.conditional_visible;
|
|
73
82
|
if (!conditionalVisible || conditionalVisible.length === 0) {
|
|
74
83
|
continue;
|
|
75
84
|
}
|
|
@@ -94,66 +103,106 @@ function Form({ model, objId, basePath, defaults, objTitleField, onCancel, onSav
|
|
|
94
103
|
}
|
|
95
104
|
return fields;
|
|
96
105
|
}, [pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema]);
|
|
97
|
-
const FinalFormActions = CustomFormActions || FormActions_1.default;
|
|
98
106
|
const watchedValues = watch(conditionalVisible.map((item) => item.source));
|
|
99
|
-
const
|
|
107
|
+
const loadData = (0, react_1.useCallback)((newId) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const values = yield loadSinglePageData({
|
|
109
|
+
model,
|
|
110
|
+
objId: newId,
|
|
111
|
+
defaults: stableDefaults,
|
|
112
|
+
objTitleField,
|
|
113
|
+
extraValidators: stableExtraValidators,
|
|
114
|
+
});
|
|
115
|
+
if (values && !axios_1.default.isAxiosError(values)) {
|
|
116
|
+
reset(values);
|
|
117
|
+
}
|
|
118
|
+
}), [loadSinglePageData, model, stableDefaults, objTitleField, stableExtraValidators, reset]);
|
|
119
|
+
const genericNavigate = (0, react_1.useCallback)((path) => {
|
|
120
|
+
if (navigate) {
|
|
121
|
+
navigate(path);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
window.location.href = path;
|
|
125
|
+
}, [navigate]);
|
|
126
|
+
const exit = (0, react_1.useCallback)(() => {
|
|
127
|
+
if (customExitRef.current) {
|
|
128
|
+
customExitRef.current();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (exitPath) {
|
|
132
|
+
genericNavigate(exitPath);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const parentPath = window.location.pathname.replace(/\/[^\/]+\/?$/, '/');
|
|
136
|
+
genericNavigate(parentPath);
|
|
137
|
+
}, [exitPath, genericNavigate]);
|
|
138
|
+
const localOnSubmit = (0, react_1.useCallback)((data, event) => __awaiter(this, void 0, void 0, function* () {
|
|
100
139
|
const currentId = objId || (0, utils_1.getTmpId)();
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
140
|
+
const response = yield onSubmit(model, currentId, data, event);
|
|
141
|
+
// console.log(response, onSaveRef.current, exitRef.current);
|
|
142
|
+
if (!axios_1.default.isAxiosError(response)) {
|
|
143
|
+
const newId = response;
|
|
144
|
+
const buttonType = (event === null || event === void 0 ? void 0 : event.nativeEvent.submitter.name) || _types_1.FormSaveActions.EXIT_ON_SAVE;
|
|
145
|
+
switch (buttonType) {
|
|
146
|
+
case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
|
|
147
|
+
loadData(undefined);
|
|
148
|
+
break;
|
|
149
|
+
case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
|
|
150
|
+
reset(Object.assign(Object.assign({}, data), { id: newId }));
|
|
151
|
+
break;
|
|
152
|
+
case _types_1.FormSaveActions.EXIT_ON_SAVE:
|
|
153
|
+
default:
|
|
154
|
+
resetPageForm();
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
// In case the user wants to do something else after saving
|
|
158
|
+
if (onSaveRef.current) {
|
|
159
|
+
onSaveRef.current(currentId, newId, buttonType);
|
|
107
160
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
161
|
+
const goToEdit = (id = 'novo') => {
|
|
162
|
+
const populatedEditPath = editPath
|
|
163
|
+
? (0, utils_2.buildEditPath)(editPath, id)
|
|
164
|
+
: `${window.location.pathname.replace(/\/[^\/]+\/?$/, '/')}${id}`;
|
|
165
|
+
genericNavigate(populatedEditPath);
|
|
166
|
+
};
|
|
167
|
+
switch (buttonType) {
|
|
168
|
+
case _types_1.FormSaveActions.SAVE_AND_CREATE_NEW:
|
|
169
|
+
goToEdit();
|
|
170
|
+
break;
|
|
171
|
+
case _types_1.FormSaveActions.SAVE_AND_CONTINUE:
|
|
172
|
+
if ((0, utils_1.isTmpId)(currentId)) {
|
|
173
|
+
goToEdit(newId);
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
case _types_1.FormSaveActions.EXIT_ON_SAVE:
|
|
177
|
+
default:
|
|
178
|
+
exit();
|
|
179
|
+
break;
|
|
111
180
|
}
|
|
112
181
|
}
|
|
113
|
-
|
|
114
|
-
|
|
182
|
+
}), [loadData, model, objId, onSubmit, reset, resetPageForm, exit, editPath, genericNavigate]);
|
|
183
|
+
const updateFormTools = (0, react_1.useCallback)(() => {
|
|
184
|
+
const currentFormTools = formToolsRef.current;
|
|
185
|
+
if (!currentFormTools ||
|
|
186
|
+
currentFormTools.errors !== errors ||
|
|
187
|
+
currentFormTools.isDirty !== isDirty ||
|
|
188
|
+
currentFormTools.reset !== reset ||
|
|
189
|
+
currentFormTools.getValues !== getValues ||
|
|
190
|
+
currentFormTools.setValue !== setValue) {
|
|
191
|
+
setFormTools({
|
|
192
|
+
errors,
|
|
193
|
+
reset,
|
|
194
|
+
getValues,
|
|
195
|
+
setValue,
|
|
196
|
+
isDirty,
|
|
197
|
+
});
|
|
115
198
|
}
|
|
116
|
-
});
|
|
199
|
+
}, [errors, getValues, isDirty, reset, setFormTools, setValue]);
|
|
117
200
|
(0, react_1.useEffect)(() => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
model,
|
|
121
|
-
objId,
|
|
122
|
-
defaults,
|
|
123
|
-
basePath,
|
|
124
|
-
objTitleField,
|
|
125
|
-
extraValidators,
|
|
126
|
-
});
|
|
127
|
-
if (values && !axios_1.default.isAxiosError(values)) {
|
|
128
|
-
reset(values);
|
|
129
|
-
setFormTools({
|
|
130
|
-
errors,
|
|
131
|
-
reset,
|
|
132
|
-
getValues,
|
|
133
|
-
setValue,
|
|
134
|
-
isDirty,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
loadData();
|
|
139
|
-
}, [model, objId, defaults, basePath, objTitleField, extraValidators]);
|
|
201
|
+
loadData(objId);
|
|
202
|
+
}, [objId, loadData]);
|
|
140
203
|
(0, react_1.useEffect)(() => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
formTools.isDirty !== isDirty ||
|
|
144
|
-
formTools.reset !== reset ||
|
|
145
|
-
formTools.getValues !== getValues ||
|
|
146
|
-
formTools.setValue !== setValue) {
|
|
147
|
-
setFormTools({
|
|
148
|
-
errors,
|
|
149
|
-
reset,
|
|
150
|
-
getValues,
|
|
151
|
-
setValue,
|
|
152
|
-
isDirty,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}, [errors, isDirty, reset, getValues, setValue, formTools]);
|
|
204
|
+
updateFormTools();
|
|
205
|
+
}, [updateFormTools]);
|
|
157
206
|
(0, react_1.useEffect)(() => {
|
|
158
207
|
if (errors && Object.keys(errors).length > 0) {
|
|
159
208
|
console.log({ errors });
|
|
@@ -172,13 +221,23 @@ function Form({ model, objId, basePath, defaults, objTitleField, onCancel, onSav
|
|
|
172
221
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
173
222
|
};
|
|
174
223
|
}, [isDirty]);
|
|
224
|
+
(0, react_1.useEffect)(() => {
|
|
225
|
+
formToolsRef.current = formTools;
|
|
226
|
+
}, [formTools]);
|
|
227
|
+
(0, react_1.useEffect)(() => {
|
|
228
|
+
onSaveRef.current = onSave;
|
|
229
|
+
}, [onSave]);
|
|
230
|
+
(0, react_1.useEffect)(() => {
|
|
231
|
+
customExitRef.current = customExit;
|
|
232
|
+
}, [customExit]);
|
|
175
233
|
if (!(pageForm === null || pageForm === void 0 ? void 0 : pageForm.schema) || (pageForm === null || pageForm === void 0 ? void 0 : pageForm.model) !== model) {
|
|
176
234
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
177
235
|
}
|
|
178
236
|
return (react_1.default.createElement(react_hook_form_1.FormProvider, Object.assign({}, methods),
|
|
179
237
|
react_1.default.createElement("form", { onSubmit: handleSubmit(localOnSubmit) },
|
|
180
|
-
react_1.default.createElement(FinalFormActions, { formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove }),
|
|
238
|
+
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 }),
|
|
181
239
|
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 }),
|
|
182
240
|
children,
|
|
183
|
-
react_1.default.createElement(FinalFormActions, { formDisabled: !isDirty, model: model, objId: objId, saveAndContinue: saveAndContinue, onCancel: onCancel, onDelete: onDelete, title: title, labelSave: labelSave, labelSaveAndContinue: labelSaveAndContinue, labelSaveAndCreateNew: labelSaveAndCreateNew, labelCancel: labelCancel, labelRemove: labelRemove
|
|
241
|
+
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 }))));
|
|
184
242
|
}
|
|
243
|
+
exports.default = Form;
|
|
@@ -6,6 +6,7 @@ export type FormActionsProps = {
|
|
|
6
6
|
objId?: Id;
|
|
7
7
|
onCancel?: React.MouseEventHandler<HTMLButtonElement>;
|
|
8
8
|
onDelete?: (removedId: Id) => void;
|
|
9
|
+
exit: () => void;
|
|
9
10
|
bottom?: boolean;
|
|
10
11
|
saveAndContinue?: boolean;
|
|
11
12
|
title?: string;
|
|
@@ -15,5 +16,5 @@ export type FormActionsProps = {
|
|
|
15
16
|
labelCancel?: string;
|
|
16
17
|
labelRemove?: string;
|
|
17
18
|
};
|
|
18
|
-
export default function FormActions({ formDisabled, model, objId, onCancel, onDelete, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }: FormActionsProps): React.JSX.Element;
|
|
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
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,
|
|
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;AAGnD,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,MAAM,IAAI,CAAC;IACjB,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,GAAG,IAAI,EAAE,EAC5C,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"}
|
|
@@ -10,8 +10,9 @@ const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
|
10
10
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
11
11
|
const styles_1 = require("../../styles");
|
|
12
12
|
const utils_1 = require("../../utils");
|
|
13
|
+
const _types_1 = require("../../@types");
|
|
13
14
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
14
|
-
function FormActions({ formDisabled, model, objId, onCancel, onDelete, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }) {
|
|
15
|
+
function FormActions({ formDisabled, model, objId, onCancel, onDelete, exit, bottom, saveAndContinue, title, labelSave, labelSaveAndContinue, labelSaveAndCreateNew, labelCancel, labelRemove, }) {
|
|
15
16
|
const { onDeleteModel, isMobile } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
16
17
|
if (isMobile && !bottom) {
|
|
17
18
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
@@ -29,15 +30,22 @@ function FormActions({ formDisabled, model, objId, onCancel, onDelete, bottom, s
|
|
|
29
30
|
if (onDelete) {
|
|
30
31
|
onDelete(objId);
|
|
31
32
|
}
|
|
33
|
+
exit();
|
|
32
34
|
}
|
|
33
35
|
};
|
|
36
|
+
const handleCancel = (event) => {
|
|
37
|
+
if (onCancel) {
|
|
38
|
+
onCancel(event);
|
|
39
|
+
}
|
|
40
|
+
exit();
|
|
41
|
+
};
|
|
34
42
|
return (react_1.default.createElement(Box_1.default, { sx: finalSx },
|
|
35
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)),
|
|
36
44
|
isMobile ? (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
37
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name:
|
|
38
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick:
|
|
45
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || 'Save'))) : (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
46
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: handleCancel }, labelCancel || 'Cancel'),
|
|
39
47
|
!isMobile && saveAndContinue && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
40
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name:
|
|
41
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name:
|
|
42
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name:
|
|
48
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CREATE_NEW, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndCreateNew || 'Save and Create New'),
|
|
49
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.SAVE_AND_CONTINUE, type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSaveAndContinue || 'Save and Continue'))),
|
|
50
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: _types_1.FormSaveActions.EXIT_ON_SAVE, type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, labelSave || 'Save')))));
|
|
43
51
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
3
|
import { UseFormRegister } from 'react-hook-form';
|
|
4
|
-
import { AutocompleteItem,
|
|
5
|
-
|
|
6
|
-
fieldsLayout?: FormFieldLayout[];
|
|
7
|
-
customFieldFormLayouts?:
|
|
8
|
-
hiddenFields?:
|
|
9
|
-
register?: UseFormRegister<Item
|
|
10
|
-
setOptionsAC?: (x: OptionsAC) => void;
|
|
11
|
-
forceReload?: boolean;
|
|
4
|
+
import { AutocompleteItem, ConditionalVisible, CustomFormFieldLayouts, ExtraSxCommonFieldProps, FieldBySchemaProps, FieldsProps, FormFieldLayout, GenericValue, Item, OptionsAC, FieldKey } from '../../@types';
|
|
5
|
+
type FormBySchemaProps<T = void> = Omit<FieldBySchemaProps<T>, 'name'> & {
|
|
6
|
+
fieldsLayout?: FormFieldLayout<T>[];
|
|
7
|
+
customFieldFormLayouts?: CustomFormFieldLayouts<T>;
|
|
8
|
+
hiddenFields?: FieldKey<T>[];
|
|
9
|
+
register?: UseFormRegister<Item<T>>;
|
|
10
|
+
setOptionsAC?: (x: OptionsAC<T>) => void;
|
|
12
11
|
isolatedGetAutoComplete?: (model: string) => Promise<AutocompleteItem[] | AxiosError>;
|
|
13
|
-
fieldsProps?:
|
|
12
|
+
fieldsProps?: FieldsProps<T>;
|
|
14
13
|
relatedEditable?: boolean;
|
|
15
|
-
autoFocusField?:
|
|
14
|
+
autoFocusField?: FieldKey<T>;
|
|
16
15
|
elevation?: number;
|
|
17
16
|
conditionalVisible?: ConditionalVisible[];
|
|
18
17
|
watchedValues?: GenericValue[];
|
|
19
|
-
}
|
|
20
|
-
export default function FormBySchema({ 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 & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
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;
|
|
21
20
|
export {};
|
|
22
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,EAAmC,eAAe,EAAmB,MAAM,iBAAiB,CAAC;AAUpG,OAAO,EACL,gBAAgB,EAEhB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAET,MAAM,cAAc,CAAC;AAOtB,KAAK,iBAAiB,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAEvE,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACzC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,GAAG,UAAU,CAAC,CAAC;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,GAAG,IAAI,EAAE,EAC7C,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAgC,EAChC,KAAK,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAgB,EAEhB,YAAY,EAAE,mBAAmB,EACjC,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EAEb,WAAW,EACX,YAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAKT,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,GAKf,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACrB,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBAiVF"}
|
|
@@ -70,7 +70,7 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
70
70
|
const { getAutoComplete: defaulGetAutoComplete, onEditModel: defaultOnEditModel, isMobile, } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
71
71
|
const getAutoComplete = (0, react_1.useMemo)(() => isolatedGetAutoComplete || defaulGetAutoComplete, [defaulGetAutoComplete, isolatedGetAutoComplete]);
|
|
72
72
|
const onEditModel = (0, react_1.useMemo)(() => (relatedEditable === false ? undefined : customOnEditModel || defaultOnEditModel), [customOnEditModel, defaultOnEditModel, relatedEditable]);
|
|
73
|
-
const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)(
|
|
73
|
+
const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)();
|
|
74
74
|
const defaultSx = { mr: 0 };
|
|
75
75
|
const { fieldsLayout, optionsACModels } = (0, react_1.useMemo)(() => {
|
|
76
76
|
if (!schema) {
|
|
@@ -90,11 +90,12 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
90
90
|
for (const row of section.rows) {
|
|
91
91
|
if (typeof row === 'string') {
|
|
92
92
|
const field = row;
|
|
93
|
-
|
|
93
|
+
const fieldSchema = schema[field];
|
|
94
|
+
if (!fieldSchema) {
|
|
94
95
|
console.log(`there is no schema for field ${field}!`);
|
|
95
96
|
continue;
|
|
96
97
|
}
|
|
97
|
-
if (['field', 'nested object'].includes(
|
|
98
|
+
if (['field', 'nested object'].includes(fieldSchema.type) &&
|
|
98
99
|
!newOptionsACModels.includes(field)) {
|
|
99
100
|
newOptionsACModels.push(field);
|
|
100
101
|
}
|
|
@@ -105,7 +106,7 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
105
106
|
}
|
|
106
107
|
if (Array.isArray(row)) {
|
|
107
108
|
for (const field of row) {
|
|
108
|
-
if (typeof field === 'string' && !schema
|
|
109
|
+
if (typeof field === 'string' && !(field in schema)) {
|
|
109
110
|
console.log(`there is no schema for field ${field}!`);
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
@@ -187,7 +188,7 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
187
188
|
}
|
|
188
189
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
189
190
|
register &&
|
|
190
|
-
hiddenFields.map((hiddenField) => (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: getValues ? getValues(hiddenField) :
|
|
191
|
+
hiddenFields.map((hiddenField) => (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: getValues ? getValues(hiddenField) : undefined, key: hiddenField })))),
|
|
191
192
|
fieldsLayout.map((section, sectionIndex) => {
|
|
192
193
|
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 },
|
|
193
194
|
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: sxSectionTitle }),
|
|
@@ -200,7 +201,9 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
200
201
|
}
|
|
201
202
|
const field = row;
|
|
202
203
|
const fieldProps = fieldsProps && field in fieldsProps ? fieldsProps[field] : {};
|
|
203
|
-
|
|
204
|
+
if (fieldProps) {
|
|
205
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
206
|
+
}
|
|
204
207
|
const isVisible = (0, utils_1.showConditionalVisibleField)(field, conditionalVisible, watchedValues);
|
|
205
208
|
if (!isVisible) {
|
|
206
209
|
return react_1.default.createElement(Box_1.default, { key: field, sx: sxRow });
|
|
@@ -223,12 +226,14 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
223
226
|
const mr = i + 1 === j.length ? 0 : 2;
|
|
224
227
|
const key = typeof field === 'string' ? field : field.key;
|
|
225
228
|
const fieldProps = fieldsProps && key in fieldsProps ? fieldsProps[key] : {};
|
|
226
|
-
fieldProps
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
if (fieldProps) {
|
|
230
|
+
fieldProps.sx =
|
|
231
|
+
'sx' in fieldProps
|
|
232
|
+
? Object.assign(Object.assign({}, fieldProps.sx), { mr }) : {
|
|
233
|
+
mr,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const isVisible = (0, utils_1.showConditionalVisibleField)(key, conditionalVisible, watchedValues);
|
|
232
237
|
if (!isVisible) {
|
|
233
238
|
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIndex}_${i}` }));
|
|
234
239
|
}
|
|
@@ -237,7 +242,9 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
237
242
|
}))));
|
|
238
243
|
}
|
|
239
244
|
const fieldProps = fieldsProps && row.key in fieldsProps ? fieldsProps[row.key] : {};
|
|
240
|
-
|
|
245
|
+
if (fieldProps) {
|
|
246
|
+
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
247
|
+
}
|
|
241
248
|
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `customElement_row_${rowIndex}` }, fieldProps)));
|
|
242
249
|
}))))));
|
|
243
250
|
})));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FieldKey, GenericValue } from '../../@types';
|
|
2
|
+
export interface FormWatcherProps<T = void> {
|
|
3
|
+
watch: FieldKey<T>[];
|
|
4
|
+
onChange: (values: GenericValue[]) => void;
|
|
4
5
|
}
|
|
5
|
-
declare
|
|
6
|
+
declare function FormWatcher<T = void>({ watch, onChange }: FormWatcherProps<T>): null;
|
|
6
7
|
export default FormWatcher;
|
|
7
8
|
//# 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":"AAGA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAQ,MAAM,cAAc,CAAC;AAE5D,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,IAAI;IACxC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;CAC5C;AAED,iBAAS,WAAW,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC,QAgBtE;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -3,7 +3,7 @@ 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
|
-
|
|
6
|
+
function FormWatcher({ watch, onChange }) {
|
|
7
7
|
const { control } = (0, react_hook_form_1.useFormContext)();
|
|
8
8
|
const values = (0, react_hook_form_1.useWatch)({
|
|
9
9
|
control,
|
|
@@ -17,5 +17,5 @@ const FormWatcher = ({ watch, onChange }) => {
|
|
|
17
17
|
}
|
|
18
18
|
}, [values, onChange]);
|
|
19
19
|
return null;
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
exports.default = FormWatcher;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,EAA8B,MAAM,iBAAiB,CAAC;AA8DjF,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,EAChD,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,WAAkB,EAClB,cAAwB,EACxB,OAAO,EAAE,cAAc,EACvB,YAAoB,EACpB,EAAc,EACd,aAAa,EACb,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,CAAC,EACf,GAAG,KAAK,EACT,EAAE,kBAAkB,iCA8DpB"}
|
|
@@ -13,6 +13,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
13
13
|
require("dayjs/locale/pt-br");
|
|
14
14
|
const utils_1 = require("../../../utils");
|
|
15
15
|
function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, index, sx = { mr: 2, mt: 2 }, autoFocus, disabled, }) {
|
|
16
|
+
var _a;
|
|
16
17
|
if (!(name in schema)) {
|
|
17
18
|
console.error(`DesktopDatePickerBySchema: could not find schema for ${name}! Not rendering`);
|
|
18
19
|
return;
|
|
@@ -37,7 +38,7 @@ function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, in
|
|
|
37
38
|
})
|
|
38
39
|
: {
|
|
39
40
|
error: errors && Boolean(errors[name]),
|
|
40
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
41
|
+
helperText: errors && errors[name] ? (_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message : fieldSchema.help_text || '',
|
|
41
42
|
};
|
|
42
43
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterDayjs_1.AdapterDayjs, adapterLocale: "pt-br" },
|
|
43
44
|
react_1.default.createElement(DesktopDatePicker_1.DesktopDatePicker, Object.assign({}, field, { value: (0, dayjs_1.default)(field.value), label: fieldSchema.label, disabled: fieldSchema.disabled === true || disabled === true, views: fieldSchema.date_views, format: inputFormat, sx: Object.assign({ mt: 2, mb: 1 }, sx), slotProps: {
|
|
@@ -13,6 +13,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
|
|
|
13
13
|
require("dayjs/locale/pt-br");
|
|
14
14
|
const utils_1 = require("../../../utils");
|
|
15
15
|
function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey, index, sx = { mr: 2, mt: 2 }, autoFocus, disabled, }) {
|
|
16
|
+
var _a;
|
|
16
17
|
if (!(name in schema)) {
|
|
17
18
|
console.error(`DesktopDateTimePickerBySchema: could not find schema for ${name}! Not rendering`);
|
|
18
19
|
return;
|
|
@@ -30,7 +31,7 @@ function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey
|
|
|
30
31
|
})
|
|
31
32
|
: {
|
|
32
33
|
error: errors && Boolean(errors[name]),
|
|
33
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
34
|
+
helperText: errors && errors[name] ? (_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message : fieldSchema.help_text || '',
|
|
34
35
|
};
|
|
35
36
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterDayjs_1.AdapterDayjs, adapterLocale: "pt-br" },
|
|
36
37
|
react_1.default.createElement(DesktopDateTimePicker_1.DesktopDateTimePicker, Object.assign({}, field, { value: (0, dayjs_1.default)(field.value), label: fieldSchema.label, disabled: fieldSchema.disabled === true || disabled === true, format: "DD/MM/YYYY HH:mm", sx: Object.assign({ mt: 2, mb: 1 }, sx), slotProps: {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { Item } from '../../../@types';
|
|
4
|
+
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<Omit<import("../../../@types").CommonFieldProps<void>, "value" | "onEditModel"> & {
|
|
5
|
+
onEditModel?: <U = any>(x: import("../../../@types").OnEditModelType<U>) => void;
|
|
6
|
+
name: string;
|
|
7
|
+
schema: {
|
|
8
|
+
[x: string]: import("../../../@types").Field;
|
|
9
|
+
};
|
|
10
|
+
control: Controller<Item<T>, any, Item<T>>;
|
|
11
|
+
errors: Controller<Item<T>>;
|
|
12
|
+
autoFocus?: boolean;
|
|
13
|
+
} & React.RefAttributes<any>>;
|
|
4
14
|
export default EditableAutocompleteFieldBySchema;
|
|
5
15
|
//# sourceMappingURL=EditableAutocompleteFieldBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditableAutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/EditableAutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EditableAutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/EditableAutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,EAAE,IAAI,EAAkC,MAAM,iBAAiB,CAAC;AAOvE,QAAA,MAAM,iCAAiC;;;;;;;;;6BAsWtC,CAAC;AAGF,eAAe,iCAAiC,CAAC"}
|
|
@@ -59,6 +59,7 @@ const DialogActions_1 = __importDefault(require("../../DialogActions"));
|
|
|
59
59
|
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
60
60
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
61
61
|
const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) => {
|
|
62
|
+
var _b;
|
|
62
63
|
var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, onValueChange, multiple = false, disabled, fieldsLayout, autoFocus } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "onValueChange", "multiple", "disabled", "fieldsLayout", "autoFocus"]);
|
|
63
64
|
const { setDialog } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
64
65
|
const [options, setOptions] = (0, react_1.useState)(null);
|
|
@@ -95,7 +96,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
97
98
|
const fieldSchema = schema[name];
|
|
98
|
-
const label = fieldSchema.label;
|
|
99
|
+
const label = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.label;
|
|
99
100
|
if (!optionsModel) {
|
|
100
101
|
optionsModel = model;
|
|
101
102
|
}
|
|
@@ -111,13 +112,13 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
111
112
|
})
|
|
112
113
|
: {
|
|
113
114
|
error: errors && Boolean(errors[name]),
|
|
114
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
115
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.help_text) || '',
|
|
115
116
|
};
|
|
116
117
|
if (!options) {
|
|
117
118
|
return null;
|
|
118
119
|
}
|
|
119
|
-
if (!disabled && !fieldSchema.disabled && onEditModel && optionsModel) {
|
|
120
|
-
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: fieldSchema.disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
120
|
+
if (!disabled && !(fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) && onEditModel && optionsModel) {
|
|
121
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
121
122
|
let valueAr = value || '';
|
|
122
123
|
if (!multiple) {
|
|
123
124
|
valueAr = [value];
|
|
@@ -256,7 +257,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
256
257
|
}
|
|
257
258
|
: undefined }))) }));
|
|
258
259
|
}
|
|
259
|
-
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: fieldSchema.disabled === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
260
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.disabled) === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
260
261
|
field.onChange(value);
|
|
261
262
|
if (onValueChange) {
|
|
262
263
|
onValueChange(e);
|
|
@@ -40,6 +40,7 @@ const VisuallyHiddenInput = (0, styles_1.styled)('input')({
|
|
|
40
40
|
width: 1,
|
|
41
41
|
});
|
|
42
42
|
function FileFieldBySchema(_a) {
|
|
43
|
+
var _b;
|
|
43
44
|
var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 }, onValueChange, autoFocus, disabled } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx", "onValueChange", "autoFocus", "disabled"]);
|
|
44
45
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
45
46
|
if (!(name in schema)) {
|
|
@@ -59,7 +60,7 @@ function FileFieldBySchema(_a) {
|
|
|
59
60
|
})
|
|
60
61
|
: {
|
|
61
62
|
error: errors && Boolean(errors[name]),
|
|
62
|
-
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
63
|
+
helperText: errors && errors[name] ? (_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message : fieldSchema.help_text || '',
|
|
63
64
|
};
|
|
64
65
|
const fileTypeStr = fieldSchema.type === 'image upload' ? 'imagem' : 'documento';
|
|
65
66
|
const accept = fieldSchema.allowed_mime_types
|