@bento-core/table 1.0.0-c3dc.2 → 1.0.0-c3dc.21

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,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.convertToCSV = convertToCSV;
7
7
  exports.createFileName = createFileName;
8
- exports.downloadJson = downloadJson;
8
+ exports.downloadData = downloadData;
9
9
  var _Dataformat = require("./Dataformat");
10
10
  var _Types = require("./Types");
11
11
  function createFileName(fileName) {
@@ -32,7 +32,7 @@ function createFileName(fileName) {
32
32
  if (seconds < 10) {
33
33
  seconds = "0".concat(seconds);
34
34
  }
35
- return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
35
+ return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds);
36
36
  }
37
37
  function convertToCSV(jsonse, keysToInclude, header) {
38
38
  const objArray = jsonse;
@@ -51,8 +51,11 @@ function convertToCSV(jsonse, keysToInclude, header) {
51
51
  } else {
52
52
  line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
53
53
  }
54
+ } else if (keyName === 'participant') {
55
+ line += entry[keyName].id;
54
56
  } else {
55
- line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
57
+ const newLine = entry[keyName] !== null ? String(entry[keyName]).replace(/"/g, '""') : '';
58
+ line += "\"".concat(newLine, "\"");
56
59
  }
57
60
  return line;
58
61
  });
@@ -66,49 +69,71 @@ function convertToCSV(jsonse, keysToInclude, header) {
66
69
  });
67
70
  return str;
68
71
  }
69
- function downloadJson(tableData, table, downloadFileName) {
72
+ function downloadData(tableData, table, downloadFileName) {
73
+ let format = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'csv';
70
74
  const {
71
75
  columns = []
72
76
  } = table;
73
77
  const filterColumns = columns.filter(_ref => {
74
78
  let {
75
- cellType
79
+ cellType,
80
+ doNotDownload
76
81
  } = _ref;
77
- return !_Types.actionCellTypes.includes(cellType);
82
+ return !_Types.actionCellTypes.includes(cellType) && !doNotDownload;
78
83
  });
79
- const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
80
- const jsonse = JSON.stringify(formatDataVal);
81
- const keysToInclude = columns.filter(_ref2 => {
82
- let {
83
- dataField
84
- } = _ref2;
85
- return dataField;
86
- }).map(_ref3 => {
87
- let {
88
- dataField
89
- } = _ref3;
90
- return dataField;
91
- });
92
- const headers = columns.filter(_ref4 => {
93
- let {
94
- dataField
95
- } = _ref4;
96
- return dataField;
97
- }).map(_ref5 => {
98
- let {
99
- header,
100
- downloadHeader
101
- } = _ref5;
102
- return downloadHeader || header;
84
+ let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
85
+ formatDataVal = formatDataVal.map(item => {
86
+ const updatedItem = {};
87
+ filterColumns.forEach(_ref2 => {
88
+ let {
89
+ dataField
90
+ } = _ref2;
91
+ updatedItem[dataField] = item[dataField];
92
+ });
93
+ return updatedItem;
103
94
  });
104
- const csv = convertToCSV(jsonse, keysToInclude, headers);
105
- const exportData = new Blob([csv], {
106
- type: 'text/csv'
95
+ let fileContent;
96
+ let fileType;
97
+ if (format === 'json') {
98
+ filterColumns.forEach(column => {
99
+ formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
100
+ });
101
+ fileContent = JSON.stringify(formatDataVal);
102
+ fileType = 'application/json';
103
+ } else {
104
+ const jsonse = JSON.stringify(formatDataVal);
105
+ const keysToInclude = filterColumns.filter(_ref3 => {
106
+ let {
107
+ dataField
108
+ } = _ref3;
109
+ return dataField;
110
+ }).map(_ref4 => {
111
+ let {
112
+ dataField
113
+ } = _ref4;
114
+ return dataField;
115
+ });
116
+ const headers = filterColumns.filter(_ref5 => {
117
+ let {
118
+ dataField
119
+ } = _ref5;
120
+ return dataField;
121
+ }).map(_ref6 => {
122
+ let {
123
+ header,
124
+ downloadHeader
125
+ } = _ref6;
126
+ return downloadHeader || header;
127
+ });
128
+ fileContent = convertToCSV(jsonse, keysToInclude, headers);
129
+ fileType = 'text/csv';
130
+ }
131
+ const exportData = new Blob([fileContent], {
132
+ type: fileType
107
133
  });
108
- const JsonURL = window.URL.createObjectURL(exportData);
109
- let tempLink = '';
110
- tempLink = document.createElement('a');
111
- tempLink.setAttribute('href', JsonURL);
134
+ const fileURL = window.URL.createObjectURL(exportData);
135
+ const tempLink = document.createElement('a');
136
+ tempLink.setAttribute('href', fileURL);
112
137
  tempLink.setAttribute('download', createFileName(downloadFileName || ''));
113
138
  document.body.appendChild(tempLink);
114
139
  tempLink.click();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.0-c3dc.2",
3
+ "version": "1.0.0-c3dc.21",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
2
  import {
3
3
  ThemeProvider,
4
- Toolbar,
5
4
  createTheme,
6
5
  } from '@material-ui/core';
7
6
  import CustomPagination from './pagination/CustomPagination';
@@ -39,45 +38,47 @@ const ExtendedView = ({
39
38
  return (
40
39
  <ThemeProvider theme={themeConfig}>
41
40
  {(numSelected === 0 && (download || manageViewColumns)) && (
42
- <Toolbar className="downloadColumnView">
43
- <DownloadButton
44
- count={table.totalRowCount || 0}
45
- queryVariables={queryVariables}
46
- table={table}
47
- buttonConfig={downloadButtonConfig}
48
- />
41
+
49
42
  <ManageColumnView
50
43
  table={table}
51
44
  manageViewColumns={manageViewColumns}
52
45
  onColumnViewChange={onColumnViewChange}
53
46
  />
54
- </Toolbar>
47
+
55
48
  )}
56
49
  {
57
- (pagination) && (
58
- <div className="downloadArea" style={downloadAreaStyle}>
59
- <CustomPagination
60
- customTheme={customTheme.tblTopPgn}
61
- rowsPerPageOptions={[10, 25, 50, 100]}
62
- component="div"
63
- count={table.totalRowCount || 0}
64
- rowsPerPage={table.rowsPerPage || 10}
65
- page={table.page || 0}
66
- onPageChange={onPageChange}
67
- onRowsPerPageChange={onRowsPerPageChange}
68
- queryVariables={queryVariables}
69
- table={table}
70
- />
71
- {/* TODO: Commented out this section, Make this options configrable on Bento. */}
72
- {/* <DownloadButton
73
- count={table.totalRowCount || 0}
74
- queryVariables={queryVariables}
75
- table={table}
76
- isIcon={false}
77
- /> */}
78
- </div>
79
- )
80
- }
50
+ (pagination) && (
51
+ <div className="downloadArea" style={(table.paginationCustomStyle && table.paginationCustomStyle.topPagination) ? table.paginationCustomStyle.topPagination : downloadAreaStyle}>
52
+ {
53
+ (table.showSearchBox) && (
54
+ <table.SearchBox />
55
+ )
56
+ }
57
+ <CustomPagination
58
+ customTheme={customTheme.tblTopPgn}
59
+ rowsPerPageOptions={[10, 25, 50, 100]}
60
+ component="div"
61
+ count={table.totalRowCount || 0}
62
+ rowsPerPage={table.rowsPerPage || 10}
63
+ page={table.page || 0}
64
+ onPageChange={onPageChange}
65
+ onRowsPerPageChange={onRowsPerPageChange}
66
+ queryVariables={queryVariables}
67
+ table={table}
68
+ />
69
+ {table.showDownloadIcon !== false
70
+ && (
71
+ <DownloadButton
72
+ count={table.totalRowCount || 0}
73
+ queryVariables={queryVariables}
74
+ table={table}
75
+ buttonConfig={downloadButtonConfig}
76
+ />
77
+ )}
78
+
79
+ </div>
80
+ )
81
+ }
81
82
  </ThemeProvider>
82
83
  );
83
84
  };
package/src/TableView.js CHANGED
@@ -10,9 +10,9 @@ import TableHeader from './header/CustomTblHeader';
10
10
  import CustomPagination from './pagination/CustomPagination';
11
11
  import CustomTableBody from './body/CustomTblBody';
12
12
  import CustomToolbar from './toolbar/CustomToolbar';
13
+ import DownloadButton from './toolbar/DownloadButtonView';
13
14
  import DisplayErrMsg from './errMsg/DisplayErrMsg';
14
15
  import ExtendedView from './ExtendedView';
15
- import DownloadButton from './toolbar/DownloadButtonView';
16
16
 
17
17
  const CustomTableContainer = (props) => {
18
18
  const { children, customTheme } = props;
@@ -29,7 +29,6 @@ const CustomTableContainer = (props) => {
29
29
  const downloadAreaStyle = {
30
30
  display: 'flex',
31
31
  borderTop: '1px solid #8A7F7C',
32
- borderBottom: '1px solid #8A7F7C',
33
32
  paddingRight: '41px',
34
33
  };
35
34
 
@@ -95,7 +94,7 @@ const TableView = ({
95
94
  table={table}
96
95
  />
97
96
  )}
98
- <div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle}>
97
+ <div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : (table.paginationCustomStyle && table.paginationCustomStyle.bottomPagination) ? table.paginationCustomStyle.bottomPagination : downloadAreaStyle}>
99
98
  <CustomPagination
100
99
  customTheme={themeConfig.tblPgn}
101
100
  rowsPerPageOptions={[10, 25, 50, 100]}
@@ -106,11 +105,15 @@ const TableView = ({
106
105
  onPageChange={onPageChange}
107
106
  onRowsPerPageChange={onRowsPerPageChange}
108
107
  />
109
- <DownloadButton
110
- count={table.totalRowCount || 0}
111
- queryVariables={queryVariables}
112
- table={table}
113
- />
108
+ {table.showDownloadIcon !== false
109
+ && (
110
+ <DownloadButton
111
+ count={table.totalRowCount || 0}
112
+ queryVariables={queryVariables}
113
+ table={table}
114
+ buttonConfig={table.extendedViewConfig.downloadButtonConfig}
115
+ />
116
+ )}
114
117
  </div>
115
118
  </>
116
119
  );
@@ -0,0 +1,3 @@
1
+ <svg width="13" height="6" viewBox="0 0 13 6" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M0.404297 0.937988L6.45817 5.93799L12.5121 0.937988H0.404297Z" fill="#CFCFCF"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="30" height="25" viewBox="0 0 30 25" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M19.4141 17.278L13.8687 12.688L19.4141 8.09799L17.7069 6.68799L10.4422 12.688L17.7069 18.688L19.4141 17.278Z" fill="#000"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="30" height="25" viewBox="0 0 30 25" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M11.323 17.278L16.8683 12.688L11.323 8.09799L13.0302 6.68799L20.2948 12.688L13.0302 18.688L11.323 17.278Z" fill="#323232"/>
3
+ </svg>
@@ -31,6 +31,9 @@ const ViewCell = ({
31
31
  row,
32
32
  }) => {
33
33
  const { cellType } = column;
34
+ function isNumeric(value) {
35
+ return /^-?\d+\.?\d*$/.test(value);
36
+ }
34
37
  switch (cellType) {
35
38
  case cellTypes.FORMAT_DATA:
36
39
  return (
@@ -53,6 +56,14 @@ const ViewCell = ({
53
56
  column={column}
54
57
  />
55
58
  );
59
+ case cellTypes.COMMA:
60
+ return (
61
+ <Typography>
62
+ {isNumeric(row[column.dataField])
63
+ ? Number(row[column.dataField]).toLocaleString()
64
+ : row[column.dataField]}
65
+ </Typography>
66
+ );
56
67
  default:
57
68
  return (
58
69
  <Typography>
@@ -12,7 +12,7 @@ const CustomLinkView = ({
12
12
  row,
13
13
  }) => {
14
14
  const { rootPath, pathParams } = column?.linkAttr;
15
- const url = pathParams.map((attr) => `#${rootPath}/`.concat(row[attr]));
15
+ const url = pathParams.map((attr) => `${rootPath}/`.concat(row[attr]));
16
16
  return (
17
17
  <Link href={url} className={cellTypes.LINK}>
18
18
  <Typography>
@@ -19,6 +19,7 @@ const ActionHeaderCell = ({
19
19
  includeSelectedIds={includeSelectedIds}
20
20
  toggleSelectAll={toggleSelectAll}
21
21
  Ids={Ids}
22
+ rows={rows}
22
23
  />
23
24
  );
24
25
  }
@@ -10,6 +10,7 @@ const CheckboxView = ({
10
10
  includeSelectedIds,
11
11
  toggleSelectAll,
12
12
  Ids,
13
+ rows,
13
14
  }) => (
14
15
  <TableCell padding="checkbox">
15
16
  <span style={{ display: 'none' }}>Select all</span>
@@ -18,7 +19,7 @@ const CheckboxView = ({
18
19
  color="primary"
19
20
  indeterminate={includeSelectedIds}
20
21
  checked={includeSelectedIds}
21
- onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds)}
22
+ onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds, rows)}
22
23
  />
23
24
  </TableCell>
24
25
  );
@@ -1,37 +1,59 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import {
4
- createTheme,
4
+ createMuiTheme,
5
5
  TablePagination,
6
6
  ThemeProvider,
7
+ IconButton,
8
+ makeStyles,
7
9
  } from '@material-ui/core';
8
- import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
10
+ import {
11
+ ArrowDropDown,
12
+ } from '@material-ui/icons';
13
+ import rightArrow from '../assets/rightArrow.svg';
14
+ import leftArrow from '../assets/leftArrow.svg';
9
15
 
10
- const defaultTheme = {
11
- MuiTablePagination: {
12
- root: {
13
- paddingRight: '50px',
14
- borderTop: '3px solid #42779a',
15
- },
16
- toolbar: {
17
- minHeight: '45px',
18
- },
16
+ const useStyles = makeStyles(() => ({
17
+ paginationRoot: {
18
+ display: 'flex',
19
+ justifyContent: 'flex-end', // Moves pagination to the right
20
+ paddingRight: '10px', // Optional spacing
21
+ },
22
+ actionsContainer: {
23
+ display: 'flex',
24
+ justifyContent: 'flex-end', // Align pagination buttons to the right
19
25
  },
20
- MuiTypography: {
21
- body2: {
22
- fontSize: '14px',
23
- textTransform: 'uppercase',
26
+ }));
27
+
28
+ const defaultTheme = createMuiTheme({
29
+ overrides: {
30
+ MuiTablePagination: {
31
+ root: {
32
+ paddingRight: '50px',
33
+ width: '100%',
34
+ },
35
+ toolbar: {
36
+ minHeight: '45px',
37
+ display: 'flex',
38
+ alignItems: 'center',
39
+ },
24
40
  },
25
- root: {
26
- fontSize: '14px',
41
+ MuiTypography: {
42
+ body2: {
43
+ fontSize: '14px',
44
+ textTransform: 'uppercase',
45
+ },
46
+ root: {
47
+ fontSize: '14px',
48
+ },
27
49
  },
28
- },
29
- MuiIconButton: {
30
- root: {
31
- padding: '2px',
50
+ MuiIconButton: {
51
+ root: {
52
+ padding: '2px',
53
+ },
32
54
  },
33
55
  },
34
- };
56
+ });
35
57
 
36
58
  const CustomPagination = ({
37
59
  rowsPerPageOptions,
@@ -41,24 +63,53 @@ const CustomPagination = ({
41
63
  onPageChange,
42
64
  onRowsPerPageChange,
43
65
  customTheme = {},
44
- }) => (
45
- <ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
46
- <TablePagination
47
- labelRowsPerPage="Results per Page:"
48
- rowsPerPageOptions={rowsPerPageOptions}
49
- component="div"
50
- count={count}
51
- rowsPerPage={rowsPerPage}
52
- page={page}
53
- onPageChange={onPageChange}
54
- onRowsPerPageChange={onRowsPerPageChange}
55
- SelectProps={{
56
- IconComponent: KeyboardArrowDownOutlinedIcon,
57
- inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
58
- }}
59
- />
60
- </ThemeProvider>
61
- );
66
+ }) => {
67
+ const classes = useStyles();
68
+ return (
69
+ <ThemeProvider
70
+ theme={createMuiTheme({ overrides: { ...defaultTheme.overrides, ...customTheme } })}
71
+ >
72
+ <TablePagination
73
+ labelRowsPerPage="Results per Page:"
74
+ rowsPerPageOptions={rowsPerPageOptions}
75
+ component="div"
76
+ count={count}
77
+ rowsPerPage={rowsPerPage}
78
+ page={page}
79
+ onPageChange={onPageChange}
80
+ onRowsPerPageChange={onRowsPerPageChange}
81
+ SelectProps={{
82
+ IconComponent: ArrowDropDown,
83
+ inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
84
+ }}
85
+ nextIconButtonProps={{
86
+ 'aria-label': 'Next page',
87
+ }}
88
+ backIconButtonProps={{
89
+ 'aria-label': 'Previous page',
90
+ }}
91
+ ActionsComponent={() => (
92
+ <div className={classes.actionsContainer}>
93
+ <IconButton
94
+ onClick={(event) => onPageChange(event, page - 1)}
95
+ disabled={page === 0}
96
+ aria-label="Previous page"
97
+ >
98
+ <img src={leftArrow} style={{ opacity: page === 0 ? 0.2 : 1 }} alt="Left Arrow" />
99
+ </IconButton>
100
+ <IconButton
101
+ onClick={(event) => onPageChange(event, page + 1)}
102
+ disabled={page >= Math.ceil(count / rowsPerPage) - 1}
103
+ aria-label="Next page"
104
+ >
105
+ <img src={rightArrow} style={{ opacity: page >= Math.ceil(count / rowsPerPage) - 1 ? 0.2 : 1 }} alt="Right Arrow" />
106
+ </IconButton>
107
+ </div>
108
+ )}
109
+ />
110
+ </ThemeProvider>
111
+ );
112
+ };
62
113
 
63
114
  CustomPagination.propTypes = {
64
115
  rowsPerPageOptions: PropTypes.arrayOf(PropTypes.number).isRequired,