drf-react-by-schema 0.12.5 → 0.13.0
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 +8 -7
- package/dist/components/DataGridBySchemaEditable.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable.js +2 -2
- package/dist/components/GenericModelList.js +11 -7
- package/dist/components/GenericRelatedModelList.js +13 -6
- package/dist/components/forms/FormBySchema.js +7 -5
- package/dist/context/APIWrapper.d.ts +1 -2
- package/dist/context/APIWrapper.js +7 -7
- package/dist/context/Overlays.js +3 -3
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -567,6 +567,7 @@ const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
|
|
|
567
567
|
});
|
|
568
568
|
exports.signUp = signUp;
|
|
569
569
|
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], disabledFields = [], isInBatches = false, loadedSchema, loadedModelOptions, page, filter, queryParams = [], sort, sumRows, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
570
|
+
const newQueryParams = [...queryParams];
|
|
570
571
|
let path = `${model}/${id}`;
|
|
571
572
|
let schemaPath = `${model}/`;
|
|
572
573
|
let schema = loadedSchema;
|
|
@@ -582,14 +583,14 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
582
583
|
// SERVER-SIDE TOTALS (sumRows):
|
|
583
584
|
if (sumRows) {
|
|
584
585
|
const sumRowsParams = sumRows.rows.map((row) => row.field).join(',');
|
|
585
|
-
|
|
586
|
+
newQueryParams.push(`sum_rows=${sumRowsParams}`);
|
|
586
587
|
}
|
|
587
588
|
// SERVER-SIDE FILTERING:
|
|
588
589
|
if (filter) {
|
|
589
590
|
if (filter.quickFilterValues &&
|
|
590
591
|
filter.quickFilterValues.length > 0 &&
|
|
591
592
|
filter.quickFilterValues[0]) {
|
|
592
|
-
|
|
593
|
+
newQueryParams.push(`search=${filter.quickFilterValues[0]}`);
|
|
593
594
|
}
|
|
594
595
|
for (const item of filter.items) {
|
|
595
596
|
if (!item.operatorValue) {
|
|
@@ -598,7 +599,7 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
598
599
|
const queryParam = item.value
|
|
599
600
|
? `columnField=${item.columnField}&operatorValue=${item.operatorValue}&value=${item.value}`
|
|
600
601
|
: `columnField=${item.columnField}&operatorValue=${item.operatorValue}`;
|
|
601
|
-
|
|
602
|
+
newQueryParams.push(queryParam);
|
|
602
603
|
}
|
|
603
604
|
}
|
|
604
605
|
// SERVER-SIDE SORTING:
|
|
@@ -607,14 +608,14 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
607
608
|
for (const item of sort) {
|
|
608
609
|
sortParams.push(item.sort === 'desc' ? `-${item.field}` : item.field);
|
|
609
610
|
}
|
|
610
|
-
|
|
611
|
+
newQueryParams.push(`ordering=${sortParams.join(',')}`);
|
|
611
612
|
}
|
|
612
613
|
// SERVER-SIDE PAGINATION:
|
|
613
614
|
if (page) {
|
|
614
|
-
|
|
615
|
+
newQueryParams.push(`page=${page + 1}`);
|
|
615
616
|
}
|
|
616
|
-
if (
|
|
617
|
-
path += `?${
|
|
617
|
+
if (newQueryParams.length > 0) {
|
|
618
|
+
path += `?${newQueryParams.join('&')}`;
|
|
618
619
|
}
|
|
619
620
|
// Only get schema and columns if not in batches or in first batch:
|
|
620
621
|
if (!schema) {
|
|
@@ -19,6 +19,7 @@ interface DataGridBySchemaEditableProps {
|
|
|
19
19
|
indexFieldViewBasePath?: string;
|
|
20
20
|
stateToLink?: object;
|
|
21
21
|
minWidth?: number;
|
|
22
|
+
loading?: boolean;
|
|
22
23
|
modelParentId?: Id;
|
|
23
24
|
modelParent?: string;
|
|
24
25
|
customColumnOperations?: (p: any) => GridEnrichedBySchemaColDef;
|
|
@@ -75,7 +75,7 @@ const ConfirmDialog_1 = require("./DataGridBySchemaEditable/ConfirmDialog");
|
|
|
75
75
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
76
76
|
const stringMask = require('string-mask');
|
|
77
77
|
const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
78
|
-
var { schema, data, rowCount = 0, columns, model, fieldKey, labelKey = 'nome', index, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', indexFieldViewBasePath, stateToLink = {}, minWidth = 80, modelParent, modelParentId, customColumnOperations, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], optionsAC: optionsACExternal } = _a, other = __rest(_a, ["schema", "data", "rowCount", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "indexFieldViewBasePath", "stateToLink", "minWidth", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "onEditModel", "isEditable", "hasBulkSelect", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows", "paginationModel", "setPaginationModel", "hideFooterComponent", "hideToolbarComponent", "tableAutoHeight", "actions", "optionsAC"]);
|
|
78
|
+
var { schema, data, rowCount = 0, columns, model, fieldKey, labelKey = 'nome', index, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', indexFieldViewBasePath, stateToLink = {}, minWidth = 80, loading, modelParent, modelParentId, customColumnOperations, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], optionsAC: optionsACExternal } = _a, other = __rest(_a, ["schema", "data", "rowCount", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "indexFieldViewBasePath", "stateToLink", "minWidth", "loading", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "onEditModel", "isEditable", "hasBulkSelect", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows", "paginationModel", "setPaginationModel", "hideFooterComponent", "hideToolbarComponent", "tableAutoHeight", "actions", "optionsAC"]);
|
|
79
79
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
80
80
|
const apiContext = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
81
81
|
const initialSnackBar = {
|
|
@@ -600,7 +600,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
600
600
|
visibleRows.current = newVisibleRowsJSON;
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
|
-
}, editMode: "row", loading: dataGridLoading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
|
|
603
|
+
}, editMode: "row", loading: dataGridLoading || loading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
|
|
604
604
|
if (isAutoHeight) {
|
|
605
605
|
return 'auto';
|
|
606
606
|
}
|
|
@@ -40,6 +40,8 @@ const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
|
40
40
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
41
41
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
42
42
|
const AddCircleOutline_1 = __importDefault(require("@mui/icons-material/AddCircleOutline"));
|
|
43
|
+
const Backdrop_1 = __importDefault(require("@mui/material/Backdrop"));
|
|
44
|
+
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
43
45
|
const DataGridBySchemaEditable_1 = __importDefault(require("./DataGridBySchemaEditable"));
|
|
44
46
|
const DataTotals_1 = __importDefault(require("./DataTotals"));
|
|
45
47
|
const DataTotalsServer_1 = __importDefault(require("./DataTotalsServer"));
|
|
@@ -50,8 +52,9 @@ const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
|
50
52
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
51
53
|
const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect = false, sumRows, isAutoHeight = true, forceReload = false, LinkComponent = null, hasHeader = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, disableScreenLoading, }) => {
|
|
52
54
|
const { serverEndPoint, isInBatches, firstBatchLength } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
53
|
-
const { onEditModel
|
|
55
|
+
const { onEditModel } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
54
56
|
const [data, setData] = (0, react_1.useState)(false);
|
|
57
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
55
58
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
56
59
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
57
60
|
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
@@ -68,7 +71,7 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
68
71
|
};
|
|
69
72
|
const loadObjectList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
73
|
if (!disableScreenLoading) {
|
|
71
|
-
|
|
74
|
+
setLoading(true);
|
|
72
75
|
}
|
|
73
76
|
switch (paginationMode) {
|
|
74
77
|
case 'client':
|
|
@@ -85,7 +88,7 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
85
88
|
const loadedData = yield (0, api_1.getGenericModelList)(loadParams);
|
|
86
89
|
if (loadedData && typeof loadedData !== 'boolean') {
|
|
87
90
|
setData(loadedData);
|
|
88
|
-
|
|
91
|
+
setLoading(false);
|
|
89
92
|
if (isInBatches && loadedData.data.length === firstBatchLength) {
|
|
90
93
|
setHideFooterPagination(true);
|
|
91
94
|
(0, api_1.getGenericModelList)(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema, loadedModelOptions: loadedData.modelOptions })).then((lastBatchData) => {
|
|
@@ -119,7 +122,7 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
119
122
|
const paginatedData = yield (0, api_1.getGenericModelList)(loadPaginatedParams);
|
|
120
123
|
if (paginatedData && typeof paginatedData !== 'boolean') {
|
|
121
124
|
setData(paginatedData);
|
|
122
|
-
|
|
125
|
+
setLoading(false);
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
console.log('error retrieving data!');
|
|
@@ -141,20 +144,21 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
141
144
|
console.error('Error: There is no endpoint defined in DRFReactBySchemaProvider!');
|
|
142
145
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
143
146
|
}
|
|
144
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, typeof data !== 'boolean' && data.columns
|
|
147
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, typeof data !== 'boolean' && data.columns ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
145
148
|
hasHeader && (react_1.default.createElement(Box_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.flexRowGrow), { mb: 2 }) },
|
|
146
149
|
react_1.default.createElement(Typography_1.default, { variant: "h5" }, data.modelOptions.verbose_name_plural || data.modelOptions.name),
|
|
147
150
|
LinkComponent && (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
148
151
|
react_1.default.createElement(LinkComponent, { to: `novo` },
|
|
149
152
|
react_1.default.createElement(Button_1.default, { variant: "contained", size: "medium", sx: { alignSelf: 'stretch' }, startIcon: react_1.default.createElement(AddCircleOutline_1.default, null) }, "Adicionar")))))),
|
|
150
153
|
react_1.default.createElement(Box_1.default, { sx: tableAutoHeight ? {} : styles_1.Layout.dataGridWithTabs },
|
|
151
|
-
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, customLinkDestination: customLinkDestination, actions: actions, optionsAC: optionsAC, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
154
|
+
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, customLinkDestination: customLinkDestination, actions: actions, optionsAC: optionsAC, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
152
155
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
153
156
|
}, LinkComponent: LinkComponent, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
154
157
|
? undefined
|
|
155
158
|
: typeof data.rowCount !== undefined
|
|
156
159
|
? data.rowCount
|
|
157
160
|
: 0 })),
|
|
158
|
-
paginationMode === 'client' ? (react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })) : (react_1.default.createElement(DataTotalsServer_1.default, { sumRows: sumRows, totals: data.sumRowsTotals })))))
|
|
161
|
+
paginationMode === 'client' ? (react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })) : (react_1.default.createElement(DataTotalsServer_1.default, { sumRows: sumRows, totals: data.sumRowsTotals })))) : (react_1.default.createElement(Backdrop_1.default, { invisible: true, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
162
|
+
react_1.default.createElement(CircularProgress_1.default, null)))));
|
|
159
163
|
};
|
|
160
164
|
exports.default = GenericModelList;
|
|
@@ -40,6 +40,8 @@ const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
|
40
40
|
const Card_1 = __importDefault(require("@mui/material/Card"));
|
|
41
41
|
const CardHeader_1 = __importDefault(require("@mui/material/CardHeader"));
|
|
42
42
|
const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
|
|
43
|
+
const Backdrop_1 = __importDefault(require("@mui/material/Backdrop"));
|
|
44
|
+
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
43
45
|
const DataGridBySchemaEditable_1 = __importDefault(require("./DataGridBySchemaEditable"));
|
|
44
46
|
const DataTotals_1 = __importDefault(require("./DataTotals"));
|
|
45
47
|
const DataTotalsServer_1 = __importDefault(require("./DataTotalsServer"));
|
|
@@ -47,19 +49,21 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
47
49
|
const utils_1 = require("../utils");
|
|
48
50
|
const api_1 = require("../api");
|
|
49
51
|
const styles_1 = require("../styles");
|
|
50
|
-
const ContentTable = ({ data, relatedModel, model, id, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, hideFooterComponent, hideToolbarComponent, onProcessRow, setData, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, hasBulkSelect, tableAutoHeight, actions, optionsAC, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
51
|
-
data.columns
|
|
52
|
-
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema, model: relatedModel, modelParent: model, modelParentId: id, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, actions: actions, optionsAC: optionsAC, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
52
|
+
const ContentTable = ({ data, relatedModel, model, loading, id, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, hideFooterComponent, hideToolbarComponent, onProcessRow, setData, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, hasBulkSelect, tableAutoHeight, actions, optionsAC, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
53
|
+
data.columns ? (react_1.default.createElement(Box_1.default, { sx: tableAutoHeight ? {} : styles_1.Layout.dataGridFixedHeight },
|
|
54
|
+
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema, model: relatedModel, modelParent: model, modelParentId: id, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, actions: actions, optionsAC: optionsAC, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
53
55
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
54
56
|
}, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
55
57
|
? undefined
|
|
56
58
|
: typeof data.rowCount !== undefined
|
|
57
59
|
? data.rowCount
|
|
58
|
-
: 0 }))),
|
|
60
|
+
: 0 }))) : (react_1.default.createElement(Backdrop_1.default, { invisible: true, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
61
|
+
react_1.default.createElement(CircularProgress_1.default, null))),
|
|
59
62
|
paginationMode === 'client' ? (react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })) : (react_1.default.createElement(DataTotalsServer_1.default, { sumRows: sumRows, totals: data.sumRowsTotals }))));
|
|
60
63
|
function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria = null, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable = true, hasBulkSelect = false, sumRows, isAutoHeight = false, isInBatches = true, noCardWrapper = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }) {
|
|
61
64
|
const [data, setData] = (0, react_1.useState)(false);
|
|
62
65
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
66
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
63
67
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
64
68
|
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
65
69
|
const { onEditModel, onDeleteRelatedModel, serverEndPoint } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
@@ -75,6 +79,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
75
79
|
return column;
|
|
76
80
|
};
|
|
77
81
|
const loadObjectList = () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
setLoading(true);
|
|
78
83
|
switch (paginationMode) {
|
|
79
84
|
case 'client':
|
|
80
85
|
const loadParams = {
|
|
@@ -94,6 +99,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
94
99
|
const loadedData = yield (0, api_1.getGenericModelList)(loadParams);
|
|
95
100
|
if (loadedData && typeof loadedData !== 'boolean') {
|
|
96
101
|
setData(loadedData);
|
|
102
|
+
setLoading(false);
|
|
97
103
|
if (isInBatches && loadedData.data.length === 100) {
|
|
98
104
|
setHideFooterPagination(true);
|
|
99
105
|
(0, api_1.getGenericModelList)(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema })).then((lastBatchData) => {
|
|
@@ -129,6 +135,7 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
129
135
|
const paginatedData = yield (0, api_1.getGenericModelList)(loadPaginatedParams);
|
|
130
136
|
if (paginatedData && typeof paginatedData !== 'boolean') {
|
|
131
137
|
setData(paginatedData);
|
|
138
|
+
setLoading(false);
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
console.log('error retrieving data!');
|
|
@@ -143,9 +150,9 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
143
150
|
loadObjectList();
|
|
144
151
|
}
|
|
145
152
|
}, [paginationModel]);
|
|
146
|
-
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(ContentTable, { data: data, model: model,
|
|
153
|
+
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(ContentTable, { data: data, relatedModel: relatedModel, model: model, loading: loading, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, onProcessRow: onProcessRow, setData: setData, sumRows: sumRows, visibleRows: visibleRows, paginationMode: paginationMode, paginationModel: paginationModel, setPaginationModel: setPaginationModel, actions: actions, optionsAC: optionsAC })) : (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
147
154
|
react_1.default.createElement(CardHeader_1.default, { title: label }),
|
|
148
155
|
react_1.default.createElement(CardContent_1.default, null,
|
|
149
|
-
react_1.default.createElement(ContentTable, { data: data, model: model,
|
|
156
|
+
react_1.default.createElement(ContentTable, { data: data, relatedModel: relatedModel, model: model, loading: loading, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, onProcessRow: onProcessRow, setData: setData, sumRows: sumRows, visibleRows: visibleRows, paginationMode: paginationMode, paginationModel: paginationModel, setPaginationModel: setPaginationModel, actions: actions, optionsAC: optionsAC }))))))));
|
|
150
157
|
}
|
|
151
158
|
exports.default = GenericRelatedModelList;
|
|
@@ -104,11 +104,13 @@ function FormBySchema(_a) {
|
|
|
104
104
|
const populateOptionsAC = (optionsACModels) => __awaiter(this, void 0, void 0, function* () {
|
|
105
105
|
const newOptionsAC = {};
|
|
106
106
|
for (const model of optionsACModels) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
if (!optionsAC || !optionsAC[model]) {
|
|
108
|
+
const ret = isolatedGetAutoComplete
|
|
109
|
+
? yield isolatedGetAutoComplete(model)
|
|
110
|
+
: yield getAutoComplete(model);
|
|
111
|
+
if (ret !== false) {
|
|
112
|
+
newOptionsAC[model] = ret;
|
|
113
|
+
}
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
if (setOptionsAC) {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DialogType, SnackBarType } from './APIWrapperContext';
|
|
3
3
|
interface APIWrapperProps {
|
|
4
|
-
setLoading: (x: boolean) => void;
|
|
5
4
|
handleLoading: (x: boolean) => void;
|
|
6
5
|
setSnackBar: (x: Partial<SnackBarType>) => void;
|
|
7
6
|
setDialog: (x: Partial<DialogType>) => void;
|
|
8
7
|
children: React.ReactNode;
|
|
9
8
|
}
|
|
10
|
-
declare function APIWrapper({
|
|
9
|
+
declare function APIWrapper({ handleLoading, setSnackBar, setDialog, children }: APIWrapperProps): JSX.Element;
|
|
11
10
|
declare const _default: React.MemoExoticComponent<typeof APIWrapper>;
|
|
12
11
|
export default _default;
|
|
@@ -53,7 +53,7 @@ const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
|
|
|
53
53
|
const api_1 = require("../api");
|
|
54
54
|
const APIWrapperContext_1 = require("./APIWrapperContext");
|
|
55
55
|
const DialogFormBySchema_1 = __importDefault(require("../components/forms/DialogFormBySchema"));
|
|
56
|
-
function APIWrapper({
|
|
56
|
+
function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
57
57
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
58
58
|
const [usuaria, setUsuaria] = (0, react_1.useState)(null);
|
|
59
59
|
const [optionsAC, setOptionsAC] = (0, react_1.useReducer)((utils_1.reducer), null);
|
|
@@ -85,7 +85,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
87
|
const loadSinglePageData = ({ model, objId, optionsACModels = null, defaults = {}, extraValidators = {}, }) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
88
|
+
handleLoading(true);
|
|
89
89
|
if (!objId || objId === 'novo') {
|
|
90
90
|
objId = (0, utils_1.getTmpId)();
|
|
91
91
|
}
|
|
@@ -99,7 +99,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
99
99
|
console.log('Houve um erro ao tentar carregar os dados!');
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
handleLoading(false);
|
|
103
103
|
if (optionsACModels) {
|
|
104
104
|
populateOptionsAC(optionsACModels);
|
|
105
105
|
}
|
|
@@ -116,7 +116,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
116
116
|
console.log('there must be a pageForm!');
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
handleLoading(true);
|
|
120
120
|
const response = yield (0, api_1.updateDataBySchema)({
|
|
121
121
|
model,
|
|
122
122
|
modelObjectId: id,
|
|
@@ -124,7 +124,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
124
124
|
data,
|
|
125
125
|
schema: pageForm.schema,
|
|
126
126
|
});
|
|
127
|
-
|
|
127
|
+
handleLoading(false);
|
|
128
128
|
if (!['number', 'string'].includes(typeof response)) {
|
|
129
129
|
onTriggerSnackBar({
|
|
130
130
|
msg: 'Houve um problema ao salvar seus dados! Por favor, entre em contato',
|
|
@@ -275,7 +275,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
275
275
|
};
|
|
276
276
|
const onDeleteModelSave = (model, id, onSuccess) => __awaiter(this, void 0, void 0, function* () {
|
|
277
277
|
setDialog({ open: false });
|
|
278
|
-
|
|
278
|
+
handleLoading(true);
|
|
279
279
|
const ret = yield (0, api_1.deleteData)(model, serverEndPoint, id);
|
|
280
280
|
if (ret !== false) {
|
|
281
281
|
onTriggerSnackBar({
|
|
@@ -287,7 +287,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
287
287
|
}
|
|
288
288
|
return true;
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
handleLoading(false);
|
|
291
291
|
onTriggerSnackBar({
|
|
292
292
|
msg: 'Houve um problema ao remover o item! Por favor, entre em contato.',
|
|
293
293
|
severity: 'error',
|
package/dist/context/Overlays.js
CHANGED
|
@@ -53,7 +53,7 @@ function Overlays({ children }) {
|
|
|
53
53
|
};
|
|
54
54
|
const [snackBar, setSnackBar] = (0, react_1.useReducer)((utils_1.reducer), initialSnackBar);
|
|
55
55
|
const [dialog, setDialog] = (0, react_1.useReducer)((utils_1.reducer), initialDialog);
|
|
56
|
-
const [loading, setLoading] = (0, react_1.useState)(
|
|
56
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
57
57
|
// give some time to stop loading when data is retrieved and must render before loading rendering:
|
|
58
58
|
const handleLoading = (loadingState) => {
|
|
59
59
|
if (loadingState) {
|
|
@@ -70,8 +70,8 @@ function Overlays({ children }) {
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
73
|
-
react_1.default.createElement(APIWrapper_1.default, {
|
|
74
|
-
react_1.default.createElement(Backdrop_1.default, { sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
73
|
+
react_1.default.createElement(APIWrapper_1.default, { handleLoading: handleLoading, setSnackBar: setSnackBar, setDialog: setDialog, children: children }),
|
|
74
|
+
react_1.default.createElement(Backdrop_1.default, { invisible: false, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
75
75
|
react_1.default.createElement(CircularProgress_1.default, null)),
|
|
76
76
|
snackBar && (react_1.default.createElement(Snackbar_1.default, { open: snackBar.open, autoHideDuration: 3000, onClose: () => {
|
|
77
77
|
setSnackBar({ open: false });
|
package/package.json
CHANGED