@ssplib/react-components 0.0.279 → 0.0.281
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.
- package/components/form/table/GenericTable.d.ts +2 -2
- package/components/form/table/Table.d.ts +1 -1
- package/components/form/table/Table.js +44 -33
- package/components/form/table/types.d.ts +78 -1
- package/components/form/table/utils.d.ts +2 -23
- package/components/form/table/utils.js +40 -74
- package/package.json +11 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TableProps2 } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Tabela cujo dados devem ser passados via props
|
|
5
5
|
*/
|
|
6
|
-
export declare function GenericTable<T>({ mediaQueryLG, columns, emptyMsg, dataPath, tableName, csv, columnSize, action, useKC, statusKeyName, csvExcludeKeys, csvExcludeKeysCSV, csvExcludeKeysAll, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvNoZipText, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, csvWithoutZip, itemCount, csvUpper, csvZipFileNamesKey, generateCsvZip, hideTitleCSV, csvExcludeUpper, multipleDataPath, expandTextMaxLength, collapsedSize, customMargin, customMarginMobile, filtersFunc, filters, orderBy, customErrorMsg, customTableStyle, id, initialData, isLoading, }:
|
|
6
|
+
export declare function GenericTable<T>({ mediaQueryLG, columns, emptyMsg, dataPath, tableName, csv, columnSize, action, useKC, statusKeyName, csvExcludeKeys, csvExcludeKeysCSV, csvExcludeKeysAll, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvNoZipText, csvAllButtonTitle, removeQuotes, normalize, csvShowAllButton, csvWithoutZip, itemCount, csvUpper, csvZipFileNamesKey, generateCsvZip, hideTitleCSV, csvExcludeUpper, multipleDataPath, expandTextMaxLength, collapsedSize, customMargin, customMarginMobile, filtersFunc, filters, orderBy, customErrorMsg, customTableStyle, id, initialData, isLoading, }: TableProps2): JSX.Element;
|
|
7
7
|
declare const _default: React.MemoExoticComponent<typeof GenericTable>;
|
|
8
8
|
export default _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps } from './types';
|
|
3
|
-
export declare function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, useKC,
|
|
3
|
+
export declare function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg, dataPath, tableName, csvConfig, csv, columnSize, action, useKC, itemCount, expandTextMaxLength, collapsedSize, customMargin, customMarginMobile, filtersFunc, filters, orderBy, customErrorMsg, customTableStyle, id, initialData, isExpandable, }: TableProps): JSX.Element;
|
|
4
4
|
declare const _default: React.MemoExoticComponent<typeof Table>;
|
|
5
5
|
export default _default;
|
|
@@ -53,8 +53,11 @@ let localTableNameCache = '';
|
|
|
53
53
|
function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
54
54
|
user: 'Nenhum dado encontrado',
|
|
55
55
|
public: 'Nenhum dado encontrado',
|
|
56
|
-
}, dataPath = '', tableName = 'Dado',
|
|
57
|
-
|
|
56
|
+
}, dataPath = '', tableName = 'Dado', csvConfig = {
|
|
57
|
+
fileName: tableName,
|
|
58
|
+
map: []
|
|
59
|
+
}, csv, columnSize, action, useKC = true, itemCount = 10, expandTextMaxLength = 50, collapsedSize = 53, customMargin = 4, customMarginMobile = 0, filtersFunc, filters = [], orderBy = [], customErrorMsg = undefined, customTableStyle = {}, id, initialData = null, isExpandable = true, }) {
|
|
60
|
+
var _a, _b;
|
|
58
61
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
59
62
|
const [error, setError] = (0, react_1.useState)(null);
|
|
60
63
|
const [data, setData] = (0, react_1.useState)(initialData);
|
|
@@ -74,7 +77,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
74
77
|
const theme = (0, material_1.useTheme)();
|
|
75
78
|
const isSmall = (0, material_1.useMediaQuery)(theme.breakpoints.only('xs'));
|
|
76
79
|
const startData = (0, react_1.useRef)(data);
|
|
77
|
-
const orderAsc = (0, react_1.useRef)(false);
|
|
80
|
+
const orderAsc = (0, react_1.useRef)((localStorage.getItem(`order-${id}`) === 'true') || false);
|
|
78
81
|
const lg = (0, material_1.useMediaQuery)(theme.breakpoints.up(2000));
|
|
79
82
|
localTableName = `tableFilter_${id}`;
|
|
80
83
|
localTableNameCache = `tableFilterCache_${id}`;
|
|
@@ -116,8 +119,31 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
116
119
|
startData.current = [];
|
|
117
120
|
}
|
|
118
121
|
else {
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
let newValue = value;
|
|
123
|
+
// começando a ordenação padrão
|
|
124
|
+
if (localStorage.getItem(`order-data-${id}`)) {
|
|
125
|
+
try {
|
|
126
|
+
const orderData = JSON.parse(localStorage.getItem(`order-data-${id}`));
|
|
127
|
+
newValue = (0, utils_1.ordenarDados)({
|
|
128
|
+
order: orderData,
|
|
129
|
+
list: value,
|
|
130
|
+
orderAsc: orderAsc.current,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
console.log(err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (orderBy.length > 0) {
|
|
138
|
+
// se não tiver salvo uma ordenação, ordena pelo primeiro da lista
|
|
139
|
+
newValue = (0, utils_1.ordenarDados)({
|
|
140
|
+
order: orderBy[0],
|
|
141
|
+
list: value,
|
|
142
|
+
orderAsc: orderAsc.current,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
setData(newValue);
|
|
146
|
+
startData.current = JSON.parse(JSON.stringify(newValue));
|
|
121
147
|
}
|
|
122
148
|
}
|
|
123
149
|
setIsLoading(false);
|
|
@@ -139,7 +165,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
139
165
|
(0, react_1.useEffect)(() => {
|
|
140
166
|
if (isLoading || error || !getData(data))
|
|
141
167
|
return;
|
|
142
|
-
|
|
168
|
+
let value = getData(data);
|
|
143
169
|
setList(value);
|
|
144
170
|
setListClone(value);
|
|
145
171
|
setPagCount((0, utils_1.getCount)(value, itemsCount));
|
|
@@ -276,27 +302,9 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
276
302
|
localStorage.removeItem(localTableName);
|
|
277
303
|
setFilterKey(new Date().getTime().toString());
|
|
278
304
|
}
|
|
279
|
-
const handleCSVDownload = (
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
csvUpper,
|
|
283
|
-
csvExcludeUpper,
|
|
284
|
-
csvExcludeKeys,
|
|
285
|
-
csvExcludeKeysCSV,
|
|
286
|
-
csvCustomKeyNames,
|
|
287
|
-
csvExcludeValidate,
|
|
288
|
-
csv,
|
|
289
|
-
multipleDataPath,
|
|
290
|
-
normalize,
|
|
291
|
-
removeQuotes,
|
|
292
|
-
hideTitleCSV,
|
|
293
|
-
generateCsvZip,
|
|
294
|
-
csvZipFileNamesKey,
|
|
295
|
-
});
|
|
296
|
-
};
|
|
297
|
-
const handleDownloadAll = (e) => {
|
|
298
|
-
const keys = Object.keys(list[0]).filter((k) => !csvExcludeKeysAll.includes(k));
|
|
299
|
-
(0, utils_1.downloadCSVAll)(e, list, keys, (csv === null || csv === void 0 ? void 0 : csv.fileName) || 'dados');
|
|
305
|
+
const handleCSVDownload = (list) => {
|
|
306
|
+
var _a;
|
|
307
|
+
(0, utils_1.downloadCSVFile)(list, csvConfig, JSON.parse((_a = localStorage.getItem(localTableName)) !== null && _a !== void 0 ? _a : '[]') || []);
|
|
300
308
|
};
|
|
301
309
|
const handleFiltrarDados = (dt) => {
|
|
302
310
|
(0, utils_1.filtrarDados)({
|
|
@@ -313,13 +321,15 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
313
321
|
});
|
|
314
322
|
};
|
|
315
323
|
const handleOrdenarDados = (x) => {
|
|
324
|
+
/** Inverter a ordem de ordenação no segundo clique */
|
|
325
|
+
orderAsc.current = !orderAsc.current;
|
|
316
326
|
const dadosOrdenados = (0, utils_1.ordenarDados)({
|
|
317
327
|
order: x,
|
|
318
328
|
list,
|
|
319
329
|
orderAsc: orderAsc.current,
|
|
320
330
|
});
|
|
321
|
-
|
|
322
|
-
|
|
331
|
+
localStorage.setItem(`order-${id}`, orderAsc.current.toString());
|
|
332
|
+
localStorage.setItem(`order-data-${id}`, JSON.stringify(x));
|
|
323
333
|
setList(dadosOrdenados);
|
|
324
334
|
};
|
|
325
335
|
if (error)
|
|
@@ -353,7 +363,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
353
363
|
react_1.default.createElement(material_1.Stack, { direction: 'row', borderRadius: 5, padding: 0 },
|
|
354
364
|
react_1.default.createElement("span", null, "Filtrar"))),
|
|
355
365
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
356
|
-
react_1.default.createElement(CustomMenu_1.default, { data: orderBy.map((x) => ({
|
|
366
|
+
orderBy.length > 0 && react_1.default.createElement(CustomMenu_1.default, { data: orderBy.map((x) => ({
|
|
357
367
|
name: x.label,
|
|
358
368
|
onClick: () => handleOrdenarDados(x),
|
|
359
369
|
})), btProps: {
|
|
@@ -459,9 +469,10 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
|
|
|
459
469
|
xs: 'column',
|
|
460
470
|
md: 'row',
|
|
461
471
|
}, justifyContent: 'flex-end', spacing: 1 },
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
472
|
+
JSON.parse((_b = localStorage.getItem(localTableName)) !== null && _b !== void 0 ? _b : '[]')
|
|
473
|
+
.filter((x) => x.value || (x.operator === 'entre' && (x.value || x.value2))).length > 0 &&
|
|
474
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(list), sx: { backgroundColor: '#a5a5a5', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, "Baixar Filtrados"),
|
|
475
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: (e) => handleCSVDownload(startData.current), sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 }, width: { xs: '100%', md: 'fit-content' } } }, "Baixar Tabela")))))),
|
|
465
476
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 1, paddingTop: 2 },
|
|
466
477
|
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', alignItems: 'center', spacing: 2 },
|
|
467
478
|
react_1.default.createElement(material_1.Button, { onClick: (e) => setListPage((s) => {
|
|
@@ -27,10 +27,87 @@ export interface FilterValue {
|
|
|
27
27
|
}[];
|
|
28
28
|
customFunc?: string;
|
|
29
29
|
}
|
|
30
|
+
export interface CsvMapProps {
|
|
31
|
+
name: string;
|
|
32
|
+
key: string;
|
|
33
|
+
useFilterValue?: {
|
|
34
|
+
label: string;
|
|
35
|
+
operators: FilterOperators[];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface CsvConfigProp {
|
|
39
|
+
fileName: string;
|
|
40
|
+
map: CsvMapProps[];
|
|
41
|
+
}
|
|
30
42
|
/**
|
|
31
43
|
* Interface para as propriedades do componente Table.
|
|
32
44
|
*/
|
|
33
45
|
export interface TableProps {
|
|
46
|
+
/** ID único da tabela */
|
|
47
|
+
id: string;
|
|
48
|
+
/** Configurações de largura para telas grandes */
|
|
49
|
+
mediaQueryLG?: {
|
|
50
|
+
all: number;
|
|
51
|
+
action: number;
|
|
52
|
+
};
|
|
53
|
+
/** Funções de transformação para filtros */
|
|
54
|
+
filtersFunc?: {
|
|
55
|
+
[key: string]: (value: string) => any;
|
|
56
|
+
};
|
|
57
|
+
/** Filtros disponíveis */
|
|
58
|
+
filters?: FilterValue[];
|
|
59
|
+
/** Ordenação por colunas */
|
|
60
|
+
orderBy?: OrderBy[];
|
|
61
|
+
/** Margem personalizada (desktop) */
|
|
62
|
+
customMargin?: number;
|
|
63
|
+
/** Margem personalizada (mobile) */
|
|
64
|
+
customMarginMobile?: number;
|
|
65
|
+
/** Estilo customizado da tabela */
|
|
66
|
+
customTableStyle?: BoxProps;
|
|
67
|
+
/** Mensagem de erro personalizada */
|
|
68
|
+
customErrorMsg?: string | ReactNode;
|
|
69
|
+
/** Colunas da tabela */
|
|
70
|
+
columns: any[];
|
|
71
|
+
/** Nome da tabela */
|
|
72
|
+
tableName: string;
|
|
73
|
+
csvConfig?: CsvConfigProp;
|
|
74
|
+
/** Altura da célula colapsada */
|
|
75
|
+
collapsedSize?: number;
|
|
76
|
+
/** Validação para exclusão de chaves no CSV */
|
|
77
|
+
csvExcludeValidate?: (key: string, value: string | number) => boolean;
|
|
78
|
+
/** Tamanho máximo do texto antes de colapsar */
|
|
79
|
+
expandTextMaxLength?: number;
|
|
80
|
+
/** Ações por linha */
|
|
81
|
+
action: (prop: any) => JSX.Element;
|
|
82
|
+
/** Configuração para exportação CSV */
|
|
83
|
+
csv?: {
|
|
84
|
+
fileName: string;
|
|
85
|
+
};
|
|
86
|
+
/** Quantidade de itens por página */
|
|
87
|
+
itemCount?: number;
|
|
88
|
+
/** Número de colunas da tabela */
|
|
89
|
+
columnSize: number;
|
|
90
|
+
/** Função para buscar dados */
|
|
91
|
+
fetchFunc?: () => Promise<Response>;
|
|
92
|
+
/** Mensagens para quando não há dados */
|
|
93
|
+
emptyMsg?: {
|
|
94
|
+
user: string;
|
|
95
|
+
public: string;
|
|
96
|
+
};
|
|
97
|
+
/** Caminho dos dados no JSON da resposta */
|
|
98
|
+
dataPath?: string;
|
|
99
|
+
/** Usa autenticação via Keycloak */
|
|
100
|
+
useKC?: boolean;
|
|
101
|
+
/** Dados iniciais da tabela */
|
|
102
|
+
initialData?: Array<{
|
|
103
|
+
[key: string]: any;
|
|
104
|
+
}> | null;
|
|
105
|
+
/** Flag de carregamento dos dados da tabela */
|
|
106
|
+
isLoading?: boolean;
|
|
107
|
+
/** Flag para mostrar ou não o botão de expandir a Linha */
|
|
108
|
+
isExpandable?: boolean;
|
|
109
|
+
}
|
|
110
|
+
export interface TableProps2 {
|
|
34
111
|
/** ID único da tabela */
|
|
35
112
|
id: string;
|
|
36
113
|
/** Configurações de largura para telas grandes */
|
|
@@ -124,7 +201,7 @@ export interface TableProps {
|
|
|
124
201
|
/** Usa autenticação via Keycloak */
|
|
125
202
|
useKC?: boolean;
|
|
126
203
|
/** Dados iniciais da tabela */
|
|
127
|
-
initialData
|
|
204
|
+
initialData?: Array<{
|
|
128
205
|
[key: string]: any;
|
|
129
206
|
}> | null;
|
|
130
207
|
/** Flag de carregamento dos dados da tabela */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { FilterValue, OrderBy } from './types';
|
|
2
|
+
import { CsvConfigProp, FilterValue, OrderBy } from './types';
|
|
3
3
|
export declare const getCount: (countData: any[], itemsCount: number) => number;
|
|
4
4
|
export declare function transformArrayObjectInString(o: Object): String;
|
|
5
5
|
export declare function removePunctuationAndAccents(text: string): string;
|
|
@@ -25,27 +25,6 @@ interface OrdenarDadosProps {
|
|
|
25
25
|
orderAsc: boolean;
|
|
26
26
|
}
|
|
27
27
|
export declare function ordenarDados({ order, list, orderAsc }: OrdenarDadosProps): any[];
|
|
28
|
-
export
|
|
29
|
-
list: any[];
|
|
30
|
-
csvUpper?: boolean;
|
|
31
|
-
csvExcludeUpper?: string[];
|
|
32
|
-
csvExcludeKeys?: string[];
|
|
33
|
-
csvExcludeKeysCSV?: string[];
|
|
34
|
-
csvExcludeKeysAll?: string[];
|
|
35
|
-
csvCustomKeyNames?: {
|
|
36
|
-
[key: string]: string;
|
|
37
|
-
};
|
|
38
|
-
csvExcludeValidate?: (key: string, value: any) => boolean;
|
|
39
|
-
csv?: {
|
|
40
|
-
fileName: string;
|
|
41
|
-
};
|
|
42
|
-
multipleDataPath?: string;
|
|
43
|
-
normalize?: boolean;
|
|
44
|
-
removeQuotes?: boolean;
|
|
45
|
-
hideTitleCSV?: boolean;
|
|
46
|
-
generateCsvZip?: boolean;
|
|
47
|
-
csvZipFileNamesKey?: string;
|
|
48
|
-
}
|
|
49
|
-
export declare function downloadCSVFile(e: React.MouseEvent, zip: boolean, options: CsvExportOptions): Promise<void>;
|
|
28
|
+
export declare function downloadCSVFile(list: any[], config: CsvConfigProp, filters: FilterValue[]): Promise<void>;
|
|
50
29
|
export declare function downloadCSVAll(e: React.MouseEvent, list: any[], keys: string[], fileName: string): void;
|
|
51
30
|
export {};
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,8 +38,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
38
|
exports.downloadCSVAll = exports.downloadCSVFile = exports.ordenarDados = exports.filtrarDados = exports.formatarString = exports.removePunctuationAndAccents = exports.transformArrayObjectInString = exports.getCount = void 0;
|
|
16
39
|
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
17
40
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
18
|
-
const jszip_1 = __importDefault(require("jszip"));
|
|
19
41
|
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
42
|
+
const XLSX = __importStar(require("xlsx"));
|
|
20
43
|
const getCount = (countData, itemsCount) => {
|
|
21
44
|
if (countData.length <= 0)
|
|
22
45
|
return 1;
|
|
@@ -273,84 +296,27 @@ function ordenarDados({ order, list, orderAsc = false }) {
|
|
|
273
296
|
return sortedList;
|
|
274
297
|
}
|
|
275
298
|
exports.ordenarDados = ordenarDados;
|
|
276
|
-
function downloadCSVFile(
|
|
299
|
+
function downloadCSVFile(list, config, filters) {
|
|
277
300
|
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
e.preventDefault();
|
|
279
|
-
const { list, csvUpper = false, csvExcludeUpper = [], csvExcludeKeys = [], csvExcludeKeysCSV = [], csvCustomKeyNames = {}, csvExcludeValidate = () => false, csv, multipleDataPath = '', normalize = false, removeQuotes = false, hideTitleCSV = false, generateCsvZip = false, csvZipFileNamesKey = '', } = options;
|
|
280
301
|
if (list.length <= 0)
|
|
281
302
|
return;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const keys = originalKeys.filter((k) => !csvExcludeKeys.includes(k));
|
|
285
|
-
const header = keys.map((k) => csvCustomKeyNames[k] || k).join(',') + '\n';
|
|
286
|
-
const zip = new jszip_1.default();
|
|
303
|
+
// definindo os campos especificados do csv
|
|
304
|
+
const newData = list.map(x => {
|
|
287
305
|
const obj = {};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
obj[
|
|
292
|
-
|
|
293
|
-
});
|
|
294
|
-
for (const [fileName, items] of Object.entries(obj)) {
|
|
295
|
-
const values = [];
|
|
296
|
-
for (const x of items) {
|
|
297
|
-
if (originalKeys.some((k) => csvExcludeValidate(k, x[k])))
|
|
298
|
-
continue;
|
|
299
|
-
const value = keys.map((k) => formatCell(x[k], k)).join(',');
|
|
300
|
-
values.push(value);
|
|
301
|
-
}
|
|
302
|
-
const csvData = hideTitleCSV ? values.join('\n') : '\uFEFF' + header + values.join('\n');
|
|
303
|
-
if (values.length > 0) {
|
|
304
|
-
zip.file(`${normalizeString(fileName)}.csv`, csvData);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const link = document.createElement('a');
|
|
308
|
-
const base = yield zip.generateAsync({ type: 'base64' });
|
|
309
|
-
link.href = 'data:application/zip;base64,' + base;
|
|
310
|
-
link.download = `${csv === null || csv === void 0 ? void 0 : csv.fileName}.zip`;
|
|
311
|
-
link.click();
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
let keys = originalKeys.filter((k) => !csvExcludeKeysCSV.includes(k));
|
|
315
|
-
if (multipleDataPath)
|
|
316
|
-
keys = ['dtInicio', 'hrInicio', ...keys.map((k) => (k === multipleDataPath ? 'hrTermino' : k))];
|
|
317
|
-
const header = keys.map((k) => csvCustomKeyNames[k] || k).join(',') + '\n';
|
|
318
|
-
const values = [];
|
|
319
|
-
for (const x of list) {
|
|
320
|
-
if (originalKeys.some((k) => csvExcludeValidate(k, x[k])))
|
|
321
|
-
continue;
|
|
322
|
-
const value = keys.map((k) => formatCell(x[k], k)).join(',');
|
|
323
|
-
if (multipleDataPath && x[multipleDataPath]) {
|
|
324
|
-
for (const d of x[multipleDataPath]) {
|
|
325
|
-
values.push(value.replace('{dtInicio}', d.dtInicio).replace('{hrInicio}', d.hrInicio).replace('{hrTermino}', d.hrTermino));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
values.push(value);
|
|
306
|
+
config.map.forEach(m => {
|
|
307
|
+
if (m.useFilterValue) {
|
|
308
|
+
const filterValue = filters.filter(f => f.label == m.useFilterValue.label && m.useFilterValue.operators.includes(f.operator)).reduce(r => r.value).value || undefined;
|
|
309
|
+
obj[m.name] = filterValue || (0, lodash_get_1.default)(x, m.key);
|
|
310
|
+
return;
|
|
330
311
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
let item = typeof cell === 'object' && cell !== null && !Array.isArray(cell) ? transformArrayObjectInString(cell).slice(1, -1) : cell;
|
|
340
|
-
if (csvUpper && typeof item === 'string' && !csvExcludeUpper.includes(key)) {
|
|
341
|
-
item = item.toUpperCase();
|
|
342
|
-
}
|
|
343
|
-
if (normalize && typeof item === 'string') {
|
|
344
|
-
item = normalizeString(item);
|
|
345
|
-
}
|
|
346
|
-
if (typeof item === 'string') {
|
|
347
|
-
return removeQuotes ? `${item}` : `"${item}"`;
|
|
348
|
-
}
|
|
349
|
-
return item;
|
|
350
|
-
}
|
|
351
|
-
function normalizeString(str) {
|
|
352
|
-
return str.normalize('NFD').replace(/[̀-ͯ]/g, '');
|
|
353
|
-
}
|
|
312
|
+
obj[m.name] = (0, lodash_get_1.default)(x, m.key);
|
|
313
|
+
});
|
|
314
|
+
return obj;
|
|
315
|
+
});
|
|
316
|
+
const worksheet = XLSX.utils.json_to_sheet(newData);
|
|
317
|
+
const workbook = XLSX.utils.book_new();
|
|
318
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, 'Teste');
|
|
319
|
+
XLSX.writeFile(workbook, `${config.fileName}.xlsx`);
|
|
354
320
|
});
|
|
355
321
|
}
|
|
356
322
|
exports.downloadCSVFile = downloadCSVFile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssplib/react-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.281",
|
|
4
4
|
"description": "SSP React Components",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Pedro Henrique <sr.hudrick@gmail.com>",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"react-dropzone": "^14.3.8",
|
|
25
25
|
"leaflet": "^1.9.4",
|
|
26
26
|
"leaflet-defaulticon-compatibility": "^0.1.2",
|
|
27
|
-
"react-leaflet": "^4.2.1"
|
|
27
|
+
"react-leaflet": "^4.2.1",
|
|
28
|
+
"xlsx": "^0.18.5"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/lodash.clonedeep": "^4.5.9",
|
|
@@ -36,9 +37,15 @@
|
|
|
36
37
|
"type": "git",
|
|
37
38
|
"url": "git+https://github.com/SSPDF/ssp-components.git"
|
|
38
39
|
},
|
|
39
|
-
"keywords": [
|
|
40
|
+
"keywords": [
|
|
41
|
+
"front",
|
|
42
|
+
"react",
|
|
43
|
+
"components",
|
|
44
|
+
"ssp",
|
|
45
|
+
"df"
|
|
46
|
+
],
|
|
40
47
|
"bugs": {
|
|
41
48
|
"url": "https://github.com/SSPDF/ssp-components/issues"
|
|
42
49
|
},
|
|
43
50
|
"homepage": "https://github.com/SSPDF/ssp-components#readme"
|
|
44
|
-
}
|
|
51
|
+
}
|