drf-react-by-schema 0.13.1 → 0.14.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.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;
@@ -1,11 +1,13 @@
1
1
  /// <reference types="react" />
2
- import { GridSelectionModel } from '@mui/x-data-grid';
3
- import { GridEnrichedBySchemaColDef, OnSelectActions } from '../../utils';
2
+ import { BulkDeleteData, BulkUpdateData, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions } from '../../utils';
4
3
  type CustomToolbarProps = {
5
4
  preparedColumns: GridEnrichedBySchemaColDef[];
6
5
  setPreparedColumns: (p: null | GridEnrichedBySchemaColDef[]) => void;
7
6
  onSelectActions?: OnSelectActions[];
8
- selectionModel: GridSelectionModel;
7
+ selectionModel: Item[];
8
+ bulkUpdateData: BulkUpdateData;
9
+ bulkDeleteData: BulkDeleteData;
10
+ bulkCreateData: (p: Id[]) => void;
9
11
  };
10
12
  /**
11
13
  *
@@ -15,8 +17,11 @@ type CustomToolbarProps = {
15
17
  * setPreparedColumns,
16
18
  * onSelectActions,
17
19
  * selectionModel,
20
+ * bulkUpdateData,
21
+ * bulkDeleteData,
22
+ * bulkCreateData,
18
23
  * }
19
24
  * @returns Custom Toolbar for the grid
20
25
  */
21
- export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, }: CustomToolbarProps) => JSX.Element;
26
+ export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }: CustomToolbarProps) => JSX.Element;
22
27
  export {};
@@ -43,10 +43,13 @@ const utils_1 = require("./utils");
43
43
  * setPreparedColumns,
44
44
  * onSelectActions,
45
45
  * selectionModel,
46
+ * bulkUpdateData,
47
+ * bulkDeleteData,
48
+ * bulkCreateData,
46
49
  * }
47
50
  * @returns Custom Toolbar for the grid
48
51
  */
49
- const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, }) => {
52
+ const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }) => {
50
53
  const apiRef = (0, x_data_grid_1.useGridApiContext)();
51
54
  const [resizeMenuAnchorEl, setResizeMenuAnchorEl] = (0, react_1.useState)(null);
52
55
  const isResizeMenuOpen = Boolean(resizeMenuAnchorEl);
@@ -74,7 +77,18 @@ const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, s
74
77
  ")"),
75
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: () => {
76
79
  closeActionsMenu();
77
- selectAction.action(selectionModel);
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);
78
92
  } }, selectAction.title)))))),
79
93
  react_1.default.createElement(x_data_grid_1.GridToolbarColumnsButton, { sx: { ml: '10px', fontSize: '13px' } }),
80
94
  react_1.default.createElement(x_data_grid_1.GridToolbarFilterButton, { 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: ({ name, setRowModesModel, dataGrid, setDataGrid, emptyItem, indexField, isEditable, }: FooterToolbarProps) => JSX.Element;
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 utils_1 = require("../../utils");
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: handleClick, sx: { ml: 2 } }, "Adicionar")),
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;
@@ -92,6 +92,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
92
92
  const [rowModesModel, setRowModesModel] = (0, react_1.useState)({});
93
93
  const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
94
94
  const [selectionModel, setSelectionModel] = (0, react_1.useState)([]);
95
+ const [selectionModelIds, setSelectionModelIds] = (0, react_1.useState)([]);
95
96
  const optionsAC = (0, react_1.useRef)(null);
96
97
  const emptyItem = (0, react_1.useRef)({});
97
98
  const yupValidationSchema = (0, react_1.useRef)(null);
@@ -388,6 +389,99 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
388
389
  });
389
390
  setPreparedColumns(cols);
390
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
+ });
391
485
  const handleDialogClose = () => {
392
486
  setDialogOpen(false);
393
487
  };
@@ -617,8 +711,10 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
617
711
  (preparedColumns.find((col) => col.field === indexField) &&
618
712
  Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter'))))));
619
713
  }, checkboxSelection: checkboxSelection, onSelectionModelChange: (newSelectionModel) => {
620
- setSelectionModel(newSelectionModel);
621
- }, disableRowSelectionOnClick: disableRowSelectionOnClick, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
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) => {
622
718
  setDataGridLoading(false);
623
719
  if (processingRow.current) {
624
720
  setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: {
@@ -647,15 +743,13 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
647
743
  },
648
744
  selectionModel,
649
745
  onSelectActions,
746
+ bulkUpdateData,
747
+ bulkDeleteData,
748
+ bulkCreateData,
650
749
  },
651
750
  footer: {
652
- name,
653
- setRowModesModel,
654
- dataGrid,
655
- setDataGrid,
656
- emptyItem,
657
- indexField,
658
751
  isEditable,
752
+ handleAddItem: handleAddItems,
659
753
  },
660
754
  filterPanel: {
661
755
  sx: {
@@ -49,7 +49,7 @@ function FieldBySchema(_a) {
49
49
  case 'choice':
50
50
  return (react_1.default.createElement(AutocompleteFieldBySchema_1.default, { index: index, name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, optionIdKey: "value", optionLabelKey: "display_name", options: options, isSemaphoric: isSemaphoric, label: label, sx: sx }));
51
51
  case 'boolean':
52
- return (react_1.default.createElement(BooleanFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx }, other)));
52
+ return (react_1.default.createElement(BooleanFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx, onValueChange: onValueChange }, other)));
53
53
  case 'decimal':
54
54
  case 'float':
55
55
  return (react_1.default.createElement(FloatFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, onValueChange: onValueChange, decimalScale: decimalScale, label: label, sx: sx }, other)));
@@ -57,7 +57,7 @@ function FieldBySchema(_a) {
57
57
  case 'integer':
58
58
  case 'password':
59
59
  default:
60
- const localMultiline = schema[name].model_multiline === true;
60
+ const localMultiline = schema[name].model_multiline === true || multiline;
61
61
  const minRows = localMultiline ? 3 : 0;
62
62
  return (react_1.default.createElement(TextFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: localMultiline, minRows: minRows, fieldKey: fieldKey, index: index, sx: sx, isPassword: schema[name].type === 'password' }, other)));
63
63
  }
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { FieldBySchemaProps } from '../../../utils';
3
- export default function BooleanFieldBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
3
+ export default function BooleanFieldBySchema({ name, schema, control, errors, fieldKey, index, sx, onValueChange, ...other }: FieldBySchemaProps): JSX.Element;
@@ -19,7 +19,7 @@ const react_hook_form_1 = require("react-hook-form");
19
19
  const Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
20
20
  const FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
21
21
  function BooleanFieldBySchema(_a) {
22
- var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 } } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx"]);
22
+ var { name, schema, control, errors, fieldKey, index, sx = { mr: 2 }, onValueChange } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "fieldKey", "index", "sx", "onValueChange"]);
23
23
  const model = name;
24
24
  if (fieldKey && index && index >= 0) {
25
25
  name = `${fieldKey}.${index}.${name}`;
@@ -36,6 +36,11 @@ function BooleanFieldBySchema(_a) {
36
36
  // error: errors && Boolean(errors[name]),
37
37
  // helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
38
38
  // };
39
- return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(FormControlLabel_1.default, { control: react_1.default.createElement(Checkbox_1.default, Object.assign({}, field, other, { value: field.value || false, checked: field.value || false, inputProps: { 'aria-label': 'controlled' } })), label: schema[model].label, required: schema[model].required })) }));
39
+ return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(FormControlLabel_1.default, { control: react_1.default.createElement(Checkbox_1.default, Object.assign({}, field, other, { value: field.value || false, checked: field.value || false, inputProps: { 'aria-label': 'controlled' }, onChange: (e) => {
40
+ if (onValueChange) {
41
+ onValueChange(e);
42
+ }
43
+ field.onChange(e);
44
+ } })), label: schema[model].label, required: schema[model].required })) }));
40
45
  }
41
46
  exports.default = BooleanFieldBySchema;
@@ -49,7 +49,7 @@ const DialogActions_1 = __importDefault(require("../../DialogActions"));
49
49
  const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
50
50
  const filter = (0, Autocomplete_1.createFilterOptions)();
51
51
  const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) => {
52
- var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, multiple = false } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "multiple"]);
52
+ var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, multiple = false, disabled = false } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "multiple", "disabled"]);
53
53
  const { setDialog } = (0, APIWrapperContext_1.useAPIWrapper)();
54
54
  const model = name;
55
55
  const label = schema[model].label;
@@ -95,7 +95,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
95
95
  ? errors[name].message
96
96
  : schema[name].help_text || '',
97
97
  };
98
- if (!schema[model].disabled && onEditModel && optionsModel) {
98
+ if (!disabled && !schema[model].disabled && onEditModel && optionsModel) {
99
99
  return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: schema[model].disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
100
100
  let valueAr = value;
101
101
  if (!multiple) {
@@ -196,7 +196,7 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
196
196
  }
197
197
  : undefined }))) }));
198
198
  }
199
- return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: schema[model].disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
199
+ return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: schema[model].disabled === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
200
200
  field.onChange(value);
201
201
  }, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: schema[model].required, margin: "normal", error: error, helperText: helperText }, other))), getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
202
202
  });
@@ -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
@@ -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, GridSelectionModel } from '@mui/x-data-grid';
3
+ import { GridActionsColDef, GridColDef, GridFilterModel, GridSortModel } 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';
@@ -109,6 +109,7 @@ export interface FieldBySchemaProps {
109
109
  minRows?: number;
110
110
  optionIdKey?: string;
111
111
  optionLabelKey?: string;
112
+ disabled?: boolean;
112
113
  }
113
114
  export interface DetailFieldBySchemaProps {
114
115
  name: string;
@@ -157,8 +158,18 @@ export declare const slugToCamelCase: (str: string) => string;
157
158
  export declare const slugify: (text: string) => string;
158
159
  export declare function mergeFilterItems(defaultFilter: GridFilterModel | undefined, filter: GridFilterModel | undefined): any;
159
160
  export type ActionType = 'editInline' | 'remove' | 'edit' | 'view';
161
+ export type BulkUpdateData = (newData: Item[]) => Promise<{
162
+ id: Id;
163
+ success: boolean;
164
+ }[]>;
165
+ export type BulkDeleteData = (ids: Id[]) => Promise<{
166
+ id: Id;
167
+ success: boolean;
168
+ }[]>;
169
+ export type OnSelectActionCustom = (selectedData: Item[], bulkUpdateData: BulkUpdateData) => void;
170
+ export type OnSelectActionTypes = OnSelectActionCustom | 'bulkDelete' | 'bulkCreate';
160
171
  export type OnSelectActions = {
161
172
  title: string;
162
- action: (p: GridSelectionModel) => void;
173
+ action: OnSelectActionTypes;
163
174
  };
164
175
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drf-react-by-schema",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "description": "Components and Tools for building a React App having Django Rest Framework (DRF) as server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",