@ssplib/react-components 0.0.126 → 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,12 +5,17 @@ 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, csvShowAllButton, itemCount, 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
+ normalize?: boolean;
10
+ csvUpper?: boolean;
11
+ removeQuotes?: boolean;
9
12
  columns: ColumnData[];
10
13
  tableName: string;
11
14
  csvShowAllButton?: boolean;
12
15
  csvAllButtonTitle?: string;
13
16
  csvButtonTitle?: string;
17
+ csvZipFileNamesKey: string;
18
+ generateCsvZip: boolean;
14
19
  csvExcludeValidate?: (key: string, value: string | number) => boolean;
15
20
  csvCustomKeyNames?: {
16
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', csvShowAllButton = false, itemCount = 10, 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,36 +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;
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
+ });
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);
241
+ }
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);
213
280
  }
214
281
  });
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
- return `"${x[k]}"`;
224
- return x[k];
225
- })
226
- .join(',');
227
- values.push(value);
228
- }
229
- });
230
- const csvData = header + values.join('\n');
231
- // download
232
- var link = window.document.createElement('a');
233
- link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURI(csvData));
234
- link.setAttribute('download', `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`);
235
- link.click();
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
+ }
236
289
  }, [list]);
237
290
  const downloadCSVAll = (0, react_1.useCallback)((e) => {
238
291
  e.preventDefault();
@@ -248,8 +301,11 @@ function Table({ columns, fetchFunc, emptyMsg = {
248
301
  return x[k]['NO_CIDADE'];
249
302
  if (k === 'rlEventoData')
250
303
  return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
251
- if (typeof x[k] === 'string')
252
- return `"${x[k]}"`;
304
+ if (typeof x[k] === 'string') {
305
+ let item = csvUpper ? x[k].toUpperCase() : x[k];
306
+ item = normalize ? item.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : item;
307
+ return removeQuotes ? `${item}` : `"${item}"`;
308
+ }
253
309
  return x[k];
254
310
  })
255
311
  .join(',');
@@ -486,7 +542,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
486
542
  react_1.default.createElement(TextField_1.default, { InputProps: {
487
543
  startAdornment: react_1.default.createElement(Search_1.default, { sx: { marginRight: 1, fill: '#c0c0c0' } }),
488
544
  }, size: 'small', onChange: onInputChange, fullWidth: true, placeholder: `Pesquisar ${tableName}` }),
489
- react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FilterAlt, null), variant: 'contained', onClick: (e) => setFilterOpen(true) }, "Filtrar")),
545
+ Object.keys(filters).length > 0 && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FilterAlt, null), variant: 'contained', onClick: (e) => setFilterOpen(true) }, "Filtrar"))),
490
546
  react_1.default.createElement(material_1.Stack, { spacing: 0.2 },
491
547
  getMaxItems().length <= 0 ? (react_1.default.createElement(material_1.Stack, { sx: { backgroundColor: '#E2E8F0', padding: 2, marginX: { xs: 2, md: 0 } }, justifyContent: 'center', alignItems: 'center' },
492
548
  react_1.default.createElement(Typography_1.default, { fontSize: 21, fontFamily: 'Inter', fontWeight: 600, textAlign: 'center' }, user ? emptyMsg.user : emptyMsg.public))) : (getMaxItems().map((x, index) => (react_1.default.createElement(material_1.Paper, { key: index, sx: { padding: 0.5, backgroundColor: index % 2 === 0 ? '#E2E8F0' : '#F8FAFC', paddingY: 2 }, elevation: 0 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.126",
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",