@ssplib/react-components 0.0.274 → 0.0.276
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/components/form/table/FilterSection.d.ts +8 -0
- package/components/form/table/FilterSection.js +217 -0
- package/components/form/table/GenericTable.d.ts +2 -2
- package/components/form/table/Table.d.ts +3 -207
- package/components/form/table/Table.js +98 -672
- package/components/form/table/TableErrorState.d.ts +9 -0
- package/components/form/table/TableErrorState.js +27 -0
- package/components/form/table/TableLoadingState.d.ts +6 -0
- package/components/form/table/TableLoadingState.js +39 -0
- package/components/form/table/types.d.ts +50 -128
- package/components/form/table/utils.d.ts +51 -0
- package/components/form/table/utils.js +383 -0
- package/package.json +3 -1
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Table = void 0;
|
|
30
|
+
const TableErrorState_1 = require("./TableErrorState");
|
|
30
31
|
const icons_material_1 = require("@mui/icons-material");
|
|
31
32
|
const Clear_1 = __importDefault(require("@mui/icons-material/Clear"));
|
|
32
33
|
const FileDownload_1 = __importDefault(require("@mui/icons-material/FileDownload"));
|
|
@@ -37,47 +38,27 @@ const Grid_1 = __importDefault(require("@mui/material/Grid"));
|
|
|
37
38
|
const Pagination_1 = __importDefault(require("@mui/material/Pagination"));
|
|
38
39
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
39
40
|
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
40
|
-
const x_date_pickers_1 = require("@mui/x-date-pickers");
|
|
41
|
-
const AdapterDayjs_1 = require("@mui/x-date-pickers/AdapterDayjs");
|
|
42
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
43
|
-
const jszip_1 = __importDefault(require("jszip"));
|
|
44
41
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
45
42
|
const react_1 = __importStar(require("react"));
|
|
46
43
|
const auth_1 = require("../../../context/auth");
|
|
47
44
|
const Modal_1 = require("../../modal/Modal");
|
|
48
45
|
const CustomMenu_1 = __importDefault(require("../../utils//CustomMenu"));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Remove punctuation marks
|
|
53
|
-
const cleanedText = normalizedText.replace(/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/g, '');
|
|
54
|
-
return cleanedText;
|
|
55
|
-
}
|
|
56
|
-
function formatarString(str) {
|
|
57
|
-
const value = typeof str !== 'string' ? str.toString() : str;
|
|
58
|
-
return value
|
|
59
|
-
.normalize('NFD')
|
|
60
|
-
.replace(/[\u0300-\u036f]/g, '')
|
|
61
|
-
.toLowerCase()
|
|
62
|
-
.trim();
|
|
63
|
-
}
|
|
64
|
-
let startData = [];
|
|
46
|
+
const TableLoadingState_1 = require("./TableLoadingState");
|
|
47
|
+
const utils_1 = require("./utils");
|
|
48
|
+
const FilterSection_1 = require("./FilterSection");
|
|
65
49
|
let isExpandAll = false;
|
|
66
50
|
let localTableName = '';
|
|
67
|
-
let orderAsc = false;
|
|
68
51
|
let filtersFuncData = {};
|
|
69
52
|
let localTableNameCache = '';
|
|
70
53
|
function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
71
54
|
user: 'Nenhum dado encontrado',
|
|
72
55
|
public: 'Nenhum dado encontrado',
|
|
73
|
-
}, dataPath = '', tableName = '
|
|
74
|
-
// filters = {},
|
|
75
|
-
// filterSeparator = '|',
|
|
76
|
-
hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMaxLength = 50, collapsedSize = 53, customMargin = 4, customMarginMobile = 0, filtersFunc, filters = [], orderBy = [], customErrorMsg = undefined, customTableStyle = {}, id, }) {
|
|
56
|
+
}, dataPath = '', tableName = 'Dado', csv, columnSize, action, useKC = true, statusKeyName = '', csvExcludeKeys = [], csvExcludeKeysCSV = [], csvExcludeKeysAll = [], csvCustomKeyNames = {}, csvExcludeValidate = (key, value) => false, csvButtonTitle = 'Salvar .CSV', csvNoZipText = 'Salvar .CSV', csvAllButtonTitle = 'Salvar todos em CSV', removeQuotes = false, normalize = false, csvShowAllButton = false, csvWithoutZip = false, itemCount = 10, csvUpper = false, csvZipFileNamesKey = '', generateCsvZip = false, hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMaxLength = 50, collapsedSize = 53, customMargin = 4, customMarginMobile = 0, filtersFunc, filters = [], orderBy = [], customErrorMsg = undefined, customTableStyle = {}, id, initialData = null, }) {
|
|
77
57
|
var _a;
|
|
78
|
-
const [isLoading, setIsLoading] = (0, react_1.useState)(
|
|
58
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
79
59
|
const [error, setError] = (0, react_1.useState)(null);
|
|
80
|
-
const [data, setData] = (0, react_1.useState)(
|
|
60
|
+
const [data, setData] = (0, react_1.useState)(initialData);
|
|
61
|
+
/** startData Dado puro, sem filtro ou ordenação */
|
|
81
62
|
const { user, userLoaded } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
82
63
|
const [list, setList] = (0, react_1.useState)([]);
|
|
83
64
|
const [listClone, setListClone] = (0, react_1.useState)([]);
|
|
@@ -86,14 +67,14 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
86
67
|
const [currentPage, setCurrentPage] = (0, react_1.useState)(0);
|
|
87
68
|
const [paginationCount, setPagCount] = (0, react_1.useState)(1);
|
|
88
69
|
const [listPage, setListPage] = (0, react_1.useState)(1);
|
|
89
|
-
const [oldSelectState, setOldSelectState] = (0, react_1.useState)('');
|
|
90
70
|
const [expandObj, setExpandObj] = (0, react_1.useState)({});
|
|
91
71
|
const [showExpandObj, setShowExpandObj] = (0, react_1.useState)({});
|
|
92
72
|
const [showExpandObjOnExited, setShowExpandObjOnExited] = (0, react_1.useState)({});
|
|
93
73
|
const [filterKey, setFilterKey] = (0, react_1.useState)('filterKey');
|
|
94
74
|
const theme = (0, material_1.useTheme)();
|
|
95
75
|
const isSmall = (0, material_1.useMediaQuery)(theme.breakpoints.only('xs'));
|
|
96
|
-
const
|
|
76
|
+
const startData = (0, react_1.useRef)(data);
|
|
77
|
+
const orderAsc = (0, react_1.useRef)(false);
|
|
97
78
|
const lg = (0, material_1.useMediaQuery)(theme.breakpoints.up(2000));
|
|
98
79
|
localTableName = `tableFilter_${id}`;
|
|
99
80
|
localTableNameCache = `tableFilterCache_${id}`;
|
|
@@ -106,6 +87,8 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
106
87
|
}
|
|
107
88
|
(0, react_1.useEffect)(() => {
|
|
108
89
|
setError(null);
|
|
90
|
+
if (!fetchFunc)
|
|
91
|
+
return;
|
|
109
92
|
if (userLoaded || !useKC) {
|
|
110
93
|
setIsLoading(true);
|
|
111
94
|
fetchFunc()
|
|
@@ -120,7 +103,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
120
103
|
return res.json().then((j) => {
|
|
121
104
|
if (j.statusCode === 204) {
|
|
122
105
|
setData({ body: { data: [] } });
|
|
123
|
-
startData = [];
|
|
106
|
+
startData.current = [];
|
|
124
107
|
}
|
|
125
108
|
else if (j.statusCode === 403)
|
|
126
109
|
setError({
|
|
@@ -130,11 +113,11 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
130
113
|
let value = dataPath ? (0, lodash_get_1.default)(j, dataPath) : j;
|
|
131
114
|
if (!value || !Array.isArray(value)) {
|
|
132
115
|
setData({ body: { data: [] } });
|
|
133
|
-
startData = [];
|
|
116
|
+
startData.current = [];
|
|
134
117
|
}
|
|
135
118
|
else {
|
|
136
119
|
setData(value);
|
|
137
|
-
startData = JSON.parse(JSON.stringify(value));
|
|
120
|
+
startData.current = JSON.parse(JSON.stringify(value));
|
|
138
121
|
}
|
|
139
122
|
}
|
|
140
123
|
setIsLoading(false);
|
|
@@ -147,13 +130,6 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
147
130
|
});
|
|
148
131
|
}
|
|
149
132
|
}, [userLoaded, fetchFunc]);
|
|
150
|
-
const getCount = (0, react_1.useCallback)((countData) => {
|
|
151
|
-
if (countData.length <= 0)
|
|
152
|
-
return 1;
|
|
153
|
-
let count = countData.length / itemsCount;
|
|
154
|
-
count = count < 1 ? 1 : count;
|
|
155
|
-
return Math.ceil(count);
|
|
156
|
-
}, [itemsCount]);
|
|
157
133
|
const getData = (0, react_1.useCallback)((dt) => {
|
|
158
134
|
if (Array.isArray(dt))
|
|
159
135
|
return dt;
|
|
@@ -166,11 +142,22 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
166
142
|
const value = getData(data);
|
|
167
143
|
setList(value);
|
|
168
144
|
setListClone(value);
|
|
169
|
-
setPagCount(getCount(value));
|
|
145
|
+
setPagCount((0, utils_1.getCount)(value, itemsCount));
|
|
170
146
|
if (localStorage.getItem(localTableName)) {
|
|
171
|
-
|
|
147
|
+
(0, utils_1.filtrarDados)({
|
|
148
|
+
filterData: JSON.parse(localStorage.getItem(localTableName)),
|
|
149
|
+
filtersFuncData: filtersFuncData,
|
|
150
|
+
localTableName: localTableName,
|
|
151
|
+
setCurrentPage: setCurrentPage,
|
|
152
|
+
setList,
|
|
153
|
+
setListClone,
|
|
154
|
+
setListPage,
|
|
155
|
+
setPagCount,
|
|
156
|
+
startData: startData.current,
|
|
157
|
+
itemsCount,
|
|
158
|
+
});
|
|
172
159
|
}
|
|
173
|
-
}, [itemsCount, isLoading, data,
|
|
160
|
+
}, [itemsCount, isLoading, data, error]);
|
|
174
161
|
(0, react_1.useEffect)(() => {
|
|
175
162
|
setCurrentPage(listPage - 1);
|
|
176
163
|
}, [listPage]);
|
|
@@ -178,11 +165,10 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
178
165
|
setListPage(page);
|
|
179
166
|
}, []);
|
|
180
167
|
function onInputChange(e) {
|
|
181
|
-
console.log(listClone);
|
|
182
168
|
const searchValue = e.target.value;
|
|
183
169
|
if (searchValue === '') {
|
|
184
170
|
setList(listClone);
|
|
185
|
-
setPagCount(getCount(getData(list)));
|
|
171
|
+
setPagCount((0, utils_1.getCount)(getData(list), itemsCount));
|
|
186
172
|
return;
|
|
187
173
|
}
|
|
188
174
|
const listData = getData(list);
|
|
@@ -242,7 +228,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
242
228
|
return;
|
|
243
229
|
}
|
|
244
230
|
}
|
|
245
|
-
if (removePunctuationAndAccents(key.toLowerCase()).includes(removePunctuationAndAccents(searchValue.toLowerCase()))) {
|
|
231
|
+
if ((0, utils_1.removePunctuationAndAccents)(key.toLowerCase()).includes((0, utils_1.removePunctuationAndAccents)(searchValue.toLowerCase()))) {
|
|
246
232
|
exists = true;
|
|
247
233
|
}
|
|
248
234
|
});
|
|
@@ -251,7 +237,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
251
237
|
newList.push(x);
|
|
252
238
|
});
|
|
253
239
|
setList(newList);
|
|
254
|
-
setPagCount(getCount(newList));
|
|
240
|
+
setPagCount((0, utils_1.getCount)(newList, itemsCount));
|
|
255
241
|
setCurrentPage(0);
|
|
256
242
|
setListPage(1);
|
|
257
243
|
}
|
|
@@ -259,201 +245,19 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
259
245
|
const start = currentPage * itemsCount;
|
|
260
246
|
return list.slice(start, start + itemsCount);
|
|
261
247
|
}, [list, itemsCount, currentPage]);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
272
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
273
|
-
}
|
|
274
|
-
return cell;
|
|
275
|
-
}
|
|
276
|
-
// download file
|
|
277
|
-
const downloadCSV = (0, react_1.useCallback)((e, zip = false) => {
|
|
278
|
-
e.preventDefault();
|
|
279
|
-
if (list.length <= 0)
|
|
280
|
-
return;
|
|
281
|
-
const originalKeys = Object.keys(list[0]);
|
|
282
|
-
if (generateCsvZip && zip) {
|
|
283
|
-
const keys = originalKeys.filter((k) => !csvExcludeKeys.includes(k));
|
|
284
|
-
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
285
|
-
const zip = new jszip_1.default();
|
|
286
|
-
const obj = {};
|
|
287
|
-
list.forEach((x) => {
|
|
288
|
-
if (!obj[x[csvZipFileNamesKey]])
|
|
289
|
-
obj[x[csvZipFileNamesKey]] = [];
|
|
290
|
-
obj[x[csvZipFileNamesKey]].push(x);
|
|
291
|
-
});
|
|
292
|
-
Object.keys(obj).forEach((objKey) => {
|
|
293
|
-
const values = [];
|
|
294
|
-
obj[objKey].forEach((x) => {
|
|
295
|
-
let include = true;
|
|
296
|
-
originalKeys.forEach((k) => {
|
|
297
|
-
//verificar se pode incluir
|
|
298
|
-
if (csvExcludeValidate(k, x[k])) {
|
|
299
|
-
include = false;
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
if (include) {
|
|
303
|
-
const value = keys
|
|
304
|
-
.map((k) => {
|
|
305
|
-
if (typeof x[k] === 'string') {
|
|
306
|
-
let item = csvUpper ? x[k].toUpperCase() : x[k];
|
|
307
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
308
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
309
|
-
}
|
|
310
|
-
else if (typeof x[k] === 'object' && !Array.isArray(x[k]) && x[k] !== null) {
|
|
311
|
-
let strItemAsObject = transformArrayObjectInString(x[k]).slice(1, -1); // k: label (Ex.: jsNaturezaEvento)
|
|
312
|
-
let item = csvUpper && !csvExcludeUpper.includes(k) ? strItemAsObject.toUpperCase() : strItemAsObject;
|
|
313
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
314
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
315
|
-
}
|
|
316
|
-
return x[k];
|
|
317
|
-
})
|
|
318
|
-
.join(',');
|
|
319
|
-
values.push(value);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
const csvData = hideTitleCSV ? values.join('\n') : '\uFEFF' + header + values.join('\n');
|
|
323
|
-
if (values.length > 0)
|
|
324
|
-
zip.file(`${objKey.normalize('NFD').replace(/[\u0300-\u036f]/g, '')}.csv`, csvData);
|
|
325
|
-
});
|
|
326
|
-
// // download
|
|
327
|
-
var link = window.document.createElement('a');
|
|
328
|
-
zip.generateAsync({ type: 'base64' }).then((base) => {
|
|
329
|
-
link.setAttribute('href', 'data:application/zip;base64,' + base);
|
|
330
|
-
link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.zip`);
|
|
331
|
-
link.click();
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
let keys = originalKeys
|
|
336
|
-
.filter((k) => !csvExcludeKeysCSV.includes(k))
|
|
337
|
-
.map((k) => {
|
|
338
|
-
if (k === multipleDataPath) {
|
|
339
|
-
return 'hrTermino';
|
|
340
|
-
}
|
|
341
|
-
return k;
|
|
342
|
-
});
|
|
343
|
-
if (multipleDataPath !== '') {
|
|
344
|
-
keys = ['dtInicio', 'hrInicio', ...keys];
|
|
345
|
-
}
|
|
346
|
-
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
347
|
-
const values = [];
|
|
348
|
-
list.forEach((x) => {
|
|
349
|
-
let include = true;
|
|
350
|
-
originalKeys.forEach((k) => {
|
|
351
|
-
//verificar se pode incluir
|
|
352
|
-
if (csvExcludeValidate(k, x[k])) {
|
|
353
|
-
include = false;
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
if (include) {
|
|
357
|
-
const value = keys
|
|
358
|
-
.map((k) => {
|
|
359
|
-
if (k === 'dtInicio')
|
|
360
|
-
return '{dtInicio}';
|
|
361
|
-
else if (k === 'hrInicio')
|
|
362
|
-
return '{hrInicio}';
|
|
363
|
-
else if (k === 'hrTermino')
|
|
364
|
-
return '{hrTermino}';
|
|
365
|
-
else {
|
|
366
|
-
if (typeof x[k] === 'string') {
|
|
367
|
-
let item = csvUpper && !csvExcludeUpper.includes(k) ? x[k].toUpperCase() : x[k];
|
|
368
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
369
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
370
|
-
}
|
|
371
|
-
else if (typeof x[k] === 'object' && !Array.isArray(x[k]) && x[k] !== null) {
|
|
372
|
-
let strItemAsObject = transformArrayObjectInString(x[k]).slice(1, -1); // k: label (Ex.: jsNaturezaEvento)
|
|
373
|
-
let item = csvUpper && !csvExcludeUpper.includes(k) ? strItemAsObject.toUpperCase() : strItemAsObject;
|
|
374
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
375
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
376
|
-
}
|
|
377
|
-
return x[k];
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
.join(',');
|
|
381
|
-
if (multipleDataPath !== '') {
|
|
382
|
-
const dates = x[multipleDataPath];
|
|
383
|
-
if (dates) {
|
|
384
|
-
;
|
|
385
|
-
dates.forEach((d) => {
|
|
386
|
-
values.push(value.replace('{dtInicio}', d.dtInicio).replace('{hrInicio}', d.hrInicio).replace('{hrTermino}', d.hrTermino));
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
values.push(value);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
248
|
+
// effect usado quando for mostrar "VER MAIS" e "VER MENOS"
|
|
249
|
+
(0, react_1.useEffect)(() => {
|
|
250
|
+
const start = currentPage * itemsCount;
|
|
251
|
+
const newList = list.slice(start, start + itemsCount);
|
|
252
|
+
let obj = {};
|
|
253
|
+
newList.forEach((x, index) => {
|
|
254
|
+
columns.forEach((c) => {
|
|
255
|
+
var _a;
|
|
256
|
+
obj[index] = obj[index] === true ? true : ((_a = (0, lodash_get_1.default)(x, c.keyName, '')) !== null && _a !== void 0 ? _a : 'Não Informado').toString().length >= expandTextMaxLength;
|
|
394
257
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
|
|
399
|
-
link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
|
|
400
|
-
link.click();
|
|
401
|
-
}
|
|
402
|
-
}, [list]);
|
|
403
|
-
function transformArrayObjectInString(o) {
|
|
404
|
-
let arrString = [];
|
|
405
|
-
if (typeof o === 'object' && !Array.isArray(o) && o !== null) {
|
|
406
|
-
for (let [key, value] of Object.entries(o)) {
|
|
407
|
-
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
|
|
408
|
-
arrString.push(key + ': ' + transformArrayObjectInString(value));
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
if (value) {
|
|
412
|
-
// Is true
|
|
413
|
-
arrString.push(key);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return '[' + arrString.join(' - ') + ']';
|
|
419
|
-
}
|
|
420
|
-
const downloadCSVAll = (0, react_1.useCallback)((e) => {
|
|
421
|
-
e.preventDefault();
|
|
422
|
-
if (list.length <= 0)
|
|
423
|
-
return;
|
|
424
|
-
const keys = Object.keys(list[0]).filter((k) => !csvExcludeKeysAll.includes(k));
|
|
425
|
-
const header = keys.join(',') + '\n';
|
|
426
|
-
const values = list
|
|
427
|
-
.map((x) => {
|
|
428
|
-
return keys
|
|
429
|
-
.map((k) => {
|
|
430
|
-
if (k === 'tbRa')
|
|
431
|
-
return x[k]['NO_CIDADE'];
|
|
432
|
-
if (k === 'rlEventoData')
|
|
433
|
-
return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
|
|
434
|
-
if (typeof x[k] === 'string') {
|
|
435
|
-
let item = csvUpper && !csvExcludeUpper.includes(k) ? x[k].toUpperCase() : x[k];
|
|
436
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
437
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
438
|
-
}
|
|
439
|
-
else if (typeof x[k] === 'object' && !Array.isArray(x[k]) && x[k] !== null) {
|
|
440
|
-
let strItemAsObject = transformArrayObjectInString(x[k]).slice(1, -1); // k: label (Ex.: jsNaturezaEvento)
|
|
441
|
-
let item = csvUpper && !csvExcludeUpper.includes(k) ? strItemAsObject.toUpperCase() : strItemAsObject;
|
|
442
|
-
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
443
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
444
|
-
}
|
|
445
|
-
return x[k];
|
|
446
|
-
})
|
|
447
|
-
.join(',');
|
|
448
|
-
})
|
|
449
|
-
.join('\n');
|
|
450
|
-
const csvData = header + values;
|
|
451
|
-
// download
|
|
452
|
-
var link = window.document.createElement('a');
|
|
453
|
-
link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
|
|
454
|
-
link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
|
|
455
|
-
link.click();
|
|
456
|
-
}, [list]);
|
|
258
|
+
});
|
|
259
|
+
setShowExpandObj(obj);
|
|
260
|
+
}, [list, itemsCount, currentPage]);
|
|
457
261
|
function expandAll() {
|
|
458
262
|
let obj = {};
|
|
459
263
|
for (let i = 0; i < itemCount; i++) {
|
|
@@ -464,265 +268,64 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
464
268
|
isExpandAll = !isExpandAll;
|
|
465
269
|
}
|
|
466
270
|
function reset() {
|
|
467
|
-
setList(startData);
|
|
468
|
-
setListClone(startData);
|
|
469
|
-
setPagCount(getCount(startData));
|
|
271
|
+
setList(startData.current);
|
|
272
|
+
setListClone(startData.current);
|
|
273
|
+
setPagCount((0, utils_1.getCount)(startData.current, itemsCount));
|
|
470
274
|
setCurrentPage(0);
|
|
471
275
|
setListPage(1);
|
|
472
276
|
localStorage.removeItem(localTableName);
|
|
473
277
|
setFilterKey(new Date().getTime().toString());
|
|
474
278
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
break;
|
|
494
|
-
case 'maior que':
|
|
495
|
-
currentData.forEach((cd) => {
|
|
496
|
-
const value = Number((0, lodash_get_1.default)(cd, dt.keyName, ''));
|
|
497
|
-
if (value > Number(dt.value)) {
|
|
498
|
-
filteredData.push(cd);
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
break;
|
|
502
|
-
case 'menor que':
|
|
503
|
-
currentData.forEach((cd) => {
|
|
504
|
-
const value = Number((0, lodash_get_1.default)(cd, dt.keyName, ''));
|
|
505
|
-
if (value < Number(dt.value)) {
|
|
506
|
-
filteredData.push(cd);
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
break;
|
|
510
|
-
}
|
|
511
|
-
break;
|
|
512
|
-
case 'string':
|
|
513
|
-
console.log('ata: ', dt.operator);
|
|
514
|
-
switch (dt.operator) {
|
|
515
|
-
case 'igual':
|
|
516
|
-
currentData.forEach((cd) => {
|
|
517
|
-
const value = (0, lodash_get_1.default)(cd, dt.keyName, '');
|
|
518
|
-
if (dt.useList) {
|
|
519
|
-
if (formatarString(value) === formatarString(dt.value.id)) {
|
|
520
|
-
filteredData.push(cd);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
if (formatarString(value) === formatarString(dt.value)) {
|
|
525
|
-
filteredData.push(cd);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
break;
|
|
530
|
-
case 'contem':
|
|
531
|
-
currentData.forEach((cd) => {
|
|
532
|
-
const value = (0, lodash_get_1.default)(cd, dt.keyName, '');
|
|
533
|
-
if (!value)
|
|
534
|
-
return;
|
|
535
|
-
if (dt.useList) {
|
|
536
|
-
if (formatarString(value).includes(formatarString(dt.value.id))) {
|
|
537
|
-
filteredData.push(cd);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
if (formatarString(value).includes(formatarString(dt.value))) {
|
|
542
|
-
filteredData.push(cd);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
break;
|
|
547
|
-
case 'tem um dos':
|
|
548
|
-
currentData.forEach((cd) => {
|
|
549
|
-
const value = (0, lodash_get_1.default)(cd, dt.keyName, '');
|
|
550
|
-
if (!value)
|
|
551
|
-
return;
|
|
552
|
-
if (dt.value.map((x) => formatarString(x.id)).includes(formatarString(value))) {
|
|
553
|
-
filteredData.push(cd);
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
break;
|
|
559
|
-
case 'date':
|
|
560
|
-
switch (dt.operator) {
|
|
561
|
-
case 'data exata':
|
|
562
|
-
currentData.forEach((cd) => {
|
|
563
|
-
const value = (0, dayjs_1.default)((0, lodash_get_1.default)(cd, dt.keyName, ''), 'DD/MM/YYYY');
|
|
564
|
-
if (!value.isValid())
|
|
565
|
-
return;
|
|
566
|
-
if (value.isSame((0, dayjs_1.default)(dt.value, 'DD/MM/YYYY'))) {
|
|
567
|
-
filteredData.push(cd);
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
break;
|
|
571
|
-
case 'entre':
|
|
572
|
-
const dateA = dt.value ? (0, dayjs_1.default)(dt.value, 'DD/MM/YYYY') : (0, dayjs_1.default)('01/01/2000', 'DD/MM/YYYY');
|
|
573
|
-
const dateB = dt.value2 ? (0, dayjs_1.default)(dt.value2, 'DD/MM/YYYY') : (0, dayjs_1.default)('31/12/2030', 'DD/MM/YYYY');
|
|
574
|
-
currentData.forEach((cd) => {
|
|
575
|
-
const value = (0, dayjs_1.default)((0, lodash_get_1.default)(cd, dt.keyName, ''), 'DD/MM/YYYY');
|
|
576
|
-
if ((value.isAfter(dateA) || value.isSame(dateA)) && (value.isBefore(dateB) || value.isSame(dateB))) {
|
|
577
|
-
filteredData.push(cd);
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
break;
|
|
583
|
-
case 'dates':
|
|
584
|
-
switch (dt.operator) {
|
|
585
|
-
case 'data inicio':
|
|
586
|
-
currentData.forEach((cd) => {
|
|
587
|
-
var _a;
|
|
588
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
589
|
-
if (dates.length <= 0)
|
|
590
|
-
return;
|
|
591
|
-
var inicioDate = dates[0];
|
|
592
|
-
var inicioValue = (0, dayjs_1.default)(inicioDate, 'DD/MM/YYYY');
|
|
593
|
-
if (inicioValue.isSame((0, dayjs_1.default)(dt.value, 'DD/MM/YYYY'))) {
|
|
594
|
-
filteredData.push(cd);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
break;
|
|
598
|
-
case 'data fim':
|
|
599
|
-
currentData.forEach((cd) => {
|
|
600
|
-
var _a;
|
|
601
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
602
|
-
if (dates.length <= 0)
|
|
603
|
-
return;
|
|
604
|
-
var fimDate = dates[dates.length - 1];
|
|
605
|
-
var fimValue = (0, dayjs_1.default)(fimDate, 'DD/MM/YYYY');
|
|
606
|
-
if (fimValue.isSame((0, dayjs_1.default)(dt.value, 'DD/MM/YYYY'))) {
|
|
607
|
-
filteredData.push(cd);
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
break;
|
|
611
|
-
case 'tem a data':
|
|
612
|
-
currentData.forEach((cd) => {
|
|
613
|
-
var _a;
|
|
614
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
615
|
-
if (dates.includes(dt.value)) {
|
|
616
|
-
filteredData.push(cd);
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
break;
|
|
620
|
-
case 'entre':
|
|
621
|
-
const dateA = dt.value ? (0, dayjs_1.default)(dt.value, 'DD/MM/YYYY') : (0, dayjs_1.default)('01/01/2000', 'DD/MM/YYYY');
|
|
622
|
-
const dateB = dt.value2 ? (0, dayjs_1.default)(dt.value2, 'DD/MM/YYYY') : (0, dayjs_1.default)('31/12/2030', 'DD/MM/YYYY');
|
|
623
|
-
currentData.forEach((cd) => {
|
|
624
|
-
var _a;
|
|
625
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
626
|
-
let isBetween = false;
|
|
627
|
-
dates.forEach((dtStr) => {
|
|
628
|
-
if (isBetween)
|
|
629
|
-
return;
|
|
630
|
-
const dt = (0, dayjs_1.default)(dtStr, 'DD/MM/YYYY');
|
|
631
|
-
if (!dt.isValid())
|
|
632
|
-
return;
|
|
633
|
-
if ((dt.isAfter(dateA) || dt.isSame(dateA)) && (dt.isBefore(dateB) || dt.isSame(dateB))) {
|
|
634
|
-
isBetween = true;
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
if (isBetween) {
|
|
638
|
-
filteredData.push(cd);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
currentData = filteredData;
|
|
279
|
+
const handleCSVDownload = (e, zip = false) => {
|
|
280
|
+
(0, utils_1.downloadCSVFile)(e, zip, {
|
|
281
|
+
list,
|
|
282
|
+
csvUpper,
|
|
283
|
+
csvExcludeUpper,
|
|
284
|
+
csvExcludeKeys,
|
|
285
|
+
csvExcludeKeysCSV,
|
|
286
|
+
csvCustomKeyNames,
|
|
287
|
+
csvExcludeValidate,
|
|
288
|
+
csv,
|
|
289
|
+
multipleDataPath,
|
|
290
|
+
normalize,
|
|
291
|
+
removeQuotes,
|
|
292
|
+
hideTitleCSV,
|
|
293
|
+
generateCsvZip,
|
|
294
|
+
csvZipFileNamesKey,
|
|
646
295
|
});
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
else {
|
|
666
|
-
if (aValue > bValue)
|
|
667
|
-
return -1;
|
|
668
|
-
if (aValue < bValue)
|
|
669
|
-
return 1;
|
|
670
|
-
}
|
|
671
|
-
return 0;
|
|
296
|
+
};
|
|
297
|
+
const handleDownloadAll = (e) => {
|
|
298
|
+
const keys = Object.keys(list[0]).filter((k) => !csvExcludeKeysAll.includes(k));
|
|
299
|
+
(0, utils_1.downloadCSVAll)(e, list, keys, (csv === null || csv === void 0 ? void 0 : csv.fileName) || 'dados');
|
|
300
|
+
};
|
|
301
|
+
const handleFiltrarDados = (dt) => {
|
|
302
|
+
(0, utils_1.filtrarDados)({
|
|
303
|
+
filterData: dt,
|
|
304
|
+
filtersFuncData: filtersFuncData,
|
|
305
|
+
localTableName: localTableName,
|
|
306
|
+
setCurrentPage: setCurrentPage,
|
|
307
|
+
setList,
|
|
308
|
+
setListClone,
|
|
309
|
+
setListPage,
|
|
310
|
+
setPagCount,
|
|
311
|
+
startData: startData.current,
|
|
312
|
+
itemsCount,
|
|
672
313
|
});
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
const newList = list.slice(start, start + itemsCount);
|
|
680
|
-
let obj = {};
|
|
681
|
-
newList.forEach((x, index) => {
|
|
682
|
-
columns.forEach((c) => {
|
|
683
|
-
var _a;
|
|
684
|
-
obj[index] = obj[index] === true ? true : ((_a = (0, lodash_get_1.default)(x, c.keyName, '')) !== null && _a !== void 0 ? _a : 'Não Informado').toString().length >= expandTextMaxLength;
|
|
685
|
-
});
|
|
314
|
+
};
|
|
315
|
+
const handleOrdenarDados = (x) => {
|
|
316
|
+
const dadosOrdenados = (0, utils_1.ordenarDados)({
|
|
317
|
+
order: x,
|
|
318
|
+
list,
|
|
319
|
+
orderAsc: orderAsc.current,
|
|
686
320
|
});
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}, [filterContainer.current]);
|
|
321
|
+
/** Inverter a ordem de ordenação no segundo clique */
|
|
322
|
+
orderAsc.current = !orderAsc.current;
|
|
323
|
+
setList(dadosOrdenados);
|
|
324
|
+
};
|
|
692
325
|
if (error)
|
|
693
|
-
return
|
|
694
|
-
react_1.default.createElement(Typography_1.default, { fontSize: 24, textAlign: 'center', fontFamily: 'Inter' },
|
|
695
|
-
error.status === 403 && 'Acesso negado',
|
|
696
|
-
error.status === 500 && (react_1.default.createElement(material_1.Box, { fontWeight: 500, textAlign: 'center' },
|
|
697
|
-
react_1.default.createElement(icons_material_1.ReportProblemRounded, { sx: { transform: 'scale(2)', marginY: 1, fill: '#3e3129' } }),
|
|
698
|
-
react_1.default.createElement(material_1.Box, null, customErrorMsg ? (customErrorMsg) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
699
|
-
"N\u00E3o foi poss\u00EDvel se conectar ao servidor no momento. Por favor, aguarde alguns instantes e tente de novo.",
|
|
700
|
-
react_1.default.createElement("br", null),
|
|
701
|
-
react_1.default.createElement("br", null),
|
|
702
|
-
"Caso precise de ajuda, entre em contato pelo email: ",
|
|
703
|
-
react_1.default.createElement("strong", null, "cdes@ssp.df.gov.br")))))))));
|
|
326
|
+
return react_1.default.createElement(TableErrorState_1.TableErrorState, { customErrorMsg: customErrorMsg, error: error });
|
|
704
327
|
if (isLoading)
|
|
705
|
-
return
|
|
706
|
-
react_1.default.createElement(material_1.Box, { width: '100%' },
|
|
707
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', alignItems: 'center', justifyItems: 'center', spacing: 2, marginY: 4 },
|
|
708
|
-
react_1.default.createElement(icons_material_1.PendingRounded, { sx: { fill: '#5e5e5e' } }),
|
|
709
|
-
react_1.default.createElement(Typography_1.default, { fontWeight: 600, fontSize: 20, textTransform: 'capitalize', textAlign: 'center', color: '#5e5e5e' },
|
|
710
|
-
"Carregando ",
|
|
711
|
-
tableName)),
|
|
712
|
-
react_1.default.createElement(material_1.LinearProgress, { color: 'inherit' }),
|
|
713
|
-
Array(10)
|
|
714
|
-
.fill('')
|
|
715
|
-
.map((x) => (react_1.default.createElement(material_1.Stack, { direction: {
|
|
716
|
-
xs: 'column',
|
|
717
|
-
md: 'row',
|
|
718
|
-
}, spacing: {
|
|
719
|
-
xs: 3,
|
|
720
|
-
md: 1,
|
|
721
|
-
}, justifyContent: 'space-between', paddingY: 8, borderBottom: '1px solid #cacaca' }, Array(7)
|
|
722
|
-
.fill(0)
|
|
723
|
-
.map((y) => (react_1.default.createElement(material_1.Box, null,
|
|
724
|
-
react_1.default.createElement(material_1.Skeleton, { width: 60 }),
|
|
725
|
-
react_1.default.createElement(material_1.Skeleton, { width: 120 }))))))))));
|
|
328
|
+
return react_1.default.createElement(TableLoadingState_1.TableLoadingState, { tableName: tableName });
|
|
726
329
|
if (!userLoaded && useKC)
|
|
727
330
|
return react_1.default.createElement(material_1.LinearProgress, null);
|
|
728
331
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -740,7 +343,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
740
343
|
borderRadius: '50px',
|
|
741
344
|
maxWidth: '600px',
|
|
742
345
|
}, size: 'small', onChange: onInputChange, fullWidth: true, placeholder: `Pesquisar ${tableName}` }),
|
|
743
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FilterAlt, null), variant: 'contained', onClick: (e) => Modal_1.MODAL.open(react_1.default.createElement(
|
|
346
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FilterAlt, null), variant: 'contained', onClick: (e) => Modal_1.MODAL.open(react_1.default.createElement(FilterSection_1.FilterMenu, { key: filterKey, reset: reset, filtrar: (dt) => handleFiltrarDados(dt), baseFilters: [...filters], filters: localStorage.getItem(localTableName) ? JSON.parse(localStorage.getItem(localTableName)) : [...filters] })), sx: {
|
|
744
347
|
borderRadius: 3,
|
|
745
348
|
paddingX: '24px',
|
|
746
349
|
paddingY: '8px',
|
|
@@ -752,7 +355,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
752
355
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
753
356
|
react_1.default.createElement(CustomMenu_1.default, { data: orderBy.map((x) => ({
|
|
754
357
|
name: x.label,
|
|
755
|
-
onClick: () =>
|
|
358
|
+
onClick: () => handleOrdenarDados(x),
|
|
756
359
|
})), btProps: {
|
|
757
360
|
startIcon: react_1.default.createElement(icons_material_1.KeyboardArrowDown, null),
|
|
758
361
|
fullWidth: true,
|
|
@@ -802,7 +405,7 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
802
405
|
}
|
|
803
406
|
return item;
|
|
804
407
|
});
|
|
805
|
-
|
|
408
|
+
handleFiltrarDados(currentValue);
|
|
806
409
|
}, size: 'small', sx: {
|
|
807
410
|
padding: 0,
|
|
808
411
|
} },
|
|
@@ -856,9 +459,9 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
856
459
|
xs: 'column',
|
|
857
460
|
md: 'row',
|
|
858
461
|
}, justifyContent: 'flex-end', spacing: 1 },
|
|
859
|
-
csvWithoutZip && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick:
|
|
860
|
-
csvShowAllButton && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick:
|
|
861
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) =>
|
|
462
|
+
csvWithoutZip && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: handleCSVDownload, sx: { backgroundColor: '#5a88b0', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvNoZipText)),
|
|
463
|
+
csvShowAllButton && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: handleDownloadAll, sx: { backgroundColor: '#64748B', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvAllButtonTitle)),
|
|
464
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(e, true), sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvButtonTitle)))))),
|
|
862
465
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 1, paddingTop: 2 },
|
|
863
466
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', alignItems: 'center', spacing: 2 },
|
|
864
467
|
react_1.default.createElement(material_1.Button, { onClick: (e) => setListPage((s) => {
|
|
@@ -898,181 +501,4 @@ hideTitleCSV = false, csvExcludeUpper = [], multipleDataPath = '', expandTextMax
|
|
|
898
501
|
react_1.default.createElement(NavigateNextRounded_1.default, { sx: { transform: 'scale(1.5)' } }))))));
|
|
899
502
|
}
|
|
900
503
|
exports.Table = Table;
|
|
901
|
-
function CriarFiltro({ filters, baseFilters, filtrar, reset }) {
|
|
902
|
-
const [data, setData] = (0, react_1.useState)(filters);
|
|
903
|
-
const [resetFields, setResetFields] = (0, react_1.useState)(false);
|
|
904
|
-
function addRule(filter) {
|
|
905
|
-
setData((dt) => {
|
|
906
|
-
return [...dt, filter];
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
const [anchorEl, setAnchorEl] = react_1.default.useState(null);
|
|
910
|
-
const open = Boolean(anchorEl);
|
|
911
|
-
const handleClick = (event) => {
|
|
912
|
-
setAnchorEl(event.currentTarget);
|
|
913
|
-
};
|
|
914
|
-
const handleClose = () => {
|
|
915
|
-
setAnchorEl(null);
|
|
916
|
-
};
|
|
917
|
-
return (react_1.default.createElement(material_1.Box, { width: {
|
|
918
|
-
xs: 'inherit',
|
|
919
|
-
md: 850,
|
|
920
|
-
} },
|
|
921
|
-
react_1.default.createElement(material_1.Menu, { open: open, onClose: handleClose, anchorEl: anchorEl }, baseFilters.map((x) => (react_1.default.createElement(material_1.MenuItem, { onClick: (e) => {
|
|
922
|
-
addRule(x);
|
|
923
|
-
setAnchorEl(null);
|
|
924
|
-
} }, x.label)))),
|
|
925
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'space-between' },
|
|
926
|
-
react_1.default.createElement(Typography_1.default, { fontWeight: 700, fontSize: 18 }, "Filtrar"),
|
|
927
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.Refresh, null), sx: {
|
|
928
|
-
textTransform: 'capitalize',
|
|
929
|
-
}, onClick: (e) => {
|
|
930
|
-
reset();
|
|
931
|
-
Modal_1.MODAL.close();
|
|
932
|
-
} }, "Limpar")),
|
|
933
|
-
react_1.default.createElement(material_1.Box, { marginBottom: 1 },
|
|
934
|
-
react_1.default.createElement(material_1.Alert, { severity: 'warning' }, "Preencha apenas os campos que deseja filtrar.")),
|
|
935
|
-
react_1.default.createElement(material_1.Stack, null, resetFields ? (data.map((d, idx) => (react_1.default.createElement(FilterRow, { filterValue: d, setReset: setResetFields, idx: idx, setDt: (valueData) => {
|
|
936
|
-
setData((dt) => {
|
|
937
|
-
let arr = [...dt];
|
|
938
|
-
arr[idx] = valueData;
|
|
939
|
-
return arr;
|
|
940
|
-
});
|
|
941
|
-
}, removeDt: () => {
|
|
942
|
-
setData((dt) => {
|
|
943
|
-
let arr = [...dt];
|
|
944
|
-
arr.splice(idx, 1);
|
|
945
|
-
return arr;
|
|
946
|
-
});
|
|
947
|
-
} })))) : (react_1.default.createElement(material_1.Box, null, data.map((d, idx) => (react_1.default.createElement(FilterRow, { filterValue: d, setReset: setResetFields, idx: idx, setDt: (valueData) => {
|
|
948
|
-
setData((dt) => {
|
|
949
|
-
let arr = [...dt];
|
|
950
|
-
arr[idx] = valueData;
|
|
951
|
-
return arr;
|
|
952
|
-
});
|
|
953
|
-
}, removeDt: () => {
|
|
954
|
-
setData((dt) => {
|
|
955
|
-
let arr = [...dt];
|
|
956
|
-
arr.splice(idx, 1);
|
|
957
|
-
return arr;
|
|
958
|
-
});
|
|
959
|
-
} })))))),
|
|
960
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 1 },
|
|
961
|
-
react_1.default.createElement(material_1.Button, { variant: 'contained', color: 'success', startIcon: react_1.default.createElement(Search_1.default, null), sx: {
|
|
962
|
-
textTransform: 'capitalize',
|
|
963
|
-
}, onClick: (e) => {
|
|
964
|
-
filtrar(data);
|
|
965
|
-
Modal_1.MODAL.close();
|
|
966
|
-
} }, "Filtrar"))));
|
|
967
|
-
}
|
|
968
|
-
function FilterRow({ filterValue, setDt, removeDt, idx, setReset, }) {
|
|
969
|
-
const [currentOperator, setCurrentOperator] = (0, react_1.useState)(filterValue.operator);
|
|
970
|
-
const [data, setData] = (0, react_1.useState)(filterValue);
|
|
971
|
-
const theme = (0, material_1.useTheme)();
|
|
972
|
-
const isSmall = (0, material_1.useMediaQuery)(theme.breakpoints.only('xs'));
|
|
973
|
-
(0, react_1.useEffect)(() => {
|
|
974
|
-
setDt(data);
|
|
975
|
-
}, [data]);
|
|
976
|
-
return (react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'end', spacing: 1, width: '100%', bgcolor: idx % 2 === 0 ? '#ededed' : 'inherit', padding: 0.5, borderRadius: 2 },
|
|
977
|
-
!isSmall && (react_1.default.createElement(Typography_1.default, { width: '100%', alignContent: 'center', fontWeight: 600, color: '#323232' }, filterValue.label)),
|
|
978
|
-
react_1.default.createElement(material_1.FormControl, { sx: {
|
|
979
|
-
width: '100%',
|
|
980
|
-
} },
|
|
981
|
-
isSmall && react_1.default.createElement(Typography_1.default, null, filterValue.label),
|
|
982
|
-
react_1.default.createElement(material_1.Select, { onChange: (e) => {
|
|
983
|
-
const value = e.target.value;
|
|
984
|
-
setData((obj) => (Object.assign(Object.assign({}, obj), { operator: value, value: '' })));
|
|
985
|
-
setCurrentOperator(value);
|
|
986
|
-
}, defaultValue: currentOperator, size: 'small', sx: {
|
|
987
|
-
bgcolor: 'white',
|
|
988
|
-
}, fullWidth: true }, filterValue.operators.map((x) => (react_1.default.createElement(material_1.MenuItem, { value: x }, x))))),
|
|
989
|
-
react_1.default.createElement(FilterField, { filterValue: filterValue, operator: data.operator, onChange: (value, type = 'value') => {
|
|
990
|
-
setData((obj) => (Object.assign(Object.assign({}, obj), { [type]: value })));
|
|
991
|
-
} })));
|
|
992
|
-
}
|
|
993
|
-
function FilterField({ filterValue, operator, onChange }) {
|
|
994
|
-
switch (filterValue.type) {
|
|
995
|
-
case 'number':
|
|
996
|
-
return (react_1.default.createElement(TextField_1.default, { type: 'number', size: 'small', placeholder: 'Valor', defaultValue: filterValue.value, onChange: (e) => {
|
|
997
|
-
onChange(e.target.value);
|
|
998
|
-
}, sx: {
|
|
999
|
-
bgcolor: 'white',
|
|
1000
|
-
}, fullWidth: true }));
|
|
1001
|
-
case 'string':
|
|
1002
|
-
if (filterValue.useList) {
|
|
1003
|
-
switch (operator) {
|
|
1004
|
-
case 'tem um dos':
|
|
1005
|
-
return (react_1.default.createElement(material_1.Autocomplete, { multiple: true, id: 'tags-standard', onChange: (e, value) => {
|
|
1006
|
-
if (value.length <= 0) {
|
|
1007
|
-
onChange('');
|
|
1008
|
-
return;
|
|
1009
|
-
}
|
|
1010
|
-
onChange(value);
|
|
1011
|
-
}, options: filterValue.useList, defaultValue: Array.isArray(filterValue.value) ? filterValue.value : [], renderInput: (params) => react_1.default.createElement(TextField_1.default, Object.assign({}, params, { variant: 'standard', placeholder: 'Escolha os valores', fullWidth: true })), fullWidth: true }));
|
|
1012
|
-
case 'contem':
|
|
1013
|
-
case 'igual':
|
|
1014
|
-
return (react_1.default.createElement(material_1.Box, { width: '100%' },
|
|
1015
|
-
react_1.default.createElement(material_1.Autocomplete, { options: filterValue.useList, onChange: (e, value) => {
|
|
1016
|
-
onChange(value);
|
|
1017
|
-
}, defaultValue: typeof filterValue.value === 'object' ? filterValue.value : undefined, isOptionEqualToValue: (option, value) => option.label === value.label, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { size: 'small', placeholder: 'Escolha um valor', fullWidth: true, sx: {
|
|
1018
|
-
bgcolor: 'white',
|
|
1019
|
-
} }))), fullWidth: true })));
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
return (react_1.default.createElement(TextField_1.default, { size: 'small', placeholder: 'Valor', defaultValue: filterValue.value, onChange: (e) => {
|
|
1023
|
-
onChange(e.target.value);
|
|
1024
|
-
}, sx: {
|
|
1025
|
-
bgcolor: 'white',
|
|
1026
|
-
}, fullWidth: true }));
|
|
1027
|
-
case 'date':
|
|
1028
|
-
case 'dates':
|
|
1029
|
-
switch (operator) {
|
|
1030
|
-
case 'data exata':
|
|
1031
|
-
case 'data fim':
|
|
1032
|
-
case 'data inicio':
|
|
1033
|
-
case 'tem a data':
|
|
1034
|
-
return (react_1.default.createElement(x_date_pickers_1.LocalizationProvider, { adapterLocale: 'pt-br', dateAdapter: AdapterDayjs_1.AdapterDayjs },
|
|
1035
|
-
react_1.default.createElement(x_date_pickers_1.DatePicker, { format: 'DD/MM/YYYY', onChange: (dt) => {
|
|
1036
|
-
onChange(dt.isValid() ? dt.format('DD/MM/YYYY') : '');
|
|
1037
|
-
}, defaultValue: filterValue.value ? (0, dayjs_1.default)(filterValue.value, 'DD/MM/YYYY') : undefined, sx: {
|
|
1038
|
-
div: {
|
|
1039
|
-
input: {
|
|
1040
|
-
paddingX: 2,
|
|
1041
|
-
paddingY: 1.05,
|
|
1042
|
-
},
|
|
1043
|
-
},
|
|
1044
|
-
width: '100%',
|
|
1045
|
-
bgcolor: 'white',
|
|
1046
|
-
}, inputRef: (params) => react_1.default.createElement(TextField_1.default, Object.assign({}, params, { size: 'small', fullWidth: true })) })));
|
|
1047
|
-
case 'entre':
|
|
1048
|
-
return (react_1.default.createElement(x_date_pickers_1.LocalizationProvider, { adapterLocale: 'pt-br', dateAdapter: AdapterDayjs_1.AdapterDayjs },
|
|
1049
|
-
react_1.default.createElement(x_date_pickers_1.DatePicker, { format: 'DD/MM/YYYY', onChange: (dt) => {
|
|
1050
|
-
onChange(dt.isValid() ? dt.format('DD/MM/YYYY') : '');
|
|
1051
|
-
}, defaultValue: filterValue.value ? (0, dayjs_1.default)(filterValue.value, 'DD/MM/YYYY') : undefined, sx: {
|
|
1052
|
-
div: {
|
|
1053
|
-
input: {
|
|
1054
|
-
paddingX: 2,
|
|
1055
|
-
paddingY: 1.05,
|
|
1056
|
-
},
|
|
1057
|
-
},
|
|
1058
|
-
width: '100%',
|
|
1059
|
-
bgcolor: 'white',
|
|
1060
|
-
}, inputRef: (params) => react_1.default.createElement(TextField_1.default, Object.assign({}, params, { size: 'small', fullWidth: true })) }),
|
|
1061
|
-
react_1.default.createElement(x_date_pickers_1.DatePicker, { format: 'DD/MM/YYYY', onChange: (dt) => {
|
|
1062
|
-
onChange(dt.isValid() ? dt.format('DD/MM/YYYY') : '', 'value2');
|
|
1063
|
-
}, defaultValue: filterValue.value2 ? (0, dayjs_1.default)(filterValue.value2, 'DD/MM/YYYY') : undefined, sx: {
|
|
1064
|
-
div: {
|
|
1065
|
-
input: {
|
|
1066
|
-
paddingX: 2,
|
|
1067
|
-
paddingY: 1.05,
|
|
1068
|
-
},
|
|
1069
|
-
},
|
|
1070
|
-
width: '100%',
|
|
1071
|
-
bgcolor: 'white',
|
|
1072
|
-
}, inputRef: (params) => react_1.default.createElement(TextField_1.default, Object.assign({}, params, { size: 'small', fullWidth: true })) })));
|
|
1073
|
-
}
|
|
1074
|
-
break;
|
|
1075
|
-
}
|
|
1076
|
-
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
1077
|
-
}
|
|
1078
504
|
exports.default = react_1.default.memo(Table);
|