drf-react-by-schema 0.20.10 → 0.21.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 +4 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +2 -9
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +27 -29
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +1 -3
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable.js +1 -0
- package/dist/components/GenericModelList.js +7 -7
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelList.js +6 -15
- package/dist/components/details/DetailBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.js +2 -2
- package/dist/components/details/DetailFieldBySchema.d.ts +1 -1
- package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailFieldBySchema.js +5 -1
- package/dist/components/forms/DialogFormBySchema.d.ts +1 -1
- 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 -2
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +3 -3
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +10 -6
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +8 -3
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +9 -4
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +8 -3
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +19 -14
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/FileFieldBySchema.js +14 -10
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.js +13 -9
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/PatternFieldBySchema.js +8 -4
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/TextFieldBySchema.js +8 -4
- package/dist/context/APIWrapper.d.ts +1 -1
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +175 -144
- package/dist/context/APIWrapperContext.d.ts +7 -8
- package/dist/context/APIWrapperContext.d.ts.map +1 -1
- package/dist/context/APIWrapperContext.js +1 -1
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +56 -15
- package/dist/context/Overlays.d.ts.map +1 -1
- package/dist/context/Overlays.js +4 -4
- package/dist/hooks/useWhyDidYouUpdate.d.ts +4 -0
- package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -0
- package/dist/hooks/useWhyDidYouUpdate.js +26 -0
- package/dist/utils.d.ts +5 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +64 -25
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function useWhyDidYouUpdate(name, props) {
|
|
5
|
+
const previousProps = (0, react_1.useRef)({});
|
|
6
|
+
(0, react_1.useEffect)(() => {
|
|
7
|
+
if (previousProps.current) {
|
|
8
|
+
const allKeys = new Set([...Object.keys(previousProps.current), ...Object.keys(props)]);
|
|
9
|
+
const changes = {};
|
|
10
|
+
allKeys.forEach((key) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (((_a = previousProps.current) === null || _a === void 0 ? void 0 : _a[key]) !== props[key]) {
|
|
13
|
+
changes[key] = {
|
|
14
|
+
from: (_b = previousProps.current) === null || _b === void 0 ? void 0 : _b[key],
|
|
15
|
+
to: props[key],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (Object.keys(changes).length > 0) {
|
|
20
|
+
console.log('[why-did-you-update]', name, changes);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
previousProps.current = props;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.default = useWhyDidYouUpdate;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
2
|
-
import { Choice, ChoiceValue, ExtraValidators, GenericValue, GridEnrichedBySchemaColDef, Item, SchemaType } from './@types';
|
|
2
|
+
import { Choice, ChoiceValue, ExtraValidators, Field, FormFieldLayout, GenericValue, GridEnrichedBySchemaColDef, Item, SchemaType } from './@types';
|
|
3
3
|
export declare const emptyByType: GenericValue;
|
|
4
4
|
export declare const getChoiceByValue: (value: ChoiceValue, choices: Choice[] | undefined) => string | null | undefined;
|
|
5
5
|
export declare const populateValues: ({ data, schema }: {
|
|
6
6
|
data: Item;
|
|
7
7
|
schema: SchemaType;
|
|
8
8
|
}) => Item;
|
|
9
|
-
export declare function buildGenericYupValidationSchema({ data, schema, many, skipFields, extraValidators, }: {
|
|
9
|
+
export declare function buildGenericYupValidationSchema({ data, schema, many, skipFields, extraValidators, uiFields, }: {
|
|
10
10
|
data: Item;
|
|
11
11
|
schema: SchemaType;
|
|
12
12
|
many?: boolean;
|
|
13
13
|
skipFields?: string[];
|
|
14
14
|
extraValidators?: ExtraValidators;
|
|
15
|
+
uiFields?: string[];
|
|
15
16
|
}): any;
|
|
16
17
|
export declare const errorProps: ({ errors, fieldKey, fieldKeyProp, index, }: {
|
|
17
18
|
errors: Item;
|
|
@@ -38,4 +39,6 @@ export declare function initViewColumns({ schema, columns, customColumnOperation
|
|
|
38
39
|
export declare function shouldMemoUpdate<T extends object>(prevProps: Readonly<T>, nextProps: Readonly<T>): boolean;
|
|
39
40
|
export declare const convertToFormData: (data: Item) => FormData;
|
|
40
41
|
export declare function formatFileSize(bytes: number): string;
|
|
42
|
+
export declare function getFieldsFromFieldsLayout(fieldsLayout: FormFieldLayout[]): string[];
|
|
43
|
+
export declare function isFieldRequired(fieldSchema: Field, isInForm?: boolean): boolean;
|
|
41
44
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EACL,MAAM,EACN,WAAW,EACX,eAAe,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA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ED,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,WAqB5C,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,mDA0B7E;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,EAAE,sBAAoB,WAWhE,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,IAAI,WAa1C,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,eAAe,GAAG,SAAS,EAC1C,MAAM,EAAE,eAAe,GAAG,SAAS,OAyBpC;AAED,wBAAsB,eAAe,CAAC,EACpC,MAAM,EACN,OAAO,EACP,sBAAsB,GACvB,EAAE;IACD,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,sBAAsB,CAAC,EAAE,CACvB,CAAC,EAAE,0BAA0B,KAC1B,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;CACvE,gBAoGA;AA0CD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,GACrB,OAAO,CAwCT;AAED,eAAO,MAAM,iBAAiB,GAAI,MAAM,IAAI,KAAG,QAuB9C,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAgB3C;AAED,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,eAAe,EAAE,YAwBxE;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,OAAO,WAYrE"}
|
package/dist/utils.js
CHANGED
|
@@ -53,6 +53,8 @@ exports.mergeFilterItems = mergeFilterItems;
|
|
|
53
53
|
exports.initViewColumns = initViewColumns;
|
|
54
54
|
exports.shouldMemoUpdate = shouldMemoUpdate;
|
|
55
55
|
exports.formatFileSize = formatFileSize;
|
|
56
|
+
exports.getFieldsFromFieldsLayout = getFieldsFromFieldsLayout;
|
|
57
|
+
exports.isFieldRequired = isFieldRequired;
|
|
56
58
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
57
59
|
const Yup = __importStar(require("yup"));
|
|
58
60
|
const string_mask_1 = __importDefault(require("string-mask"));
|
|
@@ -100,7 +102,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
100
102
|
if (key === 'id' && (0, exports.isTmpId)(data[key])) {
|
|
101
103
|
continue;
|
|
102
104
|
}
|
|
103
|
-
if (!data[key]) {
|
|
105
|
+
if (!data[key] && data[key] !== false && data[key] !== 0) {
|
|
104
106
|
values[key] = (0, exports.emptyByType)(field);
|
|
105
107
|
continue;
|
|
106
108
|
}
|
|
@@ -193,27 +195,28 @@ const getYupValidator = (type) => {
|
|
|
193
195
|
}
|
|
194
196
|
return yupFunc.transform((v) => (v === '' ? null : v)).nullable();
|
|
195
197
|
};
|
|
196
|
-
function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, }) {
|
|
198
|
+
function buildGenericYupValidationSchema({ data, schema, many = false, skipFields = [], extraValidators, uiFields, }) {
|
|
197
199
|
const yupValidator = {};
|
|
198
200
|
for (const entry of Object.entries(schema)) {
|
|
199
|
-
const [
|
|
200
|
-
if (!data || !(
|
|
201
|
+
const [field, fieldSchema] = entry;
|
|
202
|
+
if (!data || !(field in data) || field === 'id' || skipFields.includes(field)) {
|
|
201
203
|
continue;
|
|
202
204
|
}
|
|
203
205
|
// OneToMany or ManyToMany:
|
|
204
|
-
if (
|
|
205
|
-
yupValidator[
|
|
206
|
-
extraValidators &&
|
|
207
|
-
? extraValidators[
|
|
206
|
+
if (fieldSchema.type === 'field' && fieldSchema.child) {
|
|
207
|
+
yupValidator[field] =
|
|
208
|
+
extraValidators && field in extraValidators
|
|
209
|
+
? extraValidators[field]
|
|
208
210
|
: buildGenericYupValidationSchema({
|
|
209
|
-
schema:
|
|
211
|
+
schema: fieldSchema.child.children,
|
|
210
212
|
many: true,
|
|
211
|
-
data: data[
|
|
213
|
+
data: data[field],
|
|
214
|
+
uiFields,
|
|
212
215
|
});
|
|
213
216
|
continue;
|
|
214
217
|
}
|
|
215
218
|
// Nested Object:
|
|
216
|
-
if (
|
|
219
|
+
if (fieldSchema.type === 'nested object' && fieldSchema.children) {
|
|
217
220
|
// yupValidator[key] = buildGenericYupValidationSchema({
|
|
218
221
|
// schema: field.children,
|
|
219
222
|
// many: false,
|
|
@@ -225,28 +228,28 @@ function buildGenericYupValidationSchema({ data, schema, many = false, skipField
|
|
|
225
228
|
// }
|
|
226
229
|
// continue;
|
|
227
230
|
}
|
|
228
|
-
yupValidator[
|
|
229
|
-
extraValidators &&
|
|
230
|
-
? extraValidators[
|
|
231
|
-
: getYupValidator(
|
|
232
|
-
if (
|
|
233
|
-
yupValidator[
|
|
231
|
+
yupValidator[field] =
|
|
232
|
+
extraValidators && field in extraValidators
|
|
233
|
+
? extraValidators[field]
|
|
234
|
+
: getYupValidator(fieldSchema.type);
|
|
235
|
+
if (isFieldRequired(fieldSchema, (uiFields || []).includes(field))) {
|
|
236
|
+
yupValidator[field] = yupValidator[field].required('Este campo é obrigatório');
|
|
234
237
|
}
|
|
235
|
-
if (
|
|
236
|
-
yupValidator[
|
|
238
|
+
if (fieldSchema.max_length && fieldSchema.type === 'string') {
|
|
239
|
+
yupValidator[field] = yupValidator[field].max(parseInt(fieldSchema.max_length), `Este campo só pode ter no máximo ${fieldSchema.max_length} caracteres`);
|
|
237
240
|
}
|
|
238
|
-
if (
|
|
239
|
-
const maxDigits =
|
|
240
|
-
yupValidator[
|
|
241
|
+
if (fieldSchema.max_digits && fieldSchema.type === 'decimal') {
|
|
242
|
+
const maxDigits = fieldSchema.max_digits;
|
|
243
|
+
yupValidator[field] = yupValidator[field].test('len', `Este número pode ter no máximo ${maxDigits} dígitos`, (val) => {
|
|
241
244
|
if (!val) {
|
|
242
245
|
return true;
|
|
243
246
|
}
|
|
244
247
|
return val.toString().length <= maxDigits;
|
|
245
248
|
});
|
|
246
249
|
}
|
|
247
|
-
if (!
|
|
248
|
-
for (const validator of
|
|
249
|
-
yupValidator[
|
|
250
|
+
if (!fieldSchema.read_only && fieldSchema.validators_regex) {
|
|
251
|
+
for (const validator of fieldSchema.validators_regex) {
|
|
252
|
+
yupValidator[field] = yupValidator[field].matches(validator.regex, validator.message);
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
}
|
|
@@ -595,3 +598,39 @@ function formatFileSize(bytes) {
|
|
|
595
598
|
});
|
|
596
599
|
return `${formattedValue} ${units[i]}`;
|
|
597
600
|
}
|
|
601
|
+
function getFieldsFromFieldsLayout(fieldsLayout) {
|
|
602
|
+
const fields = [];
|
|
603
|
+
for (const section of fieldsLayout) {
|
|
604
|
+
if (!section.rows) {
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
for (const row of section.rows) {
|
|
608
|
+
if (typeof row === 'string') {
|
|
609
|
+
fields.push(row);
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (Array.isArray(row)) {
|
|
613
|
+
for (const field of row) {
|
|
614
|
+
if (typeof field === 'string') {
|
|
615
|
+
fields.push(field);
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return fields;
|
|
624
|
+
}
|
|
625
|
+
function isFieldRequired(fieldSchema, isInForm) {
|
|
626
|
+
if (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.required) {
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
if (fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.model_required) {
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
if ((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.ui_required) && (typeof isInForm === 'undefined' || isInForm === true)) {
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
return false;
|
|
636
|
+
}
|
package/package.json
CHANGED