@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
|
@@ -1,50 +1,73 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import { useApolloClient } from '@apollo/client';
|
|
3
8
|
import {
|
|
4
9
|
IconButton,
|
|
5
10
|
Tooltip,
|
|
6
|
-
|
|
11
|
+
makeStyles,
|
|
7
12
|
} from '@material-ui/core';
|
|
8
|
-
|
|
13
|
+
import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
|
|
9
14
|
import { CloudDownload } from '@material-ui/icons';
|
|
10
|
-
import {
|
|
15
|
+
import { downloadData } from '../util/downloadTable';
|
|
11
16
|
|
|
12
|
-
const downloadButtonStyle = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Default style for Download Button with Text.
|
|
18
|
-
const DEFAULT_BUTTON_STYLE = {
|
|
19
|
-
width: '223px',
|
|
20
|
-
height: '41px',
|
|
21
|
-
borderRadius: '5px',
|
|
22
|
-
backgroundColor: '#2A6E93',
|
|
23
|
-
color: '#fff',
|
|
24
|
-
marginTop: '10px',
|
|
25
|
-
fontFamily: 'poppins',
|
|
26
|
-
'& #cloudIcon': {
|
|
27
|
-
margin: '10px',
|
|
28
|
-
marginTop: '6px',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
17
|
+
// const downloadButtonStyle = {
|
|
18
|
+
// color: '#d1d2d3',
|
|
19
|
+
// marginTop: '7px',
|
|
20
|
+
// };
|
|
31
21
|
|
|
32
22
|
const DownloadButton = ({
|
|
33
23
|
count,
|
|
34
24
|
queryVariables,
|
|
35
25
|
table,
|
|
36
|
-
buttonConfig = {},
|
|
37
|
-
isIcon = false,
|
|
38
26
|
}) => {
|
|
27
|
+
const [listDisplay, setListDisplay] = useState('none');
|
|
28
|
+
const dropdownSelection = useRef(null);
|
|
29
|
+
const useOutsideAlerter = (ref) => {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
function handleClickOutside(event) {
|
|
32
|
+
if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
|
|
33
|
+
setListDisplay('none');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
37
|
+
return () => {
|
|
38
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
39
|
+
};
|
|
40
|
+
}, [ref]);
|
|
41
|
+
};
|
|
42
|
+
useOutsideAlerter(dropdownSelection);
|
|
43
|
+
|
|
39
44
|
if (table.paginationAPIField === 'filesInList') {
|
|
40
45
|
return <></>;
|
|
41
46
|
}
|
|
42
|
-
if (count === 0) {
|
|
43
|
-
return <CloudDownload className="disableButton" style={downloadButtonStyle} />;
|
|
44
|
-
}
|
|
45
47
|
|
|
46
48
|
const client = useApolloClient();
|
|
47
49
|
|
|
50
|
+
function cleanData(result) {
|
|
51
|
+
function hasHTMLTags(str) {
|
|
52
|
+
const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
|
|
53
|
+
return htmlTagPattern.test(str);
|
|
54
|
+
}
|
|
55
|
+
const cleanedResult = result.map((res) => {
|
|
56
|
+
const newObj = {};
|
|
57
|
+
Object.keys(res).forEach((key) => {
|
|
58
|
+
if (hasHTMLTags(res[key])) {
|
|
59
|
+
const div = document.createElement('div');
|
|
60
|
+
div.innerHTML = res[key];
|
|
61
|
+
newObj[key] = div.textContent || div.innerText || res[key];
|
|
62
|
+
} else {
|
|
63
|
+
newObj[key] = res[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return newObj;
|
|
67
|
+
});
|
|
68
|
+
return cleanedResult;
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
async function downloadSCSVFile() {
|
|
49
72
|
const {
|
|
50
73
|
query,
|
|
@@ -57,6 +80,34 @@ const DownloadButton = ({
|
|
|
57
80
|
...queryVariables,
|
|
58
81
|
page: 0,
|
|
59
82
|
first: 10000,
|
|
83
|
+
order_by: table.sortBy,
|
|
84
|
+
sort_direction: table.sortOrder,
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
.then((response) => {
|
|
88
|
+
if (paginationAPIField && response && response.data) {
|
|
89
|
+
return response.data[paginationAPIField];
|
|
90
|
+
}
|
|
91
|
+
return response.data;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
downloadData(cleanData(result), table, table.downloadFileName, 'csv');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function downloadJsonFile() {
|
|
98
|
+
const {
|
|
99
|
+
query,
|
|
100
|
+
paginationAPIField,
|
|
101
|
+
} = table;
|
|
102
|
+
|
|
103
|
+
const result = await client.query({
|
|
104
|
+
query,
|
|
105
|
+
variables: {
|
|
106
|
+
...queryVariables,
|
|
107
|
+
page: 0,
|
|
108
|
+
first: 10000,
|
|
109
|
+
order_by: table.sortBy,
|
|
110
|
+
sort_direction: table.sortOrder,
|
|
60
111
|
},
|
|
61
112
|
})
|
|
62
113
|
.then((response) => {
|
|
@@ -65,37 +116,99 @@ const DownloadButton = ({
|
|
|
65
116
|
}
|
|
66
117
|
return response.data;
|
|
67
118
|
});
|
|
68
|
-
|
|
119
|
+
downloadData(cleanData(result), table, table.downloadFileName, 'json');
|
|
69
120
|
}
|
|
70
121
|
|
|
71
122
|
const downloadTableCSV = useCallback(() => {
|
|
72
123
|
downloadSCSVFile();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
124
|
+
setListDisplay('none');
|
|
125
|
+
}, [queryVariables, table]);
|
|
126
|
+
|
|
127
|
+
const downloadTableJson = useCallback(() => {
|
|
128
|
+
downloadJsonFile();
|
|
129
|
+
setListDisplay('none');
|
|
130
|
+
}, [queryVariables, table]);
|
|
131
|
+
|
|
132
|
+
const handleClickButton = () => {
|
|
133
|
+
if (listDisplay === 'none') {
|
|
134
|
+
setListDisplay('block');
|
|
135
|
+
} else {
|
|
136
|
+
setListDisplay('none');
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const useStyles = makeStyles({
|
|
141
|
+
dropdown: {
|
|
142
|
+
width: '60px',
|
|
143
|
+
height: '25px',
|
|
144
|
+
marginTop: '8px',
|
|
145
|
+
paddingLeft: '5px',
|
|
146
|
+
border: '0.75px solid #606060',
|
|
147
|
+
borderRadius: '5px',
|
|
148
|
+
display: 'inline-block',
|
|
149
|
+
position: 'relative',
|
|
150
|
+
alignSelf: 'center',
|
|
151
|
+
},
|
|
152
|
+
dropdownList: {
|
|
153
|
+
display: 'block',
|
|
154
|
+
position: 'absolute',
|
|
155
|
+
width: '60px',
|
|
156
|
+
marginTop: '3px',
|
|
157
|
+
marginLeft: '-5px',
|
|
158
|
+
overflow: 'auto',
|
|
159
|
+
zIndex: '20',
|
|
160
|
+
border: '1.5px solid #41545E',
|
|
161
|
+
borderRadius: '5px',
|
|
162
|
+
background: '#ffffff',
|
|
163
|
+
},
|
|
164
|
+
dropdownListItem: {
|
|
165
|
+
padding: '2px 4px',
|
|
166
|
+
font: 'Poppins',
|
|
167
|
+
fontSize: '14px',
|
|
168
|
+
fontWeight: 400,
|
|
169
|
+
lineHeight: '21px',
|
|
170
|
+
'&:hover': {
|
|
171
|
+
background: '#D7D7D7',
|
|
172
|
+
cursor: 'pointer',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
arrowdownIcon: {
|
|
176
|
+
marginLeft: '5px',
|
|
177
|
+
fill: '#606060',
|
|
178
|
+
},
|
|
179
|
+
arrowdownIconDisabled: {
|
|
180
|
+
marginLeft: '5px',
|
|
181
|
+
fill: '#00000042',
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const classes = useStyles();
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div className={classes.dropdown}>
|
|
189
|
+
|
|
190
|
+
<Tooltip title={table.downloadButtonTooltipText || 'Download filtered results'}>
|
|
191
|
+
{
|
|
192
|
+
count !== 0
|
|
193
|
+
? (
|
|
194
|
+
<IconButton onClick={handleClickButton} style={{ padding: '0' }}>
|
|
195
|
+
<CloudDownload />
|
|
196
|
+
<KeyboardArrowDownOutlinedIcon className={classes.arrowdownIcon} />
|
|
197
|
+
</IconButton>
|
|
198
|
+
)
|
|
199
|
+
: (
|
|
200
|
+
<IconButton disabled>
|
|
201
|
+
<CloudDownload />
|
|
202
|
+
<KeyboardArrowDownOutlinedIcon className={classes.arrowdownIconDisabled} />
|
|
203
|
+
</IconButton>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
</Tooltip>
|
|
207
|
+
<div className={classes.dropdownList} style={{ display: listDisplay }}>
|
|
208
|
+
<div id="dropdownListItemCSV" className={classes.dropdownListItem} onClick={downloadTableCSV}>CSV</div>
|
|
209
|
+
<div id="dropdownListItemJSON" className={classes.dropdownListItem} onClick={downloadTableJson}>JSON</div>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
99
212
|
);
|
|
100
213
|
};
|
|
101
214
|
|
package/src/util/Types.js
CHANGED
|
@@ -8,6 +8,7 @@ export const FORMAT_DATA = 'FORMAT_DATA';
|
|
|
8
8
|
export const FORMAT_BYTES = 'FORMAT_BYTES';
|
|
9
9
|
export const TRANSFORM = 'TRANSFORM';
|
|
10
10
|
export const EXPAND = 'EXPAND';
|
|
11
|
+
export const COMMA = 'COMMA';
|
|
11
12
|
|
|
12
13
|
export const cellTypes = {
|
|
13
14
|
CUSTOM_ELEM,
|
|
@@ -17,6 +18,7 @@ export const cellTypes = {
|
|
|
17
18
|
DELETE,
|
|
18
19
|
DEFAULT,
|
|
19
20
|
FORMAT_DATA,
|
|
21
|
+
COMMA,
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export const cellStyles = {
|
|
@@ -22,8 +22,7 @@ export function createFileName(fileName) {
|
|
|
22
22
|
if (minutes < 10) { minutes = `0${minutes}`; }
|
|
23
23
|
|
|
24
24
|
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
|
-
|
|
26
|
-
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
25
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}`;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
@@ -43,8 +42,11 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
43
42
|
} else {
|
|
44
43
|
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
45
44
|
}
|
|
45
|
+
} else if (keyName === 'participant') {
|
|
46
|
+
line += entry[keyName].id;
|
|
46
47
|
} else {
|
|
47
|
-
|
|
48
|
+
const newLine = entry[keyName] !== null ? String(entry[keyName]).replace(/"/g, '""') : '';
|
|
49
|
+
line += `"${newLine}"`;
|
|
48
50
|
}
|
|
49
51
|
return line;
|
|
50
52
|
});
|
|
@@ -59,21 +61,45 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
59
61
|
return str;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
export function
|
|
64
|
+
export function downloadData(tableData, table, downloadFileName, format = 'csv') {
|
|
63
65
|
const { columns = [] } = table;
|
|
64
|
-
const filterColumns = columns.filter(({ cellType }) =>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
const filterColumns = columns.filter(({ cellType, doNotDownload }) => (
|
|
67
|
+
!actionCellTypes.includes(cellType) && !doNotDownload));
|
|
68
|
+
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
69
|
+
|
|
70
|
+
formatDataVal = formatDataVal.map((item) => {
|
|
71
|
+
const updatedItem = {};
|
|
72
|
+
filterColumns.forEach(({ dataField }) => {
|
|
73
|
+
updatedItem[dataField] = item[dataField];
|
|
74
|
+
});
|
|
75
|
+
return updatedItem;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
let fileContent;
|
|
79
|
+
let fileType;
|
|
80
|
+
|
|
81
|
+
if (format === 'json') {
|
|
82
|
+
filterColumns.forEach((column) => {
|
|
83
|
+
formatDataVal = JSON.parse(
|
|
84
|
+
JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
fileContent = JSON.stringify(formatDataVal);
|
|
88
|
+
fileType = 'application/json';
|
|
89
|
+
} else {
|
|
90
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
91
|
+
const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
|
|
92
|
+
.map(({ dataField }) => dataField);
|
|
93
|
+
const headers = filterColumns.filter(({ dataField }) => dataField)
|
|
94
|
+
.map(({ header, downloadHeader }) => (downloadHeader || header));
|
|
95
|
+
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
96
|
+
fileType = 'text/csv';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const exportData = new Blob([fileContent], { type: fileType });
|
|
100
|
+
const fileURL = window.URL.createObjectURL(exportData);
|
|
101
|
+
const tempLink = document.createElement('a');
|
|
102
|
+
tempLink.setAttribute('href', fileURL);
|
|
77
103
|
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
78
104
|
document.body.appendChild(tempLink);
|
|
79
105
|
tempLink.click();
|