drf-react-by-schema 0.5.2 → 0.5.3
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/api.js
CHANGED
|
@@ -377,7 +377,7 @@ const getDataGridColumns = (schema, columnFields = [], hiddenFields = [], creata
|
|
|
377
377
|
field,
|
|
378
378
|
headerName: schema[field].label,
|
|
379
379
|
hide: (hiddenFields.includes(field)),
|
|
380
|
-
creatable: (creatableFields.includes(field)),
|
|
380
|
+
creatable: (creatableFields.includes(field) || schema[field].creatable),
|
|
381
381
|
width: 100
|
|
382
382
|
};
|
|
383
383
|
return column;
|
|
@@ -74,7 +74,8 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
74
74
|
? 'id'
|
|
75
75
|
: 'value';
|
|
76
76
|
let creatableProps = {};
|
|
77
|
-
if (column.creatable || isIndexField) {
|
|
77
|
+
// if (column.creatable || isIndexField) {
|
|
78
|
+
if (column.creatable) {
|
|
78
79
|
creatableProps = {
|
|
79
80
|
freesolo: 'true',
|
|
80
81
|
filterOptions: (options, params) => {
|
|
@@ -117,7 +118,8 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
117
118
|
}, getOptionLabel: (option) => {
|
|
118
119
|
return option[labelKey];
|
|
119
120
|
}, onChange: (e, value) => {
|
|
120
|
-
if (!column.creatable && !isIndexField) {
|
|
121
|
+
// if (!column.creatable && !isIndexField) {
|
|
122
|
+
if (!column.creatable) {
|
|
121
123
|
handleChange(value);
|
|
122
124
|
return;
|
|
123
125
|
}
|
|
@@ -72,11 +72,14 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
72
72
|
const [pageForm, setPageForm] = (0, react_1.useReducer)(utils_1.reducer, initialPageForm);
|
|
73
73
|
const editModel = (0, react_1.useRef)({});
|
|
74
74
|
const jsonSchemaFormRef = (0, react_1.useRef)(null);
|
|
75
|
-
|
|
75
|
+
const updateUsuaria = () => {
|
|
76
76
|
setUsuaria(null);
|
|
77
77
|
(0, api_1.isLoggedIn)(serverEndPoint).then(usuaria => {
|
|
78
78
|
setUsuaria(usuaria || { erro: 'token inválido' });
|
|
79
79
|
});
|
|
80
|
+
};
|
|
81
|
+
(0, react_1.useEffect)(() => {
|
|
82
|
+
updateUsuaria();
|
|
80
83
|
}, []);
|
|
81
84
|
(0, react_1.useEffect)(() => {
|
|
82
85
|
setPageForm(initialPageForm);
|
|
@@ -331,6 +334,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
331
334
|
});
|
|
332
335
|
return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
|
|
333
336
|
usuaria,
|
|
337
|
+
updateUsuaria,
|
|
334
338
|
onSubmit,
|
|
335
339
|
loadSinglePageData,
|
|
336
340
|
handleLoading,
|
|
@@ -58,6 +58,7 @@ export interface DialogType {
|
|
|
58
58
|
export type DRFReactBySchemaSubmitHandler = (...args: [...[model: string, id: Id], ...Parameters<SubmitHandler<FieldValues>>]) => ReturnType<SubmitHandler<FieldValues>>;
|
|
59
59
|
export interface APIWrapperContextType {
|
|
60
60
|
usuaria: Item | null;
|
|
61
|
+
updateUsuaria: () => void;
|
|
61
62
|
onSubmit: DRFReactBySchemaSubmitHandler;
|
|
62
63
|
loadSinglePageData: (p: LoadSinglePageDataProps) => Promise<boolean | FieldValues>;
|
|
63
64
|
handleLoading: (p: boolean) => void;
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -51,6 +51,8 @@ const emptyByType = (field, forDatabase = false) => {
|
|
|
51
51
|
return 0;
|
|
52
52
|
case 'array':
|
|
53
53
|
return [];
|
|
54
|
+
case 'boolean':
|
|
55
|
+
return false;
|
|
54
56
|
default:
|
|
55
57
|
return null;
|
|
56
58
|
}
|
|
@@ -215,6 +217,11 @@ const buildGenericYupValidationSchema = ({ data, schema, many = false, skipField
|
|
|
215
217
|
return val.toString().length <= maxDigits;
|
|
216
218
|
});
|
|
217
219
|
}
|
|
220
|
+
if (field.validators_regex) {
|
|
221
|
+
for (const validator of field.validators_regex) {
|
|
222
|
+
yupValidator[key] = yupValidator[key].matches(validator.regex, validator.message);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
218
225
|
}
|
|
219
226
|
// console.log({ yupValidator });
|
|
220
227
|
return (many)
|
package/package.json
CHANGED