@ssplib/react-components 0.0.127 → 0.0.129
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,7 +5,7 @@ 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, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, itemCount, csvUpper, filters, filterSeparator, }: {
|
|
8
|
+
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, statusKeyName, csvExcludeKeys, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, itemCount, csvUpper, csvZipFileNamesKey, generateCsvZip, filters, filterSeparator, }: {
|
|
9
9
|
normalize?: boolean;
|
|
10
10
|
csvUpper?: boolean;
|
|
11
11
|
removeQuotes?: boolean;
|
|
@@ -14,6 +14,8 @@ export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableNam
|
|
|
14
14
|
csvShowAllButton?: boolean;
|
|
15
15
|
csvAllButtonTitle?: string;
|
|
16
16
|
csvButtonTitle?: string;
|
|
17
|
+
csvZipFileNamesKey?: string;
|
|
18
|
+
generateCsvZip?: boolean;
|
|
17
19
|
csvExcludeValidate?: (key: string, value: string | number) => boolean;
|
|
18
20
|
csvCustomKeyNames?: {
|
|
19
21
|
[key: string]: string;
|
|
@@ -41,11 +41,12 @@ const icons_material_1 = require("@mui/icons-material");
|
|
|
41
41
|
const FormProvider_1 = __importDefault(require("../../providers/FormProvider"));
|
|
42
42
|
const DatePicker_1 = __importDefault(require("../date/DatePicker"));
|
|
43
43
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
44
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
44
45
|
let startData = [];
|
|
45
46
|
function Table({ columns, fetchFunc, emptyMsg = {
|
|
46
47
|
user: 'Nenhum dado encontrado',
|
|
47
48
|
public: 'Nenhum dado encontrado',
|
|
48
|
-
}, dataPath = '', tableName = 'Dados', csv, columnSize, action, isPublic = false, statusKeyName = '', csvExcludeKeys = [], csvCustomKeyNames = {}, csvExcludeValidate = (key, value) => false, csvButtonTitle = 'Salvar .CSV', csvAllButtonTitle = 'Salvar todos em CSV', removeQuotes = false, normalize = false, csvShowAllButton = false, itemCount = 10, csvUpper = false, filters = {}, filterSeparator = '|', }) {
|
|
49
|
+
}, dataPath = '', tableName = 'Dados', csv, columnSize, action, isPublic = false, statusKeyName = '', csvExcludeKeys = [], 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 = {}, filterSeparator = '|', }) {
|
|
49
50
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
50
51
|
const [error, setError] = (0, react_1.useState)(null);
|
|
51
52
|
const [data, setData] = (0, react_1.useState)(null);
|
|
@@ -203,39 +204,90 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
203
204
|
const originalKeys = Object.keys(list[0]);
|
|
204
205
|
const keys = originalKeys.filter((k) => !csvExcludeKeys.includes(k));
|
|
205
206
|
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
207
|
+
if (generateCsvZip) {
|
|
208
|
+
const zip = new jszip_1.default();
|
|
209
|
+
const obj = {};
|
|
210
|
+
list.forEach((x) => {
|
|
211
|
+
if (!obj[x[csvZipFileNamesKey]])
|
|
212
|
+
obj[x[csvZipFileNamesKey]] = [];
|
|
213
|
+
obj[x[csvZipFileNamesKey]].push(x);
|
|
214
214
|
});
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
215
|
+
Object.keys(obj).forEach((objKey) => {
|
|
216
|
+
const values = [];
|
|
217
|
+
let include = true;
|
|
218
|
+
obj[objKey].forEach((x) => {
|
|
219
|
+
originalKeys.forEach((k) => {
|
|
220
|
+
//verificar se pode incluir
|
|
221
|
+
if (csvExcludeValidate(k, x[k])) {
|
|
222
|
+
include = false;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
console.log(include);
|
|
226
|
+
if (include) {
|
|
227
|
+
const value = keys
|
|
228
|
+
.map((k) => {
|
|
229
|
+
if (k === 'tbRa')
|
|
230
|
+
return x[k]['NO_CIDADE'];
|
|
231
|
+
if (k === 'rlEventoData')
|
|
232
|
+
return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
|
|
233
|
+
if (typeof x[k] === 'string') {
|
|
234
|
+
let item = csvUpper ? x[k].toUpperCase() : x[k];
|
|
235
|
+
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
236
|
+
return removeQuotes ? `${item}` : `"${item}"`;
|
|
237
|
+
}
|
|
238
|
+
return x[k];
|
|
239
|
+
})
|
|
240
|
+
.join(',');
|
|
241
|
+
values.push(value);
|
|
226
242
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
243
|
+
});
|
|
244
|
+
const csvData = '\uFEFF' + header + values.join('\n');
|
|
245
|
+
if (include)
|
|
246
|
+
zip.file(`${objKey}.csv`, csvData);
|
|
247
|
+
});
|
|
248
|
+
// // download
|
|
249
|
+
var link = window.document.createElement('a');
|
|
250
|
+
zip.generateAsync({ type: 'base64' }).then((base) => {
|
|
251
|
+
link.setAttribute('href', 'data:application/zip;base64,' + base);
|
|
252
|
+
link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.zip`);
|
|
253
|
+
link.click();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
const values = [];
|
|
258
|
+
list.forEach((x) => {
|
|
259
|
+
let include = true;
|
|
260
|
+
originalKeys.forEach((k) => {
|
|
261
|
+
//verificar se pode incluir
|
|
262
|
+
if (csvExcludeValidate(k, x[k])) {
|
|
263
|
+
include = false;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
if (include) {
|
|
267
|
+
const value = keys
|
|
268
|
+
.map((k) => {
|
|
269
|
+
if (k === 'tbRa')
|
|
270
|
+
return x[k]['NO_CIDADE'];
|
|
271
|
+
if (k === 'rlEventoData')
|
|
272
|
+
return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
|
|
273
|
+
if (typeof x[k] === 'string') {
|
|
274
|
+
let item = csvUpper ? x[k].toUpperCase() : x[k];
|
|
275
|
+
item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
|
|
276
|
+
return removeQuotes ? `${item}` : `"${item}"`;
|
|
277
|
+
}
|
|
278
|
+
return x[k];
|
|
279
|
+
})
|
|
280
|
+
.join(',');
|
|
281
|
+
values.push(value);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
const csvData = header + values.join('\n');
|
|
285
|
+
// download
|
|
286
|
+
var link = window.document.createElement('a');
|
|
287
|
+
link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
|
|
288
|
+
link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
|
|
289
|
+
link.click();
|
|
290
|
+
}
|
|
239
291
|
}, [list]);
|
|
240
292
|
const downloadCSVAll = (0, react_1.useCallback)((e) => {
|
|
241
293
|
e.preventDefault();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssplib/react-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.129",
|
|
4
4
|
"description": "SSP React Components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Pedro Henrique <sr.hudrick@gmail.com>",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"react-query": "^3.39.3",
|
|
15
15
|
"dayjs": "^1.11.7",
|
|
16
16
|
"lodash.hasin": "^4.5.2",
|
|
17
|
-
"react-google-recaptcha": "^2.1.0"
|
|
17
|
+
"react-google-recaptcha": "^2.1.0",
|
|
18
|
+
"jszip": "^3.10.1"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/lodash.get": "^4.4.7",
|