argous 1.2.231 → 1.2.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ArgousComplexTable/ArgousComplexTable.js +30 -15
- package/dist/components/ArgousComplexTableBody/ArgousComplexTableBody.js +19 -2
- package/lib/components/ArgousComplexTable/ArgousComplexTable.js +56 -43
- package/lib/components/ArgousComplexTableBody/ArgousComplexTableBody.js +51 -8
- package/package.json +1 -1
|
@@ -65,6 +65,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
65
65
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
69
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
70
|
+
to[j] = from[i];
|
|
71
|
+
return to;
|
|
72
|
+
};
|
|
68
73
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
69
74
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
70
75
|
};
|
|
@@ -174,6 +179,30 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
|
|
|
174
179
|
var _3 = react_1.useState({ qtRegs: defaultRowsPerPage, pgAtl: 1 }), ctrlPgn = _3[0], setCtrlPgn = _3[1];
|
|
175
180
|
var qtRegs = ctrlPgn.qtRegs, pgAtl = ctrlPgn.pgAtl, ordCols = ctrlPgn.ordCols;
|
|
176
181
|
var enableCheck = checkEnabled || (enableCheckIfSelected && !!selected.length);
|
|
182
|
+
var dadosNaoCortados = react_1.useMemo(function () {
|
|
183
|
+
if (method)
|
|
184
|
+
return lista || [];
|
|
185
|
+
if (lodash_1.isArray(lista) && lista.length > 0)
|
|
186
|
+
return stableSort(lista, getComparator(order, orderBy), line)
|
|
187
|
+
.filter(function (linha) { return lodash_1.isArray(line(linha)) ? line(linha).filter(function (item) { return filter ? new RegExp(".*" + filter + ".*", 'gi').test(item === null || item === void 0 ? void 0 : item.toString()) : true; }).length > 0 : true; }) || [];
|
|
188
|
+
return [];
|
|
189
|
+
}, [lista, filter, order, orderBy, method, line]);
|
|
190
|
+
var usePagination = ((rowsPerPageOptions !== 0) && (Math.ceil(((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length) / parseInt(rowsPerPageOptions[0], 10)) > 1));
|
|
191
|
+
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]);
|
|
192
|
+
var fillListToKeepHeight = react_1.useCallback(function (array) {
|
|
193
|
+
var newArray = __spreadArray([], array);
|
|
194
|
+
if (newArray.length < rowsPerPage) {
|
|
195
|
+
var gap = (rowsPerPage - newArray.length);
|
|
196
|
+
var arrayToFillGap = Array.from(Array(gap)).fill(Array.from(Array(head.length)).fill(''));
|
|
197
|
+
newArray.push.apply(newArray, arrayToFillGap);
|
|
198
|
+
}
|
|
199
|
+
return newArray;
|
|
200
|
+
}, [head, rowsPerPage]);
|
|
201
|
+
var dadosMostrados = react_1.useMemo(function () {
|
|
202
|
+
if (method || externalCtrlPgn)
|
|
203
|
+
return (usePagination) ? fillListToKeepHeight(lista || []) : (lista || []);
|
|
204
|
+
return (usePagination) ? fillListToKeepHeight(cortaDados(dadosNaoCortados) || []) : (cortaDados(dadosNaoCortados) || []);
|
|
205
|
+
}, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados, usePagination, fillListToKeepHeight]);
|
|
177
206
|
react_1.useEffect(function () {
|
|
178
207
|
dispatch({ type: 'mount', value: savedState.current });
|
|
179
208
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -246,20 +275,6 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
|
|
|
246
275
|
onSelect(selected);
|
|
247
276
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
248
277
|
}, [selected]);
|
|
249
|
-
var dadosNaoCortados = react_1.useMemo(function () {
|
|
250
|
-
if (method)
|
|
251
|
-
return lista || [];
|
|
252
|
-
if (lodash_1.isArray(lista) && lista.length > 0)
|
|
253
|
-
return stableSort(lista, getComparator(order, orderBy), line)
|
|
254
|
-
.filter(function (linha) { return lodash_1.isArray(line(linha)) ? line(linha).filter(function (item) { return filter ? new RegExp(".*" + filter + ".*", 'gi').test(item === null || item === void 0 ? void 0 : item.toString()) : true; }).length > 0 : true; }) || [];
|
|
255
|
-
return [];
|
|
256
|
-
}, [lista, filter, order, orderBy, method, line]);
|
|
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]);
|
|
258
|
-
var dadosMostrados = react_1.useMemo(function () {
|
|
259
|
-
if (method || externalCtrlPgn)
|
|
260
|
-
return lista || [];
|
|
261
|
-
return cortaDados(dadosNaoCortados) || [];
|
|
262
|
-
}, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados]);
|
|
263
278
|
var handleOpenClose = react_1.useCallback(function (index) {
|
|
264
279
|
if (index === open || (!index && index !== 0)) {
|
|
265
280
|
dispatch({ type: 'setOpen', value: undefined });
|
|
@@ -319,7 +334,7 @@ var ArgousComplexTable = react_1.forwardRef(function (_a, ref) {
|
|
|
319
334
|
onClick: onClick, onDoubleClick: onDoubleClick, indexToSelect: indexToSelect, open: open, dadosMostrados: dadosMostrados, customKey: customKey, disableCheckIf: disableCheckIf
|
|
320
335
|
})),
|
|
321
336
|
FooterComponent && react_1.default.createElement(FooterComponent, __assign({}, footerProps))),
|
|
322
|
-
(
|
|
337
|
+
(usePagination) && (react_1.default.createElement(PaginationComponent, __assign({ count: (method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length, onChangePage: function (_, value) {
|
|
323
338
|
dispatch({ type: 'setPage', value: value });
|
|
324
339
|
setCtrlPgn(__assign(__assign({}, ctrlPgn), { pgAtl: value + 1 }));
|
|
325
340
|
}, onChangeRowsPerPage: function (e) {
|
|
@@ -83,6 +83,18 @@ var useStyles = core_1.makeStyles(function (theme) { return ({
|
|
|
83
83
|
loading: {
|
|
84
84
|
textAlign: 'center',
|
|
85
85
|
padding: '7px'
|
|
86
|
+
},
|
|
87
|
+
ghost: {
|
|
88
|
+
borderBottom: '1px solid #0000',
|
|
89
|
+
userSelect: 'none',
|
|
90
|
+
'&:hover': {
|
|
91
|
+
backgroundColor: '#0000 !important'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
tableCell: {
|
|
95
|
+
overflow: 'hidden',
|
|
96
|
+
whiteSpace: 'nowrap',
|
|
97
|
+
textOverflow: 'ellipsis'
|
|
86
98
|
}
|
|
87
99
|
}); });
|
|
88
100
|
var ArgousComplexTableBody = react_1.memo(function (_a) {
|
|
@@ -118,6 +130,7 @@ var ArgousComplexTableBody = react_1.memo(function (_a) {
|
|
|
118
130
|
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true })))) : dadosMostrados.length ? dadosMostrados.map(function (linha, i) {
|
|
119
131
|
var isItemSelected = isSelected(linha[indexToSelect]);
|
|
120
132
|
var isItemOpen = i === open;
|
|
133
|
+
var fullyEmpty = !linha.some(function (value) { return !!value; });
|
|
121
134
|
var _a = rowProps({ index: i, linhaOriginal: linha, linhaFormatada: line(linha), itensSelecionados: selected }) || {}, title = _a.title, rowProperties = __rest(_a, ["title"]);
|
|
122
135
|
return react_1.default.createElement(dist_1.Draggable, { key: customKey ? lista[i][customKey] : i, render: function (draggableRef) {
|
|
123
136
|
var _a;
|
|
@@ -126,7 +139,11 @@ var ArgousComplexTableBody = react_1.memo(function (_a) {
|
|
|
126
139
|
//TODO criar proprio draggable pois esse remove classes do filho
|
|
127
140
|
react_1.default.createElement(react_1.Fragment, null,
|
|
128
141
|
react_1.default.createElement(exports.CustomTooltip, { title: lineTitle || title },
|
|
129
|
-
react_1.default.createElement(core_1.TableRow, __assign({ component: dist_1.Draggable }, rowProperties, { className: clsx_1.default((_a = {},
|
|
142
|
+
react_1.default.createElement(core_1.TableRow, __assign({ component: dist_1.Draggable }, rowProperties, { className: clsx_1.default((_a = {},
|
|
143
|
+
_a[classes.hover] = isItemSelected,
|
|
144
|
+
_a[classes.open] = (isItemOpen && !!children),
|
|
145
|
+
_a[classes.ghost] = fullyEmpty,
|
|
146
|
+
_a), lineClass(line(linha), linha, i), rowProperties.className), hover: true, role: 'checkbox', tabIndex: -1, selected: isItemSelected, style: lineStyle ? lineStyle(linha, line(linha), i) : undefined, onClick: (fullyEmpty) ? undefined : (onClick) ? function (e) { return onClick(e, linha, line(linha), i); } : (children) ? function () { return handleOpenClose(i); } : undefined, onDoubleClick: (fullyEmpty) ? undefined : (onDoubleClick) ? function (e) { return onDoubleClick(e, linha, line(linha), i); } : undefined, innerRef: draggableRef }),
|
|
130
147
|
enableDrag && react_1.default.createElement(core_1.TableCell, { padding: 'checkbox' },
|
|
131
148
|
react_1.default.createElement(core_1.Tooltip, { title: 'Arrastar' },
|
|
132
149
|
react_1.default.createElement(core_1.IconButton, { size: 'small', className: classes.dragHandle },
|
|
@@ -136,7 +153,7 @@ var ArgousComplexTableBody = react_1.memo(function (_a) {
|
|
|
136
153
|
e.stopPropagation();
|
|
137
154
|
handleClick(linha[indexToSelect]);
|
|
138
155
|
}, checked: isItemSelected })),
|
|
139
|
-
lodash_1.isArray(line(linha)) && line(linha).map(function (coluna, j) { return (react_1.default.createElement(core_1.TableCell, __assign({ key: j }, columnProps(j, coluna, linha, line(linha)), { style: columnStyles ? columnStyles[j] : undefined }), getCellContent(coluna, dadosMostrados[i], j, i))); }))),
|
|
156
|
+
lodash_1.isArray(line(linha)) && line(linha).map(function (coluna, j) { return ((fullyEmpty) ? (react_1.default.createElement(core_1.TableCell, __assign({ key: j }, columnProps(j, coluna, linha, line(linha)), { style: columnStyles ? columnStyles[j] : undefined, className: clsx_1.default(classes.tableCell, classes.ghost) }), "\u00A0")) : (react_1.default.createElement(core_1.TableCell, __assign({ key: j }, columnProps(j, coluna, linha, line(linha)), { style: columnStyles ? columnStyles[j] : undefined, className: classes.tableCell }), getCellContent(coluna, dadosMostrados[i], j, i)))); }))),
|
|
140
157
|
children && (react_1.default.createElement(core_1.TableRow, { className: classes.group },
|
|
141
158
|
react_1.default.createElement(core_1.TableCell, { colSpan: (dadosMostrados === null || dadosMostrados === void 0 ? void 0 : dadosMostrados.length) && ((_b = line(dadosMostrados[0])) === null || _b === void 0 ? void 0 : _b.length) + (enableCheck ? 1 : 0) + (enableDrag ? 1 : 0), style: { padding: open === i ? 8 : 0 }, className: 'argous-complex-table-group-cell' },
|
|
142
159
|
react_1.default.createElement(core_1.Collapse, { in: open === i, mountOnEnter: true, unmountOnExit: true }, typeof children === 'function' ? children({ linha: line(linha), linhaOriginal: linha, index: i }) : children))))));
|
|
@@ -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,
|
|
@@ -180,31 +180,60 @@ const ArgousComplexTable = forwardRef(({
|
|
|
180
180
|
code = '',
|
|
181
181
|
token = ''
|
|
182
182
|
}, ref) => {
|
|
183
|
+
|
|
183
184
|
const classes = useStyles();
|
|
184
185
|
const [state, dispatch] = useReducer(reducer, initialState(defaultRowsPerPage));
|
|
185
186
|
const memoState = useMemo(() => ({ ...state, dispatch }), [state, dispatch]);
|
|
186
187
|
const { selected, page, rowsPerPage, order, orderBy, filter, open } = memoState;
|
|
187
|
-
|
|
188
|
+
|
|
188
189
|
const [lista, setLista] = useState(dados/*.map(linha => isArray(linha) ? linha : Object.values(linha))*/ || []);
|
|
189
190
|
const [ctrlPgn, setCtrlPgn] = useState({ qtRegs: defaultRowsPerPage, pgAtl: 1 });
|
|
190
191
|
const { qtRegs, pgAtl, ordCols } = ctrlPgn;
|
|
191
|
-
|
|
192
|
+
|
|
192
193
|
const enableCheck = checkEnabled || (enableCheckIfSelected && !!selected.length);
|
|
193
|
-
|
|
194
|
+
|
|
195
|
+
const dadosNaoCortados = useMemo(() => {
|
|
196
|
+
if (method) return lista || [];
|
|
197
|
+
if (isArray(lista) && lista.length > 0) return stableSort(lista, getComparator(order, orderBy), line)
|
|
198
|
+
.filter(linha => isArray(line(linha)) ? line(linha).filter(item => filter ? new RegExp(`.*${filter}.*`, 'gi').test(item?.toString()) : true).length > 0 : true) || [];
|
|
199
|
+
return [];
|
|
200
|
+
}, [lista, filter, order, orderBy, method, line]);
|
|
201
|
+
|
|
202
|
+
const usePagination = ((rowsPerPageOptions !== 0) && (Math.ceil(((method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length) / parseInt(rowsPerPageOptions[0], 10)) > 1));
|
|
203
|
+
|
|
204
|
+
const cortaDados = useCallback((dados) => dados
|
|
205
|
+
?.slice(defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage, defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage + rowsPerPage),
|
|
206
|
+
[page, rowsPerPage, defaultRowsPerPage]);
|
|
207
|
+
|
|
208
|
+
const fillListToKeepHeight = useCallback((array) => {
|
|
209
|
+
let newArray = [...array];
|
|
210
|
+
if (newArray.length < rowsPerPage) {
|
|
211
|
+
const gap = (rowsPerPage - newArray.length);
|
|
212
|
+
const arrayToFillGap = Array.from(Array(gap)).fill(Array.from(Array(head.length)).fill(''));
|
|
213
|
+
newArray.push(...arrayToFillGap);
|
|
214
|
+
}
|
|
215
|
+
return newArray;
|
|
216
|
+
}, [head, rowsPerPage]);
|
|
217
|
+
|
|
218
|
+
const dadosMostrados = useMemo(() => {
|
|
219
|
+
if (method || externalCtrlPgn) return (usePagination) ? fillListToKeepHeight(lista || []) : (lista || []);
|
|
220
|
+
return (usePagination) ? fillListToKeepHeight(cortaDados(dadosNaoCortados) || []) : (cortaDados(dadosNaoCortados) || []);
|
|
221
|
+
}, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados, usePagination, fillListToKeepHeight]);
|
|
222
|
+
|
|
194
223
|
useEffect(() => {
|
|
195
224
|
dispatch({ type: 'mount', value: savedState.current });
|
|
196
225
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
197
226
|
}, []);
|
|
198
|
-
|
|
227
|
+
|
|
199
228
|
useEffect(() => {
|
|
200
|
-
return () => savedState.current = state;
|
|
229
|
+
return () => savedState.current = state;
|
|
201
230
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
202
231
|
}, [state]);
|
|
203
|
-
|
|
232
|
+
|
|
204
233
|
useEffect(() => {
|
|
205
234
|
if (isArray(dados)) setLista(dados/*.map(linha => isArray(linha) ? linha : Object.values(linha))*/ || []);
|
|
206
235
|
}, [dados]);
|
|
207
|
-
|
|
236
|
+
|
|
208
237
|
const retornaAcao = useCallback((pgAtl, page) => {
|
|
209
238
|
if (page === pgAtl) return undefined;
|
|
210
239
|
else if (page === pgAtl + 1) return 'N';
|
|
@@ -213,7 +242,7 @@ const ArgousComplexTable = forwardRef(({
|
|
|
213
242
|
else if (page === 0) return 'F';
|
|
214
243
|
return `S=${page}`;
|
|
215
244
|
}, [ctrlPgn.recordCount]);
|
|
216
|
-
|
|
245
|
+
|
|
217
246
|
const buscaMetodo = useCallback(async () => {
|
|
218
247
|
if (!method || !allowMethodRequest) return;
|
|
219
248
|
dispatch({ type: 'setLoading', value: true });
|
|
@@ -233,45 +262,29 @@ const ArgousComplexTable = forwardRef(({
|
|
|
233
262
|
dispatch({ type: 'setLoading', value: false });
|
|
234
263
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
235
264
|
}, [method, allowMethodRequest, qtRegs, pgAtl, retornaAcao, ctrlPgn.pgAtl, page, orderBy, order, methodPrms, handleMethodError, methodResultList, code, token]);
|
|
236
|
-
|
|
265
|
+
|
|
237
266
|
useEffect(() => {
|
|
238
267
|
buscaMetodo();
|
|
239
268
|
}, [buscaMetodo]);
|
|
240
|
-
|
|
269
|
+
|
|
241
270
|
const fielValue = useMemo(() => /*isArray(getField(field, 'value')) ? */getField(field, 'value')/*?.map(item => isArray(item) ? item : Object.values(item)) : []*/, [field]);
|
|
242
|
-
|
|
271
|
+
|
|
243
272
|
useEffect(() => {
|
|
244
273
|
if (field && !isEqual(lista, fielValue)) setLista(fielValue || []);
|
|
245
274
|
}, [field, lista, fielValue]);
|
|
246
|
-
|
|
275
|
+
|
|
247
276
|
useEffect(() => {
|
|
248
277
|
if (method || field || externalCtrlPgn) return;
|
|
249
278
|
if (isArray(lista) && lista.length > 0 && page === Math.ceil(method ? ctrlPgn.recordCount : lista.length / parseInt(rowsPerPage, 10))) dispatch({ type: 'decremmentPage' });
|
|
250
279
|
}, [page, method, lista.length, rowsPerPage, ctrlPgn.recordCount, lista, field, externalCtrlPgn]);
|
|
251
|
-
|
|
280
|
+
|
|
252
281
|
useEffect(() => dispatch({ type: 'setSelected', value: [] }), [lista]);
|
|
253
|
-
|
|
282
|
+
|
|
254
283
|
useEffect(() => {
|
|
255
284
|
if (onSelect) onSelect(selected);
|
|
256
285
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
257
286
|
}, [selected]);
|
|
258
|
-
|
|
259
|
-
const dadosNaoCortados = useMemo(() => {
|
|
260
|
-
if (method) return lista || [];
|
|
261
|
-
if (isArray(lista) && lista.length > 0) return stableSort(lista, getComparator(order, orderBy), line)
|
|
262
|
-
.filter(linha => isArray(line(linha)) ? line(linha).filter(item => filter ? new RegExp(`.*${filter}.*`, 'gi').test(item?.toString()) : true).length > 0 : true) || [];
|
|
263
|
-
return [];
|
|
264
|
-
}, [lista, filter, order, orderBy, method, line]);
|
|
265
|
-
|
|
266
|
-
const cortaDados = useCallback((dados) => dados
|
|
267
|
-
?.slice(defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage, defaultRowsPerPage === 0 ? (undefined) : page * rowsPerPage + rowsPerPage),
|
|
268
|
-
[page, rowsPerPage, defaultRowsPerPage]);
|
|
269
|
-
|
|
270
|
-
const dadosMostrados = useMemo(() => {
|
|
271
|
-
if (method || externalCtrlPgn) return lista || [];
|
|
272
|
-
return cortaDados(dadosNaoCortados) || [];
|
|
273
|
-
}, [method, externalCtrlPgn, lista, dadosNaoCortados, cortaDados]);
|
|
274
|
-
|
|
287
|
+
|
|
275
288
|
const handleOpenClose = useCallback((index) => {
|
|
276
289
|
if (index === open || (!index && index !== 0)) {
|
|
277
290
|
dispatch({ type: 'setOpen', value: undefined });
|
|
@@ -281,7 +294,7 @@ const ArgousComplexTable = forwardRef(({
|
|
|
281
294
|
if (onOpen) onOpen({ linhaOriginal: dadosMostrados[index], linhaFormatada: line(dadosMostrados[index]) });
|
|
282
295
|
}
|
|
283
296
|
}, [open, onClose, onOpen, dadosMostrados, dispatch, line]);
|
|
284
|
-
|
|
297
|
+
|
|
285
298
|
useImperativeHandle(ref, () => ({
|
|
286
299
|
setOpen: index => handleOpenClose(index),
|
|
287
300
|
getOpen: dadosMostrados[open],
|
|
@@ -353,7 +366,7 @@ const ArgousComplexTable = forwardRef(({
|
|
|
353
366
|
}}/>
|
|
354
367
|
{FooterComponent && <FooterComponent {...footerProps}/>}
|
|
355
368
|
</Table>
|
|
356
|
-
{(
|
|
369
|
+
{(usePagination) && (
|
|
357
370
|
<PaginationComponent
|
|
358
371
|
count={(method || externalCtrlPgn) ? ctrlPgn.recordCount : dadosNaoCortados.length}
|
|
359
372
|
onChangePage={(_, value) => {
|
|
@@ -373,7 +386,7 @@ const ArgousComplexTable = forwardRef(({
|
|
|
373
386
|
</TableContext.Provider>
|
|
374
387
|
);
|
|
375
388
|
});
|
|
376
|
-
|
|
389
|
+
|
|
377
390
|
ArgousComplexTable.propTypes = {
|
|
378
391
|
dados: PropTypes.array,
|
|
379
392
|
head: PropTypes.array,
|
|
@@ -411,5 +424,5 @@ ArgousComplexTable.propTypes = {
|
|
|
411
424
|
externalCtrlPgn: PropTypes.object,
|
|
412
425
|
setExternalCtrlPgn: PropTypes.func
|
|
413
426
|
};
|
|
414
|
-
|
|
427
|
+
|
|
415
428
|
export default memo(ArgousComplexTable, isEqual);
|
|
@@ -37,6 +37,18 @@ const useStyles = makeStyles(theme => ({
|
|
|
37
37
|
loading: {
|
|
38
38
|
textAlign: 'center',
|
|
39
39
|
padding: '7px'
|
|
40
|
+
},
|
|
41
|
+
ghost: {
|
|
42
|
+
borderBottom: '1px solid #0000',
|
|
43
|
+
userSelect: 'none',
|
|
44
|
+
'&:hover': {
|
|
45
|
+
backgroundColor: '#0000 !important'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
tableCell: {
|
|
49
|
+
overflow: 'hidden',
|
|
50
|
+
whiteSpace: 'nowrap',
|
|
51
|
+
textOverflow: 'ellipsis'
|
|
40
52
|
}
|
|
41
53
|
}));
|
|
42
54
|
|
|
@@ -96,10 +108,13 @@ const ArgousComplexTableBody = memo(({
|
|
|
96
108
|
{loading ? (
|
|
97
109
|
<TableRow><TableCell className={classes.loading} colSpan={dadosMostrados?.length && line(dadosMostrados[0])?.length + (enableCheck ? 1 : 0) + (enableDrag ? 1 : 0)}><CircularProgress disableShrink/></TableCell></TableRow>
|
|
98
110
|
) : dadosMostrados.length ? dadosMostrados.map((linha, i) => {
|
|
111
|
+
|
|
99
112
|
const isItemSelected = isSelected(linha[indexToSelect]);
|
|
100
113
|
const isItemOpen = i === open;
|
|
101
|
-
|
|
114
|
+
const fullyEmpty = !linha.some((value) => !!value);
|
|
102
115
|
const { title, ...rowProperties } = rowProps({ index: i, linhaOriginal: linha, linhaFormatada: line(linha), itensSelecionados: selected }) || {};
|
|
116
|
+
|
|
117
|
+
|
|
103
118
|
return <Draggable key={customKey ? lista[i][customKey] : i} render={draggableRef => (
|
|
104
119
|
//TODO criar proprio draggable pois esse remove classes do filho
|
|
105
120
|
<Fragment>
|
|
@@ -107,15 +122,25 @@ const ArgousComplexTableBody = memo(({
|
|
|
107
122
|
<TableRow
|
|
108
123
|
component={Draggable}
|
|
109
124
|
{...rowProperties}
|
|
110
|
-
className={
|
|
125
|
+
className={
|
|
126
|
+
clsx(
|
|
127
|
+
{
|
|
128
|
+
[classes.hover]: isItemSelected,
|
|
129
|
+
[classes.open]: (isItemOpen && !!children),
|
|
130
|
+
[classes.ghost]: fullyEmpty
|
|
131
|
+
},
|
|
132
|
+
lineClass(line(linha), linha, i),
|
|
133
|
+
rowProperties.className
|
|
134
|
+
)
|
|
135
|
+
}
|
|
111
136
|
hover
|
|
112
137
|
role='checkbox'
|
|
113
138
|
tabIndex={-1}
|
|
114
139
|
selected={isItemSelected}
|
|
115
140
|
style={lineStyle ? lineStyle(linha, line(linha), i) : undefined}
|
|
116
|
-
onClick={onClick ? e => onClick(e, linha, line(linha), i) : children ? () => handleOpenClose(i) : undefined}
|
|
117
|
-
onDoubleClick={onDoubleClick ? e => onDoubleClick(e, linha, line(linha), i) : undefined}
|
|
118
|
-
innerRef={draggableRef}
|
|
141
|
+
onClick={(fullyEmpty) ? undefined : (onClick) ? e => onClick(e, linha, line(linha), i) : (children) ? () => handleOpenClose(i) : undefined}
|
|
142
|
+
onDoubleClick={(fullyEmpty) ? undefined : (onDoubleClick) ? e => onDoubleClick(e, linha, line(linha), i) : undefined}
|
|
143
|
+
innerRef={draggableRef}
|
|
119
144
|
>
|
|
120
145
|
{enableDrag && <TableCell padding='checkbox'>
|
|
121
146
|
<Tooltip title='Arrastar'>
|
|
@@ -131,7 +156,25 @@ const ArgousComplexTableBody = memo(({
|
|
|
131
156
|
}} checked={isItemSelected} />
|
|
132
157
|
</TableCell>}
|
|
133
158
|
{isArray(line(linha)) && line(linha).map((coluna, j) => (
|
|
134
|
-
|
|
159
|
+
(fullyEmpty) ? (
|
|
160
|
+
<TableCell
|
|
161
|
+
key={j}
|
|
162
|
+
{...columnProps(j, coluna, linha, line(linha))}
|
|
163
|
+
style={columnStyles ? columnStyles[j] : undefined}
|
|
164
|
+
className={clsx(classes.tableCell, classes.ghost)}
|
|
165
|
+
>
|
|
166
|
+
|
|
167
|
+
</TableCell>
|
|
168
|
+
) : (
|
|
169
|
+
<TableCell
|
|
170
|
+
key={j}
|
|
171
|
+
{...columnProps(j, coluna, linha, line(linha))}
|
|
172
|
+
style={columnStyles ? columnStyles[j] : undefined}
|
|
173
|
+
className={classes.tableCell}
|
|
174
|
+
>
|
|
175
|
+
{getCellContent(coluna, dadosMostrados[i], j, i)}
|
|
176
|
+
</TableCell>
|
|
177
|
+
)
|
|
135
178
|
))}
|
|
136
179
|
</TableRow>
|
|
137
180
|
</CustomTooltip>
|
|
@@ -139,7 +182,7 @@ const ArgousComplexTableBody = memo(({
|
|
|
139
182
|
<TableRow className={classes.group}>
|
|
140
183
|
<TableCell colSpan={dadosMostrados?.length && line(dadosMostrados[0])?.length + (enableCheck ? 1 : 0) + (enableDrag ? 1 : 0)} style={{ padding: open === i ? 8 : 0 }} className='argous-complex-table-group-cell'>
|
|
141
184
|
<Collapse in={open === i} mountOnEnter unmountOnExit>
|
|
142
|
-
{typeof children === 'function' ? children({ linha: line(linha), linhaOriginal: linha, index: i }) : children}
|
|
185
|
+
{typeof children === 'function' ? children({ linha: line(linha), linhaOriginal: linha, index: i }) : children}
|
|
143
186
|
</Collapse>
|
|
144
187
|
</TableCell>
|
|
145
188
|
</TableRow>
|
|
@@ -158,5 +201,5 @@ export const CustomTooltip = ({ title, children }) => {
|
|
|
158
201
|
if (title) return <Tooltip arrow title={title}>
|
|
159
202
|
{children}
|
|
160
203
|
</Tooltip>;
|
|
161
|
-
return children;
|
|
204
|
+
return children;
|
|
162
205
|
};
|