@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.
- package/dist/ExtendedView.js +9 -11
- package/dist/TableView.js +5 -5
- package/dist/assets/downArrow.svg +3 -0
- package/dist/assets/leftArrow.svg +3 -0
- package/dist/assets/rightArrow.svg +3 -0
- package/dist/body/DisplayBodyCell.js +5 -0
- package/dist/body/components/CustomLinkView.js +1 -1
- package/dist/header/ActionHeaderCell.js +2 -1
- package/dist/header/components/CheckBoxView.js +3 -2
- package/dist/pagination/CustomPagination.js +76 -26
- package/dist/toolbar/DownloadButtonView.js +152 -45
- package/dist/util/Types.js +5 -2
- package/dist/util/downloadTable.js +62 -37
- package/package.json +1 -1
- package/src/ExtendedView.js +34 -33
- package/src/TableView.js +11 -8
- package/src/assets/downArrow.svg +3 -0
- package/src/assets/leftArrow.svg +3 -0
- package/src/assets/rightArrow.svg +3 -0
- package/src/body/DisplayBodyCell.js +11 -0
- package/src/body/components/CustomLinkView.js +1 -1
- package/src/header/ActionHeaderCell.js +1 -0
- package/src/header/components/CheckBoxView.js +2 -1
- package/src/pagination/CustomPagination.js +91 -40
- package/src/toolbar/DownloadButtonView.js +168 -55
- package/src/util/Types.js +2 -0
- package/src/util/downloadTable.js +43 -17
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertToCSV = convertToCSV;
|
|
7
7
|
exports.createFileName = createFileName;
|
|
8
|
-
exports.
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
109
|
-
|
|
110
|
-
tempLink
|
|
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
package/src/ExtendedView.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
47
|
+
|
|
55
48
|
)}
|
|
56
49
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
);
|
|
@@ -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) =>
|
|
15
|
+
const url = pathParams.map((attr) => `${rootPath}/`.concat(row[attr]));
|
|
16
16
|
return (
|
|
17
17
|
<Link href={url} className={cellTypes.LINK}>
|
|
18
18
|
<Typography>
|
|
@@ -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
|
-
|
|
4
|
+
createMuiTheme,
|
|
5
5
|
TablePagination,
|
|
6
6
|
ThemeProvider,
|
|
7
|
+
IconButton,
|
|
8
|
+
makeStyles,
|
|
7
9
|
} from '@material-ui/core';
|
|
8
|
-
import
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
41
|
+
MuiTypography: {
|
|
42
|
+
body2: {
|
|
43
|
+
fontSize: '14px',
|
|
44
|
+
textTransform: 'uppercase',
|
|
45
|
+
},
|
|
46
|
+
root: {
|
|
47
|
+
fontSize: '14px',
|
|
48
|
+
},
|
|
27
49
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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,
|