@ssplib/react-components 0.0.283 → 0.0.285
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from './types';
|
|
3
|
-
export declare function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg, dataPath, tableName,
|
|
3
|
+
export declare function Table({ mediaQueryLG, columns, csvConfig, fetchFunc, emptyMsg, dataPath, tableName, columnSize, action, useKC, itemCount, expandTextMaxLength, collapsedSize, customMargin, customMarginMobile, filtersFunc, filters, orderBy, customErrorMsg, customTableStyle, id, initialData, isExpandable, }: TableProps): JSX.Element;
|
|
4
4
|
declare const _default: React.MemoExoticComponent<typeof Table>;
|
|
5
5
|
export default _default;
|
|
@@ -50,13 +50,10 @@ let isExpandAll = false;
|
|
|
50
50
|
let localTableName = '';
|
|
51
51
|
let filtersFuncData = {};
|
|
52
52
|
let localTableNameCache = '';
|
|
53
|
-
function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
53
|
+
function Table({ mediaQueryLG, columns, csvConfig, fetchFunc, emptyMsg = {
|
|
54
54
|
user: 'Nenhum dado encontrado',
|
|
55
55
|
public: 'Nenhum dado encontrado',
|
|
56
|
-
}, dataPath = '', tableName = 'Dado',
|
|
57
|
-
fileName: tableName,
|
|
58
|
-
map: []
|
|
59
|
-
}, columnSize, action, useKC = true, itemCount = 10, expandTextMaxLength = 50, collapsedSize = 53, customMargin = 4, customMarginMobile = 0, filtersFunc, filters = [], orderBy = [], customErrorMsg = undefined, customTableStyle = {}, id, initialData = null, isExpandable = true, }) {
|
|
56
|
+
}, dataPath = '', tableName = 'Dado', columnSize, action, useKC = true, itemCount = 10, expandTextMaxLength = 50, collapsedSize = 53, customMargin = 4, customMarginMobile = 0, filtersFunc, filters = [], orderBy = [], customErrorMsg = undefined, customTableStyle = {}, id, initialData = null, isExpandable = true, }) {
|
|
60
57
|
var _a, _b;
|
|
61
58
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
62
59
|
const [error, setError] = (0, react_1.useState)(null);
|
|
@@ -302,9 +299,11 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
302
299
|
localStorage.removeItem(localTableName);
|
|
303
300
|
setFilterKey(new Date().getTime().toString());
|
|
304
301
|
}
|
|
305
|
-
const handleCSVDownload = (list) => {
|
|
302
|
+
const handleCSVDownload = (list, all = false) => {
|
|
306
303
|
var _a;
|
|
307
|
-
|
|
304
|
+
if (!csvConfig)
|
|
305
|
+
return;
|
|
306
|
+
(0, utils_1.downloadCSVFile)(list, Object.assign(Object.assign({}, csvConfig), (all ? { downloadAll: true } : {})), JSON.parse((_a = localStorage.getItem(localTableName)) !== null && _a !== void 0 ? _a : '[]') || []);
|
|
308
307
|
};
|
|
309
308
|
const handleFiltrarDados = (dt) => {
|
|
310
309
|
(0, utils_1.filtrarDados)({
|
|
@@ -465,14 +464,14 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
465
464
|
}, spacing: {
|
|
466
465
|
xs: 2,
|
|
467
466
|
md: 0,
|
|
468
|
-
}, justifyContent: 'space-between', alignItems: 'center' }, csvConfig
|
|
467
|
+
}, justifyContent: 'space-between', alignItems: 'center' }, csvConfig && (react_1.default.createElement(material_1.Stack, { direction: {
|
|
469
468
|
xs: 'column',
|
|
470
469
|
md: 'row',
|
|
471
470
|
}, justifyContent: 'flex-end', spacing: 1 },
|
|
472
471
|
JSON.parse((_b = localStorage.getItem(localTableName)) !== null && _b !== void 0 ? _b : '[]')
|
|
473
472
|
.filter((x) => x.value || (x.operator === 'entre' && (x.value || x.value2))).length > 0 &&
|
|
474
473
|
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(list), sx: { backgroundColor: '#a5a5a5', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, "Baixar Filtrados"),
|
|
475
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(startData.current), sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, "Baixar Tabela")))))),
|
|
474
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(startData.current, true), sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, "Baixar Tabela")))))),
|
|
476
475
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 1, paddingTop: 2 },
|
|
477
476
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', alignItems: 'center', spacing: 2 },
|
|
478
477
|
react_1.default.createElement(material_1.Button, { onClick: (e) => setListPage((s) => {
|
|
@@ -30,6 +30,8 @@ export interface FilterValue {
|
|
|
30
30
|
export interface CsvMapProps {
|
|
31
31
|
name: string;
|
|
32
32
|
key: string;
|
|
33
|
+
onlyFilter?: boolean;
|
|
34
|
+
onlyAll?: boolean;
|
|
33
35
|
useFilterValue?: {
|
|
34
36
|
label: string;
|
|
35
37
|
operators: FilterOperators[];
|
|
@@ -37,7 +39,10 @@ export interface CsvMapProps {
|
|
|
37
39
|
}
|
|
38
40
|
export interface CsvConfigProp {
|
|
39
41
|
fileName: string;
|
|
40
|
-
|
|
42
|
+
downloadAll?: boolean;
|
|
43
|
+
customFiltered?: (list: any[], filters: FilterValue[]) => any[];
|
|
44
|
+
customAll?: (list: any[], filters: FilterValue[]) => any[];
|
|
45
|
+
map?: CsvMapProps[];
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
48
|
* Interface para as propriedades do componente Table.
|
|
@@ -208,7 +208,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
|
|
|
208
208
|
case 'data inicio':
|
|
209
209
|
currentData.forEach((cd) => {
|
|
210
210
|
var _a;
|
|
211
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
211
|
+
const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
|
|
212
212
|
if (dates.length <= 0)
|
|
213
213
|
return;
|
|
214
214
|
var inicioDate = dates[0];
|
|
@@ -221,9 +221,10 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
|
|
|
221
221
|
case 'data fim':
|
|
222
222
|
currentData.forEach((cd) => {
|
|
223
223
|
var _a;
|
|
224
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
224
|
+
const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
|
|
225
225
|
if (dates.length <= 0)
|
|
226
226
|
return;
|
|
227
|
+
console.log(dates);
|
|
227
228
|
var fimDate = dates[dates.length - 1];
|
|
228
229
|
var fimValue = (0, dayjs_1.default)(fimDate, 'DD/MM/YYYY');
|
|
229
230
|
if (fimValue.isSame((0, dayjs_1.default)(dt.value, 'DD/MM/YYYY'))) {
|
|
@@ -234,7 +235,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
|
|
|
234
235
|
case 'tem a data':
|
|
235
236
|
currentData.forEach((cd) => {
|
|
236
237
|
var _a;
|
|
237
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
238
|
+
const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
|
|
238
239
|
if (dates.includes(dt.value)) {
|
|
239
240
|
filteredData.push(cd);
|
|
240
241
|
}
|
|
@@ -245,7 +246,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
|
|
|
245
246
|
const dateB = dt.value2 ? (0, dayjs_1.default)(dt.value2, 'DD/MM/YYYY') : (0, dayjs_1.default)('31/12/2030', 'DD/MM/YYYY');
|
|
246
247
|
currentData.forEach((cd) => {
|
|
247
248
|
var _a;
|
|
248
|
-
const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
|
|
249
|
+
const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
|
|
249
250
|
let isBetween = false;
|
|
250
251
|
dates.forEach((dtStr) => {
|
|
251
252
|
if (isBetween)
|
|
@@ -300,22 +301,31 @@ function downloadCSVFile(list, config, filters) {
|
|
|
300
301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
301
302
|
if (list.length <= 0)
|
|
302
303
|
return;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
304
|
+
let data = [];
|
|
305
|
+
if (config.downloadAll && config.customAll)
|
|
306
|
+
data = config.customAll(list, filters);
|
|
307
|
+
else if (!config.downloadAll && config.customFiltered)
|
|
308
|
+
data = config.customFiltered(list, filters);
|
|
309
|
+
else {
|
|
310
|
+
// definindo os campos especificados do csv
|
|
311
|
+
list.forEach(x => {
|
|
312
|
+
const obj = {};
|
|
313
|
+
config.map.forEach(m => {
|
|
314
|
+
// opção de usar o valor do filtro no próprio campo
|
|
315
|
+
if (m.useFilterValue && !config.downloadAll && !m.onlyAll) {
|
|
316
|
+
const filterValueList = filters.filter(f => f.label == m.useFilterValue.label && m.useFilterValue.operators.includes(f.operator));
|
|
317
|
+
const filterValue = filterValueList.length > 0 ? (filterValueList.reduce(r => r.value).value || undefined) : undefined;
|
|
318
|
+
obj[m.name] = filterValue || (0, lodash_get_1.default)(x, m.key);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (m.onlyFilter)
|
|
322
|
+
return;
|
|
323
|
+
obj[m.name] = (0, lodash_get_1.default)(x, m.key);
|
|
324
|
+
});
|
|
325
|
+
data.push(obj);
|
|
315
326
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const worksheet = XLSX.utils.json_to_sheet(newData);
|
|
327
|
+
}
|
|
328
|
+
const worksheet = XLSX.utils.json_to_sheet(data);
|
|
319
329
|
const workbook = XLSX.utils.book_new();
|
|
320
330
|
XLSX.utils.book_append_sheet(workbook, worksheet, config.fileName);
|
|
321
331
|
XLSX.writeFile(workbook, `${config.fileName}.xlsx`);
|