drf-react-by-schema 0.20.3 → 0.20.4
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.
|
@@ -133,7 +133,7 @@ function DetailBySchema({ values, schema, columns, loading, editLink, editLabel,
|
|
|
133
133
|
setPreparedColumns(null);
|
|
134
134
|
};
|
|
135
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
|
-
}, []);
|
|
136
|
+
}, [fieldsLayoutInitial]);
|
|
137
137
|
if (!fieldsLayout || loading || !formattedValues) {
|
|
138
138
|
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
139
139
|
react_1.default.createElement(CardContent_1.default, null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { UseFormRegister } from 'react-hook-form';
|
|
3
|
-
import { CommonFieldProps, FieldBySchemaProps, FormFieldLayout, Item, OptionsAC } from '../../@types';
|
|
3
|
+
import { CommonFieldProps, ExtraSxCommonFieldProps, FieldBySchemaProps, FormFieldLayout, Item, OptionsAC } from '../../@types';
|
|
4
4
|
interface FormBySchemaProps extends Omit<FieldBySchemaProps, 'name'> {
|
|
5
5
|
fieldsLayout?: FormFieldLayout[];
|
|
6
6
|
customFieldFormLayouts?: Record<string, FormFieldLayout[]>;
|
|
@@ -12,7 +12,8 @@ interface FormBySchemaProps extends Omit<FieldBySchemaProps, 'name'> {
|
|
|
12
12
|
fieldsProps?: Record<string, CommonFieldProps>;
|
|
13
13
|
relatedEditable?: boolean;
|
|
14
14
|
autoFocusField?: string;
|
|
15
|
+
elevation?: number;
|
|
15
16
|
}
|
|
16
|
-
export default function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC,
|
|
17
|
+
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, fieldsProps, hiddenFields, isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation, sxRow, sxRowMultiple, sxSection, sxSectionTitle, }: FormBySchemaProps & Omit<ExtraSxCommonFieldProps, 'sx' | 'sxField' | 'sxLabel' | 'sxValue' | 'sxValueList' | 'sxValueListItem' | 'sxValueListItemText'>): React.JSX.Element;
|
|
17
18
|
export {};
|
|
18
19
|
//# 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,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AASlD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,IAAI,EACJ,SAAS,EACV,MAAM,cAAc,CAAC;AAGtB,UAAU,iBAAkB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAClE,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;IACjC,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IAC3D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,CAAC;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,OAAO,CAAC;IA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EAAE,iBAAiB,EAC9B,OAAO,EACP,YAAoB,EACpB,KAAK,EACL,YAAgB,EAEhB,YAAY,EAAE,mBAAmB,EACjC,sBAAsB,EAEtB,WAAW,EACX,YAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAKT,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,GAKf,EAAE,iBAAiB,GAClB,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBA2QF"}
|
|
@@ -55,7 +55,16 @@ const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgre
|
|
|
55
55
|
const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
|
|
56
56
|
const styles_1 = require("../../styles");
|
|
57
57
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
58
|
-
function FormBySchema({ schema, control, errors, register, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC,
|
|
58
|
+
function FormBySchema({ schema, control, errors, register, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, optionsModel, getOptionLabel, renderOption, onEditModel: customOnEditModel, options, isSemaphoric = false, label, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, customFieldFormLayouts, fieldsProps, hiddenFields = [], isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation,
|
|
59
|
+
// sx,
|
|
60
|
+
// sxField,
|
|
61
|
+
// sxLabel,
|
|
62
|
+
sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
63
|
+
// sxValue,
|
|
64
|
+
// sxValueList,
|
|
65
|
+
// sxValueListItem,
|
|
66
|
+
// sxValueListItemText,
|
|
67
|
+
}) {
|
|
59
68
|
const { getAutoComplete: defaulGetAutoComplete, onEditModel: defaultOnEditModel, optionsAC: externalOptionsAC, } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
60
69
|
const getAutoComplete = isolatedGetAutoComplete || defaulGetAutoComplete;
|
|
61
70
|
const onEditModel = relatedEditable === false ? undefined : customOnEditModel || defaultOnEditModel;
|
|
@@ -157,7 +166,7 @@ function FormBySchema({ schema, control, errors, register, multiline = false, se
|
|
|
157
166
|
if (fieldsLayout.length === 0 ||
|
|
158
167
|
(setOptionsAC && !optionsAC) ||
|
|
159
168
|
(!setOptionsAC && !localOptionsAC)) {
|
|
160
|
-
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
169
|
+
return (react_1.default.createElement(Card_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.formCard), { sxSection }), elevation: elevation },
|
|
161
170
|
react_1.default.createElement(CardContent_1.default, null,
|
|
162
171
|
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBoxWhite },
|
|
163
172
|
react_1.default.createElement(CircularProgress_1.default, null)))));
|
|
@@ -166,8 +175,8 @@ function FormBySchema({ schema, control, errors, register, multiline = false, se
|
|
|
166
175
|
register &&
|
|
167
176
|
hiddenFields.map((hiddenField) => (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: getValues ? getValues(hiddenField) : null, key: hiddenField })))),
|
|
168
177
|
fieldsLayout.map((section, sectionIndex) => {
|
|
169
|
-
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard, key: `section_${sectionIndex}
|
|
170
|
-
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title }),
|
|
178
|
+
return (react_1.default.createElement(Card_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.formCard), { sxSection }), key: `section_${sectionIndex}`, elevation: elevation },
|
|
179
|
+
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: sxSectionTitle }),
|
|
171
180
|
react_1.default.createElement(CardContent_1.default, null,
|
|
172
181
|
section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
|
|
173
182
|
section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
|
|
@@ -175,13 +184,13 @@ function FormBySchema({ schema, control, errors, register, multiline = false, se
|
|
|
175
184
|
const field = row;
|
|
176
185
|
const fieldProps = fieldsProps && field in fieldsProps ? fieldsProps[field] : {};
|
|
177
186
|
fieldProps.sx = 'sx' in fieldProps ? fieldProps.sx : defaultSx;
|
|
178
|
-
return (react_1.default.createElement(
|
|
187
|
+
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
179
188
|
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: setOptionsAC ? optionsAC : localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, fieldsLayout: customFieldFormLayouts && field in customFieldFormLayouts
|
|
180
189
|
? customFieldFormLayouts[field]
|
|
181
190
|
: undefined, options: options, isSemaphoric: isSemaphoric, label: label, decimalScale: decimalScale, autoFocus: autoFocusField === field || (sectionIndex === 0 && rowIndex === 0) }, fieldProps))));
|
|
182
191
|
}
|
|
183
192
|
if (Array.isArray(row)) {
|
|
184
|
-
return (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
|
|
193
|
+
return (react_1.default.createElement(Box_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.inLineForm), { sxRowMultiple }), key: `row_${rowIndex}` },
|
|
185
194
|
react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => {
|
|
186
195
|
const mr = i + 1 === j.length ? 0 : 2;
|
|
187
196
|
const key = typeof field === 'string' ? field : field.key;
|
package/dist/utils.js
CHANGED
|
@@ -137,7 +137,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
137
137
|
return values;
|
|
138
138
|
};
|
|
139
139
|
exports.populateValues = populateValues;
|
|
140
|
-
const getYupValidator = (type) => {
|
|
140
|
+
const getYupValidator = (type, required) => {
|
|
141
141
|
let yupFunc;
|
|
142
142
|
try {
|
|
143
143
|
switch (type) {
|
|
@@ -191,7 +191,7 @@ const getYupValidator = (type) => {
|
|
|
191
191
|
catch (e) {
|
|
192
192
|
yupFunc = Yup.string();
|
|
193
193
|
}
|
|
194
|
-
return yupFunc.nullable();
|
|
194
|
+
return required ? yupFunc : yupFunc.transform((v) => (v === '' ? null : v)).nullable();
|
|
195
195
|
};
|
|
196
196
|
function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, }) {
|
|
197
197
|
const yupValidator = {};
|
|
@@ -228,8 +228,8 @@ function buildGenericYupValidationSchema({ data, schema, many = false, skipField
|
|
|
228
228
|
yupValidator[key] =
|
|
229
229
|
extraValidators && key in extraValidators
|
|
230
230
|
? extraValidators[key]
|
|
231
|
-
: getYupValidator(field.type);
|
|
232
|
-
if (field.model_required) {
|
|
231
|
+
: getYupValidator(field.type, field.required || field.model_required);
|
|
232
|
+
if (field.required || field.model_required) {
|
|
233
233
|
yupValidator[key] = yupValidator[key].required('Este campo é obrigatório');
|
|
234
234
|
}
|
|
235
235
|
if (field.max_length && field.type === 'string') {
|
package/package.json
CHANGED