@ssplib/react-components 0.0.142 → 0.0.144
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.
|
@@ -5,15 +5,18 @@ interface ColumnData {
|
|
|
5
5
|
size?: number;
|
|
6
6
|
}
|
|
7
7
|
type FilterTypes = 'a-z' | 'z-a' | 'items' | 'date-interval' | 'data-a-z' | 'data-z-a';
|
|
8
|
-
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, statusKeyName, csvExcludeKeys, csvExcludeKeysAll, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, itemCount, csvUpper, csvZipFileNamesKey, generateCsvZip, filters, hideTitleCSV, filterSeparator, }: {
|
|
8
|
+
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, statusKeyName, csvExcludeKeys, csvExcludeKeysAll, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvNoZipText, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, csvWithoutZip, itemCount, csvUpper, csvZipFileNamesKey, generateCsvZip, filters, hideTitleCSV, filterSeparator, filterStorageName, }: {
|
|
9
9
|
normalize?: boolean;
|
|
10
10
|
csvUpper?: boolean;
|
|
11
|
+
filterStorageName?: string;
|
|
11
12
|
removeQuotes?: boolean;
|
|
12
13
|
columns: ColumnData[];
|
|
13
14
|
tableName: string;
|
|
14
15
|
csvShowAllButton?: boolean;
|
|
16
|
+
csvWithoutZip?: boolean;
|
|
15
17
|
csvAllButtonTitle?: string;
|
|
16
18
|
csvButtonTitle?: string;
|
|
19
|
+
csvNoZipText?: string;
|
|
17
20
|
csvZipFileNamesKey?: string;
|
|
18
21
|
generateCsvZip?: boolean;
|
|
19
22
|
csvExcludeValidate?: (key: string, value: string | number) => boolean;
|
|
@@ -46,7 +46,7 @@ let startData = [];
|
|
|
46
46
|
function Table({ columns, fetchFunc, emptyMsg = {
|
|
47
47
|
user: 'Nenhum dado encontrado',
|
|
48
48
|
public: 'Nenhum dado encontrado',
|
|
49
|
-
}, dataPath = '', tableName = 'Dados', csv, columnSize, action, isPublic = false, statusKeyName = '', csvExcludeKeys = [], csvExcludeKeysAll = [], csvCustomKeyNames = {}, csvExcludeValidate = (key, value) => false, csvButtonTitle = 'Salvar .CSV', csvAllButtonTitle = 'Salvar todos em CSV', removeQuotes = false, normalize = false, csvShowAllButton = false, itemCount = 10, csvUpper = false, csvZipFileNamesKey = '', generateCsvZip = false, filters = {}, hideTitleCSV = false, filterSeparator = '|', }) {
|
|
49
|
+
}, dataPath = '', tableName = 'Dados', csv, columnSize, action, isPublic = false, statusKeyName = '', csvExcludeKeys = [], 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, filters = {}, hideTitleCSV = false, filterSeparator = '|', filterStorageName = 'tableFilters', }) {
|
|
50
50
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
51
51
|
const [error, setError] = (0, react_1.useState)(null);
|
|
52
52
|
const [data, setData] = (0, react_1.useState)(null);
|
|
@@ -83,7 +83,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
83
83
|
else {
|
|
84
84
|
setData(j);
|
|
85
85
|
startData = JSON.parse(JSON.stringify(j));
|
|
86
|
-
const oldFilters = localStorage.getItem(
|
|
86
|
+
const oldFilters = localStorage.getItem(filterStorageName);
|
|
87
87
|
if (oldFilters) {
|
|
88
88
|
const filters = JSON.parse(oldFilters);
|
|
89
89
|
setAppliedFilters(filters);
|
|
@@ -205,14 +205,14 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
205
205
|
return list.slice(start, start + itemsCount);
|
|
206
206
|
}, [list, itemsCount, currentPage]);
|
|
207
207
|
// download file
|
|
208
|
-
const downloadCSV = (0, react_1.useCallback)((e) => {
|
|
208
|
+
const downloadCSV = (0, react_1.useCallback)((e, zip = false) => {
|
|
209
209
|
e.preventDefault();
|
|
210
210
|
if (list.length <= 0)
|
|
211
211
|
return;
|
|
212
212
|
const originalKeys = Object.keys(list[0]);
|
|
213
213
|
const keys = originalKeys.filter((k) => !csvExcludeKeys.includes(k));
|
|
214
214
|
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
215
|
-
if (generateCsvZip) {
|
|
215
|
+
if (generateCsvZip && zip) {
|
|
216
216
|
const zip = new jszip_1.default();
|
|
217
217
|
const obj = {};
|
|
218
218
|
list.forEach((x) => {
|
|
@@ -371,7 +371,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
371
371
|
});
|
|
372
372
|
if (!canContinue) {
|
|
373
373
|
setAppliedFilters([]);
|
|
374
|
-
localStorage.setItem(
|
|
374
|
+
localStorage.setItem(filterStorageName, JSON.stringify([]));
|
|
375
375
|
setList(rawList);
|
|
376
376
|
setPagCount(getCount(rawList));
|
|
377
377
|
setCurrentPage(0);
|
|
@@ -565,7 +565,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
565
565
|
referencekey,
|
|
566
566
|
},
|
|
567
567
|
];
|
|
568
|
-
localStorage.setItem(
|
|
568
|
+
localStorage.setItem(filterStorageName, JSON.stringify(value));
|
|
569
569
|
return value;
|
|
570
570
|
});
|
|
571
571
|
};
|
|
@@ -573,7 +573,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
573
573
|
const value = JSON.parse(JSON.stringify(Array.isArray(startData) ? startData : (0, lodash_get_1.default)(startData, dataPath)));
|
|
574
574
|
setList(value);
|
|
575
575
|
setAppliedFilters([]);
|
|
576
|
-
localStorage.setItem(
|
|
576
|
+
localStorage.setItem(filterStorageName, JSON.stringify([]));
|
|
577
577
|
};
|
|
578
578
|
const removeFilter = (uniqueName) => {
|
|
579
579
|
if (uniqueName === 'isDate')
|
|
@@ -581,7 +581,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
581
581
|
else
|
|
582
582
|
setAppliedFilters((s) => {
|
|
583
583
|
const value = s.filter((x) => x.uniqueName !== uniqueName);
|
|
584
|
-
localStorage.setItem(
|
|
584
|
+
localStorage.setItem(filterStorageName, JSON.stringify(value));
|
|
585
585
|
return value;
|
|
586
586
|
});
|
|
587
587
|
};
|
|
@@ -597,7 +597,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
597
597
|
id: from + keyName,
|
|
598
598
|
},
|
|
599
599
|
];
|
|
600
|
-
localStorage.setItem(
|
|
600
|
+
localStorage.setItem(filterStorageName, JSON.stringify(value));
|
|
601
601
|
return value;
|
|
602
602
|
});
|
|
603
603
|
};
|
|
@@ -653,8 +653,9 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
653
653
|
xs: 'column',
|
|
654
654
|
md: 'row',
|
|
655
655
|
}, justifyContent: 'flex-end', spacing: 1 },
|
|
656
|
+
csvWithoutZip && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#5a88b0', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvButtonTitle)),
|
|
656
657
|
csvShowAllButton && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSVAll, sx: { backgroundColor: '#64748B', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvAllButtonTitle)),
|
|
657
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvButtonTitle)))))),
|
|
658
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => downloadCSV(e, true), sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, csvButtonTitle)))))),
|
|
658
659
|
react_1.default.createElement(material_1.SwipeableDrawer, { anchor: isSmall ? 'bottom' : 'right', open: filterOpen, onClose: (e) => setFilterOpen(false), onOpen: (e) => setFilterOpen(true) },
|
|
659
660
|
react_1.default.createElement(material_1.List, { sx: { minWidth: 310 } }, Object.keys(filters).map((f, fIndex) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
660
661
|
react_1.default.createElement(material_1.ListItemButton, { onClick: (e) => setFilterCollapse((s) => s.map((x, idx) => {
|