drf-react-by-schema 0.13.0 → 0.14.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.d.ts +1 -1
- package/dist/api.js +8 -7
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +13 -3
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +37 -2
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +2 -12
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +2 -21
- package/dist/components/DataGridBySchemaEditable.d.ts +2 -1
- package/dist/components/DataGridBySchemaEditable.js +107 -8
- package/dist/components/GenericModelList.d.ts +3 -2
- package/dist/components/GenericModelList.js +2 -2
- package/dist/components/GenericRelatedModelList.d.ts +3 -2
- package/dist/components/GenericRelatedModelList.js +5 -5
- package/dist/context/APIWrapper.js +4 -0
- package/dist/context/APIWrapperContext.d.ts +2 -1
- package/dist/context/APIWrapperContext.js +1 -0
- package/dist/utils.d.ts +14 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Item, SchemaType, modelOptionsType, DataSchemaColumnsType, ItemSchemaCo
|
|
|
3
3
|
import { GridFilterModel, GridSortModel } from '@mui/x-data-grid';
|
|
4
4
|
import { AlertColor } from '@mui/material/Alert';
|
|
5
5
|
type Id = string | number | null;
|
|
6
|
-
interface TargetApiParams {
|
|
6
|
+
export interface TargetApiParams {
|
|
7
7
|
path: string;
|
|
8
8
|
serverEndPoint: serverEndPointType | null;
|
|
9
9
|
data: Item;
|
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 }) => {
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { GridEnrichedBySchemaColDef } from '../../utils';
|
|
2
|
+
import { BulkDeleteData, BulkUpdateData, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions } from '../../utils';
|
|
3
3
|
type CustomToolbarProps = {
|
|
4
4
|
preparedColumns: GridEnrichedBySchemaColDef[];
|
|
5
5
|
setPreparedColumns: (p: null | GridEnrichedBySchemaColDef[]) => void;
|
|
6
|
+
onSelectActions?: OnSelectActions[];
|
|
7
|
+
selectionModel: Item[];
|
|
8
|
+
bulkUpdateData: BulkUpdateData;
|
|
9
|
+
bulkDeleteData: BulkDeleteData;
|
|
10
|
+
bulkCreateData: (p: Id[]) => void;
|
|
6
11
|
};
|
|
7
12
|
/**
|
|
8
13
|
*
|
|
9
14
|
*
|
|
10
15
|
* @param {CustomToolbarProps} {
|
|
11
16
|
* preparedColumns,
|
|
12
|
-
* setPreparedColumns
|
|
17
|
+
* setPreparedColumns,
|
|
18
|
+
* onSelectActions,
|
|
19
|
+
* selectionModel,
|
|
20
|
+
* bulkUpdateData,
|
|
21
|
+
* bulkDeleteData,
|
|
22
|
+
* bulkCreateData,
|
|
13
23
|
* }
|
|
14
24
|
* @returns Custom Toolbar for the grid
|
|
15
25
|
*/
|
|
16
|
-
export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns }: CustomToolbarProps) => JSX.Element;
|
|
26
|
+
export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }: CustomToolbarProps) => JSX.Element;
|
|
17
27
|
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,16 @@ const utils_1 = require("./utils");
|
|
|
39
40
|
*
|
|
40
41
|
* @param {CustomToolbarProps} {
|
|
41
42
|
* preparedColumns,
|
|
42
|
-
* setPreparedColumns
|
|
43
|
+
* setPreparedColumns,
|
|
44
|
+
* onSelectActions,
|
|
45
|
+
* selectionModel,
|
|
46
|
+
* bulkUpdateData,
|
|
47
|
+
* bulkDeleteData,
|
|
48
|
+
* bulkCreateData,
|
|
43
49
|
* }
|
|
44
50
|
* @returns Custom Toolbar for the grid
|
|
45
51
|
*/
|
|
46
|
-
const CustomToolbar = ({ preparedColumns, setPreparedColumns }) => {
|
|
52
|
+
const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }) => {
|
|
47
53
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
48
54
|
const [resizeMenuAnchorEl, setResizeMenuAnchorEl] = (0, react_1.useState)(null);
|
|
49
55
|
const isResizeMenuOpen = Boolean(resizeMenuAnchorEl);
|
|
@@ -53,8 +59,37 @@ const CustomToolbar = ({ preparedColumns, setPreparedColumns }) => {
|
|
|
53
59
|
const closeResizeMenu = () => {
|
|
54
60
|
setResizeMenuAnchorEl(null);
|
|
55
61
|
};
|
|
62
|
+
const [actionsMenuAnchorEl, setActionsMenuAnchorEl] = (0, react_1.useState)(null);
|
|
63
|
+
const isActionsMenuOpen = Boolean(actionsMenuAnchorEl);
|
|
64
|
+
const openActionsMenu = (event) => {
|
|
65
|
+
setActionsMenuAnchorEl(event.currentTarget);
|
|
66
|
+
};
|
|
67
|
+
const closeActionsMenu = () => {
|
|
68
|
+
setActionsMenuAnchorEl(null);
|
|
69
|
+
};
|
|
56
70
|
return (react_1.default.createElement(x_data_grid_1.GridToolbarContainer, { sx: { justifyContent: 'space-between' } },
|
|
57
71
|
react_1.default.createElement("div", { style: { display: 'flex', flexWrap: 'wrap' } },
|
|
72
|
+
onSelectActions && onSelectActions.length > 0 && selectionModel.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
73
|
+
react_1.default.createElement(Button_1.default, { onClick: openActionsMenu, sx: { ml: '0px', fontSize: '13px', color: '#000' } },
|
|
74
|
+
react_1.default.createElement(ArrowDropDown_1.default, { sx: { mr: '6px' } }),
|
|
75
|
+
"A\u00E7\u00F5es (",
|
|
76
|
+
selectionModel.length,
|
|
77
|
+
")"),
|
|
78
|
+
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: () => {
|
|
79
|
+
closeActionsMenu();
|
|
80
|
+
if (typeof selectAction.action === 'string') {
|
|
81
|
+
const ids = selectionModel.map((item) => item.id);
|
|
82
|
+
if (selectAction.action === 'bulkDelete') {
|
|
83
|
+
bulkDeleteData(ids);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (selectAction.action === 'bulkCreate') {
|
|
87
|
+
bulkCreateData(ids);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
selectAction.action(selectionModel, bulkUpdateData);
|
|
92
|
+
} }, selectAction.title)))))),
|
|
58
93
|
react_1.default.createElement(x_data_grid_1.GridToolbarColumnsButton, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
59
94
|
react_1.default.createElement(x_data_grid_1.GridToolbarFilterButton, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
60
95
|
react_1.default.createElement(x_data_grid_1.GridToolbarDensitySelector, { sx: { ml: '10px', fontSize: '13px' } }),
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Item } from '../../utils';
|
|
3
2
|
type FooterToolbarProps = {
|
|
4
|
-
name: string;
|
|
5
|
-
setRowModesModel: (p: any) => any;
|
|
6
|
-
dataGrid: {
|
|
7
|
-
data: Item[];
|
|
8
|
-
};
|
|
9
|
-
setDataGrid: (p: any) => any;
|
|
10
|
-
emptyItem: {
|
|
11
|
-
current: Record<string, any>;
|
|
12
|
-
};
|
|
13
|
-
indexField: string;
|
|
14
3
|
isEditable: boolean;
|
|
4
|
+
handleAddItem: () => void;
|
|
15
5
|
};
|
|
16
|
-
export declare const FooterToolbar: ({
|
|
6
|
+
export declare const FooterToolbar: ({ isEditable, handleAddItem }: FooterToolbarProps) => JSX.Element;
|
|
17
7
|
export {};
|
|
@@ -8,28 +8,9 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
9
9
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
10
10
|
const Add_1 = __importDefault(require("@mui/icons-material/Add"));
|
|
11
|
-
const
|
|
12
|
-
const FooterToolbar = ({ name, setRowModesModel, dataGrid, setDataGrid, emptyItem, indexField, isEditable, }) => {
|
|
13
|
-
const handleClick = () => {
|
|
14
|
-
const id = (0, utils_1.getTmpId)();
|
|
15
|
-
emptyItem.current.id = id;
|
|
16
|
-
const newData = [Object.assign({}, emptyItem.current), ...dataGrid.data];
|
|
17
|
-
setDataGrid({
|
|
18
|
-
data: newData,
|
|
19
|
-
});
|
|
20
|
-
setRowModesModel((oldModel) => (Object.assign(Object.assign({}, oldModel), { [id]: { mode: x_data_grid_1.GridRowModes.Edit, fieldToFocus: indexField } })));
|
|
21
|
-
// Ugly hack to scroll to top, since scroll to cell is only available in Pro
|
|
22
|
-
const el = document.querySelector(`.dataGrid_${name} .MuiDataGrid-virtualScroller`);
|
|
23
|
-
// console.log(el, name);
|
|
24
|
-
if (el) {
|
|
25
|
-
el.scrollTop = 0;
|
|
26
|
-
setTimeout(() => {
|
|
27
|
-
el.scrollTop = 0;
|
|
28
|
-
}, 10);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
11
|
+
const FooterToolbar = ({ isEditable, handleAddItem }) => {
|
|
31
12
|
return (react_1.default.createElement(x_data_grid_1.GridFooterContainer, null,
|
|
32
|
-
isEditable && (react_1.default.createElement(Button_1.default, { color: "primary", startIcon: react_1.default.createElement(Add_1.default, null), onClick:
|
|
13
|
+
isEditable && (react_1.default.createElement(Button_1.default, { color: "primary", startIcon: react_1.default.createElement(Add_1.default, null), onClick: handleAddItem, sx: { ml: 2 } }, "Adicionar")),
|
|
33
14
|
react_1.default.createElement(x_data_grid_1.GridFooter, { sx: isEditable ? { border: 'none' } : { width: '100%' } })));
|
|
34
15
|
};
|
|
35
16
|
exports.FooterToolbar = FooterToolbar;
|
|
@@ -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 {
|
|
@@ -30,6 +30,7 @@ interface DataGridBySchemaEditableProps {
|
|
|
30
30
|
onEditModel?: (p: OnEditModelType) => void;
|
|
31
31
|
isEditable?: boolean;
|
|
32
32
|
hasBulkSelect?: boolean;
|
|
33
|
+
onSelectActions?: OnSelectActions[];
|
|
33
34
|
sx?: SxProps;
|
|
34
35
|
isAutoHeight?: boolean;
|
|
35
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, 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"]);
|
|
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,8 @@ 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)([]);
|
|
95
|
+
const [selectionModelIds, setSelectionModelIds] = (0, react_1.useState)([]);
|
|
94
96
|
const optionsAC = (0, react_1.useRef)(null);
|
|
95
97
|
const emptyItem = (0, react_1.useRef)({});
|
|
96
98
|
const yupValidationSchema = (0, react_1.useRef)(null);
|
|
@@ -387,6 +389,99 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
387
389
|
});
|
|
388
390
|
setPreparedColumns(cols);
|
|
389
391
|
};
|
|
392
|
+
const handleAddItems = (numberOfRows = 1) => {
|
|
393
|
+
const newRows = [];
|
|
394
|
+
for (let i = 0; i < numberOfRows; i++) {
|
|
395
|
+
const id = (0, utils_1.getTmpId)();
|
|
396
|
+
newRows.push(Object.assign(Object.assign({}, emptyItem.current), { id }));
|
|
397
|
+
}
|
|
398
|
+
const newData = [...newRows, ...dataGrid.data];
|
|
399
|
+
setDataGrid({
|
|
400
|
+
data: newData,
|
|
401
|
+
});
|
|
402
|
+
setRowModesModel((oldModel) => {
|
|
403
|
+
const newModel = Object.assign({}, oldModel);
|
|
404
|
+
newRows.map((newRow) => {
|
|
405
|
+
newModel[newRow.id] = { mode: x_data_grid_1.GridRowModes.Edit, fieldToFocus: indexField };
|
|
406
|
+
});
|
|
407
|
+
return newModel;
|
|
408
|
+
});
|
|
409
|
+
// Ugly hack to scroll to top, since scroll to cell is only available in Pro
|
|
410
|
+
const el = document.querySelector(`.dataGrid_${name} .MuiDataGrid-virtualScroller`);
|
|
411
|
+
// console.log(el, name);
|
|
412
|
+
if (el) {
|
|
413
|
+
el.scrollTop = 0;
|
|
414
|
+
setTimeout(() => {
|
|
415
|
+
el.scrollTop = 0;
|
|
416
|
+
}, 10);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
const bulkUpdateData = (newData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
420
|
+
const promises = [];
|
|
421
|
+
const ids = [];
|
|
422
|
+
newData.map((item) => {
|
|
423
|
+
promises.push((0, api_1.updateDataBySchema)({
|
|
424
|
+
model,
|
|
425
|
+
modelObjectId: item.id,
|
|
426
|
+
serverEndPoint,
|
|
427
|
+
data: item,
|
|
428
|
+
schema,
|
|
429
|
+
}));
|
|
430
|
+
ids.push(item.id);
|
|
431
|
+
});
|
|
432
|
+
const results = yield Promise.all(promises);
|
|
433
|
+
setSelectionModel([]);
|
|
434
|
+
setSelectionModelIds([]);
|
|
435
|
+
setDataGrid({
|
|
436
|
+
data: newData,
|
|
437
|
+
});
|
|
438
|
+
setSnackBar({
|
|
439
|
+
open: true,
|
|
440
|
+
severity: 'success',
|
|
441
|
+
msg: 'Alterações salvas com sucesso',
|
|
442
|
+
});
|
|
443
|
+
return results.map((result, index) => {
|
|
444
|
+
return {
|
|
445
|
+
id: ids[index],
|
|
446
|
+
success: typeof result !== 'object' && !isNaN(parseInt(result)),
|
|
447
|
+
};
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
const bulkDeleteData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
451
|
+
const promises = [];
|
|
452
|
+
ids.map((id) => {
|
|
453
|
+
promises.push((0, api_1.deleteData)(model, serverEndPoint, id));
|
|
454
|
+
});
|
|
455
|
+
setDataGridLoading(true);
|
|
456
|
+
const results = yield Promise.all(promises);
|
|
457
|
+
setSelectionModel([]);
|
|
458
|
+
setSelectionModelIds([]);
|
|
459
|
+
setDataGrid({
|
|
460
|
+
data: data.filter((item) => !ids.includes(item.id)),
|
|
461
|
+
});
|
|
462
|
+
setDataGridLoading(false);
|
|
463
|
+
setSnackBar({
|
|
464
|
+
open: true,
|
|
465
|
+
severity: 'success',
|
|
466
|
+
msg: 'Itens apagados com sucesso',
|
|
467
|
+
});
|
|
468
|
+
return results.map((result, index) => {
|
|
469
|
+
return {
|
|
470
|
+
id: ids[index],
|
|
471
|
+
success: result,
|
|
472
|
+
};
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
const bulkCreateData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
476
|
+
handleAddItems(ids.length);
|
|
477
|
+
setSelectionModel([]);
|
|
478
|
+
setSelectionModelIds([]);
|
|
479
|
+
setSnackBar({
|
|
480
|
+
open: true,
|
|
481
|
+
severity: 'success',
|
|
482
|
+
msg: 'Linhas adicionadas com sucesso',
|
|
483
|
+
});
|
|
484
|
+
});
|
|
390
485
|
const handleDialogClose = () => {
|
|
391
486
|
setDialogOpen(false);
|
|
392
487
|
};
|
|
@@ -615,7 +710,11 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
615
710
|
!Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
|
|
616
711
|
(preparedColumns.find((col) => col.field === indexField) &&
|
|
617
712
|
Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter'))))));
|
|
618
|
-
}, checkboxSelection: checkboxSelection,
|
|
713
|
+
}, checkboxSelection: checkboxSelection, onSelectionModelChange: (newSelectionModel) => {
|
|
714
|
+
const selectedData = dataGrid.data.filter((item) => newSelectionModel.includes(item.id));
|
|
715
|
+
setSelectionModel(selectedData);
|
|
716
|
+
setSelectionModelIds(newSelectionModel);
|
|
717
|
+
}, selectionModel: selectionModelIds, disableRowSelectionOnClick: disableRowSelectionOnClick, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
|
|
619
718
|
setDataGridLoading(false);
|
|
620
719
|
if (processingRow.current) {
|
|
621
720
|
setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: {
|
|
@@ -642,15 +741,15 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
642
741
|
console.log(e);
|
|
643
742
|
return [];
|
|
644
743
|
},
|
|
744
|
+
selectionModel,
|
|
745
|
+
onSelectActions,
|
|
746
|
+
bulkUpdateData,
|
|
747
|
+
bulkDeleteData,
|
|
748
|
+
bulkCreateData,
|
|
645
749
|
},
|
|
646
750
|
footer: {
|
|
647
|
-
name,
|
|
648
|
-
setRowModesModel,
|
|
649
|
-
dataGrid,
|
|
650
|
-
setDataGrid,
|
|
651
|
-
emptyItem,
|
|
652
|
-
indexField,
|
|
653
751
|
isEditable,
|
|
752
|
+
handleAddItem: handleAddItems,
|
|
654
753
|
},
|
|
655
754
|
filterPanel: {
|
|
656
755
|
sx: {
|
|
@@ -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;
|
|
@@ -50,7 +50,7 @@ const utils_1 = require("../utils");
|
|
|
50
50
|
const api_1 = require("../api");
|
|
51
51
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
52
52
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
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, }) => {
|
|
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, }) => {
|
|
54
54
|
const { serverEndPoint, isInBatches, firstBatchLength } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
55
55
|
const { onEditModel } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
56
56
|
const [data, setData] = (0, react_1.useState)(false);
|
|
@@ -151,7 +151,7 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
151
151
|
react_1.default.createElement(LinkComponent, { to: `novo` },
|
|
152
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")))))),
|
|
153
153
|
react_1.default.createElement(Box_1.default, { sx: tableAutoHeight ? {} : styles_1.Layout.dataGridWithTabs },
|
|
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) => {
|
|
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) => {
|
|
155
155
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
156
156
|
}, LinkComponent: LinkComponent, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
157
157
|
? undefined
|
|
@@ -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 {};
|
|
@@ -49,9 +49,9 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
49
49
|
const utils_1 = require("../utils");
|
|
50
50
|
const api_1 = require("../api");
|
|
51
51
|
const styles_1 = require("../styles");
|
|
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,
|
|
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
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) => {
|
|
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) => {
|
|
55
55
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
56
56
|
}, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
57
57
|
? undefined
|
|
@@ -60,7 +60,7 @@ const ContentTable = ({ data, relatedModel, model, loading, id, indexField, inde
|
|
|
60
60
|
: 0 }))) : (react_1.default.createElement(Backdrop_1.default, { invisible: true, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
61
61
|
react_1.default.createElement(CircularProgress_1.default, null))),
|
|
62
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 }))));
|
|
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, }) {
|
|
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, }) {
|
|
64
64
|
const [data, setData] = (0, react_1.useState)(false);
|
|
65
65
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
66
66
|
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
@@ -150,9 +150,9 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
150
150
|
loadObjectList();
|
|
151
151
|
}
|
|
152
152
|
}, [paginationModel]);
|
|
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 },
|
|
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 },
|
|
154
154
|
react_1.default.createElement(CardHeader_1.default, { title: label }),
|
|
155
155
|
react_1.default.createElement(CardContent_1.default, null,
|
|
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 }))))))));
|
|
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 }))))))));
|
|
157
157
|
}
|
|
158
158
|
exports.default = GenericRelatedModelList;
|
|
@@ -403,6 +403,9 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
403
403
|
return yield (0, api_1.getSignUpOptions)(serverEndPoint);
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
|
+
function localUpdateModel(params) {
|
|
407
|
+
return (0, api_1.updateData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
408
|
+
}
|
|
406
409
|
return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
|
|
407
410
|
usuaria,
|
|
408
411
|
updateUsuaria,
|
|
@@ -430,6 +433,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
430
433
|
// Remove after integrating new "onEditModel" to package:
|
|
431
434
|
serverEndPoint,
|
|
432
435
|
editModel,
|
|
436
|
+
updateModel: localUpdateModel,
|
|
433
437
|
populateOptionsAC,
|
|
434
438
|
} }, children));
|
|
435
439
|
}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { FieldValues, SubmitHandler, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
3
3
|
import { AxiosResponse } from 'axios';
|
|
4
4
|
import { ItemSchemaColumnsType, Id, Item, SchemaType, DataSchemaColumnsType } from '../utils';
|
|
5
|
-
import { GetGenericModelListProps } from '../api';
|
|
5
|
+
import { GetGenericModelListProps, TargetApiParams } from '../api';
|
|
6
6
|
import { serverEndPointType } from './DRFReactBySchemaContext';
|
|
7
7
|
export interface LoadSinglePageDataProps {
|
|
8
8
|
model: string;
|
|
@@ -92,6 +92,7 @@ export interface APIWrapperContextType {
|
|
|
92
92
|
} | undefined>;
|
|
93
93
|
serverEndPoint: serverEndPointType;
|
|
94
94
|
editModel: React.MutableRefObject<Item>;
|
|
95
|
+
updateModel: (p: Omit<TargetApiParams, 'serverEndPoint'>) => Promise<boolean>;
|
|
95
96
|
populateOptionsAC: (optionsACModels: string[]) => void;
|
|
96
97
|
}
|
|
97
98
|
export declare const APIWrapperContext: React.Context<APIWrapperContextType>;
|
|
@@ -41,6 +41,7 @@ exports.APIWrapperContext = react_1.default.createContext({
|
|
|
41
41
|
// Remove after integrating new "onEditModel" to package:
|
|
42
42
|
serverEndPoint: { url: '', apiTokenUrl: '' },
|
|
43
43
|
editModel: { current: {} },
|
|
44
|
+
updateModel: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
44
45
|
populateOptionsAC: () => undefined,
|
|
45
46
|
});
|
|
46
47
|
const useAPIWrapper = () => {
|
package/dist/utils.d.ts
CHANGED
|
@@ -157,4 +157,18 @@ 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 BulkUpdateData = (newData: Item[]) => Promise<{
|
|
161
|
+
id: Id;
|
|
162
|
+
success: boolean;
|
|
163
|
+
}[]>;
|
|
164
|
+
export type BulkDeleteData = (ids: Id[]) => Promise<{
|
|
165
|
+
id: Id;
|
|
166
|
+
success: boolean;
|
|
167
|
+
}[]>;
|
|
168
|
+
export type OnSelectActionCustom = (selectedData: Item[], bulkUpdateData: BulkUpdateData) => void;
|
|
169
|
+
export type OnSelectActionTypes = OnSelectActionCustom | 'bulkDelete' | 'bulkCreate';
|
|
170
|
+
export type OnSelectActions = {
|
|
171
|
+
title: string;
|
|
172
|
+
action: OnSelectActionTypes;
|
|
173
|
+
};
|
|
160
174
|
export {};
|
package/package.json
CHANGED