@ssplib/react-components 0.0.127 → 0.0.128

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,88 @@ 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
- const values = [];
207
- list.forEach((x) => {
208
- let include = true;
209
- originalKeys.forEach((k) => {
210
- //verificar se pode incluir
211
- if (csvExcludeValidate(k, x[k])) {
212
- include = false;
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
- if (include) {
216
- const value = keys
217
- .map((k) => {
218
- if (k === 'tbRa')
219
- return x[k]['NO_CIDADE'];
220
- if (k === 'rlEventoData')
221
- return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
222
- if (typeof x[k] === 'string') {
223
- let item = csvUpper ? x[k].toUpperCase() : x[k];
224
- item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
225
- return removeQuotes ? `${item}` : `"${item}"`;
215
+ Object.keys(obj).forEach((objKey) => {
216
+ const values = [];
217
+ obj[objKey].forEach((x) => {
218
+ let include = true;
219
+ originalKeys.forEach((k) => {
220
+ //verificar se pode incluir
221
+ if (csvExcludeValidate(k, x[k])) {
222
+ include = false;
223
+ }
224
+ });
225
+ if (include) {
226
+ const value = keys
227
+ .map((k) => {
228
+ if (k === 'tbRa')
229
+ return x[k]['NO_CIDADE'];
230
+ if (k === 'rlEventoData')
231
+ return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
232
+ if (typeof x[k] === 'string') {
233
+ let item = csvUpper ? x[k].toUpperCase() : x[k];
234
+ item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
235
+ return removeQuotes ? `${item}` : `"${item}"`;
236
+ }
237
+ return x[k];
238
+ })
239
+ .join(',');
240
+ values.push(value);
226
241
  }
227
- return x[k];
228
- })
229
- .join(',');
230
- values.push(value);
231
- }
232
- });
233
- const csvData = header + values.join('\n');
234
- // download
235
- var link = window.document.createElement('a');
236
- link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
237
- link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
238
- link.click();
242
+ });
243
+ const csvData = '\uFEFF' + header + values.join('\n');
244
+ zip.file(`${objKey}.csv`, csvData);
245
+ });
246
+ // // download
247
+ var link = window.document.createElement('a');
248
+ zip.generateAsync({ type: 'base64' }).then((base) => {
249
+ link.setAttribute('href', 'data:application/zip;base64,' + base);
250
+ link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.zip`);
251
+ link.click();
252
+ });
253
+ }
254
+ else {
255
+ const values = [];
256
+ list.forEach((x) => {
257
+ let include = true;
258
+ originalKeys.forEach((k) => {
259
+ //verificar se pode incluir
260
+ if (csvExcludeValidate(k, x[k])) {
261
+ include = false;
262
+ }
263
+ });
264
+ if (include) {
265
+ const value = keys
266
+ .map((k) => {
267
+ if (k === 'tbRa')
268
+ return x[k]['NO_CIDADE'];
269
+ if (k === 'rlEventoData')
270
+ return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
271
+ if (typeof x[k] === 'string') {
272
+ let item = csvUpper ? x[k].toUpperCase() : x[k];
273
+ item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
274
+ return removeQuotes ? `${item}` : `"${item}"`;
275
+ }
276
+ return x[k];
277
+ })
278
+ .join(',');
279
+ values.push(value);
280
+ }
281
+ });
282
+ const csvData = header + values.join('\n');
283
+ // download
284
+ var link = window.document.createElement('a');
285
+ link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
286
+ link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
287
+ link.click();
288
+ }
239
289
  }, [list]);
240
290
  const downloadCSVAll = (0, react_1.useCallback)((e) => {
241
291
  e.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
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",