@ssplib/react-components 0.0.55 → 0.0.57

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,12 @@ 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, csvExcludeValidate, }: {
6
+ export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, statusKeyName, csvExcludeKeys, csvCustomKeyNames, csvExcludeValidate, csvButtonTitle, csvAllButtonTitle, csvShowAllButton, }: {
7
7
  columns: ColumnData[];
8
8
  tableName: string;
9
+ csvShowAllButton?: boolean;
10
+ csvAllButtonTitle?: string;
11
+ csvButtonTitle?: string;
9
12
  csvExcludeValidate?: (key: string, value: string | number) => boolean;
10
13
  csvCustomKeyNames?: {
11
14
  [key: string]: string;
@@ -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 = {}, csvExcludeValidate = (key, value) => false, }) {
43
+ }, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, statusKeyName = '', csvExcludeKeys = [], csvCustomKeyNames = {}, csvExcludeValidate = (key, value) => false, csvButtonTitle = 'Salvar .CSV', csvAllButtonTitle = 'Salvar Tudo como CSV', csvShowAllButton = 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,18 +167,52 @@ function Table({ columns, fetchFunc, emptyMsg = {
167
167
  e.preventDefault();
168
168
  if (list.length <= 0)
169
169
  return;
170
- const keys = Object.keys(list[0]).filter((k) => !csvExcludeKeys.includes(k));
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
173
  const values = [];
173
174
  list.forEach((x) => {
174
175
  let include = true;
175
- const value = keys
176
- .map((k) => {
176
+ originalKeys.forEach((k) => {
177
177
  //verificar se pode incluir
178
178
  if (csvExcludeValidate(k, x[k])) {
179
179
  include = false;
180
- return;
181
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');
198
+ // download
199
+ const a = document.createElement('a');
200
+ a.href = 'data:text/csv;charset=utf-8,' + csvData;
201
+ a.download = `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`;
202
+ document.body.appendChild(a);
203
+ a.click();
204
+ document.body.removeChild(a);
205
+ }, [list]);
206
+ const downloadCSVAll = (0, react_1.useCallback)((e) => {
207
+ e.preventDefault();
208
+ if (list.length <= 0)
209
+ return;
210
+ const keys = Object.keys(list[0]);
211
+ const header = keys.join(',') + '\n';
212
+ const values = list
213
+ .map((x) => {
214
+ return keys
215
+ .map((k) => {
182
216
  if (k === 'tbRa')
183
217
  return x[k]['NO_CIDADE'];
184
218
  if (k === 'rlEventoData')
@@ -188,10 +222,9 @@ function Table({ columns, fetchFunc, emptyMsg = {
188
222
  return x[k];
189
223
  })
190
224
  .join(',');
191
- if (include)
192
- values.push(value);
193
- });
194
- const csvData = header + values.join('\n');
225
+ })
226
+ .join('\n');
227
+ const csvData = header + values;
195
228
  // download
196
229
  const a = document.createElement('a');
197
230
  a.href = 'data:text/csv;charset=utf-8,' + csvData;
@@ -256,8 +289,9 @@ function Table({ columns, fetchFunc, emptyMsg = {
256
289
  react_1.default.createElement(Grid_1.default, { item: true, xs: 12, md: 12 / columnSize },
257
290
  react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'center', justifyContent: isSmall ? 'start' : 'flex-end', sx: { height: '100%', paddingBottom: isSmall ? 2 : 0 } }, action(x))))))))),
258
291
  getMaxItems().length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
259
- csv && (react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 2 },
260
- react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 } } }, "Salvar .CSV"))),
292
+ csv && (react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 2, spacing: 1 },
293
+ csvShowAllButton && (react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSVAll, sx: { backgroundColor: '#64748B', marginRight: { xs: 2, md: 0 } } }, csvAllButtonTitle)),
294
+ react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 } } }, csvButtonTitle))),
261
295
  react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 4 },
262
296
  react_1.default.createElement(Pagination_1.default, { count: paginationCount, siblingCount: isSmall ? 0 : 1, size: 'large', onChange: onPaginationChange, page: listPage })))))));
263
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",