drf-react-by-schema 0.5.3 → 0.6.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.
@@ -71,9 +71,8 @@ const FooterToolbar_1 = require("./DataGridBySchemaEditable/FooterToolbar");
71
71
  const ConfirmDialog_1 = require("./DataGridBySchemaEditable/ConfirmDialog");
72
72
  const APIWrapperContext_1 = require("../context/APIWrapperContext");
73
73
  const stringMask = require('string-mask');
74
- ;
75
74
  const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
76
- var { schema, data, columns, model, fieldKey, labelKey = 'nome', index, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', stateToLink = {}, minWidth = 80, modelParent, modelParentId, customColumnOperations, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows } = _a, other = __rest(_a, ["schema", "data", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "stateToLink", "minWidth", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "onEditModel", "isEditable", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows"]);
75
+ var { schema, data, rowCount = 0, columns, model, fieldKey, labelKey = 'nome', index, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', stateToLink = {}, minWidth = 80, modelParent, modelParentId, customColumnOperations, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined } = _a, other = __rest(_a, ["schema", "data", "rowCount", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "stateToLink", "minWidth", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "onEditModel", "isEditable", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows", "paginationModel", "setPaginationModel"]);
77
76
  const { serverEndPoint } = DRFReactBySchemaContext_1.DRFReactBySchemaContext
78
77
  ? react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext)
79
78
  : { serverEndPoint: null };
@@ -81,10 +80,12 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
81
80
  const initialSnackBar = {
82
81
  open: false,
83
82
  msg: '',
84
- severity: 'info'
83
+ severity: 'info',
85
84
  };
86
85
  const [snackBar, setSnackBar] = (0, react_1.useState)(initialSnackBar);
87
- const [dataGrid, setDataGrid] = (0, react_1.useState)({ data: [] });
86
+ const [dataGrid, setDataGrid] = (0, react_1.useState)({
87
+ data: [],
88
+ });
88
89
  const [preparedColumns, setPreparedColumns] = (0, react_1.useState)(null);
89
90
  const [dataGridLoading, setDataGridLoading] = (0, react_1.useState)(false);
90
91
  const [rowModesModel, setRowModesModel] = (0, react_1.useState)({});
@@ -101,8 +102,12 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
101
102
  if (!schema[col.field]) {
102
103
  continue;
103
104
  }
104
- if (['field', 'nested object'].includes(schema[col.field].type) && !(col.field in optionsAC.current)) {
105
- const options = yield (0, api_1.getAutoComplete)({ model: col.field, serverEndPoint });
105
+ if (['field', 'nested object'].includes(schema[col.field].type) &&
106
+ !(col.field in optionsAC.current)) {
107
+ const options = yield (0, api_1.getAutoComplete)({
108
+ model: col.field,
109
+ serverEndPoint,
110
+ });
106
111
  if (options) {
107
112
  optionsAC.current[col.field] = options;
108
113
  continue;
@@ -115,7 +120,10 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
115
120
  continue;
116
121
  }
117
122
  if (col.field === indexField && addExistingModel && !optionsAC.current[col.field]) {
118
- const options = yield (0, api_1.getAutoComplete)({ model: addExistingModel, serverEndPoint });
123
+ const options = yield (0, api_1.getAutoComplete)({
124
+ model: addExistingModel,
125
+ serverEndPoint,
126
+ });
119
127
  if (options) {
120
128
  optionsAC.current[col.field] = options;
121
129
  continue;
@@ -139,105 +147,112 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
139
147
  if (isInEditMode) {
140
148
  return [
141
149
  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" }),
142
- 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" })
150
+ 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" }),
143
151
  ];
144
152
  }
145
153
  return [
146
154
  react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `edit_${id}`, icon: react_1.default.createElement(Edit_1.default, null), label: "Edit", onClick: handleEditClick(id), color: "inherit" }),
147
- 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" })
155
+ 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" }),
148
156
  ];
149
- }
157
+ },
150
158
  });
151
159
  }
152
160
  cols = [...cols, ...columns];
153
- cols = cols.map(col => {
161
+ cols = cols.map((col) => {
154
162
  if (!schema[col.field]) {
155
163
  return col;
156
164
  }
157
- const isIndexField = (indexField !== '' && (col.field === indexField));
165
+ const isIndexField = indexField !== '' && col.field === indexField;
158
166
  let column = col;
159
167
  if (isIndexField) {
160
168
  col.isIndexField = true;
161
169
  }
162
- column.editable = (isEditable) && (!schema[col.field].read_only || ['field', 'nested object'].includes(schema[col.field].type));
170
+ column.editable =
171
+ isEditable &&
172
+ (!schema[col.field].read_only ||
173
+ ['field', 'nested object'].includes(schema[col.field].type));
174
+ if (['field', 'nested object'].includes(schema[col.field].type)) {
175
+ column.creatable =
176
+ 'related_editable' in schema[col.field]
177
+ ? schema[col.field].related_editable
178
+ : column.creatable;
179
+ }
163
180
  switch (schema[col.field].type) {
164
181
  case 'date':
165
182
  column.type = 'date';
166
- column.valueFormatter = params => params.value
167
- ? (0, moment_1.default)(params.value).format('DD/MM/YYYY')
168
- : '';
169
- column.filterOperators = (0, utils_2.quantityOnlyOperators)({ type: 'date' });
183
+ column.valueFormatter = (params) => params.value ? (0, moment_1.default)(params.value).format('DD/MM/YYYY') : '';
184
+ column.filterOperators = (0, utils_2.quantityOnlyOperators)({
185
+ type: 'date',
186
+ });
170
187
  break;
171
188
  case 'datetime':
172
189
  column.type = 'dateTime';
173
190
  column.minWidth = 180;
174
- column.valueFormatter = params => params.value
175
- ? (0, moment_1.default)(params.value).format('DD/MM/YYYY HH:mm')
176
- : '';
191
+ column.valueFormatter = (params) => params.value ? (0, moment_1.default)(params.value).format('DD/MM/YYYY HH:mm') : '';
177
192
  break;
178
193
  case 'nested object':
179
194
  column.minWidth = 150;
180
195
  if (isEditable) {
181
- column.valueFormatter = params => {
182
- return (!params.value) ? '' : params.value.label;
196
+ column.valueFormatter = (params) => {
197
+ return !params.value ? '' : params.value.label;
183
198
  };
184
199
  column.filterable = false;
185
200
  column.sortComparator = (v1, v2, param1, param2) => {
186
201
  return (0, x_data_grid_1.gridStringOrNumberComparator)(v1.label, v2.label, param1, param2);
187
202
  };
188
- column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, onEditModel: onEditModel }));
203
+ column.renderEditCell = (params) => (react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, onEditModel: onEditModel })));
189
204
  break;
190
205
  }
191
- column.valueGetter = params => {
192
- return (!params.value) ? '' : params.value.label;
206
+ column.valueGetter = (params) => {
207
+ return !params.value ? '' : params.value.label;
193
208
  };
194
209
  break;
195
210
  case 'field':
196
211
  column.orderable = false;
197
212
  if (isEditable) {
198
213
  column.minWidth = 300;
199
- column.valueFormatter = params => {
200
- return (!params.value || !Array.isArray(params.value))
214
+ column.valueFormatter = (params) => {
215
+ return !params.value || !Array.isArray(params.value)
201
216
  ? ''
202
- : params.value.map(val => val.label).join(', ');
217
+ : params.value.map((val) => val.label).join(', ');
203
218
  };
204
219
  column.filterable = false;
205
- column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, multiple: schema[col.field].many || false }));
220
+ column.renderEditCell = (params) => (react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, multiple: schema[col.field].many || false })));
206
221
  break;
207
222
  }
208
- column.valueGetter = params => {
209
- return (!params.value || !Array.isArray(params.value))
223
+ column.valueGetter = (params) => {
224
+ return !params.value || !Array.isArray(params.value)
210
225
  ? ''
211
- : params.value.map(val => val.label).join(', ');
226
+ : params.value.map((val) => val.label).join(', ');
212
227
  };
213
228
  break;
214
229
  case 'choice':
215
230
  if (isEditable) {
216
231
  column.minWidth = 150;
217
- column.valueFormatter = params => {
218
- return (!params.value) ? '' : params.value.display_name;
232
+ column.valueFormatter = (params) => {
233
+ return !params.value ? '' : params.value.display_name;
219
234
  };
220
235
  column.filterable = false;
221
236
  column.sortComparator = (v1, v2, param1, param2) => {
222
237
  return (0, x_data_grid_1.gridStringOrNumberComparator)(v1.display_name, v2.display_name, param1, param2);
223
238
  };
224
- column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField }));
239
+ column.renderEditCell = (params) => (react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField })));
225
240
  break;
226
241
  }
227
- column.valueGetter = params => {
228
- return (!params.value) ? '' : params.value.display_name;
242
+ column.valueGetter = (params) => {
243
+ return !params.value ? '' : params.value.display_name;
229
244
  };
230
245
  break;
231
246
  case 'boolean':
232
247
  if (isEditable) {
233
- column.valueFormatter = params => {
234
- return (params.value) ? 'Sim' : 'Não';
248
+ column.valueFormatter = (params) => {
249
+ return params.value ? 'Sim' : 'Não';
235
250
  };
236
- column.renderEditCell = (params) => react_1.default.createElement(BooleanInputCell_1.BooleanInputCell, Object.assign({}, params, { column: column }));
251
+ column.renderEditCell = (params) => (react_1.default.createElement(BooleanInputCell_1.BooleanInputCell, Object.assign({}, params, { column: column })));
237
252
  break;
238
253
  }
239
- column.valueGetter = params => {
240
- return (params.value) ? 'Sim' : 'Não';
254
+ column.valueGetter = (params) => {
255
+ return params.value ? 'Sim' : 'Não';
241
256
  };
242
257
  break;
243
258
  case 'decimal':
@@ -247,32 +262,36 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
247
262
  const suffix = schema[col.field].suffix || '';
248
263
  const isCurrency = schema[col.field].is_currency;
249
264
  column.type = 'number';
250
- column.valueFormatter = params => {
251
- return (!params.value)
265
+ column.valueFormatter = (params) => {
266
+ return !params.value
252
267
  ? ''
253
268
  : parseFloat(params.value).toLocaleString('pt-BR', {
254
269
  minimumFractionDigits: decimalScale,
255
- maximumFractionDigits: decimalScale
270
+ maximumFractionDigits: decimalScale,
256
271
  });
257
272
  };
258
273
  if (isEditable) {
259
- column.renderEditCell = (params) => react_1.default.createElement(GridDecimalInput_1.GridDecimalInput, Object.assign({}, params, { decimalScale: decimalScale, isCurrency: isCurrency, prefix: prefix, suffix: suffix, column: column }));
274
+ column.renderEditCell = (params) => (react_1.default.createElement(GridDecimalInput_1.GridDecimalInput, Object.assign({}, params, { decimalPlaces: decimalScale, isCurrency: isCurrency, prefix: prefix, suffix: suffix, column: column })));
260
275
  }
261
- column.filterOperators = (0, utils_2.quantityOnlyOperators)({ type: 'float' });
276
+ column.filterOperators = (0, utils_2.quantityOnlyOperators)({
277
+ type: 'float',
278
+ });
262
279
  break;
263
280
  case 'number':
264
281
  case 'integer':
265
282
  column.type = 'number';
266
- column.filterOperators = (0, utils_2.quantityOnlyOperators)({ type: 'number' });
283
+ column.filterOperators = (0, utils_2.quantityOnlyOperators)({
284
+ type: 'number',
285
+ });
267
286
  break;
268
287
  }
269
288
  if (indexFieldMinWidth && !column.minWidth) {
270
- column.minWidth = (col.field === indexField) ? indexFieldMinWidth : minWidth;
289
+ column.minWidth = col.field === indexField ? indexFieldMinWidth : minWidth;
271
290
  }
272
291
  if (indexField) {
273
292
  if (col.field === indexField) {
274
293
  column.flex = 1;
275
- column.renderCell = params => {
294
+ column.renderCell = (params) => {
276
295
  if (LinkComponent && customLinkDestination) {
277
296
  return (react_1.default.createElement(LinkComponent, { to: `${customLinkDestination(params)}`, state: stateToLink }, params.formattedValue));
278
297
  }
@@ -280,9 +299,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
280
299
  !indexFieldBasePath ||
281
300
  (['field', 'nested object'].includes(schema[col.field].type) &&
282
301
  (!params.row[col.field] || !params.row[col.field].id))) {
283
- return (react_1.default.createElement(react_1.default.Fragment, null, params.formattedValue));
302
+ return react_1.default.createElement(react_1.default.Fragment, null, params.formattedValue);
284
303
  }
285
- const targetId = (['field', 'nested object'].includes(schema[col.field].type))
304
+ const targetId = ['field', 'nested object'].includes(schema[col.field].type)
286
305
  ? params.row[col.field].id.toString()
287
306
  : params.row.id.toString();
288
307
  return (react_1.default.createElement(LinkComponent, { to: `${indexFieldBasePath}${targetId}`, state: stateToLink }, params.formattedValue));
@@ -293,7 +312,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
293
312
  addExistingModel) {
294
313
  column.renderEditCell = (params) => {
295
314
  if (!(0, utils_1.isTmpId)(params.id)) {
296
- return (react_1.default.createElement(x_data_grid_1.GridEditInputCell, Object.assign({}, params)));
315
+ return react_1.default.createElement(x_data_grid_1.GridEditInputCell, Object.assign({}, params));
297
316
  }
298
317
  return (react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: true })));
299
318
  };
@@ -306,7 +325,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
306
325
  }
307
326
  // format numbers:
308
327
  if (column.patternFormat) {
309
- column.valueFormatter = params => {
328
+ column.valueFormatter = (params) => {
310
329
  if (!params.value || typeof params.value !== 'string') {
311
330
  return params.value;
312
331
  }
@@ -314,7 +333,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
314
333
  return formattedValue;
315
334
  };
316
335
  if (isEditable) {
317
- column.renderEditCell = params => react_1.default.createElement(GridPatternInput_1.GridPatternInput, Object.assign({}, params, { patternFormat: column.patternFormat }));
336
+ column.renderEditCell = (params) => (react_1.default.createElement(GridPatternInput_1.GridPatternInput, Object.assign({}, params, { patternFormat: column.patternFormat })));
318
337
  }
319
338
  }
320
339
  // Finally!
@@ -346,14 +365,14 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
346
365
  setDialogOpen(false);
347
366
  return;
348
367
  }
349
- const newData = dataGrid.data.filter(row => row.id !== idToRemove.current);
368
+ const newData = dataGrid.data.filter((row) => row.id !== idToRemove.current);
350
369
  setDataGrid(Object.assign(Object.assign({}, dataGrid), { data: newData }));
351
370
  if (modelParent && modelParentId && apiContext) {
352
371
  apiContext.onDeleteRelatedModel({
353
372
  model: modelParent,
354
373
  id: modelParentId,
355
374
  relatedModel: model,
356
- relatedModelId: idToRemove.current
375
+ relatedModelId: idToRemove.current,
357
376
  });
358
377
  }
359
378
  // Reflect changes to the outside, for example for doing global calculations over multiple rows:
@@ -365,9 +384,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
365
384
  };
366
385
  const handleCancelClick = (id) => () => {
367
386
  setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [id]: { mode: x_data_grid_1.GridRowModes.View, ignoreModifications: true } }));
368
- const editedRow = dataGrid.data.find(row => row.id === id);
387
+ const editedRow = dataGrid.data.find((row) => row.id === id);
369
388
  if (editedRow && editedRow.isNew) {
370
- setDataGrid(Object.assign(Object.assign({}, dataGrid), { data: dataGrid.data.filter(row => row.id !== id) }));
389
+ setDataGrid(Object.assign(Object.assign({}, dataGrid), { data: dataGrid.data.filter((row) => row.id !== id) }));
371
390
  }
372
391
  };
373
392
  (0, react_1.useEffect)(() => {
@@ -385,7 +404,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
385
404
  emptyItem.current[col.field] = defaultValues[col.field];
386
405
  continue;
387
406
  }
388
- emptyItem.current[col.field] = (schema[col.field])
407
+ emptyItem.current[col.field] = schema[col.field]
389
408
  ? (0, utils_1.emptyByType)(schema[col.field])
390
409
  : null;
391
410
  }
@@ -397,10 +416,10 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
397
416
  yupValidationSchema.current = (0, utils_1.buildGenericYupValidationSchema)({
398
417
  data: emptyItem.current,
399
418
  schema,
400
- skipFields
419
+ skipFields,
401
420
  });
402
421
  setDataGrid({
403
- data
422
+ data,
404
423
  });
405
424
  }, [data]);
406
425
  (0, react_1.useEffect)(() => {
@@ -417,14 +436,18 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
417
436
  return false;
418
437
  }
419
438
  setDataGridLoading(true);
420
- const indexCol = preparedColumns.find(col => col.field === indexField);
439
+ const indexCol = preparedColumns.find((col) => col.field === indexField);
421
440
  processingRow.current = newRow.id;
422
441
  yield yupValidationSchema.current.validate(newRow);
423
- const onlyAddExisting = (indexField &&
442
+ const onlyAddExisting = indexField &&
424
443
  (0, utils_1.isTmpId)(newRow.id) &&
425
- (newRow[indexField] && !(0, utils_1.isTmpId)(newRow[indexField].id)) &&
426
- (!indexCol || !indexCol.valueFormatter));
427
- const createNewItem = (indexField && (0, utils_1.isTmpId)(newRow.id) && newRow[indexField] && (0, utils_1.isTmpId)(newRow[indexField].id));
444
+ newRow[indexField] &&
445
+ !(0, utils_1.isTmpId)(newRow[indexField].id) &&
446
+ (!indexCol || !indexCol.valueFormatter);
447
+ const createNewItem = indexField &&
448
+ (0, utils_1.isTmpId)(newRow.id) &&
449
+ newRow[indexField] &&
450
+ (0, utils_1.isTmpId)(newRow[indexField].id);
428
451
  if (onlyAddExisting) {
429
452
  const row = {};
430
453
  row.id_to_add = newRow[indexField].id;
@@ -453,7 +476,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
453
476
  relatedModelId: newRow.id,
454
477
  newRow,
455
478
  schema,
456
- onlyAddExisting
479
+ onlyAddExisting,
457
480
  });
458
481
  const responseAsData = response;
459
482
  if ((onlyAddExisting && typeof response != 'boolean') ||
@@ -487,79 +510,112 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
487
510
  setDataGridLoading(false);
488
511
  return false;
489
512
  });
490
- const customPaddings = (isAutoHeight)
513
+ const customPaddings = isAutoHeight
491
514
  ? {
492
- '&.MuiDataGrid-root--densityCompact .MuiDataGrid-cell': { py: '8px' },
493
- '&.MuiDataGrid-root--densityStandard .MuiDataGrid-cell': { py: '15px' },
494
- '&.MuiDataGrid-root--densityComfortable .MuiDataGrid-cell': { py: '22px' }
515
+ '&.MuiDataGrid-root--densityCompact .MuiDataGrid-cell': {
516
+ py: '8px',
517
+ },
518
+ '&.MuiDataGrid-root--densityStandard .MuiDataGrid-cell': {
519
+ py: '15px',
520
+ },
521
+ '&.MuiDataGrid-root--densityComfortable .MuiDataGrid-cell': {
522
+ py: '22px',
523
+ },
495
524
  }
496
525
  : undefined;
497
526
  return (react_1.default.createElement(Box_1.default, { className: `dataGrid_${name}`, sx: { height: '100%' } },
498
- preparedColumns === null
499
- ? react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBox },
500
- react_1.default.createElement(CircularProgress_1.default, null))
501
- : react_1.default.createElement(x_data_grid_1.DataGrid, { rows: dataGrid.data, columns: preparedColumns, onStateChange: (state) => {
502
- if (setVisibleRows) {
503
- const newVisibleRows = Object.entries(state.filter.visibleRowsLookup)
504
- .filter(entry => { return entry[1] === true; })
505
- .map((entry) => { return entry[0]; });
506
- const newVisibleRowsJSON = JSON.stringify(newVisibleRows);
507
- if (newVisibleRowsJSON !== visibleRows.current) {
508
- setVisibleRows(newVisibleRows);
509
- visibleRows.current = newVisibleRowsJSON;
510
- }
511
- }
512
- }, editMode: "row", loading: dataGridLoading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
513
- if (isAutoHeight) {
514
- return 'auto';
515
- }
516
- return null;
517
- }, isCellEditable: params => {
518
- var _a;
519
- return (((_a = rowModesModel[params.row.id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit &&
520
- (!(0, utils_1.isTmpId)(params.row.id) ||
521
- ((0, utils_1.isTmpId)(params.row.id) &&
522
- (params.field === indexField ||
523
- !optionsAC.current ||
524
- !Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
525
- (preparedColumns.find(col => col.field === indexField) &&
526
- Object.prototype.hasOwnProperty.call(preparedColumns.find(col => col.field === indexField), 'valueFormatter'))))));
527
- }, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
528
- setDataGridLoading(false);
529
- if (processingRow.current) {
530
- setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: { mode: x_data_grid_1.GridRowModes.Edit } }));
531
- }
532
- const msg = `Erro em "${e.path}": ${e.errors}`;
533
- setSnackBar({
534
- open: true,
535
- severity: 'error',
536
- msg
527
+ preparedColumns === null ? (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBox },
528
+ react_1.default.createElement(CircularProgress_1.default, null))) : (react_1.default.createElement(x_data_grid_1.DataGrid, { rows: dataGrid.data, columns: preparedColumns, onStateChange: (state) => {
529
+ if (setVisibleRows) {
530
+ const newVisibleRows = Object.entries(state.filter.visibleRowsLookup)
531
+ .filter((entry) => {
532
+ return entry[1] === true;
533
+ })
534
+ .map((entry) => {
535
+ return entry[0];
537
536
  });
538
- console.log(e);
539
- }, components: { Toolbar: CustomToolbar_1.CustomToolbar, Footer: FooterToolbar_1.FooterToolbar }, componentsProps: {
540
- toolbar: {
541
- preparedColumns,
542
- setPreparedColumns,
543
- showQuickFilter: true,
544
- quickFilterProps: { debounceMs: 500 }
545
- },
546
- footer: {
547
- name,
548
- setRowModesModel,
549
- dataGrid,
550
- setDataGrid,
551
- emptyItem,
552
- indexField,
553
- isEditable
537
+ const newVisibleRowsJSON = JSON.stringify(newVisibleRows);
538
+ if (newVisibleRowsJSON !== visibleRows.current) {
539
+ setVisibleRows(newVisibleRows);
540
+ visibleRows.current = newVisibleRowsJSON;
541
+ }
542
+ }
543
+ }, editMode: "row", loading: dataGridLoading, hideFooterPagination: hideFooterPagination, getRowHeight: () => {
544
+ if (isAutoHeight) {
545
+ return 'auto';
546
+ }
547
+ return null;
548
+ }, isCellEditable: (params) => {
549
+ var _a;
550
+ return (((_a = rowModesModel[params.row.id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit &&
551
+ (!(0, utils_1.isTmpId)(params.row.id) ||
552
+ ((0, utils_1.isTmpId)(params.row.id) &&
553
+ (params.field === indexField ||
554
+ !optionsAC.current ||
555
+ !Object.prototype.hasOwnProperty.call(optionsAC.current, indexField) ||
556
+ (preparedColumns.find((col) => col.field === indexField) &&
557
+ Object.prototype.hasOwnProperty.call(preparedColumns.find((col) => col.field === indexField), 'valueFormatter'))))));
558
+ }, rowModesModel: rowModesModel, onRowEditStart: handleRowEditStart, onRowEditStop: handleRowEditStop, processRowUpdate: processRowUpdate, onProcessRowUpdateError: (e) => {
559
+ setDataGridLoading(false);
560
+ if (processingRow.current) {
561
+ setRowModesModel(Object.assign(Object.assign({}, rowModesModel), { [processingRow.current]: {
562
+ mode: x_data_grid_1.GridRowModes.Edit,
563
+ } }));
564
+ }
565
+ const msg = `Erro em "${e.path}": ${e.errors}`;
566
+ setSnackBar({
567
+ open: true,
568
+ severity: 'error',
569
+ msg,
570
+ });
571
+ console.log(e);
572
+ }, components: {
573
+ Toolbar: CustomToolbar_1.CustomToolbar,
574
+ Footer: FooterToolbar_1.FooterToolbar,
575
+ }, componentsProps: {
576
+ toolbar: {
577
+ preparedColumns,
578
+ setPreparedColumns,
579
+ showQuickFilter: true,
580
+ quickFilterProps: { debounceMs: 500 },
581
+ },
582
+ footer: {
583
+ name,
584
+ setRowModesModel,
585
+ dataGrid,
586
+ setDataGrid,
587
+ emptyItem,
588
+ indexField,
589
+ isEditable,
590
+ },
591
+ filterPanel: {
592
+ sx: {
593
+ '& .MuiDataGrid-filterFormValueInput': {
594
+ width: 300,
595
+ },
554
596
  },
555
- filterPanel: {
556
- sx: {
557
- '& .MuiDataGrid-filterFormValueInput': { width: 300 }
558
- }
597
+ },
598
+ }, experimentalFeatures: { newEditingApi: isEditable }, sx: customPaddings, paginationMode: paginationModel ? 'server' : 'client', onPageChange: (newPage) => {
599
+ if (setPaginationModel && paginationModel) {
600
+ setPaginationModel(Object.assign(Object.assign({}, paginationModel), { page: newPage }));
601
+ }
602
+ }, onPageSizeChange: (newPageSize) => {
603
+ if (setPaginationModel && paginationModel) {
604
+ setPaginationModel(Object.assign(Object.assign({}, paginationModel), { pageSize: newPageSize }));
605
+ }
606
+ }, rowCount: paginationModel && typeof rowCount !== 'undefined'
607
+ ? rowCount
608
+ : undefined, pageSize: paginationModel ? paginationModel.pageSize : 100, rowsPerPageOptions: [2], filterMode: paginationModel ? 'server' : 'client', onFilterModelChange: paginationModel
609
+ ? (newFilter) => {
610
+ if (setPaginationModel && paginationModel) {
611
+ setPaginationModel(Object.assign(Object.assign({}, paginationModel), { filter: newFilter }));
559
612
  }
560
- }, experimentalFeatures: { newEditingApi: isEditable }, sx: customPaddings }),
613
+ }
614
+ : undefined })),
561
615
  react_1.default.createElement(ConfirmDialog_1.ConfirmDialog, { open: dialogOpen, onClose: handleDialogClose, onConfirm: handleDeleteSave }),
562
- react_1.default.createElement(Snackbar_1.default, { open: snackBar.open, autoHideDuration: 5000, onClose: () => { setSnackBar(Object.assign(Object.assign({}, initialSnackBar), { open: false })); }, anchorOrigin: { vertical: 'top', horizontal: 'center' } },
616
+ react_1.default.createElement(Snackbar_1.default, { open: snackBar.open, autoHideDuration: 5000, onClose: () => {
617
+ setSnackBar(Object.assign(Object.assign({}, initialSnackBar), { open: false }));
618
+ }, anchorOrigin: { vertical: 'top', horizontal: 'center' } },
563
619
  react_1.default.createElement(Alert_1.default, { severity: snackBar.severity }, snackBar.msg))));
564
620
  });
565
621
  DataGridBySchemaEditable.displayName = 'DataGridBySchemaEditable';
@@ -13,8 +13,9 @@ interface GenericModelListProps {
13
13
  isAutoHeight?: boolean;
14
14
  model: string;
15
15
  forceReload: boolean;
16
- LinkComponent?: JSX.Element | null;
16
+ LinkComponent?: any | null;
17
17
  hasHeader: boolean;
18
+ paginationMode: 'server' | 'client';
18
19
  }
19
- declare const GenericModelList: ({ columnFields, hiddenFields, minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight, model, forceReload, LinkComponent, hasHeader, }: GenericModelListProps) => JSX.Element;
20
+ declare const GenericModelList: ({ columnFields, hiddenFields, minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight, model, forceReload, LinkComponent, hasHeader, paginationMode, }: GenericModelListProps) => JSX.Element;
20
21
  export default GenericModelList;