argous 1.2.178 → 1.2.179

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.
@@ -31,7 +31,7 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
31
31
  */
32
32
  footerProps?: object,
33
33
  /**
34
- * Array de dados fornecido paa a tabela
34
+ * Array de dados fornecido para a tabela
35
35
  */
36
36
  dados?: Array<Array<any> | Object>,
37
37
  /**
@@ -131,7 +131,19 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
131
131
  /**
132
132
  * Props repassados ao componente toolbar
133
133
  */
134
- toolbarProps?: any
134
+ toolbarProps?: any,
135
+ /**
136
+ * Objeto de controle da paginação/ordenação que será fornecido à tabela e ao método externo
137
+ */
138
+ externalCtrlPgn?: object,
139
+ /**
140
+ * Função que é chamada para setar o externalCtrlPgn sempre que os controles de paginação/ordenação mudarem
141
+ *
142
+ * @param value - Objeto com parâmetros da paginação/ordenação para ser enviado ao método
143
+ *
144
+ * @returns {void} Sem retorno
145
+ */
146
+ setExternalCtrlPgn?: (value: Object) => void
135
147
  }
136
148
 
137
149
  declare function ArgousComplexTable(props: ArgousComplexTableProps): JSX.Element
@@ -165,7 +165,7 @@ var initialState = function (defaultRowsPerPage) { return ({
165
165
  loading: false
166
166
  }); };
167
167
  var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
168
- var _b = _a.ToolbarComponent, ToolbarComponent = _b === void 0 ? __1.ArgousComplexTableToolbar : _b, _c = _a.HeadComponent, HeadComponent = _c === void 0 ? __1.ArgousComplexTableHead : _c, _d = _a.BodyComponent, BodyComponent = _d === void 0 ? __1.ArgousComplexTableBody : _d, _e = _a.PaginationComponent, PaginationComponent = _e === void 0 ? __1.ArgousComplexPagination : _e, _f = _a.FooterComponent, FooterComponent = _f === void 0 ? undefined : _f, footerProps = _a.footerProps, dados = _a.dados, _g = _a.head, head = _g === void 0 ? [] : _g, _h = _a.line, line = _h === void 0 ? function (i) { return i; } : _h, actions = _a.actions, title = _a.title, _j = _a.defaultRowsPerPage, defaultRowsPerPage = _j === void 0 ? 10 : _j, _k = _a.rowsPerPageOptions, rowsPerPageOptions = _k === void 0 ? [10, 25, 50] : _k, checkEnabled = _a.enableCheck, disableCheckIf = _a.disableCheckIf, showCount = _a.showCount, lineStyle = _a.lineStyle, _l = _a.lineClass, lineClass = _l === void 0 ? function () { return undefined; } : _l, onClick = _a.onClick, onDoubleClick = _a.onDoubleClick, _m = _a.children, children = _m === void 0 ? undefined : _m, style = _a.style, className = _a.className, columnStyles = _a.columnStyles, headerColumnStyles = _a.headerColumnStyles, columnOptions = _a.columnOptions, disableFilter = _a.disableFilter, _o = _a.filterLabel, filterLabel = _o === void 0 ? 'Filtro' : _o, _p = _a.indexToSelect, indexToSelect = _p === void 0 ? 0 : _p, _q = _a.disableSorting, disableSorting = _q === void 0 ? [] : _q, _r = _a.size, size = _r === void 0 ? 'small' : _r, onOpen = _a.onOpen, lineTitle = _a.lineTitle, onClose = _a.onClose, method = _a.method, methodPrms = _a.methodPrms, _s = _a.methodResultList, methodResultList = _s === void 0 ? 'lista' : _s, onMethodResponse = _a.onMethodResponse, _t = _a.handleMethodError, handleMethodError = _t === void 0 ? true : _t, _u = _a.allowMethodRequest, allowMethodRequest = _u === void 0 ? true : _u, field = _a.field, fixedToolbar = _a.fixedToolbar, onSelect = _a.onSelect, customKey = _a.customKey, _v = _a.columnProps, columnProps = _v === void 0 ? function () { return ''; } : _v, _w = _a.rowProps, rowProps = _w === void 0 ? function () { return ''; } : _w, _x = _a.savedState, savedState = _x === void 0 ? {} : _x, containerProps = _a.containerProps, _y = _a.onClickAway, onClickAway = _y === void 0 ? function () { return undefined; } : _y, enableCheckIfSelected = _a.enableCheckIfSelected, enableDrag = _a.enableDrag, onDrop = _a.onDrop, tableProps = _a.tableProps, toolbarProps = _a.toolbarProps;
168
+ var _b = _a.ToolbarComponent, ToolbarComponent = _b === void 0 ? __1.ArgousComplexTableToolbar : _b, _c = _a.HeadComponent, HeadComponent = _c === void 0 ? __1.ArgousComplexTableHead : _c, _d = _a.BodyComponent, BodyComponent = _d === void 0 ? __1.ArgousComplexTableBody : _d, _e = _a.PaginationComponent, PaginationComponent = _e === void 0 ? __1.ArgousComplexPagination : _e, _f = _a.FooterComponent, FooterComponent = _f === void 0 ? undefined : _f, footerProps = _a.footerProps, dados = _a.dados, _g = _a.head, head = _g === void 0 ? [] : _g, _h = _a.line, line = _h === void 0 ? function (i) { return i; } : _h, actions = _a.actions, title = _a.title, _j = _a.defaultRowsPerPage, defaultRowsPerPage = _j === void 0 ? 10 : _j, _k = _a.rowsPerPageOptions, rowsPerPageOptions = _k === void 0 ? [10, 25, 50] : _k, checkEnabled = _a.enableCheck, disableCheckIf = _a.disableCheckIf, showCount = _a.showCount, lineStyle = _a.lineStyle, _l = _a.lineClass, lineClass = _l === void 0 ? function () { return undefined; } : _l, onClick = _a.onClick, onDoubleClick = _a.onDoubleClick, _m = _a.children, children = _m === void 0 ? undefined : _m, style = _a.style, className = _a.className, columnStyles = _a.columnStyles, headerColumnStyles = _a.headerColumnStyles, columnOptions = _a.columnOptions, disableFilter = _a.disableFilter, _o = _a.filterLabel, filterLabel = _o === void 0 ? 'Filtro' : _o, _p = _a.indexToSelect, indexToSelect = _p === void 0 ? 0 : _p, _q = _a.disableSorting, disableSorting = _q === void 0 ? [] : _q, _r = _a.size, size = _r === void 0 ? 'small' : _r, onOpen = _a.onOpen, lineTitle = _a.lineTitle, onClose = _a.onClose, method = _a.method, methodPrms = _a.methodPrms, _s = _a.methodResultList, methodResultList = _s === void 0 ? 'lista' : _s, onMethodResponse = _a.onMethodResponse, _t = _a.handleMethodError, handleMethodError = _t === void 0 ? true : _t, _u = _a.allowMethodRequest, allowMethodRequest = _u === void 0 ? true : _u, field = _a.field, fixedToolbar = _a.fixedToolbar, onSelect = _a.onSelect, customKey = _a.customKey, _v = _a.columnProps, columnProps = _v === void 0 ? function () { return ''; } : _v, _w = _a.rowProps, rowProps = _w === void 0 ? function () { return ''; } : _w, _x = _a.savedState, savedState = _x === void 0 ? {} : _x, containerProps = _a.containerProps, _y = _a.onClickAway, onClickAway = _y === void 0 ? function () { return undefined; } : _y, enableCheckIfSelected = _a.enableCheckIfSelected, enableDrag = _a.enableDrag, onDrop = _a.onDrop, tableProps = _a.tableProps, toolbarProps = _a.toolbarProps, externalCtrlPgn = _a.externalCtrlPgn, setExternalCtrlPgn = _a.setExternalCtrlPgn;
169
169
  var classes = useStyles();
170
170
  var _z = react_1.useReducer(reducer, initialState(defaultRowsPerPage)), state = _z[0], dispatch = _z[1];
171
171
  var memoState = react_1.useMemo(function () { return (__assign(__assign({}, state), { dispatch: dispatch })); }, [state, dispatch]);
@@ -176,9 +176,11 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
176
176
  var enableCheck = checkEnabled || (enableCheckIfSelected && !!selected.length);
177
177
  react_1.useEffect(function () {
178
178
  dispatch({ type: 'mount', value: savedState.current });
179
+ // eslint-disable-next-line react-hooks/exhaustive-deps
179
180
  }, []);
180
181
  react_1.useEffect(function () {
181
182
  return function () { return savedState.current = state; };
183
+ // eslint-disable-next-line react-hooks/exhaustive-deps
182
184
  }, [state]);
183
185
  react_1.useEffect(function () {
184
186
  if (lodash_1.isArray(dados))
@@ -216,14 +218,14 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
216
218
  res = _g.sent();
217
219
  onMethodResponse && onMethodResponse(res);
218
220
  if (res.status) {
219
- setCtrlPgn(__assign(__assign({}, res.ctrlPgn), { recordCount: ((_a = res.ctrlPgn) === null || _a === void 0 ? void 0 : _a.recordCount) || ((_b = res[methodResultList]) === null || _b === void 0 ? void 0 : _b.length) < ((_c = res.ctrlPgn) === null || _c === void 0 ? void 0 : _c.qtRegs) ? (_d = res[methodResultList]) === null || _d === void 0 ? void 0 : _d.length : ((_e = res.ctrlPgn) === null || _e === void 0 ? void 0 : _e.qtPaginas) * ((_f = res.ctrlPgn) === null || _f === void 0 ? void 0 : _f.qtRegs) }));
221
+ setCtrlPgn(__assign(__assign({}, res.ctrlPgn), { recordCount: ((((_a = res.ctrlPgn) === null || _a === void 0 ? void 0 : _a.recordCount) || ((_b = res[methodResultList]) === null || _b === void 0 ? void 0 : _b.length)) < ((_c = res.ctrlPgn) === null || _c === void 0 ? void 0 : _c.qtRegs)) ? (_d = res[methodResultList]) === null || _d === void 0 ? void 0 : _d.length : ((_e = res.ctrlPgn) === null || _e === void 0 ? void 0 : _e.qtPaginas) * ((_f = res.ctrlPgn) === null || _f === void 0 ? void 0 : _f.qtRegs) }));
220
222
  setLista(res[methodResultList] || []);
221
223
  }
222
224
  dispatch({ type: 'setLoading', value: false });
223
225
  return [2 /*return*/];
224
226
  }
225
227
  });
226
- }); }, [method, qtRegs, pgAtl, order, orderBy, retornaAcao, ctrlPgn.pgAtl, page, methodPrms, methodResultList, handleMethodError, allowMethodRequest]);
228
+ }); }, [method, allowMethodRequest, qtRegs, pgAtl, retornaAcao, ctrlPgn.pgAtl, page, orderBy, order, methodPrms, handleMethodError, methodResultList]);
227
229
  react_1.useEffect(function () {
228
230
  buscaMetodo();
229
231
  }, [buscaMetodo]);
@@ -233,15 +235,16 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
233
235
  setLista(fielValue || []);
234
236
  }, [field, lista, fielValue]);
235
237
  react_1.useEffect(function () {
236
- if (method || field)
238
+ if (method || field || externalCtrlPgn)
237
239
  return;
238
240
  if (lodash_1.isArray(lista) && lista.length > 0 && page === Math.ceil(method ? ctrlPgn.recordCount : lista.length / parseInt(rowsPerPage, 10)))
239
241
  dispatch({ type: 'decremmentPage' });
240
- }, [page, method, lista.length, rowsPerPage, ctrlPgn.recordCount, lista, field]);
242
+ }, [page, method, lista.length, rowsPerPage, ctrlPgn.recordCount, lista, field, externalCtrlPgn]);
241
243
  react_1.useEffect(function () { return dispatch({ type: 'setSelected', value: [] }); }, [lista]);
242
244
  react_1.useEffect(function () {
243
245
  if (onSelect)
244
246
  onSelect(selected);
247
+ // eslint-disable-next-line react-hooks/exhaustive-deps
245
248
  }, [selected]);
246
249
  var dadosNaoCortados = react_1.useMemo(function () {
247
250
  if (method)
@@ -253,10 +256,10 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
253
256
  }, [lista, filter, order, orderBy, method, line]);
254
257
  var cortaDados = react_1.useCallback(function (dados) { return dados === null || dados === void 0 ? void 0 : dados.slice(defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage, defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage + rowsPerPage); }, [page, rowsPerPage, defaultRowsPerPage]);
255
258
  var dadosMostrados = react_1.useMemo(function () {
256
- if (method)
259
+ if (method || externalCtrlPgn)
257
260
  return lista || [];
258
261
  return cortaDados(dadosNaoCortados) || [];
259
- }, [method, lista, dadosNaoCortados, cortaDados]);
262
+ }, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados]);
260
263
  var handleOpenClose = react_1.useCallback(function (index) {
261
264
  if (index === open || (!index && index !== 0)) {
262
265
  dispatch({ type: 'setOpen', value: undefined });
@@ -276,25 +279,56 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
276
279
  setSelected: function (s) { return dispatch({ type: 'setSelected', value: lodash_1.isFunction(s) ? s(selected, dadosMostrados) : s }); },
277
280
  setLoading: function (value) { return dispatch({ type: 'setLoading', value: value }); }
278
281
  }); });
282
+ //________________EXTERNAL_CTRL_PGN____________________________________________________________________________
283
+ var _2 = react_1.useState(true), bounced = _2[0], setBounced = _2[1];
284
+ var getFullCtrlPgn = function (internal) {
285
+ var ctrl = internal ? ctrlPgn : externalCtrlPgn;
286
+ return __assign({ acao: retornaAcao(ctrl.pgAtl, page + 1), tpOrdem: orderBy >= 0 ? (order === 'asc' ? 'A' : 'D') : undefined, indOrdem: orderBy >= 0 ? orderBy : undefined }, ctrl);
287
+ };
288
+ react_1.useEffect(function () {
289
+ if (!method && setExternalCtrlPgn) {
290
+ var fullCtrlPgn = __assign(__assign({}, ctrlPgn), { acao: retornaAcao(ctrlPgn.pgAtl, page + 1), tpOrdem: orderBy >= 0 ? (order === 'asc' ? 'A' : 'D') : undefined, indOrdem: orderBy >= 0 ? orderBy : undefined });
291
+ var fullExternalCtrlPgn = getFullCtrlPgn();
292
+ if (!bounced && !lodash_1.isEqual(fullCtrlPgn, fullExternalCtrlPgn))
293
+ setExternalCtrlPgn(fullCtrlPgn);
294
+ else if (bounced)
295
+ setBounced(false);
296
+ }
297
+ // eslint-disable-next-line react-hooks/exhaustive-deps
298
+ }, [ctrlPgn, order, orderBy, page]);
299
+ react_1.useEffect(function () {
300
+ var _a;
301
+ if (!method && externalCtrlPgn && ((_a = Object.keys(externalCtrlPgn)) === null || _a === void 0 ? void 0 : _a.length)) {
302
+ var fullCtrlPgn = getFullCtrlPgn(true);
303
+ var fullExternalCtrlPgn = getFullCtrlPgn();
304
+ if (!lodash_1.isEqual(fullExternalCtrlPgn, fullCtrlPgn)) {
305
+ setCtrlPgn(__assign(__assign({}, fullExternalCtrlPgn), { recordCount: (((externalCtrlPgn === null || externalCtrlPgn === void 0 ? void 0 : externalCtrlPgn.recordCount) || (dados === null || dados === void 0 ? void 0 : dados.length)) < (externalCtrlPgn === null || externalCtrlPgn === void 0 ? void 0 : externalCtrlPgn.qtRegs)) ? dados === null || dados === void 0 ? void 0 : dados.length : (externalCtrlPgn === null || externalCtrlPgn === void 0 ? void 0 : externalCtrlPgn.qtPaginas) * (externalCtrlPgn === null || externalCtrlPgn === void 0 ? void 0 : externalCtrlPgn.qtRegs) }));
306
+ setBounced(true);
307
+ }
308
+ }
309
+ // eslint-disable-next-line react-hooks/exhaustive-deps
310
+ }, [externalCtrlPgn]);
311
+ //_____________________________________________________________________________________________________________
279
312
  return (react_1.default.createElement(exports.TableContext.Provider, { value: __assign(__assign({}, memoState), { dadosMostrados: dadosMostrados, lista: lista, indexToSelect: indexToSelect, method: method }) },
280
313
  react_1.default.createElement(core_1.ClickAwayListener, { onClickAway: onClickAway },
281
314
  react_1.default.createElement(core_1.TableContainer, __assign({ component: core_1.Paper, variant: 'outlined', style: style }, containerProps, { className: clsx_1.default(classes.root, className) }),
282
315
  react_1.default.createElement(ToolbarComponent, __assign({ numSelected: selected.length, disableFilter: disableFilter || !!method }, __assign({ actions: actions, title: title, selected: selected, filter: filter, filterLabel: filterLabel, lista: lista, indexToSelect: indexToSelect, fixedToolbar: fixedToolbar }, toolbarProps))),
283
316
  react_1.default.createElement(core_1.Table, __assign({}, __assign(__assign({}, tableProps), { size: size })),
284
- react_1.default.createElement(HeadComponent, __assign({ size: method ? ctrlPgn.recordCount : dadosNaoCortados.length, numSelected: selected.length, rowCount: (rowsPerPage > (method ? ctrlPgn.recordCount : dadosNaoCortados.length)) ? method ? ctrlPgn.recordCount : dadosNaoCortados.length : rowsPerPage || dadosNaoCortados.length }, { head: head, order: order, orderBy: orderBy, enableCheck: enableCheck, headerColumnStyles: headerColumnStyles, disableSorting: disableSorting, ordCols: ordCols, method: method, cortaDados: cortaDados, disableCheckIf: disableCheckIf, line: line, enableDrag: enableDrag })),
317
+ react_1.default.createElement(HeadComponent, __assign({ size: (method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length, numSelected: selected.length, rowCount: (rowsPerPage > ((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length)) ? ((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length) : (rowsPerPage || dadosNaoCortados.length) }, { head: head, order: order, orderBy: orderBy, enableCheck: enableCheck, headerColumnStyles: headerColumnStyles, disableSorting: disableSorting, ordCols: ordCols, method: method, cortaDados: cortaDados, disableCheckIf: disableCheckIf, line: line, enableDrag: enableDrag })),
285
318
  react_1.default.createElement(BodyComponent, __assign({}, {
286
319
  children: children, line: line, lineStyle: lineStyle, lineTitle: lineTitle, handleOpenClose: handleOpenClose, lineClass: lineClass, enableDrag: enableDrag,
287
320
  enableCheck: enableCheck, columnStyles: columnStyles, head: head, columnOptions: columnOptions, columnProps: columnProps, rowProps: rowProps, onDrop: onDrop,
288
321
  onClick: onClick, onDoubleClick: onDoubleClick, indexToSelect: indexToSelect, open: open, dadosMostrados: dadosMostrados, customKey: customKey, disableCheckIf: disableCheckIf
289
322
  })),
290
323
  FooterComponent && react_1.default.createElement(FooterComponent, __assign({}, footerProps))),
291
- rowsPerPageOptions !== 0 && Math.ceil(method ? ctrlPgn.recordCount : dadosNaoCortados.length / parseInt(rowsPerPageOptions[0], 10)) > 1 && (react_1.default.createElement(PaginationComponent, __assign({ count: method ? ctrlPgn.recordCount : dadosNaoCortados.length, onChangePage: function (_, value) {
324
+ rowsPerPageOptions !== 0 && Math.ceil((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length / parseInt(rowsPerPageOptions[0], 10)) > 1 && (react_1.default.createElement(PaginationComponent, __assign({ count: (method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length, onChangePage: function (_, value) {
292
325
  dispatch({ type: 'setPage', value: value });
293
326
  setCtrlPgn(__assign(__assign({}, ctrlPgn), { pgAtl: value + 1 }));
294
327
  }, onChangeRowsPerPage: function (e) {
295
328
  dispatch({ type: 'setRowsPerPage', value: parseInt(e.target.value, 10) });
296
329
  dispatch({ type: 'setPage', value: 0 });
297
330
  setCtrlPgn(__assign(__assign({}, ctrlPgn), { pgAtl: 1, qtRegs: parseInt(e.target.value, 10) }));
331
+ setExternalCtrlPgn && setExternalCtrlPgn(__assign(__assign({}, externalCtrlPgn), { pgAtl: 1, qtRegs: parseInt(e.target.value, 10) }));
298
332
  } }, { showCount: showCount, page: page, rowsPerPageOptions: rowsPerPageOptions, rowsPerPage: rowsPerPage })))))));
299
333
  });
300
334
  ArgousComplexTable.propTypes = {
@@ -328,6 +362,10 @@ ArgousComplexTable.propTypes = {
328
362
  methodPrms: prop_types_1.default.object,
329
363
  field: prop_types_1.default.string,
330
364
  fixedToolbar: prop_types_1.default.bool,
331
- onSelect: prop_types_1.default.func
365
+ onSelect: prop_types_1.default.func,
366
+ handleMethodError: prop_types_1.default.bool,
367
+ allowMethodRequest: prop_types_1.default.bool,
368
+ externalCtrlPgn: prop_types_1.default.object,
369
+ setExternalCtrlPgn: prop_types_1.default.func
332
370
  };
333
371
  exports.default = react_1.memo(ArgousComplexTable, lodash_1.isEqual);
@@ -31,7 +31,7 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
31
31
  */
32
32
  footerProps?: object,
33
33
  /**
34
- * Array de dados fornecido paa a tabela
34
+ * Array de dados fornecido para a tabela
35
35
  */
36
36
  dados?: Array<Array<any> | Object>,
37
37
  /**
@@ -131,7 +131,19 @@ export interface ArgousComplexTableProps extends ArgousComplexTableBodyProps, Ar
131
131
  /**
132
132
  * Props repassados ao componente toolbar
133
133
  */
134
- toolbarProps?: any
134
+ toolbarProps?: any,
135
+ /**
136
+ * Objeto de controle da paginação/ordenação que será fornecido à tabela e ao método externo
137
+ */
138
+ externalCtrlPgn?: object,
139
+ /**
140
+ * Função que é chamada para setar o externalCtrlPgn sempre que os controles de paginação/ordenação mudarem
141
+ *
142
+ * @param value - Objeto com parâmetros da paginação/ordenação para ser enviado ao método
143
+ *
144
+ * @returns {void} Sem retorno
145
+ */
146
+ setExternalCtrlPgn?: (value: Object) => void
135
147
  }
136
148
 
137
149
  declare function ArgousComplexTable(props: ArgousComplexTableProps): JSX.Element
@@ -18,9 +18,9 @@ const useStyles = makeStyles({
18
18
  }
19
19
  }
20
20
  });
21
-
21
+
22
22
  export const TableContext = createContext();
23
-
23
+
24
24
  const ehData = valor => {
25
25
  const retorno = (format) => moment(valor, format).format('YYYYMMDDHHmmss');
26
26
  if (/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/.test(valor)) return retorno('DD/MM/YYYY');
@@ -29,7 +29,7 @@ const ehData = valor => {
29
29
  if (/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(.\d)*/.test(valor)) return retorno('YYYY-MM-DD HH:mm:ss');
30
30
  return valor;
31
31
  };
32
-
32
+
33
33
  function descendingComparator(a, b, orderBy) {
34
34
  const aO = ehData(a[orderBy]);
35
35
  const bO = ehData(b[orderBy]);
@@ -37,13 +37,13 @@ function descendingComparator(a, b, orderBy) {
37
37
  if (bO > aO) return 1;
38
38
  return 0;
39
39
  }
40
-
40
+
41
41
  function getComparator(order, orderBy) {
42
42
  return order === 'desc'
43
43
  ? (a, b) => descendingComparator(a, b, orderBy)
44
44
  : (a, b) => -descendingComparator(a, b, orderBy);
45
45
  }
46
-
46
+
47
47
  function stableSort(array, comparator, line) {
48
48
  const stabilizedThis = array.map((el, index) => [el, line(el), index]);
49
49
  stabilizedThis.sort((a, b) => {
@@ -53,7 +53,7 @@ function stableSort(array, comparator, line) {
53
53
  });
54
54
  return stabilizedThis.map((el) => el[0]);
55
55
  }
56
-
56
+
57
57
  const reducer = (state, action) => {
58
58
  switch (action.type) {
59
59
  case 'setSelected':
@@ -108,7 +108,7 @@ const reducer = (state, action) => {
108
108
  return state;
109
109
  }
110
110
  };
111
-
111
+
112
112
  const initialState = (defaultRowsPerPage) => ({
113
113
  selected: [],
114
114
  page: 0,
@@ -119,7 +119,7 @@ const initialState = (defaultRowsPerPage) => ({
119
119
  open: undefined,
120
120
  loading: false
121
121
  });
122
-
122
+
123
123
  const ArgousComplexTable = forwardRef(({
124
124
  ToolbarComponent = ArgousComplexTableToolbar,
125
125
  HeadComponent = ArgousComplexTableHead,
@@ -174,31 +174,35 @@ const ArgousComplexTable = forwardRef(({
174
174
  enableDrag,
175
175
  onDrop,
176
176
  tableProps,
177
- toolbarProps
177
+ toolbarProps,
178
+ externalCtrlPgn,
179
+ setExternalCtrlPgn
178
180
  }, ref) => {
179
181
  const classes = useStyles();
180
182
  const [state, dispatch] = useReducer(reducer, initialState(defaultRowsPerPage));
181
183
  const memoState = useMemo(() => ({ ...state, dispatch }), [state, dispatch]);
182
184
  const { selected, page, rowsPerPage, order, orderBy, filter, open } = memoState;
183
-
185
+
184
186
  const [lista, setLista] = useState(dados/*.map(linha => isArray(linha) ? linha : Object.values(linha))*/ || []);
185
187
  const [ctrlPgn, setCtrlPgn] = useState({ qtRegs: defaultRowsPerPage, pgAtl: 1 });
186
188
  const { qtRegs, pgAtl, ordCols } = ctrlPgn;
187
-
189
+
188
190
  const enableCheck = checkEnabled || (enableCheckIfSelected && !!selected.length);
189
-
191
+
190
192
  useEffect(() => {
191
193
  dispatch({ type: 'mount', value: savedState.current });
194
+ // eslint-disable-next-line react-hooks/exhaustive-deps
192
195
  }, []);
193
-
196
+
194
197
  useEffect(() => {
195
198
  return () => savedState.current = state;
199
+ // eslint-disable-next-line react-hooks/exhaustive-deps
196
200
  }, [state]);
197
-
201
+
198
202
  useEffect(() => {
199
203
  if (isArray(dados)) setLista(dados/*.map(linha => isArray(linha) ? linha : Object.values(linha))*/ || []);
200
204
  }, [dados]);
201
-
205
+
202
206
  const retornaAcao = useCallback((pgAtl, page) => {
203
207
  if (page === pgAtl) return undefined;
204
208
  else if (page === pgAtl + 1) return 'N';
@@ -207,7 +211,7 @@ const ArgousComplexTable = forwardRef(({
207
211
  else if (page === 0) return 'F';
208
212
  return `S=${page}`;
209
213
  }, [ctrlPgn.recordCount]);
210
-
214
+
211
215
  const buscaMetodo = useCallback(async () => {
212
216
  if (!method || !allowMethodRequest) return;
213
217
  dispatch({ type: 'setLoading', value: true });
@@ -221,49 +225,51 @@ const ArgousComplexTable = forwardRef(({
221
225
  }, handleMethodError);
222
226
  onMethodResponse && onMethodResponse(res);
223
227
  if (res.status) {
224
- setCtrlPgn({ ...res.ctrlPgn, recordCount: res.ctrlPgn?.recordCount || res[methodResultList]?.length < res.ctrlPgn?.qtRegs ? res[methodResultList]?.length : res.ctrlPgn?.qtPaginas * res.ctrlPgn?.qtRegs });
228
+ setCtrlPgn({ ...res.ctrlPgn, recordCount: ((res.ctrlPgn?.recordCount || res[methodResultList]?.length) < res.ctrlPgn?.qtRegs) ? res[methodResultList]?.length : res.ctrlPgn?.qtPaginas * res.ctrlPgn?.qtRegs });
225
229
  setLista(res[methodResultList] || []);
226
230
  }
227
231
  dispatch({ type: 'setLoading', value: false });
228
- }, [method, qtRegs, pgAtl, order, orderBy, retornaAcao, ctrlPgn.pgAtl, page, methodPrms, methodResultList, handleMethodError, allowMethodRequest]);
229
-
232
+ // eslint-disable-next-line react-hooks/exhaustive-deps
233
+ }, [method, allowMethodRequest, qtRegs, pgAtl, retornaAcao, ctrlPgn.pgAtl, page, orderBy, order, methodPrms, handleMethodError, methodResultList]);
234
+
230
235
  useEffect(() => {
231
236
  buscaMetodo();
232
237
  }, [buscaMetodo]);
233
-
234
- const fielValue = useMemo(() => /*isArray(getField(field, 'value')) ? */getField(field, 'value')/*?.map(item => isArray(item) ? item : Object.values(item)) : []*/, [field]);
235
238
 
239
+ const fielValue = useMemo(() => /*isArray(getField(field, 'value')) ? */getField(field, 'value')/*?.map(item => isArray(item) ? item : Object.values(item)) : []*/, [field]);
240
+
236
241
  useEffect(() => {
237
242
  if (field && !isEqual(lista, fielValue)) setLista(fielValue || []);
238
243
  }, [field, lista, fielValue]);
239
-
244
+
240
245
  useEffect(() => {
241
- if (method || field) return;
246
+ if (method || field || externalCtrlPgn) return;
242
247
  if (isArray(lista) && lista.length > 0 && page === Math.ceil(method ? ctrlPgn.recordCount : lista.length / parseInt(rowsPerPage, 10))) dispatch({ type: 'decremmentPage' });
243
- }, [page, method, lista.length, rowsPerPage, ctrlPgn.recordCount, lista, field]);
244
-
245
- useEffect(() => dispatch({ type: 'setSelected', value: [] }), [lista]);
248
+ }, [page, method, lista.length, rowsPerPage, ctrlPgn.recordCount, lista, field, externalCtrlPgn]);
246
249
 
250
+ useEffect(() => dispatch({ type: 'setSelected', value: [] }), [lista]);
251
+
247
252
  useEffect(() => {
248
253
  if (onSelect) onSelect(selected);
254
+ // eslint-disable-next-line react-hooks/exhaustive-deps
249
255
  }, [selected]);
250
-
256
+
251
257
  const dadosNaoCortados = useMemo(() => {
252
258
  if (method) return lista || [];
253
259
  if (isArray(lista) && lista.length > 0) return stableSort(lista, getComparator(order, orderBy), line)
254
260
  .filter(linha => isArray(line(linha)) ? line(linha).filter(item => filter ? new RegExp(`.*${filter}.*`, 'gi').test(item?.toString()) : true).length > 0 : true) || [];
255
261
  return [];
256
262
  }, [lista, filter, order, orderBy, method, line]);
257
-
263
+
258
264
  const cortaDados = useCallback((dados) => dados
259
265
  ?.slice(defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage, defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage + rowsPerPage),
260
266
  [page, rowsPerPage, defaultRowsPerPage]);
261
-
267
+
262
268
  const dadosMostrados = useMemo(() => {
263
- if (method) return lista || [];
269
+ if (method || externalCtrlPgn) return lista || [];
264
270
  return cortaDados(dadosNaoCortados) || [];
265
- }, [method, lista, dadosNaoCortados, cortaDados]);
266
-
271
+ }, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados]);
272
+
267
273
  const handleOpenClose = useCallback((index) => {
268
274
  if (index === open || (!index && index !== 0)) {
269
275
  dispatch({ type: 'setOpen', value: undefined });
@@ -273,7 +279,7 @@ const ArgousComplexTable = forwardRef(({
273
279
  if (onOpen) onOpen({ linhaOriginal: dadosMostrados[index], linhaFormatada: line(dadosMostrados[index]) });
274
280
  }
275
281
  }, [open, onClose, onOpen, dadosMostrados, dispatch, line]);
276
-
282
+
277
283
  useImperativeHandle(ref, () => ({
278
284
  setOpen: index => handleOpenClose(index),
279
285
  getOpen: dadosMostrados[open],
@@ -282,6 +288,51 @@ const ArgousComplexTable = forwardRef(({
282
288
  setLoading: value => dispatch({ type: 'setLoading', value })
283
289
  }));
284
290
 
291
+
292
+ //________________EXTERNAL_CTRL_PGN____________________________________________________________________________
293
+
294
+ const [bounced, setBounced] = useState(true);
295
+
296
+ const getFullCtrlPgn = (internal) => {
297
+ const ctrl = internal ? ctrlPgn : externalCtrlPgn;
298
+ return {
299
+ acao: retornaAcao(ctrl.pgAtl, page + 1),
300
+ tpOrdem: orderBy >= 0 ? (order === 'asc' ? 'A' : 'D') : undefined,
301
+ indOrdem: orderBy >= 0 ? orderBy : undefined,
302
+ ...ctrl
303
+ };
304
+ };
305
+
306
+ useEffect(() => {
307
+ if (!method && setExternalCtrlPgn) {
308
+ const fullCtrlPgn = {
309
+ ...ctrlPgn,
310
+ acao: retornaAcao(ctrlPgn.pgAtl, page + 1),
311
+ tpOrdem: orderBy >= 0 ? (order === 'asc' ? 'A' : 'D') : undefined,
312
+ indOrdem: orderBy >= 0 ? orderBy : undefined
313
+ };
314
+ const fullExternalCtrlPgn = getFullCtrlPgn();
315
+ if (!bounced && !isEqual(fullCtrlPgn, fullExternalCtrlPgn)) setExternalCtrlPgn(fullCtrlPgn);
316
+ else if (bounced) setBounced(false);
317
+ }
318
+ // eslint-disable-next-line react-hooks/exhaustive-deps
319
+ }, [ctrlPgn, order, orderBy, page]);
320
+
321
+ useEffect(() => {
322
+ if (!method && externalCtrlPgn && Object.keys(externalCtrlPgn)?.length) {
323
+ const fullCtrlPgn = getFullCtrlPgn(true);
324
+ const fullExternalCtrlPgn = getFullCtrlPgn();
325
+ if (!isEqual(fullExternalCtrlPgn, fullCtrlPgn)) {
326
+ setCtrlPgn({ ...fullExternalCtrlPgn, recordCount: ((externalCtrlPgn?.recordCount || dados?.length) < externalCtrlPgn?.qtRegs) ? dados?.length : externalCtrlPgn?.qtPaginas * externalCtrlPgn?.qtRegs });
327
+ setBounced(true);
328
+ }
329
+ }
330
+ // eslint-disable-next-line react-hooks/exhaustive-deps
331
+ }, [externalCtrlPgn]);
332
+
333
+ //_____________________________________________________________________________________________________________
334
+
335
+
285
336
  return (
286
337
  <TableContext.Provider value={{ ...memoState, dadosMostrados, lista, indexToSelect, method }}>
287
338
  <ClickAwayListener onClickAway={onClickAway}>
@@ -292,9 +343,9 @@ const ArgousComplexTable = forwardRef(({
292
343
  {...{ actions, title, selected, filter, filterLabel, lista, indexToSelect, fixedToolbar, ...toolbarProps }} />
293
344
  <Table {...{ ...tableProps, size }}>
294
345
  <HeadComponent
295
- size={method ? ctrlPgn.recordCount : dadosNaoCortados.length}
346
+ size={(method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length}
296
347
  numSelected={selected.length}
297
- rowCount={(rowsPerPage > (method ? ctrlPgn.recordCount : dadosNaoCortados.length)) ? method ? ctrlPgn.recordCount : dadosNaoCortados.length : rowsPerPage || dadosNaoCortados.length}
348
+ rowCount={(rowsPerPage > ((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length)) ? ((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length) : (rowsPerPage || dadosNaoCortados.length)}
298
349
  {...{ head, order, orderBy, enableCheck, headerColumnStyles, disableSorting, ordCols, method, cortaDados, disableCheckIf, line, enableDrag }}
299
350
  />
300
351
  <BodyComponent
@@ -305,9 +356,9 @@ const ArgousComplexTable = forwardRef(({
305
356
  }}/>
306
357
  {FooterComponent && <FooterComponent {...footerProps}/>}
307
358
  </Table>
308
- {rowsPerPageOptions !== 0 && Math.ceil(method ? ctrlPgn.recordCount : dadosNaoCortados.length / parseInt(rowsPerPageOptions[0], 10)) > 1 && (
359
+ {rowsPerPageOptions !== 0 && Math.ceil((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length / parseInt(rowsPerPageOptions[0], 10)) > 1 && (
309
360
  <PaginationComponent
310
- count={method ? ctrlPgn.recordCount : dadosNaoCortados.length}
361
+ count={(method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length}
311
362
  onChangePage={(_, value) => {
312
363
  dispatch({ type: 'setPage', value });
313
364
  setCtrlPgn({ ...ctrlPgn, pgAtl: value + 1 });
@@ -316,6 +367,7 @@ const ArgousComplexTable = forwardRef(({
316
367
  dispatch({ type: 'setRowsPerPage', value: parseInt(e.target.value, 10) });
317
368
  dispatch({ type: 'setPage', value: 0 });
318
369
  setCtrlPgn({ ...ctrlPgn, pgAtl: 1, qtRegs: parseInt(e.target.value, 10) });
370
+ setExternalCtrlPgn && setExternalCtrlPgn({ ...externalCtrlPgn, pgAtl: 1, qtRegs: parseInt(e.target.value, 10) });
319
371
  }}
320
372
  {...{ showCount, page, rowsPerPageOptions, rowsPerPage }} />
321
373
  )}
@@ -324,7 +376,7 @@ const ArgousComplexTable = forwardRef(({
324
376
  </TableContext.Provider>
325
377
  );
326
378
  });
327
-
379
+
328
380
  ArgousComplexTable.propTypes = {
329
381
  dados: PropTypes.array,
330
382
  head: PropTypes.array,
@@ -356,7 +408,11 @@ ArgousComplexTable.propTypes = {
356
408
  methodPrms: PropTypes.object,
357
409
  field: PropTypes.string,
358
410
  fixedToolbar: PropTypes.bool,
359
- onSelect: PropTypes.func
411
+ onSelect: PropTypes.func,
412
+ handleMethodError: PropTypes.bool,
413
+ allowMethodRequest: PropTypes.bool,
414
+ externalCtrlPgn: PropTypes.object,
415
+ setExternalCtrlPgn: PropTypes.func
360
416
  };
361
-
417
+
362
418
  export default memo(ArgousComplexTable, isEqual);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argous",
3
- "version": "1.2.178",
3
+ "version": "1.2.179",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",