@ssplib/react-components 0.0.284 → 0.0.286

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.
@@ -28,12 +28,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const material_1 = require("@mui/material");
30
30
  const system_1 = require("@mui/system");
31
+ const axios_1 = __importDefault(require("axios"));
31
32
  const lodash_get_1 = __importDefault(require("lodash.get"));
32
33
  const react_1 = __importStar(require("react"));
34
+ const react_dropzone_1 = require("react-dropzone");
33
35
  const auth_1 = require("../../../context/auth");
34
36
  const form_1 = require("../../../context/form");
35
- const react_dropzone_1 = require("react-dropzone");
36
- const axios_1 = __importDefault(require("axios"));
37
37
  const icons_1 = require("../../icons/icons");
38
38
  function bytesToMegabytes(bytes) {
39
39
  const megabytes = bytes / (1024 * 1024);
@@ -51,13 +51,6 @@ function bytesToKBorMB(bytes) {
51
51
  return `${MBValue.toFixed(1)}MB`;
52
52
  }
53
53
  }
54
- function LinearProgressWithLabel(props) {
55
- return (react_1.default.createElement(material_1.Box, { sx: { display: 'flex', alignItems: 'center' } },
56
- react_1.default.createElement(material_1.Box, { sx: { width: '100%', mr: 1 } },
57
- react_1.default.createElement(material_1.LinearProgress, Object.assign({ variant: 'determinate' }, props))),
58
- react_1.default.createElement(material_1.Box, { sx: { minWidth: 3 } },
59
- react_1.default.createElement(material_1.Typography, { variant: 'body2', color: 'text.secondary' }, `${Math.round(props.value)}%`))));
60
- }
61
54
  function DropFileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, sizeLimit = 4, xs = 12, sm, md, route = '', tstToken = '', dropZoneOptions, }) {
62
55
  const { getRootProps, getInputProps } = (0, react_dropzone_1.useDropzone)(Object.assign({ multiple, useFsAccessApi: true, onDrop: (dropFiles) => {
63
56
  const fileList = [];
@@ -219,7 +212,7 @@ function DropFileUpload({ name, tipoArquivo, title, required = false, multiple =
219
212
  backgroundColor: '#DE3F50',
220
213
  borderRadius: '8px',
221
214
  } }, "Remover")))),
222
- progress > 0 && progress < 100 && (react_1.default.createElement(LinearProgressWithLabel, { value: progress, sx: {
215
+ progress > 0 && progress < 100 && (react_1.default.createElement(material_1.LinearProgress, { value: progress, sx: {
223
216
  backgroundColor: '#103D6A',
224
217
  '.MuiLinearProgress-bar': {
225
218
  backgroundColor: '#BDDDFA',
@@ -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, csvConfig, columnSize, action, useKC, itemCount, expandTextMaxLength, collapsedSize, customMargin, customMarginMobile, filtersFunc, filters, orderBy, customErrorMsg, customTableStyle, id, initialData, isExpandable, }: TableProps): JSX.Element;
3
+ export declare function Table({ mediaQueryLG, columns, csvConfig, fetchFunc, emptyMsg, dataPath, tableName, 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;
@@ -50,13 +50,10 @@ let isExpandAll = false;
50
50
  let localTableName = '';
51
51
  let filtersFuncData = {};
52
52
  let localTableNameCache = '';
53
- function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
53
+ function Table({ mediaQueryLG, columns, csvConfig, fetchFunc, emptyMsg = {
54
54
  user: 'Nenhum dado encontrado',
55
55
  public: 'Nenhum dado encontrado',
56
- }, dataPath = '', tableName = 'Dado', csvConfig = {
57
- fileName: tableName,
58
- map: []
59
- }, 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, }) {
56
+ }, dataPath = '', tableName = 'Dado', 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
57
  var _a, _b;
61
58
  const [isLoading, setIsLoading] = (0, react_1.useState)(false);
62
59
  const [error, setError] = (0, react_1.useState)(null);
@@ -304,6 +301,8 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
304
301
  }
305
302
  const handleCSVDownload = (list, all = false) => {
306
303
  var _a;
304
+ if (!csvConfig)
305
+ return;
307
306
  (0, utils_1.downloadCSVFile)(list, Object.assign(Object.assign({}, csvConfig), (all ? { downloadAll: true } : {})), JSON.parse((_a = localStorage.getItem(localTableName)) !== null && _a !== void 0 ? _a : '[]') || []);
308
307
  };
309
308
  const handleFiltrarDados = (dt) => {
@@ -465,7 +464,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
465
464
  }, spacing: {
466
465
  xs: 2,
467
466
  md: 0,
468
- }, justifyContent: 'space-between', alignItems: 'center' }, csvConfig.map.length > 0 && (react_1.default.createElement(material_1.Stack, { direction: {
467
+ }, justifyContent: 'space-between', alignItems: 'center' }, csvConfig && (react_1.default.createElement(material_1.Stack, { direction: {
469
468
  xs: 'column',
470
469
  md: 'row',
471
470
  }, justifyContent: 'flex-end', spacing: 1 },
@@ -30,6 +30,8 @@ export interface FilterValue {
30
30
  export interface CsvMapProps {
31
31
  name: string;
32
32
  key: string;
33
+ onlyFilter?: boolean;
34
+ onlyAll?: boolean;
33
35
  useFilterValue?: {
34
36
  label: string;
35
37
  operators: FilterOperators[];
@@ -38,7 +40,9 @@ export interface CsvMapProps {
38
40
  export interface CsvConfigProp {
39
41
  fileName: string;
40
42
  downloadAll?: boolean;
41
- map: CsvMapProps[];
43
+ customFiltered?: (list: any[], filters: FilterValue[]) => any[];
44
+ customAll?: (list: any[], filters: FilterValue[]) => any[];
45
+ map?: CsvMapProps[];
42
46
  }
43
47
  /**
44
48
  * Interface para as propriedades do componente Table.
@@ -208,7 +208,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
208
208
  case 'data inicio':
209
209
  currentData.forEach((cd) => {
210
210
  var _a;
211
- const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
211
+ const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
212
212
  if (dates.length <= 0)
213
213
  return;
214
214
  var inicioDate = dates[0];
@@ -221,9 +221,10 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
221
221
  case 'data fim':
222
222
  currentData.forEach((cd) => {
223
223
  var _a;
224
- const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
224
+ const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
225
225
  if (dates.length <= 0)
226
226
  return;
227
+ console.log(dates);
227
228
  var fimDate = dates[dates.length - 1];
228
229
  var fimValue = (0, dayjs_1.default)(fimDate, 'DD/MM/YYYY');
229
230
  if (fimValue.isSame((0, dayjs_1.default)(dt.value, 'DD/MM/YYYY'))) {
@@ -234,7 +235,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
234
235
  case 'tem a data':
235
236
  currentData.forEach((cd) => {
236
237
  var _a;
237
- const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
238
+ const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
238
239
  if (dates.includes(dt.value)) {
239
240
  filteredData.push(cd);
240
241
  }
@@ -245,7 +246,7 @@ function filtrarDados({ filterData, startData, filtersFuncData = {}, localTableN
245
246
  const dateB = dt.value2 ? (0, dayjs_1.default)(dt.value2, 'DD/MM/YYYY') : (0, dayjs_1.default)('31/12/2030', 'DD/MM/YYYY');
246
247
  currentData.forEach((cd) => {
247
248
  var _a;
248
- const dates = (_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : [];
249
+ const dates = ((_a = filtersFuncData[dt.customFunc]((0, lodash_get_1.default)(cd, dt.keyName, ''))) !== null && _a !== void 0 ? _a : []).filter(d => d !== undefined && d !== '');
249
250
  let isBetween = false;
250
251
  dates.forEach((dtStr) => {
251
252
  if (isBetween)
@@ -300,22 +301,31 @@ function downloadCSVFile(list, config, filters) {
300
301
  return __awaiter(this, void 0, void 0, function* () {
301
302
  if (list.length <= 0)
302
303
  return;
303
- // definindo os campos especificados do csv
304
- const newData = list.map(x => {
305
- const obj = {};
306
- config.map.forEach(m => {
307
- // opção de usar o valor do filtro no próprio campo
308
- if (m.useFilterValue && !config.downloadAll) {
309
- const filterValueList = filters.filter(f => f.label == m.useFilterValue.label && m.useFilterValue.operators.includes(f.operator));
310
- const filterValue = filterValueList.length > 0 ? (filterValueList.reduce(r => r.value).value || undefined) : undefined;
311
- obj[m.name] = filterValue || (0, lodash_get_1.default)(x, m.key);
312
- return;
313
- }
314
- obj[m.name] = (0, lodash_get_1.default)(x, m.key);
304
+ let data = [];
305
+ if (config.downloadAll && config.customAll)
306
+ data = config.customAll(list, filters);
307
+ else if (!config.downloadAll && config.customFiltered)
308
+ data = config.customFiltered(list, filters);
309
+ else {
310
+ // definindo os campos especificados do csv
311
+ list.forEach(x => {
312
+ const obj = {};
313
+ config.map.forEach(m => {
314
+ // opção de usar o valor do filtro no próprio campo
315
+ if (m.useFilterValue && !config.downloadAll && !m.onlyAll) {
316
+ const filterValueList = filters.filter(f => f.label == m.useFilterValue.label && m.useFilterValue.operators.includes(f.operator));
317
+ const filterValue = filterValueList.length > 0 ? (filterValueList.reduce(r => r.value).value || undefined) : undefined;
318
+ obj[m.name] = filterValue || (0, lodash_get_1.default)(x, m.key);
319
+ return;
320
+ }
321
+ if (m.onlyFilter)
322
+ return;
323
+ obj[m.name] = (0, lodash_get_1.default)(x, m.key);
324
+ });
325
+ data.push(obj);
315
326
  });
316
- return obj;
317
- });
318
- const worksheet = XLSX.utils.json_to_sheet(newData);
327
+ }
328
+ const worksheet = XLSX.utils.json_to_sheet(data);
319
329
  const workbook = XLSX.utils.book_new();
320
330
  XLSX.utils.book_append_sheet(workbook, worksheet, config.fileName);
321
331
  XLSX.writeFile(workbook, `${config.fileName}.xlsx`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.284",
3
+ "version": "0.0.286",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",
@@ -37,15 +37,9 @@
37
37
  "type": "git",
38
38
  "url": "git+https://github.com/SSPDF/ssp-components.git"
39
39
  },
40
- "keywords": [
41
- "front",
42
- "react",
43
- "components",
44
- "ssp",
45
- "df"
46
- ],
40
+ "keywords": ["front", "react", "components", "ssp", "df"],
47
41
  "bugs": {
48
42
  "url": "https://github.com/SSPDF/ssp-components/issues"
49
43
  },
50
44
  "homepage": "https://github.com/SSPDF/ssp-components#readme"
51
- }
45
+ }