drf-react-by-schema 0.21.0 → 0.21.2
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.d.ts.map +1 -1
- package/dist/api.js +1 -9
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +1 -3
- 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/forms/FieldBySchema.d.ts +1 -1
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/FieldBySchema.js +5 -0
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +3 -3
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +3 -3
- package/dist/context/APIWrapper.d.ts +1 -1
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +167 -149
- package/dist/context/APIWrapperContext.d.ts +5 -7
- 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.js +1 -1
- package/package.json +1 -1
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mC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,cAAc,GAAU,SAAS,IAAI,EAAE,gBAAgB,cAAc,GAAG,IAAI,iBAsBxF,CAAC;AAEF,eAAO,MAAM,QAAQ,eAGpB,CAAC;AAEF,eAAO,MAAM,MAAM,eAMlB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,IAAI,SAShD,CAAC;AA0BF,eAAO,MAAM,UAAU,GAAU,gBAAgB,cAAc,GAAG,IAAI,0BAYrE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,gBAAgB,cAAc,GAAG,IAAI,iBAmB3E,CAAC;AAEF,eAAO,MAAM,MAAM,GAAU,MAAM,IAAI,EAAE,gBAAgB,cAAc,GAAG,IAAI,iBA+C7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAU,oNAkBvC,wBAAwB,2CAyH1B,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,8DAMnC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,2CA8BA,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,gBAAgB,cAAc,GAAG,IAAI,iBASvE,CAAC"}
|
package/dist/api.js
CHANGED
|
@@ -408,19 +408,16 @@ const createOrUpdateData = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
408
408
|
});
|
|
409
409
|
exports.createOrUpdateData = createOrUpdateData;
|
|
410
410
|
const prepareDataBySchemaRecursive = ({ data, schema }) => {
|
|
411
|
-
// console.log('Entered prepareDataBySchema', schema);
|
|
412
411
|
let requiresMultipart = false;
|
|
413
412
|
const dbData = {};
|
|
414
413
|
for (const [key, field] of Object.entries(schema)) {
|
|
415
|
-
// console.log(key, field, data);
|
|
416
414
|
if (!(key in data) || (key === 'id' && (0, utils_1.isTmpId)(data[key]))) {
|
|
417
415
|
continue;
|
|
418
416
|
}
|
|
419
|
-
if (!data[key]) {
|
|
417
|
+
if (typeof data[key] !== 'boolean' && !data[key]) {
|
|
420
418
|
dbData[key] = (0, utils_1.emptyByType)(field, true);
|
|
421
419
|
continue;
|
|
422
420
|
}
|
|
423
|
-
// console.log({ key, data: data[key] });
|
|
424
421
|
// Check for file upload fields
|
|
425
422
|
if (['file upload', 'image upload'].includes(field.type)) {
|
|
426
423
|
requiresMultipart = true;
|
|
@@ -471,7 +468,6 @@ const prepareDataBySchemaRecursive = ({ data, schema }) => {
|
|
|
471
468
|
// Default:
|
|
472
469
|
dbData[key] = data[key];
|
|
473
470
|
}
|
|
474
|
-
// console.log({dbData});
|
|
475
471
|
return {
|
|
476
472
|
data: dbData,
|
|
477
473
|
requiresMultipart,
|
|
@@ -491,7 +487,6 @@ const updateDataBySchema = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
491
487
|
if (!path) {
|
|
492
488
|
path = model;
|
|
493
489
|
}
|
|
494
|
-
// DEBUG console.log({ model, modelObjectId, path, data, dbData });
|
|
495
490
|
const response = yield (0, exports.createOrUpdateData)({
|
|
496
491
|
path,
|
|
497
492
|
serverEndPoint,
|
|
@@ -595,7 +590,6 @@ const refreshToken = (serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
|
|
|
595
590
|
};
|
|
596
591
|
}
|
|
597
592
|
const refreshToken = localStorage.getItem('refreshToken');
|
|
598
|
-
// console.log('entrou refreshToken', refreshToken);
|
|
599
593
|
(0, exports.setAuthToken)(null);
|
|
600
594
|
if (!refreshToken) {
|
|
601
595
|
return false;
|
|
@@ -803,10 +797,8 @@ const getGenericModelList = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
803
797
|
});
|
|
804
798
|
}
|
|
805
799
|
if (loadedSchema) {
|
|
806
|
-
// DEBUG console.log({ path, data });
|
|
807
800
|
return { data, rowCount, sumRowsTotals };
|
|
808
801
|
}
|
|
809
|
-
// DEBUG console.log({ path, data, columns, schema });
|
|
810
802
|
return { data, columns, schema, modelOptions, rowCount, sumRowsTotals };
|
|
811
803
|
});
|
|
812
804
|
exports.getGenericModelList = getGenericModelList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGridMobile.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/DataGridMobile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,YAAY,EAAuB,MAAM,OAAO,CAAC;AAI7E,OAAO,EAEL,0BAA0B,EAC1B,IAAI,EACJ,wBAAwB,EACxB,eAAe,EACf,UAAU,EAEX,MAAM,cAAc,CAAC;AAItB,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,EAAE,CAAC;IACb,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,MAAM,EAAE,UAAU,CAAC;IACnB,sBAAsB,CAAC,EAAE,CACvB,CAAC,EAAE,0BAA0B,KAC1B,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACtE,oBAAoB,EAAE,wBAAwB,CAAC;IAC/C,qBAAqB,CAAC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IAClD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,QAAA,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"DataGridMobile.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/DataGridMobile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,YAAY,EAAuB,MAAM,OAAO,CAAC;AAI7E,OAAO,EAEL,0BAA0B,EAC1B,IAAI,EACJ,wBAAwB,EACxB,eAAe,EACf,UAAU,EAEX,MAAM,cAAc,CAAC;AAItB,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,EAAE,CAAC;IACb,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,MAAM,EAAE,UAAU,CAAC;IACnB,sBAAsB,CAAC,EAAE,CACvB,CAAC,EAAE,0BAA0B,KAC1B,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACtE,oBAAoB,EAAE,wBAAwB,CAAC;IAC/C,qBAAqB,CAAC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IAClD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,QAAA,MAAM,cAAc,qFAyFnB,CAAC;AAIF,eAAe,cAAc,CAAC"}
|
|
@@ -85,11 +85,9 @@ const DataGridMobile = (0, react_1.forwardRef)(({ name, columns, schema, data, c
|
|
|
85
85
|
}
|
|
86
86
|
setFormattedData(newData);
|
|
87
87
|
}, [data, preparedColumns]);
|
|
88
|
-
if (formattedData.length === 0) {
|
|
89
|
-
return (react_1.default.createElement(Box_1.default, null, MobileRenderNoResults ? (react_1.default.createElement(MobileRenderNoResults, null)) : (react_1.default.createElement(Typography_1.default, null, "N\u00E3o h\u00E1 resultados"))));
|
|
90
|
-
}
|
|
91
88
|
return (react_1.default.createElement(Box_1.default, null,
|
|
92
89
|
!hideQuickFilterBar && paginationModel && setPaginationModel && (react_1.default.createElement(MobileSearchBar_1.default, { paginationModel: paginationModel, setPaginationModel: setPaginationModel })),
|
|
90
|
+
formattedData.length === 0 && (react_1.default.createElement(react_1.default.Fragment, null, MobileRenderNoResults ? (react_1.default.createElement(MobileRenderNoResults, null)) : (react_1.default.createElement(Typography_1.default, null, "N\u00E3o h\u00E1 resultados")))),
|
|
93
91
|
formattedData.map((row, index) => (react_1.default.createElement(MobileListRenderItem, { key: `${name}_${index}`, item: row.item, id: row.id, index: index })))));
|
|
94
92
|
});
|
|
95
93
|
DataGridMobile.displayName = 'DataGridMobile';
|
|
@@ -158,13 +158,13 @@ function GenericModelList({ model, columnFields, hiddenFields, creatableFields,
|
|
|
158
158
|
(0, react_1.useEffect)(() => {
|
|
159
159
|
loadObjectList();
|
|
160
160
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
|
-
}, [model, defaultFilter, queryParams, hiddenFields]);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}, [paginationModel]);
|
|
161
|
+
}, [model, defaultFilter, queryParams, hiddenFields, paginationModel]);
|
|
162
|
+
// useEffect(() => {
|
|
163
|
+
// if (paginationMode === 'server') {
|
|
164
|
+
// loadObjectList();
|
|
165
|
+
// }
|
|
166
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
167
|
+
// }, [paginationModel]);
|
|
168
168
|
if (!serverEndPoint) {
|
|
169
169
|
console.error('Error: There is no endpoint defined in DRFReactBySchemaProvider!');
|
|
170
170
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericRelatedModelList.d.ts","sourceRoot":"","sources":["../../src/components/GenericRelatedModelList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAuB,YAAY,EAAe,MAAM,OAAO,CAAC;AAI9E,OAAO,EAAE,eAAe,EAAa,MAAM,kBAAkB,CAAC;AAG9D,OAAO,EACL,UAAU,EAEV,eAAe,EACf,0BAA0B,EAC1B,EAAE,EACF,IAAI,EACJ,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EACf,SAAS,EAET,WAAW,EACZ,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"GenericRelatedModelList.d.ts","sourceRoot":"","sources":["../../src/components/GenericRelatedModelList.tsx"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B,EACpB,WAAkB,EAClB,aAAqB,EACrB,cAAyB,EACzB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,SAAS,EACT,aAAa,EACb,aAAa,EACb,eAAe,EAEf,oBAAoB,EACpB,qBAAqB,GACtB,EAAE,4BAA4B,qBA+O9B;;AAED,wBAAqE"}
|
|
@@ -51,7 +51,6 @@ const CardHeader_1 = __importDefault(require("@mui/material/CardHeader"));
|
|
|
51
51
|
const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
|
|
52
52
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
53
53
|
const utils_1 = require("../utils");
|
|
54
|
-
const api_1 = require("../api");
|
|
55
54
|
const styles_1 = require("../styles");
|
|
56
55
|
const GenericRelatedModelListTable_1 = __importDefault(require("./GenericRelatedModelListTable"));
|
|
57
56
|
function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields = ['id'], creatableFields, disabledFields, usuaria = null, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, onDataChange, reloadAfterRowUpdate, customColumnOperations, isEditable = true, hasBulkSelect = false, onSelectActions, sumRows, isAutoHeight = false, isInBatches = true, noCardWrapper = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, hideColumnsButton, hideFilterButton, hideDensityButton, hideExportButton, hideQuickFilterBar, tableAutoHeight, actions, optionsAC, defaultValues, LinkComponent, extraValidators, MobileListRenderItem, MobileRenderNoResults, }) {
|
|
@@ -60,7 +59,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
60
59
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
61
60
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
62
61
|
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
63
|
-
const { onEditModel, onDeleteRelatedModel,
|
|
62
|
+
const { onEditModel, onDeleteRelatedModel, getGenericModelList } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
64
63
|
const finalCustomColumnOperations = (0, react_1.useCallback)((column) => __awaiter(this, void 0, void 0, function* () {
|
|
65
64
|
if (minWidthFields) {
|
|
66
65
|
if (column.field in minWidthFields) {
|
|
@@ -88,16 +87,15 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
88
87
|
usuaria,
|
|
89
88
|
isInBatches,
|
|
90
89
|
queryParams,
|
|
91
|
-
serverEndPoint,
|
|
92
90
|
filter: defaultFilter,
|
|
93
91
|
};
|
|
94
|
-
const loadedData = yield
|
|
92
|
+
const loadedData = yield getGenericModelList(loadParams);
|
|
95
93
|
if (loadedData && typeof loadedData !== 'boolean') {
|
|
96
94
|
setData(loadedData);
|
|
97
95
|
setLoading(false);
|
|
98
96
|
if (isInBatches && loadedData.data.length === 100) {
|
|
99
97
|
setHideFooterPagination(true);
|
|
100
|
-
|
|
98
|
+
getGenericModelList(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema })).then((lastBatchData) => {
|
|
101
99
|
if (lastBatchData) {
|
|
102
100
|
setData(Object.assign(Object.assign({}, loadedData), { data: [...loadedData.data, ...lastBatchData.data] }));
|
|
103
101
|
setHideFooterPagination(false);
|
|
@@ -112,7 +110,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
112
110
|
const page = paginationModel ? paginationModel.page : 0;
|
|
113
111
|
const sort = paginationModel ? paginationModel.sort : undefined;
|
|
114
112
|
const filter = (0, utils_1.mergeFilterItems)(defaultFilter, paginationModel ? paginationModel.filter : undefined);
|
|
115
|
-
const paginatedData = yield
|
|
113
|
+
const paginatedData = yield getGenericModelList({
|
|
116
114
|
model,
|
|
117
115
|
id,
|
|
118
116
|
relatedModel,
|
|
@@ -125,7 +123,6 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
125
123
|
sort,
|
|
126
124
|
sumRows,
|
|
127
125
|
queryParams,
|
|
128
|
-
serverEndPoint,
|
|
129
126
|
});
|
|
130
127
|
if (paginatedData && typeof paginatedData !== 'boolean') {
|
|
131
128
|
setData(paginatedData);
|
|
@@ -149,9 +146,9 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
149
146
|
paginationModel,
|
|
150
147
|
queryParams,
|
|
151
148
|
relatedModel,
|
|
152
|
-
serverEndPoint,
|
|
153
149
|
sumRows,
|
|
154
150
|
usuaria,
|
|
151
|
+
getGenericModelList,
|
|
155
152
|
]);
|
|
156
153
|
const onDataChangeLocal = (0, react_1.useCallback)((newData) => {
|
|
157
154
|
if (!data) {
|
|
@@ -169,13 +166,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
169
166
|
(0, react_1.useEffect)(() => {
|
|
170
167
|
loadObjectList();
|
|
171
168
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
|
-
}, [id, model, defaultFilter, queryParams]);
|
|
173
|
-
(0, react_1.useEffect)(() => {
|
|
174
|
-
if (paginationMode === 'server') {
|
|
175
|
-
loadObjectList();
|
|
176
|
-
}
|
|
177
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
|
-
}, [paginationModel]);
|
|
169
|
+
}, [id, model, defaultFilter, queryParams, paginationModel]);
|
|
179
170
|
return (react_1.default.createElement(react_1.default.Fragment, null, typeof data !== 'boolean' && data.columns && (react_1.default.createElement(react_1.default.Fragment, null, noCardWrapper ? (react_1.default.createElement(GenericRelatedModelListTable_1.default, { data: data, relatedModel: relatedModel, model: model, loading: loading, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onSelectActions: onSelectActions, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, visibleRows: visibleRows, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, hideColumnsButton: hideColumnsButton, hideFilterButton: hideFilterButton, hideDensityButton: hideDensityButton, hideExportButton: hideExportButton, hideQuickFilterBar: hideQuickFilterBar, onProcessRow: onProcessRow, onDataChange: onDataChangeLocal, sumRows: sumRows, paginationMode: paginationMode, paginationModel: paginationModel, setPaginationModel: setPaginationModel, actions: actions, optionsAC: optionsAC, defaultValues: defaultValues, LinkComponent: LinkComponent, extraValidators: extraValidators, MobileListRenderItem: MobileListRenderItem, MobileRenderNoResults: MobileRenderNoResults })) : (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
180
171
|
react_1.default.createElement(CardHeader_1.default, { title: label }),
|
|
181
172
|
react_1.default.createElement(CardContent_1.default, null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../@types';
|
|
3
|
-
export default function FieldBySchema({ name, schema, control, errors, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, fieldsLayout, sx, options, isSemaphoric, label, onValueChange, decimalScale, autoFocus, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
3
|
+
export default function FieldBySchema({ name, schema, control, errors, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, fieldsLayout, sx, options, isSemaphoric, label, onValueChange, decimalScale, autoFocus, ...other }: FieldBySchemaProps): React.JSX.Element | null;
|
|
4
4
|
//# sourceMappingURL=FieldBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAYlD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,SAAiB,EACjB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAiB,EACjB,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,EAAE,EACF,OAAO,EACP,YAAoB,EACpB,KAAK,EACL,aAAa,EACb,YAAgB,EAChB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"FieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAYlD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EACpC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,SAAiB,EACjB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAiB,EACjB,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,EAAE,EACF,OAAO,EACP,YAAoB,EACpB,KAAK,EACL,aAAa,EACb,YAAgB,EAChB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,kBAAkB,4BAiMpB"}
|
|
@@ -29,6 +29,11 @@ function FieldBySchema(_a) {
|
|
|
29
29
|
var _b, _c;
|
|
30
30
|
var { name, schema, control, errors, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, fieldsLayout, sx, options, isSemaphoric = false, label, onValueChange, decimalScale = 2, autoFocus } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "fieldsLayout", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale", "autoFocus"]);
|
|
31
31
|
const fieldSchema = schema[name];
|
|
32
|
+
// prevent switching from uncontrolled inputs (undefined) to controlled:
|
|
33
|
+
if (getValues && getValues(name) === undefined) {
|
|
34
|
+
// TODO: see how to do this check using control instead of getValues, since it is optional
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
32
37
|
switch (fieldSchema.type) {
|
|
33
38
|
case 'date':
|
|
34
39
|
return (react_1.default.createElement(DesktopDatePickerBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange, autoFocus: autoFocus }, other)));
|
|
@@ -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,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWlD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,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,KAA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AAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAiB,EACjB,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,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,qBAmRF"}
|
|
@@ -55,7 +55,7 @@ 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
|
|
58
|
+
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, fieldsProps, hiddenFields = [], isolatedGetAutoComplete, relatedEditable, autoFocusField, elevation,
|
|
59
59
|
// sx,
|
|
60
60
|
// sxField,
|
|
61
61
|
// sxLabel,
|
|
@@ -66,8 +66,8 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
66
66
|
// sxValueListItemText,
|
|
67
67
|
}) {
|
|
68
68
|
const { getAutoComplete: defaulGetAutoComplete, onEditModel: defaultOnEditModel } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
69
|
-
const getAutoComplete = isolatedGetAutoComplete || defaulGetAutoComplete;
|
|
70
|
-
const onEditModel = relatedEditable === false ? undefined : customOnEditModel || defaultOnEditModel;
|
|
69
|
+
const getAutoComplete = (0, react_1.useMemo)(() => isolatedGetAutoComplete || defaulGetAutoComplete, [defaulGetAutoComplete, isolatedGetAutoComplete]);
|
|
70
|
+
const onEditModel = (0, react_1.useMemo)(() => (relatedEditable === false ? undefined : customOnEditModel || defaultOnEditModel), [customOnEditModel, defaultOnEditModel, relatedEditable]);
|
|
71
71
|
const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)(undefined);
|
|
72
72
|
const defaultSx = { mr: 0 };
|
|
73
73
|
const { fieldsLayout, optionsACModels } = (0, react_1.useMemo)(() => {
|
|
@@ -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;AAQnD,OAAO,EAAQ,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAO3D,QAAA,MAAM,iCAAiC,
|
|
1
|
+
{"version":3,"file":"EditableAutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/EditableAutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAQnD,OAAO,EAAQ,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAO3D,QAAA,MAAM,iCAAiC,gFAoWtC,CAAC;AAGF,eAAe,iCAAiC,CAAC"}
|
|
@@ -113,7 +113,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
113
113
|
error: errors && Boolean(errors[name]),
|
|
114
114
|
helperText: errors && errors[name] ? errors[name].message : fieldSchema.help_text || '',
|
|
115
115
|
};
|
|
116
|
-
if (options
|
|
116
|
+
if (!options) {
|
|
117
117
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
118
118
|
}
|
|
119
119
|
if (!disabled && !fieldSchema.disabled && onEditModel && optionsModel) {
|
|
@@ -221,7 +221,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
221
221
|
];
|
|
222
222
|
}
|
|
223
223
|
return filtered;
|
|
224
|
-
}, handleHomeEndKeys: true, getOptionLabel: getOptionLabel
|
|
224
|
+
}, handleHomeEndKeys: true, getOptionKey: ({ id }) => id, getOptionLabel: getOptionLabel
|
|
225
225
|
? getOptionLabel
|
|
226
226
|
: (option) => {
|
|
227
227
|
// Value selected with enter, right from the input
|
|
@@ -261,7 +261,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, _) =>
|
|
|
261
261
|
if (onValueChange) {
|
|
262
262
|
onValueChange(e);
|
|
263
263
|
}
|
|
264
|
-
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema), margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText }, other))), getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
264
|
+
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: (0, utils_1.isFieldRequired)(fieldSchema), margin: "normal", error: error, autoFocus: autoFocus, helperText: helperText }, other))), getOptionKey: ({ id }) => id, getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
265
265
|
});
|
|
266
266
|
EditableAutocompleteFieldBySchema.displayName = 'EditableAutocompleteFieldBySchema';
|
|
267
267
|
exports.default = EditableAutocompleteFieldBySchema;
|
|
@@ -3,7 +3,7 @@ import { DialogType, SnackBarType } from './APIWrapperContext';
|
|
|
3
3
|
interface APIWrapperProps {
|
|
4
4
|
handleLoading: (x: boolean) => void;
|
|
5
5
|
setSnackBar: (x: Partial<SnackBarType>) => void;
|
|
6
|
-
setDialog:
|
|
6
|
+
setDialog: React.ActionDispatch<[newState: Partial<DialogType> | null]>;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
}
|
|
9
9
|
declare function APIWrapper({ handleLoading, setSnackBar, setDialog, children }: APIWrapperProps): React.JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"APIWrapper.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwE,MAAM,OAAO,CAAC;AA4C7F,OAAO,EAEL,UAAU,EAQV,YAAY,EACb,MAAM,qBAAqB,CAAC;AAG7B,UAAU,eAAe;IACvB,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,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AASD,iBAAS,UAAU,CAAC,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,eAAe,qBA+oBvF;;AAED,wBAAsC"}
|
|
@@ -78,20 +78,114 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
78
78
|
const [optionsAC, setOptionsAC] = (0, react_1.useReducer)((utils_1.reducer), null);
|
|
79
79
|
const [pageForm, setPageForm] = (0, react_1.useReducer)((utils_1.reducer), initialPageForm);
|
|
80
80
|
const editModel = (0, react_1.useRef)({});
|
|
81
|
-
|
|
81
|
+
// BASIC OPERATIONS DEPENDING DIRECTLY ON SERVER_ENDPOINT:
|
|
82
|
+
const localGetRawData = (0, react_1.useCallback)((route) => {
|
|
83
|
+
return (0, api_1.getRawData)({ path: route, serverEndPoint });
|
|
84
|
+
}, [serverEndPoint]);
|
|
85
|
+
const localGetAutoComplete = (0, react_1.useCallback)((model) => {
|
|
86
|
+
return (0, api_1.getAutoComplete)({ model, serverEndPoint });
|
|
87
|
+
}, [serverEndPoint]);
|
|
88
|
+
const localGetGenericModelList = (0, react_1.useCallback)((params) => {
|
|
89
|
+
return (0, api_1.getGenericModelList)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
90
|
+
}, [serverEndPoint]);
|
|
91
|
+
const localGetAllModels = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const response = yield (0, api_1.getAllModels)(serverEndPoint);
|
|
93
|
+
if ('isAxiosError' in response) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
return response;
|
|
97
|
+
}), [serverEndPoint]);
|
|
98
|
+
const localLoginByPayload = (0, react_1.useCallback)((payload) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const response = yield (0, api_1.loginByPayload)(payload, serverEndPoint);
|
|
100
|
+
if (typeof response !== 'boolean') {
|
|
101
|
+
console.log({
|
|
102
|
+
error: response,
|
|
103
|
+
payload,
|
|
104
|
+
});
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return response;
|
|
108
|
+
}), [serverEndPoint]);
|
|
109
|
+
const localSignUp = (0, react_1.useCallback)((data) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const response = yield (0, api_1.signUp)(data, serverEndPoint);
|
|
111
|
+
if ('isAxiosError' in response) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return response;
|
|
115
|
+
}), [serverEndPoint]);
|
|
116
|
+
const localGetSignupOptions = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const response = yield (0, api_1.getSignUpOptions)(serverEndPoint);
|
|
118
|
+
if ('isAxiosError' in response) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return response;
|
|
122
|
+
}), [serverEndPoint]);
|
|
123
|
+
const signOut = (0, react_1.useCallback)(() => {
|
|
124
|
+
(0, api_1.clearJWT)();
|
|
82
125
|
setUsuaria(null);
|
|
83
|
-
|
|
84
|
-
|
|
126
|
+
}, []);
|
|
127
|
+
const localUpdateModel = (0, react_1.useCallback)((params) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const response = yield (0, api_1.updateData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
129
|
+
if ('isAxiosError' in response) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return response;
|
|
133
|
+
}), [serverEndPoint]);
|
|
134
|
+
const postData = (0, react_1.useCallback)((params) => __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const response = yield (0, api_1.createData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
136
|
+
if ('isAxiosError' in response) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return response;
|
|
140
|
+
}), [serverEndPoint]);
|
|
141
|
+
const updateUsuaria = (0, react_1.useCallback)(() => {
|
|
142
|
+
(0, api_1.isLoggedIn)(serverEndPoint).then((newUsuaria) => {
|
|
143
|
+
setUsuaria(newUsuaria || { erro: 'token inválido' });
|
|
85
144
|
});
|
|
86
|
-
};
|
|
87
|
-
|
|
145
|
+
}, [serverEndPoint]);
|
|
146
|
+
// END OF SERVER_ENDPOINT DEPENDENT FUNCTIONS
|
|
147
|
+
const onTriggerSnackBar = (0, react_1.useCallback)(({ msg, severity = 'info' }) => {
|
|
88
148
|
setSnackBar({
|
|
89
149
|
open: true,
|
|
90
150
|
msg,
|
|
91
151
|
severity,
|
|
92
152
|
});
|
|
93
|
-
};
|
|
94
|
-
const
|
|
153
|
+
}, [setSnackBar]);
|
|
154
|
+
const populateInitialValues = (0, react_1.useCallback)((_a) => {
|
|
155
|
+
var { id, extraValidators, fieldsLayout } = _a, object = __rest(_a, ["id", "extraValidators", "fieldsLayout"]);
|
|
156
|
+
const values = (0, utils_1.populateValues)(object);
|
|
157
|
+
const uiFields = fieldsLayout
|
|
158
|
+
? (0, utils_1.getFieldsFromFieldsLayout)(fieldsLayout)
|
|
159
|
+
: object.columns
|
|
160
|
+
? Object.keys(object.columns)
|
|
161
|
+
: undefined;
|
|
162
|
+
const yupSchema = (0, utils_1.buildGenericYupValidationSchema)(Object.assign(Object.assign({}, object), { data: values, extraValidators,
|
|
163
|
+
uiFields }));
|
|
164
|
+
setPageForm({
|
|
165
|
+
id,
|
|
166
|
+
schema: object.schema,
|
|
167
|
+
columns: object.columns,
|
|
168
|
+
initialValues: values,
|
|
169
|
+
validationSchema: yupSchema,
|
|
170
|
+
forceReload: false,
|
|
171
|
+
});
|
|
172
|
+
return values;
|
|
173
|
+
}, []);
|
|
174
|
+
const populateOptionsAC = (0, react_1.useCallback)((optionsACModels) => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const promises = [];
|
|
176
|
+
for (const model of optionsACModels) {
|
|
177
|
+
promises.push(localGetAutoComplete(model));
|
|
178
|
+
}
|
|
179
|
+
const results = yield Promise.all(promises);
|
|
180
|
+
const newOptionsAC = {};
|
|
181
|
+
results.map((result, index) => {
|
|
182
|
+
if (result !== false) {
|
|
183
|
+
newOptionsAC[optionsACModels[index]] = result;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
setOptionsAC(newOptionsAC);
|
|
187
|
+
}), [localGetAutoComplete]);
|
|
188
|
+
const loadSinglePageData = (0, react_1.useCallback)((_a) => __awaiter(this, [_a], void 0, function* ({ model, objId, optionsACModels, defaults = {}, extraValidators, fieldsLayout, }) {
|
|
95
189
|
handleLoading(true);
|
|
96
190
|
if (!objId || objId === 'novo') {
|
|
97
191
|
objId = (0, utils_1.getTmpId)();
|
|
@@ -111,15 +205,15 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
111
205
|
populateOptionsAC(optionsACModels);
|
|
112
206
|
}
|
|
113
207
|
for (const [field, value] of Object.entries(defaults)) {
|
|
114
|
-
if (!object.data[field]) {
|
|
208
|
+
if (!object.data[field] && typeof object.data[field] !== 'boolean') {
|
|
115
209
|
object.data[field] = value;
|
|
116
210
|
}
|
|
117
211
|
}
|
|
118
212
|
const values = populateInitialValues(Object.assign({ id: objId, extraValidators,
|
|
119
213
|
fieldsLayout }, object));
|
|
120
214
|
return values;
|
|
121
|
-
});
|
|
122
|
-
const onSubmit = (model, id, data) => __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
}), [handleLoading, populateInitialValues, populateOptionsAC, serverEndPoint]);
|
|
216
|
+
const onSubmit = (0, react_1.useCallback)((model, id, data) => __awaiter(this, void 0, void 0, function* () {
|
|
123
217
|
if (!pageForm || !pageForm.schema) {
|
|
124
218
|
console.log('there must be a pageForm!');
|
|
125
219
|
return false;
|
|
@@ -152,42 +246,8 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
152
246
|
msg: id ? 'Dados atualizados com sucesso!' : 'Criado com sucesso!',
|
|
153
247
|
});
|
|
154
248
|
return response.id;
|
|
155
|
-
});
|
|
156
|
-
const
|
|
157
|
-
const promises = [];
|
|
158
|
-
for (const model of optionsACModels) {
|
|
159
|
-
promises.push(localGetAutoComplete(model));
|
|
160
|
-
}
|
|
161
|
-
const results = yield Promise.all(promises);
|
|
162
|
-
const newOptionsAC = {};
|
|
163
|
-
results.map((result, index) => {
|
|
164
|
-
if (result !== false) {
|
|
165
|
-
newOptionsAC[optionsACModels[index]] = result;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
setOptionsAC(newOptionsAC);
|
|
169
|
-
});
|
|
170
|
-
const populateInitialValues = (_a) => {
|
|
171
|
-
var { id, extraValidators, fieldsLayout } = _a, object = __rest(_a, ["id", "extraValidators", "fieldsLayout"]);
|
|
172
|
-
const values = (0, utils_1.populateValues)(object);
|
|
173
|
-
const uiFields = fieldsLayout
|
|
174
|
-
? (0, utils_1.getFieldsFromFieldsLayout)(fieldsLayout)
|
|
175
|
-
: object.columns
|
|
176
|
-
? Object.keys(object.columns)
|
|
177
|
-
: undefined;
|
|
178
|
-
const yupSchema = (0, utils_1.buildGenericYupValidationSchema)(Object.assign(Object.assign({}, object), { data: values, extraValidators,
|
|
179
|
-
uiFields }));
|
|
180
|
-
setPageForm({
|
|
181
|
-
id,
|
|
182
|
-
schema: object.schema,
|
|
183
|
-
columns: object.columns,
|
|
184
|
-
initialValues: values,
|
|
185
|
-
validationSchema: yupSchema,
|
|
186
|
-
forceReload: false,
|
|
187
|
-
});
|
|
188
|
-
return values;
|
|
189
|
-
};
|
|
190
|
-
const onEditModelSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
}), [handleLoading, onTriggerSnackBar, optionsAC, pageForm, populateOptionsAC, serverEndPoint]);
|
|
250
|
+
const onEditModelSave = (0, react_1.useCallback)((data) => __awaiter(this, void 0, void 0, function* () {
|
|
191
251
|
setDialog({ open: false });
|
|
192
252
|
handleLoading(true);
|
|
193
253
|
const { fieldKey, index, model, id, setValue, getValues, schema } = editModel.current;
|
|
@@ -227,8 +287,8 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
227
287
|
}
|
|
228
288
|
handleLoading(false);
|
|
229
289
|
return true;
|
|
230
|
-
});
|
|
231
|
-
const onEditModelDataGridSave = (_a) => __awaiter(this, [_a], void 0, function* ({ model, newRow, schema
|
|
290
|
+
}), [handleLoading, onTriggerSnackBar, populateOptionsAC, serverEndPoint, setDialog]);
|
|
291
|
+
const onEditModelDataGridSave = (0, react_1.useCallback)((_a) => __awaiter(this, [_a], void 0, function* ({ model, newRow, schema }) {
|
|
232
292
|
const response = yield (0, api_1.updateDataBySchema)({
|
|
233
293
|
model,
|
|
234
294
|
modelObjectId: newRow.id,
|
|
@@ -254,8 +314,8 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
254
314
|
severity: 'info',
|
|
255
315
|
});
|
|
256
316
|
return response;
|
|
257
|
-
});
|
|
258
|
-
const onEditModel = ({ fieldKey, index, model, id, labelKey, setValue, getValues, fieldsLayout, initialValuesPartial, }) => {
|
|
317
|
+
}), [onTriggerSnackBar, serverEndPoint]);
|
|
318
|
+
const onEditModel = (0, react_1.useCallback)(({ fieldKey, index, model, id, labelKey, setValue, getValues, fieldsLayout, initialValuesPartial, }) => {
|
|
259
319
|
setDialog({
|
|
260
320
|
open: true,
|
|
261
321
|
loading: true,
|
|
@@ -302,19 +362,8 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
302
362
|
schema: result.schema,
|
|
303
363
|
};
|
|
304
364
|
});
|
|
305
|
-
};
|
|
306
|
-
const
|
|
307
|
-
setDialog({
|
|
308
|
-
open: true,
|
|
309
|
-
loading: false,
|
|
310
|
-
title: 'Apagar',
|
|
311
|
-
Body: 'Tem certeza de que deseja apagar este item?',
|
|
312
|
-
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, handleSave: (event) => {
|
|
313
|
-
return onDeleteModelSave(model, id, onSuccess, event);
|
|
314
|
-
}, btnConfirm: "Sim, apagar" })),
|
|
315
|
-
});
|
|
316
|
-
};
|
|
317
|
-
const onDeleteModelSave = (model, id, onSuccess, event) => __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
}, [localGetAutoComplete, onEditModelSave, optionsAC, serverEndPoint, setDialog]);
|
|
366
|
+
const onDeleteModelSave = (0, react_1.useCallback)((model, id, onSuccess, event) => __awaiter(this, void 0, void 0, function* () {
|
|
318
367
|
setDialog({ open: false });
|
|
319
368
|
handleLoading(true);
|
|
320
369
|
const ret = yield (0, api_1.deleteData)(model, serverEndPoint, id);
|
|
@@ -334,8 +383,19 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
334
383
|
severity: 'error',
|
|
335
384
|
});
|
|
336
385
|
return false;
|
|
337
|
-
});
|
|
338
|
-
const
|
|
386
|
+
}), [handleLoading, onTriggerSnackBar, serverEndPoint, setDialog]);
|
|
387
|
+
const onDeleteModel = (0, react_1.useCallback)((model, id, onSuccess) => {
|
|
388
|
+
setDialog({
|
|
389
|
+
open: true,
|
|
390
|
+
loading: false,
|
|
391
|
+
title: 'Apagar',
|
|
392
|
+
Body: 'Tem certeza de que deseja apagar este item?',
|
|
393
|
+
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, handleSave: (event) => {
|
|
394
|
+
return onDeleteModelSave(model, id, onSuccess, event);
|
|
395
|
+
}, btnConfirm: "Sim, apagar" })),
|
|
396
|
+
});
|
|
397
|
+
}, [onDeleteModelSave, setDialog]);
|
|
398
|
+
const onEditRelatedModelSave = (0, react_1.useCallback)((_a) => __awaiter(this, [_a], void 0, function* ({ model, id, relatedModel, newRow, schema, onlyAddExisting, }) {
|
|
339
399
|
const updateUrl = `${model}/${id}/${relatedModel}`;
|
|
340
400
|
if (onlyAddExisting) {
|
|
341
401
|
const response = yield (0, api_1.addExistingRelatedModel)({
|
|
@@ -398,8 +458,8 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
398
458
|
severity: 'info',
|
|
399
459
|
});
|
|
400
460
|
return response;
|
|
401
|
-
});
|
|
402
|
-
const onDeleteRelatedModel = (_a) => __awaiter(this, [_a], void 0, function* ({ model, id, relatedModel, relatedModelId
|
|
461
|
+
}), [onTriggerSnackBar, serverEndPoint]);
|
|
462
|
+
const onDeleteRelatedModel = (0, react_1.useCallback)((_a) => __awaiter(this, [_a], void 0, function* ({ model, id, relatedModel, relatedModelId }) {
|
|
403
463
|
const deleteUrl = `${model}/${id}/${relatedModel}`;
|
|
404
464
|
const response = yield (0, api_1.deleteData)(deleteUrl, serverEndPoint, relatedModelId);
|
|
405
465
|
if (response !== true) {
|
|
@@ -418,90 +478,14 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
418
478
|
severity: 'info',
|
|
419
479
|
});
|
|
420
480
|
return response;
|
|
421
|
-
});
|
|
481
|
+
}), [onTriggerSnackBar, serverEndPoint]);
|
|
422
482
|
(0, react_1.useEffect)(() => {
|
|
423
483
|
updateUsuaria();
|
|
424
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
425
|
-
}, []);
|
|
426
|
-
(0, react_1.useEffect)(() => {
|
|
427
484
|
setPageForm(initialPageForm);
|
|
485
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
428
486
|
}, []);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
432
|
-
}
|
|
433
|
-
function localGetRawData(route) {
|
|
434
|
-
return (0, api_1.getRawData)({ path: route, serverEndPoint });
|
|
435
|
-
}
|
|
436
|
-
function localGetAutoComplete(model) {
|
|
437
|
-
return (0, api_1.getAutoComplete)({ model, serverEndPoint });
|
|
438
|
-
}
|
|
439
|
-
function localGetGenericModelList(params) {
|
|
440
|
-
return (0, api_1.getGenericModelList)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
441
|
-
}
|
|
442
|
-
function localGetAllModels() {
|
|
443
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
-
const response = yield (0, api_1.getAllModels)(serverEndPoint);
|
|
445
|
-
if ('isAxiosError' in response) {
|
|
446
|
-
return [];
|
|
447
|
-
}
|
|
448
|
-
return response;
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
function localLoginByPayload(payload) {
|
|
452
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
-
const response = yield (0, api_1.loginByPayload)(payload, serverEndPoint);
|
|
454
|
-
if (typeof response !== 'boolean') {
|
|
455
|
-
console.log({
|
|
456
|
-
error: response,
|
|
457
|
-
payload,
|
|
458
|
-
});
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
return response;
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
function localSignUp(data) {
|
|
465
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
466
|
-
const response = yield (0, api_1.signUp)(data, serverEndPoint);
|
|
467
|
-
if ('isAxiosError' in response) {
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
return response;
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
function localGetSignupOptions() {
|
|
474
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
475
|
-
const response = yield (0, api_1.getSignUpOptions)(serverEndPoint);
|
|
476
|
-
if ('isAxiosError' in response) {
|
|
477
|
-
return false;
|
|
478
|
-
}
|
|
479
|
-
return response;
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
function signOut() {
|
|
483
|
-
(0, api_1.clearJWT)();
|
|
484
|
-
setUsuaria(null);
|
|
485
|
-
}
|
|
486
|
-
function localUpdateModel(params) {
|
|
487
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
488
|
-
const response = yield (0, api_1.updateData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
489
|
-
if ('isAxiosError' in response) {
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
return response;
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
function postData(params) {
|
|
496
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
497
|
-
const response = yield (0, api_1.createData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
498
|
-
if ('isAxiosError' in response) {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
return response;
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
|
|
487
|
+
const contextValue = (0, react_1.useMemo)(() => {
|
|
488
|
+
return {
|
|
505
489
|
usuaria,
|
|
506
490
|
updateUsuaria,
|
|
507
491
|
onSubmit,
|
|
@@ -532,11 +516,45 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
532
516
|
signOut,
|
|
533
517
|
postData: postData,
|
|
534
518
|
// Remove after integrating new "onEditModel" to package:
|
|
535
|
-
serverEndPoint,
|
|
519
|
+
// serverEndPoint,
|
|
536
520
|
editModel,
|
|
537
521
|
updateModel: localUpdateModel,
|
|
538
522
|
populateOptionsAC,
|
|
539
523
|
isMobile,
|
|
540
|
-
}
|
|
524
|
+
};
|
|
525
|
+
}, [
|
|
526
|
+
handleLoading,
|
|
527
|
+
isMobile,
|
|
528
|
+
loadSinglePageData,
|
|
529
|
+
localGetAllModels,
|
|
530
|
+
localGetAutoComplete,
|
|
531
|
+
localGetGenericModelList,
|
|
532
|
+
localGetRawData,
|
|
533
|
+
localGetSignupOptions,
|
|
534
|
+
localLoginByPayload,
|
|
535
|
+
localSignUp,
|
|
536
|
+
localUpdateModel,
|
|
537
|
+
onDeleteModel,
|
|
538
|
+
onDeleteRelatedModel,
|
|
539
|
+
onEditModel,
|
|
540
|
+
onEditModelDataGridSave,
|
|
541
|
+
onEditModelSave,
|
|
542
|
+
onEditRelatedModelSave,
|
|
543
|
+
onSubmit,
|
|
544
|
+
onTriggerSnackBar,
|
|
545
|
+
optionsAC,
|
|
546
|
+
pageForm,
|
|
547
|
+
populateOptionsAC,
|
|
548
|
+
postData,
|
|
549
|
+
setDialog,
|
|
550
|
+
signOut,
|
|
551
|
+
updateUsuaria,
|
|
552
|
+
usuaria,
|
|
553
|
+
]);
|
|
554
|
+
if (!serverEndPoint) {
|
|
555
|
+
console.error('There must be a serverEndPoint properly configured for apiWrapper to work!');
|
|
556
|
+
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
557
|
+
}
|
|
558
|
+
return react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: contextValue }, children);
|
|
541
559
|
}
|
|
542
560
|
exports.default = react_1.default.memo(APIWrapper);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ActionDispatch } from 'react';
|
|
2
2
|
import { FieldValues, SubmitHandler, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
3
3
|
import { AlertColor, AlertPropsColorOverrides } from '@mui/material/Alert';
|
|
4
4
|
import { OverridableStringUnion } from '@mui/types';
|
|
5
5
|
import { ObjectSchema } from 'yup';
|
|
6
6
|
import { ItemSchemaColumnsType, Id, Item, SchemaType, DataSchemaColumnsType, OnSuccessEvent, OptionsAC, GenericValue, FormFieldLayout, TargetApiParamsLocal, TargetApiPostParamsLocal, GetGenericModelListPropsLocal, GridEnrichedBySchemaColDef, ExtraValidators } from '../@types';
|
|
7
|
-
import { ServerEndPoint } from './DRFReactBySchemaContext';
|
|
8
7
|
export interface LoadSinglePageDataProps {
|
|
9
8
|
model: string;
|
|
10
9
|
objId?: Id;
|
|
@@ -76,10 +75,10 @@ export interface APIWrapperContextType {
|
|
|
76
75
|
onSubmit: DRFReactBySchemaSubmitHandler;
|
|
77
76
|
loadSinglePageData: (p: LoadSinglePageDataProps) => Promise<false | Item>;
|
|
78
77
|
handleLoading: (p: boolean) => void;
|
|
79
|
-
optionsACState:
|
|
78
|
+
optionsACState: (OptionsAC | ActionDispatch<[newState: Partial<OptionsAC> | null]> | null)[];
|
|
80
79
|
optionsAC: OptionsAC | null;
|
|
81
80
|
setOptionsAC: (x: Partial<OptionsAC>) => void;
|
|
82
|
-
pageFormState:
|
|
81
|
+
pageFormState: (PageFormType | ActionDispatch<[newState: Partial<PageFormType> | null]> | null)[];
|
|
83
82
|
pageForm: PageFormType | null;
|
|
84
83
|
setPageForm: (x: Partial<PageFormType>) => void;
|
|
85
84
|
onEditModel: (p: OnEditModelType) => void;
|
|
@@ -89,7 +88,7 @@ export interface APIWrapperContextType {
|
|
|
89
88
|
onEditRelatedModelSave: (p: OnEditRelatedModelType) => Promise<false | Item | ItemSchemaColumnsType>;
|
|
90
89
|
onDeleteRelatedModel: (p: OnDeleteRelatedModelType) => Promise<boolean>;
|
|
91
90
|
onTriggerSnackBar: (p: SnackBarType) => void;
|
|
92
|
-
setDialog:
|
|
91
|
+
setDialog: React.ActionDispatch<[newState: Partial<DialogType> | null]>;
|
|
93
92
|
getRawData: (route: string) => Promise<GenericValue>;
|
|
94
93
|
getAutoComplete: (model: string) => Promise<false | Item[]>;
|
|
95
94
|
getGenericModelList: (x: GetGenericModelListPropsLocal) => Promise<false | DataSchemaColumnsType>;
|
|
@@ -99,8 +98,7 @@ export interface APIWrapperContextType {
|
|
|
99
98
|
signUp: (data: Item) => Promise<false | Item>;
|
|
100
99
|
signOut: () => void;
|
|
101
100
|
postData: (params: TargetApiPostParamsLocal) => Promise<false | Item>;
|
|
102
|
-
|
|
103
|
-
editModel: React.MutableRefObject<Item>;
|
|
101
|
+
editModel: React.RefObject<Item>;
|
|
104
102
|
updateModel: (p: TargetApiParamsLocal) => Promise<false | Item>;
|
|
105
103
|
populateOptionsAC: (optionsACModels: string[]) => void;
|
|
106
104
|
isMobile: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIWrapperContext.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapperContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"APIWrapperContext.d.ts","sourceRoot":"","sources":["../../src/context/APIWrapperContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,wB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SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAChE,iBAAiB,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACvD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,iBAAiB,sCAoC5B,CAAC;AAEH,eAAO,MAAM,aAAa,6BAGzB,CAAC"}
|
|
@@ -45,7 +45,7 @@ exports.APIWrapperContext = react_1.default.createContext({
|
|
|
45
45
|
signOut: () => undefined,
|
|
46
46
|
postData: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
47
47
|
// Remove after integrating new "onEditModel" to package:
|
|
48
|
-
serverEndPoint: { url: '', apiTokenUrl: '' },
|
|
48
|
+
// serverEndPoint: { url: '', apiTokenUrl: '' },
|
|
49
49
|
editModel: { current: {} },
|
|
50
50
|
updateModel: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
51
51
|
populateOptionsAC: () => undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DRFReactBySchemaProvider.d.ts","sourceRoot":"","sources":["../../src/context/DRFReactBySchemaProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"DRFReactBySchemaProvider.d.ts","sourceRoot":"","sources":["../../src/context/DRFReactBySchemaProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EACL,2BAA2B,EAG5B,MAAM,2BAA2B,CAAC;AAEnC,UAAU,6BAA8B,SAAQ,2BAA2B;IACzE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;GAKG;AACH,QAAA,MAAM,wBAAwB,GAAI,qEAM/B,6BAA6B,sBAyD/B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
|
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 =
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
7
40
|
const styles_1 = require("@mui/material/styles");
|
|
8
41
|
const CssBaseline_1 = __importDefault(require("@mui/material/CssBaseline"));
|
|
9
42
|
const theme_1 = __importDefault(require("../styles/theme"));
|
|
@@ -16,7 +49,11 @@ const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
|
|
|
16
49
|
* @returns {*}
|
|
17
50
|
*/
|
|
18
51
|
const DRFReactBySchemaProvider = ({ serverEndPoint, theme, isInBatches, firstBatchLength, children, }) => {
|
|
19
|
-
|
|
52
|
+
const newServerEndPoint = (0, react_1.useMemo)(() => {
|
|
53
|
+
if (!serverEndPoint) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const newServerEndPoint = Object.assign({}, serverEndPoint);
|
|
20
57
|
const defaultKeys = [
|
|
21
58
|
'autocomplete',
|
|
22
59
|
'api',
|
|
@@ -27,28 +64,32 @@ const DRFReactBySchemaProvider = ({ serverEndPoint, theme, isInBatches, firstBat
|
|
|
27
64
|
];
|
|
28
65
|
for (const key of defaultKeys) {
|
|
29
66
|
if (key === 'getToken') {
|
|
30
|
-
|
|
67
|
+
newServerEndPoint[key] = newServerEndPoint.apiTokenUrl;
|
|
31
68
|
continue;
|
|
32
69
|
}
|
|
33
70
|
const hybridKey = typeof key === 'string' ? key : key[0];
|
|
34
71
|
const hybridUrl = typeof key === 'string' ? key : key[1];
|
|
35
|
-
if (
|
|
72
|
+
if (newServerEndPoint[hybridKey]) {
|
|
36
73
|
continue;
|
|
37
74
|
}
|
|
38
|
-
|
|
39
|
-
? `${
|
|
40
|
-
: `${
|
|
75
|
+
newServerEndPoint[hybridKey] = ['refreshToken', 'verifyToken'].includes(hybridKey)
|
|
76
|
+
? `${newServerEndPoint.apiTokenUrl}${hybridUrl}/`
|
|
77
|
+
: `${newServerEndPoint.url}/${hybridUrl}`;
|
|
41
78
|
}
|
|
42
|
-
|
|
43
|
-
|
|
79
|
+
return newServerEndPoint;
|
|
80
|
+
}, [serverEndPoint]);
|
|
81
|
+
const mergedTheme = (0, react_1.useMemo)(() => {
|
|
82
|
+
return theme ? Object.assign(Object.assign({}, theme_1.default), theme) : theme_1.default;
|
|
83
|
+
}, [theme]);
|
|
84
|
+
const contextValue = (0, react_1.useMemo)(() => ({
|
|
85
|
+
serverEndPoint: newServerEndPoint,
|
|
86
|
+
theme: mergedTheme,
|
|
87
|
+
isInBatches,
|
|
88
|
+
firstBatchLength,
|
|
89
|
+
}), [firstBatchLength, isInBatches, mergedTheme, newServerEndPoint]);
|
|
44
90
|
return (react_1.default.createElement(styles_1.ThemeProvider, { theme: mergedTheme },
|
|
45
91
|
react_1.default.createElement(CssBaseline_1.default, null),
|
|
46
|
-
react_1.default.createElement(DRFReactBySchemaContext_1.DRFReactBySchemaContext.Provider, { value:
|
|
47
|
-
serverEndPoint,
|
|
48
|
-
theme: mergedTheme,
|
|
49
|
-
isInBatches,
|
|
50
|
-
firstBatchLength,
|
|
51
|
-
} },
|
|
92
|
+
react_1.default.createElement(DRFReactBySchemaContext_1.DRFReactBySchemaContext.Provider, { value: contextValue },
|
|
52
93
|
react_1.default.createElement(Overlays_1.default, null, children))));
|
|
53
94
|
};
|
|
54
95
|
exports.default = DRFReactBySchemaProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Overlays.d.ts","sourceRoot":"","sources":["../../src/context/Overlays.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Overlays.d.ts","sourceRoot":"","sources":["../../src/context/Overlays.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4C,MAAM,OAAO,CAAC;AAejE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,qBA6E3E"}
|
package/dist/context/Overlays.js
CHANGED
|
@@ -66,7 +66,7 @@ function Overlays({ children }) {
|
|
|
66
66
|
const [dialog, setDialog] = (0, react_1.useReducer)((utils_1.reducer), initialDialog);
|
|
67
67
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
68
68
|
// give some time to stop loading when data is retrieved and must render before loading rendering:
|
|
69
|
-
const handleLoading = (loadingState) => {
|
|
69
|
+
const handleLoading = (0, react_1.useCallback)((loadingState) => {
|
|
70
70
|
if (loadingState) {
|
|
71
71
|
setLoading(true);
|
|
72
72
|
return;
|
|
@@ -74,12 +74,12 @@ function Overlays({ children }) {
|
|
|
74
74
|
setTimeout(() => {
|
|
75
75
|
setLoading(false);
|
|
76
76
|
}, 300);
|
|
77
|
-
};
|
|
78
|
-
const handleDialogClose = () => {
|
|
77
|
+
}, []);
|
|
78
|
+
const handleDialogClose = (0, react_1.useCallback)(() => {
|
|
79
79
|
setDialog({
|
|
80
80
|
open: false,
|
|
81
81
|
});
|
|
82
|
-
};
|
|
82
|
+
}, []);
|
|
83
83
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
84
84
|
react_1.default.createElement(APIWrapper_1.default, { handleLoading: handleLoading, setSnackBar: setSnackBar, setDialog: setDialog }, children),
|
|
85
85
|
react_1.default.createElement(Backdrop_1.default, { invisible: false, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWhyDidYouUpdate.d.ts","sourceRoot":"","sources":["../../src/hooks/useWhyDidYouUpdate.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,iBAAS,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,QAwB5E;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -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.js
CHANGED
|
@@ -102,7 +102,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
102
102
|
if (key === 'id' && (0, exports.isTmpId)(data[key])) {
|
|
103
103
|
continue;
|
|
104
104
|
}
|
|
105
|
-
if (!data[key]) {
|
|
105
|
+
if (!data[key] && data[key] !== false && data[key] !== 0) {
|
|
106
106
|
values[key] = (0, exports.emptyByType)(field);
|
|
107
107
|
continue;
|
|
108
108
|
}
|
package/package.json
CHANGED