drf-react-by-schema 0.15.2 → 0.15.3

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.
Files changed (49) hide show
  1. package/dist/api.d.ts +16 -22
  2. package/dist/api.js +253 -144
  3. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +1 -1
  4. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +2 -11
  5. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +3 -12
  6. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +2 -2
  7. package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +2 -2
  8. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +2 -2
  9. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +3 -3
  10. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +2 -2
  11. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +4 -4
  12. package/dist/components/DataGridBySchemaEditable/utils.d.ts +2 -2
  13. package/dist/components/DataGridBySchemaEditable.d.ts +8 -7
  14. package/dist/components/DataGridBySchemaEditable.js +128 -108
  15. package/dist/components/DataTotals.d.ts +2 -2
  16. package/dist/components/DataTotals.js +9 -10
  17. package/dist/components/DataTotalsServer.d.ts +2 -2
  18. package/dist/components/DialogActions.d.ts +1 -1
  19. package/dist/components/FormButtons.d.ts +1 -1
  20. package/dist/components/GenericModelList.d.ts +8 -8
  21. package/dist/components/GenericModelList.js +3 -3
  22. package/dist/components/GenericRelatedModelList.d.ts +6 -6
  23. package/dist/components/GenericRelatedModelList.js +4 -4
  24. package/dist/components/details/DetailBySchema.d.ts +2 -2
  25. package/dist/components/details/DetailFieldBySchema.d.ts +2 -2
  26. package/dist/components/forms/DialogFormBySchema.d.ts +3 -3
  27. package/dist/components/forms/FieldBySchema.d.ts +2 -2
  28. package/dist/components/forms/FormBySchema.d.ts +2 -2
  29. package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +2 -2
  30. package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +2 -2
  31. package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +2 -2
  32. package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +2 -2
  33. package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +2 -1
  34. package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +2 -2
  35. package/dist/components/forms/inputs/TextFieldBySchema.d.ts +2 -2
  36. package/dist/context/APIWrapper.d.ts +1 -1
  37. package/dist/context/APIWrapper.js +95 -50
  38. package/dist/context/APIWrapperContext.d.ts +10 -14
  39. package/dist/context/APIWrapperContext.js +1 -1
  40. package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
  41. package/dist/context/Form.d.ts +1 -1
  42. package/dist/context/FormContext.d.ts +0 -1
  43. package/dist/context/Overlays.d.ts +1 -1
  44. package/dist/styles/layout.d.ts +1 -1
  45. package/dist/styles/theme.d.ts +1 -1
  46. package/dist/utils.d.ts +37 -14
  47. package/package.json +7 -6
  48. package/dist/components/DialogJSONSchemaForm.d.ts +0 -13
  49. package/dist/components/DialogJSONSchemaForm.js +0 -20
@@ -4,5 +4,5 @@ type FConfirmDialogProps = {
4
4
  onClose: (p: any) => void;
5
5
  onConfirm: (p: any) => void;
6
6
  };
7
- export declare const ConfirmDialog: React.MemoExoticComponent<({ open, onClose, onConfirm }: FConfirmDialogProps) => JSX.Element>;
7
+ export declare const ConfirmDialog: React.MemoExoticComponent<({ open, onClose, onConfirm }: FConfirmDialogProps) => React.JSX.Element>;
8
8
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { BulkDeleteData, BulkUpdateData, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions } from '../../utils';
3
3
  type CustomToolbarProps = {
4
4
  preparedColumns: GridEnrichedBySchemaColDef[];
@@ -12,16 +12,7 @@ type CustomToolbarProps = {
12
12
  /**
13
13
  *
14
14
  *
15
- * @param {CustomToolbarProps} {
16
- * preparedColumns,
17
- * setPreparedColumns,
18
- * onSelectActions,
19
- * selectionModel,
20
- * bulkUpdateData,
21
- * bulkDeleteData,
22
- * bulkCreateData,
23
- * }
24
15
  * @returns Custom Toolbar for the grid
25
16
  */
26
- export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }: CustomToolbarProps) => JSX.Element;
17
+ export declare const CustomToolbar: ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }: CustomToolbarProps) => React.JSX.Element;
27
18
  export {};
@@ -38,15 +38,6 @@ const utils_1 = require("./utils");
38
38
  /**
39
39
  *
40
40
  *
41
- * @param {CustomToolbarProps} {
42
- * preparedColumns,
43
- * setPreparedColumns,
44
- * onSelectActions,
45
- * selectionModel,
46
- * bulkUpdateData,
47
- * bulkDeleteData,
48
- * bulkCreateData,
49
- * }
50
41
  * @returns Custom Toolbar for the grid
51
42
  */
52
43
  const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, selectionModel, bulkUpdateData, bulkDeleteData, bulkCreateData, }) => {
@@ -90,9 +81,9 @@ const CustomToolbar = ({ preparedColumns, setPreparedColumns, onSelectActions, s
90
81
  }
91
82
  selectAction.action(selectionModel, bulkUpdateData);
92
83
  } }, selectAction.title)))))),
93
- react_1.default.createElement(x_data_grid_1.GridToolbarColumnsButton, { sx: { ml: '10px', fontSize: '13px' } }),
94
- react_1.default.createElement(x_data_grid_1.GridToolbarFilterButton, { sx: { ml: '10px', fontSize: '13px' } }),
95
- react_1.default.createElement(x_data_grid_1.GridToolbarDensitySelector, { sx: { ml: '10px', fontSize: '13px' } }),
84
+ react_1.default.createElement(x_data_grid_1.GridToolbarColumnsButton, { sx: { ml: '10px', fontSize: '13px' }, placeholder: '' }),
85
+ react_1.default.createElement(x_data_grid_1.GridToolbarFilterButton, { sx: { ml: '10px', fontSize: '13px' }, placeholder: '' }),
86
+ react_1.default.createElement(x_data_grid_1.GridToolbarDensitySelector, { sx: { ml: '10px', fontSize: '13px' }, placeholder: '' }),
96
87
  react_1.default.createElement(Button_1.default, { onClick: openResizeMenu, sx: { ml: '0px', fontSize: '13px' } },
97
88
  react_1.default.createElement(Expand_1.default, { sx: { transform: 'rotate(90deg)', mr: '6px' } }),
98
89
  "Ajustar"),
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  type FooterToolbarProps = {
3
3
  isEditable: boolean;
4
4
  handleAddItem: () => void;
5
5
  };
6
- export declare const FooterToolbar: ({ isEditable, handleAddItem }: FooterToolbarProps) => JSX.Element;
6
+ export declare const FooterToolbar: ({ isEditable, handleAddItem }: FooterToolbarProps) => React.JSX.Element;
7
7
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { CalendarPickerView } from '@mui/x-date-pickers/CalendarPicker';
3
3
  type GridDateInputProps = {
4
4
  field: string;
@@ -7,5 +7,5 @@ type GridDateInputProps = {
7
7
  column: object;
8
8
  dateViews?: CalendarPickerView[] | undefined;
9
9
  };
10
- export declare const GridDateInput: ({ id, value, field, dateViews, }: GridDateInputProps) => JSX.Element;
10
+ export declare const GridDateInput: ({ id, value, field, dateViews, }: GridDateInputProps) => React.JSX.Element;
11
11
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  type GridDecimalInputProps = {
3
3
  field: string;
4
4
  id: number | string;
@@ -9,5 +9,5 @@ type GridDecimalInputProps = {
9
9
  suffix?: string;
10
10
  isCurrency?: boolean;
11
11
  };
12
- export declare const GridDecimalInput: ({ id, value, field, decimalPlaces, prefix, suffix, isCurrency, }: GridDecimalInputProps) => JSX.Element;
12
+ export declare const GridDecimalInput: ({ id, value, field, decimalPlaces, prefix, suffix, isCurrency, }: GridDecimalInputProps) => React.JSX.Element;
13
13
  export {};
@@ -1,9 +1,9 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  type GridPatternInputProps = {
3
3
  field: string;
4
4
  id: number | string;
5
- value?: any;
5
+ value?: string | number | null;
6
6
  patternFormat?: string;
7
7
  };
8
- export declare const GridPatternInput: ({ id, value, field, patternFormat }: GridPatternInputProps) => JSX.Element;
8
+ export declare const GridPatternInput: ({ id, value, field, patternFormat, }: GridPatternInputProps) => React.JSX.Element;
9
9
  export {};
@@ -17,13 +17,13 @@ const react_1 = __importDefault(require("react"));
17
17
  const x_data_grid_1 = require("@mui/x-data-grid");
18
18
  const react_number_format_1 = require("react-number-format");
19
19
  const TextField_1 = __importDefault(require("@mui/material/TextField"));
20
- const GridPatternInput = ({ id, value, field, patternFormat = 'cpf' }) => {
20
+ const GridPatternInput = ({ id, value, field, patternFormat = 'cpf', }) => {
21
21
  const apiRef = (0, x_data_grid_1.useGridApiContext)();
22
22
  const handleChange = (newValue) => __awaiter(void 0, void 0, void 0, function* () {
23
23
  yield apiRef.current.setEditCellValue({ id, field, value: newValue });
24
24
  apiRef.current.stopCellEditMode({ id, field });
25
25
  });
26
- return (react_1.default.createElement(react_number_format_1.PatternFormat, { key: field, id: field, onValueChange: (values, sourceInfo) => {
26
+ return (react_1.default.createElement(react_number_format_1.PatternFormat, { key: field, id: field, onValueChange: (values) => {
27
27
  handleChange(values.value);
28
28
  }, value: value, valueIsNumericString: true, format: patternFormat, mask: "_", customInput: TextField_1.default }));
29
29
  };
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
2
- export declare const InputNumberInterval: (props: any) => JSX.Element;
3
- export declare const InputDateInterval: (props: any) => JSX.Element;
4
- export declare const InputFloatInterval: (props: any) => JSX.Element;
1
+ import React from 'react';
2
+ export declare const InputNumberInterval: (props: any) => React.JSX.Element;
3
+ export declare const InputDateInterval: (props: any) => React.JSX.Element;
4
+ export declare const InputFloatInterval: (props: any) => React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { GridApi } from '@mui/x-data-grid';
2
+ import { GridApi, GridFilterOperator } from '@mui/x-data-grid';
3
3
  import { GridEnrichedBySchemaColDef } from '../../utils';
4
4
  export type ResizeType = 'condense' | 'maxContent' | 'fitScreen';
5
5
  /**
@@ -12,4 +12,4 @@ export type ResizeType = 'condense' | 'maxContent' | 'fitScreen';
12
12
  export declare function resizeColumns(columns: GridEnrichedBySchemaColDef[], resizeType: ResizeType, apiRef: React.MutableRefObject<GridApi>): GridEnrichedBySchemaColDef[];
13
13
  export declare const quantityOnlyOperators: ({ type }: {
14
14
  type: string;
15
- }) => GridFilterOperator[];
15
+ }) => GridFilterOperator<any, any, any>[];
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions } from '../utils';
2
+ import { GridRowId, GridRenderCellParams } from '@mui/x-data-grid';
3
3
  import { SxProps } from '@mui/material';
4
+ import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions, OptionsAC } from '../utils';
4
5
  import { OnEditModelType } from '../context/APIWrapperContext';
5
6
  interface DataGridBySchemaEditableProps {
6
7
  schema: SchemaType;
@@ -22,11 +23,11 @@ interface DataGridBySchemaEditableProps {
22
23
  loading?: boolean;
23
24
  modelParentId?: Id;
24
25
  modelParent?: string;
25
- customColumnOperations?: (p: any) => GridEnrichedBySchemaColDef;
26
- customLinkDestination?: (p: any) => string;
26
+ customColumnOperations?: (p: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef | Promise<GridEnrichedBySchemaColDef>;
27
+ customLinkDestination?: (p: GridRenderCellParams) => string;
27
28
  LinkComponent?: any;
28
- onProcessRow?: (p: any) => void;
29
- onDataChange?: (p: any) => void;
29
+ onProcessRow?: (p: Item) => void;
30
+ onDataChange?: (p: Item[]) => void;
30
31
  onEditModel?: (p: OnEditModelType) => void;
31
32
  isEditable?: boolean;
32
33
  hasBulkSelect?: boolean;
@@ -35,14 +36,14 @@ interface DataGridBySchemaEditableProps {
35
36
  isAutoHeight?: boolean;
36
37
  defaultValues?: Item;
37
38
  hideFooterPagination?: boolean;
38
- setVisibleRows?: (p: any) => void;
39
+ setVisibleRows?: (p: GridRowId[]) => void;
39
40
  paginationModel?: PaginationModel;
40
41
  setPaginationModel?: (x: PaginationModel) => void;
41
42
  hideFooterComponent?: boolean;
42
43
  hideToolbarComponent?: boolean;
43
44
  tableAutoHeight?: boolean;
44
45
  actions?: Partial<ActionType>[];
45
- optionsAC?: Record<string, Item[]>;
46
+ optionsAC?: OptionsAC;
46
47
  }
47
48
  declare const DataGridBySchemaEditable: React.ForwardRefExoticComponent<DataGridBySchemaEditableProps & React.RefAttributes<unknown>>;
48
49
  export default DataGridBySchemaEditable;
@@ -31,17 +31,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
45
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
36
  };
@@ -59,6 +48,7 @@ const Check_1 = __importDefault(require("@mui/icons-material/Check"));
59
48
  const Undo_1 = __importDefault(require("@mui/icons-material/Undo"));
60
49
  const Snackbar_1 = __importDefault(require("@mui/material/Snackbar"));
61
50
  const Alert_1 = __importDefault(require("@mui/material/Alert"));
51
+ const string_mask_1 = __importDefault(require("string-mask"));
62
52
  const styles_1 = require("../styles");
63
53
  const api_1 = require("../api");
64
54
  const utils_1 = require("../utils");
@@ -73,9 +63,7 @@ const BooleanInputCell_1 = require("./DataGridBySchemaEditable/BooleanInputCell"
73
63
  const FooterToolbar_1 = require("./DataGridBySchemaEditable/FooterToolbar");
74
64
  const ConfirmDialog_1 = require("./DataGridBySchemaEditable/ConfirmDialog");
75
65
  const APIWrapperContext_1 = require("../context/APIWrapperContext");
76
- const stringMask = require('string-mask');
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, 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"]);
66
+ const DataGridBySchemaEditable = (0, react_1.forwardRef)(({ schema, data, rowCount = 0, columns, model, 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, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], optionsAC: optionsACExternal, }, ref) => {
79
67
  const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
80
68
  const apiContext = (0, APIWrapperContext_1.useAPIWrapper)();
81
69
  const initialSnackBar = {
@@ -89,7 +77,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
89
77
  });
90
78
  const [preparedColumns, setPreparedColumns] = (0, react_1.useState)(null);
91
79
  const [dataGridLoading, setDataGridLoading] = (0, react_1.useState)(false);
92
- const [rowModesModel, setRowModesModel] = (0, react_1.useState)({});
80
+ const [rowModesModel, setRowModesModel] = (0, react_1.useState)();
93
81
  const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
94
82
  const [selectionModel, setSelectionModel] = (0, react_1.useState)([]);
95
83
  const [selectionModelIds, setSelectionModelIds] = (0, react_1.useState)([]);
@@ -141,30 +129,56 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
141
129
  }
142
130
  }
143
131
  });
144
- const initColumns = () => {
132
+ const initColumns = () => __awaiter(void 0, void 0, void 0, function* () {
145
133
  let cols = [];
146
134
  if (isEditable) {
135
+ const handleSaveClick = (id) => () => {
136
+ if (id) {
137
+ setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.View } }));
138
+ }
139
+ };
140
+ const handleCancelClick = (id) => () => {
141
+ if (id) {
142
+ setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.View, ignoreModifications: true } }));
143
+ }
144
+ setDataGrid((currentDataGrid) => {
145
+ const editedRow = currentDataGrid.data.find((row) => row.id === id);
146
+ if (editedRow && editedRow.isNew) {
147
+ return Object.assign(Object.assign({}, currentDataGrid), { data: currentDataGrid.data.filter((row) => row.id !== id) });
148
+ }
149
+ return currentDataGrid;
150
+ });
151
+ };
152
+ const handleEditInlineClick = (id) => () => {
153
+ if (id) {
154
+ setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.Edit } }));
155
+ }
156
+ };
147
157
  cols.push({
148
158
  field: 'actions',
149
159
  headerName: '',
150
160
  type: 'actions',
151
161
  getActions: ({ id }) => {
152
- var _a;
153
- const isInEditMode = ((_a = rowModesModel[id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit;
162
+ if (!id) {
163
+ return [];
164
+ }
165
+ const isInEditMode = rowModesModel &&
166
+ rowModesModel[id] &&
167
+ rowModesModel[id].mode === x_data_grid_1.GridRowModes.Edit;
154
168
  if (isInEditMode) {
155
169
  return [
156
- react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `save_${id}`, icon: react_1.default.createElement(Check_1.default, null), label: "Salvar", onClick: handleSaveClick(id), color: "success", onResize: () => null, onResizeCapture: () => null, showInMenu: false }),
157
- react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `cancel_${id}`, icon: react_1.default.createElement(Undo_1.default, null), label: "Cancelar", onClick: handleCancelClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false }),
170
+ react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `save_${id}`, icon: react_1.default.createElement(Check_1.default, null), label: "Salvar", onClick: handleSaveClick(id), color: "success", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' }),
171
+ react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `cancel_${id}`, icon: react_1.default.createElement(Undo_1.default, null), label: "Cancelar", onClick: handleCancelClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' }),
158
172
  ];
159
173
  }
160
174
  const actionItems = [];
161
175
  actions.map((action) => {
162
176
  switch (action) {
163
177
  case 'editInline':
164
- actionItems.push(react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `editInline_${id}`, icon: actions.includes('edit') ? (react_1.default.createElement(Bolt_1.default, null)) : (react_1.default.createElement(Edit_1.default, null)), label: "Edit inline", onClick: handleEditInlineClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false }));
178
+ actionItems.push(react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `editInline_${id}`, icon: actions.includes('edit') ? (react_1.default.createElement(Bolt_1.default, null)) : (react_1.default.createElement(Edit_1.default, null)), label: "Edit inline", onClick: handleEditInlineClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' }));
165
179
  break;
166
180
  case 'remove':
167
- actionItems.push(react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `remove_${id}`, icon: react_1.default.createElement(Clear_1.default, null), label: "Delete", onClick: handleDeleteClick(id), color: "error", onResize: () => null, onResizeCapture: () => null, showInMenu: false }));
181
+ actionItems.push(react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `remove_${id}`, icon: react_1.default.createElement(Clear_1.default, null), label: "Delete", onClick: handleDeleteClick(id), color: "error", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' }));
168
182
  break;
169
183
  case 'edit':
170
184
  if (!LinkComponent) {
@@ -172,7 +186,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
172
186
  break;
173
187
  }
174
188
  actionItems.push(react_1.default.createElement(LinkComponent, { key: `edit_${id}`, to: `${indexFieldBasePath}${id}`, state: stateToLink },
175
- react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { icon: react_1.default.createElement(Edit_1.default, null), label: "Edit", color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false })));
189
+ react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { icon: react_1.default.createElement(Edit_1.default, null), label: "Edit", color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' })));
176
190
  break;
177
191
  case 'view':
178
192
  if (!LinkComponent) {
@@ -184,7 +198,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
184
198
  break;
185
199
  }
186
200
  actionItems.push(react_1.default.createElement(LinkComponent, { key: `view_${id}`, to: `${indexFieldViewBasePath}${id}`, state: stateToLink },
187
- react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { icon: react_1.default.createElement(Visibility_1.default, null), label: "View", color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false })));
201
+ react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { icon: react_1.default.createElement(Visibility_1.default, null), label: "View", color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' })));
188
202
  break;
189
203
  }
190
204
  });
@@ -193,7 +207,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
193
207
  });
194
208
  }
195
209
  cols = [...cols, ...columns];
196
- cols = cols.map((col) => {
210
+ const colsPromises = cols.map((col) => __awaiter(void 0, void 0, void 0, function* () {
197
211
  if (!schema[col.field]) {
198
212
  return col;
199
213
  }
@@ -373,7 +387,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
373
387
  if (!params.value || typeof params.value !== 'string') {
374
388
  return params.value;
375
389
  }
376
- const formattedValue = new stringMask(column.patternFormat, {}).apply(params.value);
390
+ const formattedValue = new string_mask_1.default(column.patternFormat, {}).apply(params.value);
377
391
  return formattedValue;
378
392
  };
379
393
  if (isEditable && !col.disabled) {
@@ -382,20 +396,23 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
382
396
  }
383
397
  // Custom column operations:
384
398
  if (customColumnOperations) {
385
- column = customColumnOperations(column);
399
+ column = yield customColumnOperations(column);
386
400
  }
387
401
  // Finally!
388
402
  return column;
389
- });
403
+ }));
404
+ cols = yield Promise.all(colsPromises);
390
405
  setPreparedColumns(cols);
391
- };
406
+ });
392
407
  const handleAddItems = (numberOfRows = 1) => {
393
408
  const newRows = [];
394
409
  for (let i = 0; i < numberOfRows; i++) {
395
410
  const id = (0, utils_1.getTmpId)();
396
411
  newRows.push(Object.assign(Object.assign({}, emptyItem.current), { id }));
397
412
  }
398
- const newData = [...newRows, ...dataGrid.data];
413
+ const newData = tableAutoHeight
414
+ ? [...dataGrid.data, ...newRows]
415
+ : [...newRows, ...dataGrid.data];
399
416
  setDataGrid({
400
417
  data: newData,
401
418
  });
@@ -406,14 +423,16 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
406
423
  });
407
424
  return newModel;
408
425
  });
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(() => {
426
+ if (!tableAutoHeight) {
427
+ // Ugly hack to scroll to top, since scroll to cell is only available in Pro
428
+ const el = document.querySelector(`.dataGrid_${name} .MuiDataGrid-virtualScroller`);
429
+ // console.log(el, name);
430
+ if (el) {
415
431
  el.scrollTop = 0;
416
- }, 10);
432
+ setTimeout(() => {
433
+ el.scrollTop = 0;
434
+ }, 10);
435
+ }
417
436
  }
418
437
  };
419
438
  const bulkUpdateData = (newData) => __awaiter(void 0, void 0, void 0, function* () {
@@ -443,7 +462,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
443
462
  return results.map((result, index) => {
444
463
  return {
445
464
  id: ids[index],
446
- success: typeof result !== 'object' && !isNaN(parseInt(result)),
465
+ success: 'isAxiosError' in result,
447
466
  };
448
467
  });
449
468
  });
@@ -468,7 +487,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
468
487
  return results.map((result, index) => {
469
488
  return {
470
489
  id: ids[index],
471
- success: result,
490
+ success: result === true,
472
491
  };
473
492
  });
474
493
  });
@@ -485,18 +504,6 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
485
504
  const handleDialogClose = () => {
486
505
  setDialogOpen(false);
487
506
  };
488
- const handleRowEditStart = (params, event) => {
489
- event.defaultMuiPrevented = true;
490
- };
491
- const handleRowEditStop = (params, event) => {
492
- event.defaultMuiPrevented = true;
493
- };
494
- const handleEditInlineClick = (id) => () => {
495
- setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.Edit } }));
496
- };
497
- const handleSaveClick = (id) => () => {
498
- setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.View } }));
499
- };
500
507
  const handleDeleteClick = (id) => () => {
501
508
  idToRemove.current = id;
502
509
  setDialogOpen(true);
@@ -523,13 +530,6 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
523
530
  idToRemove.current = null;
524
531
  setDialogOpen(false);
525
532
  };
526
- const handleCancelClick = (id) => () => {
527
- setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.View, ignoreModifications: true } }));
528
- const editedRow = dataGrid.data.find((row) => row.id === id);
529
- if (editedRow && editedRow.isNew) {
530
- setDataGrid(Object.assign(Object.assign({}, dataGrid), { data: dataGrid.data.filter((row) => row.id !== id) }));
531
- }
532
- };
533
533
  (0, react_1.useEffect)(() => {
534
534
  if (!columns) {
535
535
  setDataGrid({ data: [] });
@@ -571,42 +571,42 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
571
571
  updateOptionsAC().then(() => {
572
572
  initColumns();
573
573
  });
574
- }, [rowModesModel, columns]);
575
- const processRowUpdate = (newRow) => __awaiter(void 0, void 0, void 0, function* () {
574
+ }, [rowModesModel]);
575
+ const processRowUpdate = (editedRow) => __awaiter(void 0, void 0, void 0, function* () {
576
576
  if (!preparedColumns || !yupValidationSchema.current) {
577
577
  return false;
578
578
  }
579
579
  setDataGridLoading(true);
580
580
  const indexCol = preparedColumns.find((col) => col.field === indexField);
581
- processingRow.current = newRow.id;
582
- yield yupValidationSchema.current.validate(newRow);
581
+ processingRow.current = editedRow.id;
582
+ yield yupValidationSchema.current.validate(editedRow);
583
583
  const onlyAddExisting = indexField &&
584
- (0, utils_1.isTmpId)(newRow.id) &&
585
- newRow[indexField] &&
586
- !(0, utils_1.isTmpId)(newRow[indexField].id) &&
584
+ (0, utils_1.isTmpId)(editedRow.id) &&
585
+ editedRow[indexField] &&
586
+ !(0, utils_1.isTmpId)(editedRow[indexField].id) &&
587
587
  (!indexCol || !indexCol.valueFormatter);
588
588
  const createNewItem = indexField &&
589
- (0, utils_1.isTmpId)(newRow.id) &&
590
- newRow[indexField] &&
591
- (0, utils_1.isTmpId)(newRow[indexField].id);
589
+ (0, utils_1.isTmpId)(editedRow.id) &&
590
+ editedRow[indexField] &&
591
+ (0, utils_1.isTmpId)(editedRow[indexField].id);
592
592
  if (onlyAddExisting) {
593
593
  const row = {};
594
- row.id_to_add = newRow[indexField].id;
595
- for (const [key, value] of Object.entries(newRow[indexField])) {
594
+ row.id_to_add = editedRow[indexField].id;
595
+ for (const [key, value] of Object.entries(editedRow[indexField])) {
596
596
  if (key === 'id') {
597
- row[key] = newRow.id;
597
+ row[key] = editedRow.id;
598
598
  continue;
599
599
  }
600
600
  row[key] = value;
601
601
  }
602
- newRow = Object.assign({}, row);
602
+ editedRow = Object.assign({}, row);
603
603
  }
604
- if (createNewItem && newRow[indexField]) {
605
- if (newRow[indexField].inputValue) {
606
- newRow[indexField] = newRow[indexField].inputValue;
604
+ if (createNewItem && editedRow[indexField]) {
605
+ if (editedRow[indexField].inputValue) {
606
+ editedRow[indexField] = editedRow[indexField].inputValue;
607
607
  }
608
608
  if (addExistingModel) {
609
- newRow[indexField] = newRow[indexField].label;
609
+ editedRow[indexField] = editedRow[indexField].label;
610
610
  }
611
611
  }
612
612
  if (modelParent && modelParentId && apiContext) {
@@ -614,23 +614,20 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
614
614
  model: modelParent,
615
615
  id: modelParentId,
616
616
  relatedModel: model,
617
- relatedModelId: newRow.id,
618
- newRow,
617
+ relatedModelId: editedRow.id,
618
+ newRow: editedRow,
619
619
  schema,
620
620
  onlyAddExisting,
621
621
  });
622
- const responseAsData = response;
623
- if ((onlyAddExisting && typeof response != 'boolean') ||
624
- (parseInt(response) && (createNewItem || !onlyAddExisting))) {
622
+ if (response !== false && (onlyAddExisting || createNewItem || !onlyAddExisting)) {
625
623
  updateOptionsAC();
626
624
  const data = [...dataGrid.data];
625
+ const newRow = 'data' in response && 'schema' in response
626
+ ? response.data
627
+ : response;
627
628
  for (const i in data) {
628
- if (data[i].id === newRow.id) {
629
- data[i] = onlyAddExisting ? responseAsData.data : newRow;
630
- if ((0, utils_1.isTmpId)(newRow.id)) {
631
- const newId = parseInt(response);
632
- data[i].id = newId || responseAsData.data.id;
633
- }
629
+ if (data[i].id === editedRow.id) {
630
+ data[i] = newRow;
634
631
  // This is for cases where users want to do custom operations after saving the row,
635
632
  // like for example make calculations among columns.
636
633
  if (onProcessRow) {
@@ -652,13 +649,32 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
652
649
  }
653
650
  const response = yield apiContext.onEditModelDataGridSave({
654
651
  model,
655
- id: newRow.id,
656
- newRow,
652
+ id: editedRow.id,
653
+ newRow: editedRow,
657
654
  schema,
658
655
  });
656
+ console.log(response);
659
657
  setDataGridLoading(false);
660
- if (response) {
661
- newRow.id = response;
658
+ if (response !== false) {
659
+ updateOptionsAC();
660
+ const data = [...dataGrid.data];
661
+ const newRow = response;
662
+ for (const i in data) {
663
+ if (data[i].id === editedRow.id) {
664
+ data[i] = newRow;
665
+ // This is for cases where users want to do custom operations after saving the row,
666
+ // like for example make calculations among columns.
667
+ if (onProcessRow) {
668
+ onProcessRow(data[i]);
669
+ }
670
+ // Reflect the changes to the outside, for example for global calculations over all data
671
+ if (onDataChange) {
672
+ onDataChange(data);
673
+ }
674
+ setDataGrid({ data });
675
+ break;
676
+ }
677
+ }
662
678
  return newRow;
663
679
  }
664
680
  return false;
@@ -700,21 +716,24 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
700
716
  return 'auto';
701
717
  }
702
718
  return null;
703
- }, isCellEditable: (params) => {
704
- var _a;
705
- return (((_a = rowModesModel[params.row.id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit &&
706
- (!(0, utils_1.isTmpId)(params.row.id) ||
707
- ((0, utils_1.isTmpId)(params.row.id) &&
708
- (params.field === indexField ||
709
- !optionsAC.current ||
710
- !Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
711
- (preparedColumns.find((col) => col.field === indexField) &&
712
- Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter'))))));
713
- }, checkboxSelection: checkboxSelection, onSelectionModelChange: (newSelectionModel) => {
719
+ }, isCellEditable: (params) => (rowModesModel &&
720
+ rowModesModel[params.row.id] &&
721
+ rowModesModel[params.row.id].mode === x_data_grid_1.GridRowModes.Edit &&
722
+ (!(0, utils_1.isTmpId)(params.row.id) ||
723
+ ((0, utils_1.isTmpId)(params.row.id) &&
724
+ (params.field === indexField ||
725
+ !optionsAC.current ||
726
+ !Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
727
+ (preparedColumns.find((col) => col.field === indexField) &&
728
+ Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter')))))), checkboxSelection: checkboxSelection, onSelectionModelChange: (newSelectionModel) => {
714
729
  const selectedData = dataGrid.data.filter((item) => newSelectionModel.includes(item.id));
715
730
  setSelectionModel(selectedData);
716
731
  setSelectionModelIds(newSelectionModel);
717
- }, selectionModel: selectionModelIds, disableRowSelectionOnClick: disableRowSelectionOnClick, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
732
+ }, selectionModel: selectionModelIds, disableSelectionOnClick: disableRowSelectionOnClick, rowModesModel: rowModesModel, onRowEditStart: (params, event) => {
733
+ event.defaultMuiPrevented = true;
734
+ }, onRowEditStop: (params, event) => {
735
+ event.defaultMuiPrevented = true;
736
+ }, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
718
737
  setDataGridLoading(false);
719
738
  if (processingRow.current) {
720
739
  setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: {
@@ -737,10 +756,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
737
756
  setPreparedColumns,
738
757
  showQuickFilter: true,
739
758
  quickFilterProps: { debounceMs: 500 },
740
- getRowsToExport: (e) => {
741
- console.log(e);
742
- return [];
743
- },
759
+ // getRowsToExport: () => {
760
+ // return [];
761
+ // },
744
762
  selectionModel,
745
763
  onSelectActions,
746
764
  bulkUpdateData,
@@ -749,7 +767,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
749
767
  },
750
768
  footer: {
751
769
  isEditable,
752
- handleAddItem: handleAddItems,
770
+ handleAddItem: () => {
771
+ handleAddItems();
772
+ },
753
773
  },
754
774
  filterPanel: {
755
775
  sx: {