@ssplib/react-components 0.0.54 → 0.0.56
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.
|
@@ -3,9 +3,10 @@ interface ColumnData {
|
|
|
3
3
|
title: string;
|
|
4
4
|
keyName: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, statusKeyName, csvExcludeKeys, csvCustomKeyNames, }: {
|
|
6
|
+
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, statusKeyName, csvExcludeKeys, csvCustomKeyNames, csvExcludeValidate, }: {
|
|
7
7
|
columns: ColumnData[];
|
|
8
8
|
tableName: string;
|
|
9
|
+
csvExcludeValidate?: (key: string, value: string | number) => boolean;
|
|
9
10
|
csvCustomKeyNames?: {
|
|
10
11
|
[key: string]: string;
|
|
11
12
|
};
|
|
@@ -40,7 +40,7 @@ const auth_1 = require("../../../context/auth");
|
|
|
40
40
|
function Table({ columns, fetchFunc, emptyMsg = {
|
|
41
41
|
user: 'Nenhum dado encontrado',
|
|
42
42
|
public: 'Nenhum dado encontrado',
|
|
43
|
-
}, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, statusKeyName = '', csvExcludeKeys = [], csvCustomKeyNames = {}, }) {
|
|
43
|
+
}, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, statusKeyName = '', csvExcludeKeys = [], csvCustomKeyNames = {}, csvExcludeValidate = (key, value) => false, }) {
|
|
44
44
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
45
45
|
const [error, setError] = (0, react_1.useState)(null);
|
|
46
46
|
const [data, setData] = (0, react_1.useState)(null);
|
|
@@ -167,24 +167,34 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
167
167
|
e.preventDefault();
|
|
168
168
|
if (list.length <= 0)
|
|
169
169
|
return;
|
|
170
|
-
const
|
|
170
|
+
const originalKeys = Object.keys(list[0]);
|
|
171
|
+
const keys = originalKeys.filter((k) => !csvExcludeKeys.includes(k));
|
|
171
172
|
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
172
|
-
const values =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
173
|
+
const values = [];
|
|
174
|
+
list.forEach((x) => {
|
|
175
|
+
let include = true;
|
|
176
|
+
originalKeys.forEach((k) => {
|
|
177
|
+
//verificar se pode incluir
|
|
178
|
+
if (csvExcludeValidate(k, x[k])) {
|
|
179
|
+
include = false;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (include) {
|
|
183
|
+
const value = keys
|
|
184
|
+
.map((k) => {
|
|
185
|
+
if (k === 'tbRa')
|
|
186
|
+
return x[k]['NO_CIDADE'];
|
|
187
|
+
if (k === 'rlEventoData')
|
|
188
|
+
return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
|
|
189
|
+
if (typeof x[k] === 'string')
|
|
190
|
+
return `"${x[k]}"`;
|
|
191
|
+
return x[k];
|
|
192
|
+
})
|
|
193
|
+
.join(',');
|
|
194
|
+
values.push(value);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const csvData = header + values.join('\n');
|
|
188
198
|
// download
|
|
189
199
|
const a = document.createElement('a');
|
|
190
200
|
a.href = 'data:text/csv;charset=utf-8,' + csvData;
|