@ssplib/react-components 0.0.56 → 0.0.58

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);
@@ -203,6 +203,36 @@ function Table({ columns, fetchFunc, emptyMsg = {
203
203
  a.click();
204
204
  document.body.removeChild(a);
205
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) => {
216
+ if (k === 'tbRa')
217
+ return x[k]['NO_CIDADE'];
218
+ if (k === 'rlEventoData')
219
+ return `${x[k][0]['DT_INICIO']} - ${x[k][0]['HR_INICIO']}`;
220
+ if (typeof x[k] === 'string')
221
+ return `"${x[k]}"`;
222
+ return x[k];
223
+ })
224
+ .join(',');
225
+ })
226
+ .join('\n');
227
+ const csvData = header + values;
228
+ // download
229
+ const a = document.createElement('a');
230
+ a.href = 'data:text/csv;charset=utf-8,' + csvData;
231
+ a.download = `${csv === null || csv === void 0 ? void 0 : csv.fileName}.csv`;
232
+ document.body.appendChild(a);
233
+ a.click();
234
+ document.body.removeChild(a);
235
+ }, [list]);
206
236
  const getStatusMsg = (0, react_1.useCallback)((cod) => {
207
237
  switch (cod) {
208
238
  case 'P':
@@ -259,8 +289,12 @@ function Table({ columns, fetchFunc, emptyMsg = {
259
289
  react_1.default.createElement(Grid_1.default, { item: true, xs: 12, md: 12 / columnSize },
260
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))))))))),
261
291
  getMaxItems().length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
262
- csv && (react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 2 },
263
- 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: {
293
+ xs: 'column',
294
+ md: 'row',
295
+ }, justifyContent: 'flex-end', marginTop: 2, spacing: 1 },
296
+ 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 }, width: { xs: '100%', md: 'fit-content' } } }, csvAllButtonTitle)),
297
+ 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 }, width: { xs: '100%', md: 'fit-content' } } }, csvButtonTitle))),
264
298
  react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 4 },
265
299
  react_1.default.createElement(Pagination_1.default, { count: paginationCount, siblingCount: isSmall ? 0 : 1, size: 'large', onChange: onPaginationChange, page: listPage })))))));
266
300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",