drf-react-by-schema 0.12.6 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +16 -14
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +8 -3
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +23 -2
- package/dist/components/DataGridBySchemaEditable.d.ts +3 -1
- package/dist/components/DataGridBySchemaEditable.js +8 -3
- package/dist/components/GenericModelList.d.ts +3 -2
- package/dist/components/GenericModelList.js +12 -8
- package/dist/components/GenericRelatedModelList.d.ts +3 -2
- package/dist/components/GenericRelatedModelList.js +14 -7
- package/dist/context/APIWrapper.d.ts +1 -2
- package/dist/context/APIWrapper.js +7 -7
- package/dist/context/Overlays.js +3 -3
- package/dist/utils.d.ts +5 -1
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -300,13 +300,14 @@ const createOrUpdateData = ({ path, serverEndPoint, data, id, }) => __awaiter(vo
|
|
|
300
300
|
if (!responseCreate || Object.prototype.hasOwnProperty.call(responseCreate, 'errors')) {
|
|
301
301
|
return responseCreate;
|
|
302
302
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
303
|
+
return responseCreate.data.id;
|
|
304
|
+
// const responseUpdate = await updateData({
|
|
305
|
+
// path,
|
|
306
|
+
// serverEndPoint,
|
|
307
|
+
// data,
|
|
308
|
+
// id: responseCreate.data.id,
|
|
309
|
+
// });
|
|
310
|
+
// return responseUpdate;
|
|
310
311
|
});
|
|
311
312
|
exports.createOrUpdateData = createOrUpdateData;
|
|
312
313
|
const prepareDataBySchema = ({ data, schema }) => {
|
|
@@ -567,6 +568,7 @@ const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
|
|
|
567
568
|
});
|
|
568
569
|
exports.signUp = signUp;
|
|
569
570
|
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* () {
|
|
571
|
+
const newQueryParams = [...queryParams];
|
|
570
572
|
let path = `${model}/${id}`;
|
|
571
573
|
let schemaPath = `${model}/`;
|
|
572
574
|
let schema = loadedSchema;
|
|
@@ -582,14 +584,14 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
582
584
|
// SERVER-SIDE TOTALS (sumRows):
|
|
583
585
|
if (sumRows) {
|
|
584
586
|
const sumRowsParams = sumRows.rows.map((row) => row.field).join(',');
|
|
585
|
-
|
|
587
|
+
newQueryParams.push(`sum_rows=${sumRowsParams}`);
|
|
586
588
|
}
|
|
587
589
|
// SERVER-SIDE FILTERING:
|
|
588
590
|
if (filter) {
|
|
589
591
|
if (filter.quickFilterValues &&
|
|
590
592
|
filter.quickFilterValues.length > 0 &&
|
|
591
593
|
filter.quickFilterValues[0]) {
|
|
592
|
-
|
|
594
|
+
newQueryParams.push(`search=${filter.quickFilterValues[0]}`);
|
|
593
595
|
}
|
|
594
596
|
for (const item of filter.items) {
|
|
595
597
|
if (!item.operatorValue) {
|
|
@@ -598,7 +600,7 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
598
600
|
const queryParam = item.value
|
|
599
601
|
? `columnField=${item.columnField}&operatorValue=${item.operatorValue}&value=${item.value}`
|
|
600
602
|
: `columnField=${item.columnField}&operatorValue=${item.operatorValue}`;
|
|
601
|
-
|
|
603
|
+
newQueryParams.push(queryParam);
|
|
602
604
|
}
|
|
603
605
|
}
|
|
604
606
|
// SERVER-SIDE SORTING:
|
|
@@ -607,14 +609,14 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
607
609
|
for (const item of sort) {
|
|
608
610
|
sortParams.push(item.sort === 'desc' ? `-${item.field}` : item.field);
|
|
609
611
|
}
|
|
610
|
-
|
|
612
|
+
newQueryParams.push(`ordering=${sortParams.join(',')}`);
|
|
611
613
|
}
|
|
612
614
|
// SERVER-SIDE PAGINATION:
|
|
613
615
|
if (page) {
|
|
614
|
-
|
|
616
|
+
newQueryParams.push(`page=${page + 1}`);
|
|
615
617
|
}
|
|
616
|
-
if (
|
|
617
|
-
path += `?${
|
|
618
|
+
if (newQueryParams.length > 0) {
|
|
619
|
+
path += `?${newQueryParams.join('&')}`;
|
|
618
620
|
}
|
|
619
621
|
// Only get schema and columns if not in batches or in first batch:
|
|
620
622
|
if (!schema) {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { GridSelectionModel } from '@mui/x-data-grid';
|
|
3
|
+
import { GridEnrichedBySchemaColDef, OnSelectActions } from '../../utils';
|
|
3
4
|
type CustomToolbarProps = {
|
|
4
5
|
preparedColumns: GridEnrichedBySchemaColDef[];
|
|
5
6
|
setPreparedColumns: (p: null | GridEnrichedBySchemaColDef[]) => void;
|
|
7
|
+
onSelectActions?: OnSelectActions[];
|
|
8
|
+
selectionModel: GridSelectionModel;
|
|
6
9
|
};
|
|
7
10
|
/**
|
|
8
11
|
*
|
|
9
12
|
*
|
|
10
13
|
* @param {CustomToolbarProps} {
|
|
11
14
|
* preparedColumns,
|
|
12
|
-
* setPreparedColumns
|
|
15
|
+
* setPreparedColumns,
|
|
16
|
+
* onSelectActions,
|
|
17
|
+
* selectionModel,
|
|
13
18
|
* }
|
|
14
19
|
* @returns Custom Toolbar for the grid
|
|
15
20
|
*/
|
|
16
|
-
export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns }: CustomToolbarProps) => JSX.Element;
|
|
21
|
+
export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, }: CustomToolbarProps) => JSX.Element;
|
|
17
22
|
export {};
|
|
@@ -31,6 +31,7 @@ const react_1 = __importStar(require("react"));
|
|
|
31
31
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
32
32
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
33
33
|
const Expand_1 = __importDefault(require("@mui/icons-material/Expand"));
|
|
34
|
+
const ArrowDropDown_1 = __importDefault(require("@mui/icons-material/ArrowDropDown"));
|
|
34
35
|
const Menu_1 = __importDefault(require("@mui/material/Menu"));
|
|
35
36
|
const MenuItem_1 = __importDefault(require("@mui/material/MenuItem"));
|
|
36
37
|
const utils_1 = require("./utils");
|
|
@@ -39,11 +40,13 @@ const utils_1 = require("./utils");
|
|
|
39
40
|
*
|
|
40
41
|
* @param {CustomToolbarProps} {
|
|
41
42
|
* preparedColumns,
|
|
42
|
-
* setPreparedColumns
|
|
43
|
+
* setPreparedColumns,
|
|
44
|
+
* onSelectActions,
|
|
45
|
+
* selectionModel,
|
|
43
46
|
* }
|
|
44
47
|
* @returns Custom Toolbar for the grid
|
|
45
48
|
*/
|
|
46
|
-
const CustomToolbar = ({ preparedColumns, setPreparedColumns }) => {
|
|
49
|
+
const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, }) => {
|
|
47
50
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
48
51
|
const [resizeMenuAnchorEl, setResizeMenuAnchorEl] = (0, react_1.useState)(null);
|
|
49
52
|
const isResizeMenuOpen = Boolean(resizeMenuAnchorEl);
|
|
@@ -53,8 +56,26 @@ const CustomToolbar = ({ preparedColumns, setPreparedColumns }) => {
|
|
|
53
56
|
const closeResizeMenu = () => {
|
|
54
57
|
setResizeMenuAnchorEl(null);
|
|
55
58
|
};
|
|
59
|
+
const [actionsMenuAnchorEl, setActionsMenuAnchorEl] = (0, react_1.useState)(null);
|
|
60
|
+
const isActionsMenuOpen = Boolean(actionsMenuAnchorEl);
|
|
61
|
+
const openActionsMenu = (event) => {
|
|
62
|
+
setActionsMenuAnchorEl(event.currentTarget);
|
|
63
|
+
};
|
|
64
|
+
const closeActionsMenu = () => {
|
|
65
|
+
setActionsMenuAnchorEl(null);
|
|
66
|
+
};
|
|
56
67
|
return (react_1.default.createElement(x_data_grid_1.GridToolbarContainer, { sx: { justifyContent: 'space-between' } },
|
|
57
68
|
react_1.default.createElement("div", { style: { display: 'flex', flexWrap: 'wrap' } },
|
|
69
|
+
onSelectActions && onSelectActions.length > 0 && selectionModel.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
70
|
+
react_1.default.createElement(Button_1.default, { onClick: openActionsMenu, sx: { ml: '0px', fontSize: '13px', color: '#000' } },
|
|
71
|
+
react_1.default.createElement(ArrowDropDown_1.default, { sx: { mr: '6px' } }),
|
|
72
|
+
"A\u00E7\u00F5es (",
|
|
73
|
+
selectionModel.length,
|
|
74
|
+
")"),
|
|
75
|
+
react_1.default.createElement(Menu_1.default, { anchorEl: actionsMenuAnchorEl, open: isActionsMenuOpen, onClose: closeActionsMenu }, onSelectActions.map((selectAction, index) => (react_1.default.createElement(MenuItem_1.default, { key: `onSelectAction_${index}`, onClick: () => {
|
|
76
|
+
closeActionsMenu();
|
|
77
|
+
selectAction.action(selectionModel);
|
|
78
|
+
} }, selectAction.title)))))),
|
|
58
79
|
react_1.default.createElement(x_data_grid_1.GridToolbarColumnsButton, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
59
80
|
react_1.default.createElement(x_data_grid_1.GridToolbarFilterButton, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
60
81
|
react_1.default.createElement(x_data_grid_1.GridToolbarDensitySelector, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType } from '../utils';
|
|
2
|
+
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions } from '../utils';
|
|
3
3
|
import { SxProps } from '@mui/material';
|
|
4
4
|
import { OnEditModelType } from '../context/APIWrapperContext';
|
|
5
5
|
interface DataGridBySchemaEditableProps {
|
|
@@ -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;
|
|
@@ -29,6 +30,7 @@ interface DataGridBySchemaEditableProps {
|
|
|
29
30
|
onEditModel?: (p: OnEditModelType) => void;
|
|
30
31
|
isEditable?: boolean;
|
|
31
32
|
hasBulkSelect?: boolean;
|
|
33
|
+
onSelectActions?: OnSelectActions[];
|
|
32
34
|
sx?: SxProps;
|
|
33
35
|
isAutoHeight?: boolean;
|
|
34
36
|
defaultValues?: Item;
|
|
@@ -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, onSelectActions, 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", "onSelectActions", "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 = {
|
|
@@ -91,6 +91,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
91
91
|
const [dataGridLoading, setDataGridLoading] = (0, react_1.useState)(false);
|
|
92
92
|
const [rowModesModel, setRowModesModel] = (0, react_1.useState)({});
|
|
93
93
|
const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
|
|
94
|
+
const [selectionModel, setSelectionModel] = (0, react_1.useState)([]);
|
|
94
95
|
const optionsAC = (0, react_1.useRef)(null);
|
|
95
96
|
const emptyItem = (0, react_1.useRef)({});
|
|
96
97
|
const yupValidationSchema = (0, react_1.useRef)(null);
|
|
@@ -600,7 +601,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
600
601
|
visibleRows.current = newVisibleRowsJSON;
|
|
601
602
|
}
|
|
602
603
|
}
|
|
603
|
-
}, editMode: "row", loading: dataGridLoading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
|
|
604
|
+
}, editMode: "row", loading: dataGridLoading || loading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
|
|
604
605
|
if (isAutoHeight) {
|
|
605
606
|
return 'auto';
|
|
606
607
|
}
|
|
@@ -615,7 +616,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
615
616
|
!Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
|
|
616
617
|
(preparedColumns.find((col) => col.field === indexField) &&
|
|
617
618
|
Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter'))))));
|
|
618
|
-
}, checkboxSelection: checkboxSelection,
|
|
619
|
+
}, checkboxSelection: checkboxSelection, onSelectionModelChange: (newSelectionModel) => {
|
|
620
|
+
setSelectionModel(newSelectionModel);
|
|
621
|
+
}, disableRowSelectionOnClick: disableRowSelectionOnClick, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
|
|
619
622
|
setDataGridLoading(false);
|
|
620
623
|
if (processingRow.current) {
|
|
621
624
|
setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: {
|
|
@@ -642,6 +645,8 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
642
645
|
console.log(e);
|
|
643
646
|
return [];
|
|
644
647
|
},
|
|
648
|
+
selectionModel,
|
|
649
|
+
onSelectActions,
|
|
645
650
|
},
|
|
646
651
|
footer: {
|
|
647
652
|
name,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
|
-
import { GridEnrichedBySchemaColDef, ActionType, Item } from '../utils';
|
|
3
|
+
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericModelListProps {
|
|
6
6
|
model: string;
|
|
@@ -18,6 +18,7 @@ interface GenericModelListProps {
|
|
|
18
18
|
customLinkDestination?: (p: any) => string;
|
|
19
19
|
isEditable?: boolean;
|
|
20
20
|
hasBulkSelect?: boolean;
|
|
21
|
+
onSelectActions?: OnSelectActions[];
|
|
21
22
|
sumRows?: SumRowsType;
|
|
22
23
|
isAutoHeight?: boolean;
|
|
23
24
|
forceReload: boolean;
|
|
@@ -33,5 +34,5 @@ interface GenericModelListProps {
|
|
|
33
34
|
optionsAC?: Record<string, Item[]>;
|
|
34
35
|
disableScreenLoading?: boolean;
|
|
35
36
|
}
|
|
36
|
-
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, disableScreenLoading, }: GenericModelListProps) => JSX.Element;
|
|
37
|
+
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, disableScreenLoading, }: GenericModelListProps) => JSX.Element;
|
|
37
38
|
export default GenericModelList;
|
|
@@ -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"));
|
|
@@ -48,10 +50,11 @@ const utils_1 = require("../utils");
|
|
|
48
50
|
const api_1 = require("../api");
|
|
49
51
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
50
52
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
51
|
-
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, }) => {
|
|
53
|
+
const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect = false, onSelectActions, 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, onSelectActions: onSelectActions, 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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
|
-
import { ActionType, GridEnrichedBySchemaColDef, Id, Item } from '../utils';
|
|
3
|
+
import { ActionType, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericRelatedModelListProps {
|
|
6
6
|
model: string;
|
|
@@ -21,6 +21,7 @@ interface GenericRelatedModelListProps {
|
|
|
21
21
|
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef;
|
|
22
22
|
isEditable?: boolean;
|
|
23
23
|
hasBulkSelect?: boolean;
|
|
24
|
+
onSelectActions?: OnSelectActions[];
|
|
24
25
|
sumRows?: SumRowsType;
|
|
25
26
|
isAutoHeight?: boolean;
|
|
26
27
|
isInBatches?: boolean;
|
|
@@ -34,5 +35,5 @@ interface GenericRelatedModelListProps {
|
|
|
34
35
|
actions?: Partial<ActionType>[];
|
|
35
36
|
optionsAC?: Record<string, Item[]>;
|
|
36
37
|
}
|
|
37
|
-
export default function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable, hasBulkSelect, sumRows, isAutoHeight, isInBatches, noCardWrapper, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }: GenericRelatedModelListProps): JSX.Element;
|
|
38
|
+
export default function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, isInBatches, noCardWrapper, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }: GenericRelatedModelListProps): JSX.Element;
|
|
38
39
|
export {};
|
|
@@ -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, onSelectActions, 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, onSelectActions: onSelectActions, 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
|
-
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, }) {
|
|
63
|
+
function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria = null, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable = true, hasBulkSelect = false, onSelectActions, 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, onSelectActions: onSelectActions, 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, onSelectActions: onSelectActions, 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;
|
|
@@ -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, { invisible:
|
|
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/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CalendarPickerView } from '@mui/x-date-pickers/CalendarPicker';
|
|
3
|
-
import { GridActionsColDef, GridColDef, GridFilterModel, GridSortModel } from '@mui/x-data-grid';
|
|
3
|
+
import { GridActionsColDef, GridColDef, GridFilterModel, GridSortModel, GridSelectionModel } from '@mui/x-data-grid';
|
|
4
4
|
import { Control, FieldValues, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
5
5
|
import { AutocompleteRenderOptionState, SxProps } from '@mui/material';
|
|
6
6
|
import { OnEditModelType } from './context/APIWrapperContext';
|
|
@@ -157,4 +157,8 @@ export declare const slugToCamelCase: (str: string) => string;
|
|
|
157
157
|
export declare const slugify: (text: string) => string;
|
|
158
158
|
export declare function mergeFilterItems(defaultFilter: GridFilterModel | undefined, filter: GridFilterModel | undefined): any;
|
|
159
159
|
export type ActionType = 'editInline' | 'remove' | 'edit' | 'view';
|
|
160
|
+
export type OnSelectActions = {
|
|
161
|
+
title: string;
|
|
162
|
+
action: (p: GridSelectionModel) => void;
|
|
163
|
+
};
|
|
160
164
|
export {};
|
package/package.json
CHANGED