@bento-core/table 1.0.1-ccdihub.9 → 1.0.1-icdc.1

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.
Files changed (37) hide show
  1. package/dist/ExtendedView.js +11 -5
  2. package/dist/TableView.js +13 -3
  3. package/dist/body/ActionBodyCell.js +4 -1
  4. package/dist/body/CustomTblBody.js +6 -2
  5. package/dist/body/components/CheckBoxView.js +7 -9
  6. package/dist/body/components/DeleteCellView.js +6 -2
  7. package/dist/header/ActionHeaderCell.js +3 -1
  8. package/dist/header/ColumnGrouping.js +52 -0
  9. package/dist/header/CustomCell.js +2 -1
  10. package/dist/header/CustomTblHeader.js +10 -3
  11. package/dist/header/components/CheckBoxView.js +8 -16
  12. package/dist/header/components/DeleteCellView.js +11 -6
  13. package/dist/header/components/RemoveAllDialog.js +3 -1
  14. package/dist/pagination/CustomPagination.js +1 -7
  15. package/dist/toolbar/DownloadButtonView.js +54 -5
  16. package/dist/toolbar/ManageColumnView.js +7 -8
  17. package/dist/util/Dataformat.js +41 -1
  18. package/dist/util/downloadTable.js +109 -0
  19. package/package.json +10 -12
  20. package/src/ExtendedView.js +35 -25
  21. package/src/TableView.js +10 -0
  22. package/src/body/ActionBodyCell.js +3 -0
  23. package/src/body/CustomTblBody.js +5 -1
  24. package/src/body/components/CheckBoxView.js +23 -12
  25. package/src/body/components/DeleteCellView.js +28 -16
  26. package/src/header/ActionHeaderCell.js +2 -0
  27. package/src/header/ColumnGrouping.js +55 -0
  28. package/src/header/CustomCell.js +1 -0
  29. package/src/header/CustomTblHeader.js +5 -0
  30. package/src/header/components/CheckBoxView.js +10 -9
  31. package/src/header/components/DeleteCellView.js +41 -26
  32. package/src/header/components/RemoveAllDialog.js +2 -0
  33. package/src/pagination/CustomPagination.js +0 -4
  34. package/src/toolbar/DownloadButtonView.js +54 -3
  35. package/src/toolbar/ManageColumnView.js +9 -6
  36. package/src/util/Dataformat.js +25 -0
  37. package/src/util/downloadTable.js +74 -0
@@ -13,10 +13,12 @@ function RemoveAllDialogView(props) {
13
13
  toggleDisplay,
14
14
  count,
15
15
  removeAllFiles,
16
+ onDeleteAllFiles,
16
17
  } = props;
17
18
  const deleteAllFiles = () => {
18
19
  removeAllFiles();
19
20
  toggleDisplay();
21
+ onDeleteAllFiles();
20
22
  };
21
23
  return (
22
24
  <>
@@ -50,10 +50,6 @@ const CustomPagination = ({
50
50
  page={page}
51
51
  onPageChange={onPageChange}
52
52
  onRowsPerPageChange={onRowsPerPageChange}
53
- SelectProps={{
54
- inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
55
- native: true,
56
- }}
57
53
  />
58
54
  </ThemeProvider>
59
55
  );
@@ -1,21 +1,72 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
+ import { useApolloClient } from '@apollo/client';
2
3
  import {
3
4
  IconButton,
4
5
  Tooltip,
5
6
  } from '@material-ui/core';
6
7
  import { CloudDownload } from '@material-ui/icons';
8
+ import { downloadJson } from '../util/downloadTable';
7
9
 
8
10
  const DownloadButton = ({
9
11
  download,
12
+ rows,
13
+ table,
14
+ queryVariables,
15
+ server,
10
16
  }) => {
11
17
  if (!download) {
12
18
  return null;
13
19
  }
20
+ const {
21
+ downloadCsv = 'download',
22
+ downloadTable,
23
+ downloadFileName,
24
+ } = download;
25
+
26
+ const client = useApolloClient();
27
+
28
+ async function downloadSCSVFile() {
29
+ const {
30
+ query,
31
+ paginationAPIField,
32
+ } = table;
33
+
34
+ const result = await client.query({
35
+ query,
36
+ variables: {
37
+ ...queryVariables,
38
+ page: 0,
39
+ first: 10000,
40
+ },
41
+ })
42
+ .then((response) => {
43
+ if (paginationAPIField && response && response.data) {
44
+ return response.data[paginationAPIField];
45
+ }
46
+ return response.data;
47
+ });
48
+ downloadJson(result, table, downloadFileName);
49
+ }
50
+
51
+ const downloadTableCSV = useCallback(() => {
52
+ if (downloadTable) {
53
+ downloadTable();
54
+ } else if (!downloadTable && !server) {
55
+ downloadJson(rows, table, downloadFileName);
56
+ } else {
57
+ downloadSCSVFile();
58
+ }
59
+ }, [queryVariables]);
14
60
 
15
61
  return (
16
62
  <>
17
- <Tooltip title={download.downloadCsv}>
18
- <IconButton>
63
+ <Tooltip
64
+ title={downloadCsv}
65
+ className="download-icon"
66
+ >
67
+ <IconButton
68
+ onClick={downloadTableCSV}
69
+ >
19
70
  <CloudDownload />
20
71
  </IconButton>
21
72
  </Tooltip>
@@ -26,7 +26,7 @@ const ManageColumnView = ({
26
26
  return null;
27
27
  }
28
28
  const [anchorEl, setAnchorEl] = useState(null);
29
- const handleClick = (event) => {
29
+ const toggleDisplay = (event) => {
30
30
  setAnchorEl(event.currentTarget);
31
31
  };
32
32
 
@@ -39,7 +39,11 @@ const ManageColumnView = ({
39
39
  return (
40
40
  <>
41
41
  <Tooltip title={manageViewColumns.title}>
42
- <IconButton variant="contained" onClick={handleClick}>
42
+ <IconButton
43
+ variant="contained"
44
+ onClick={toggleDisplay}
45
+ className="manageViewColumnBtn"
46
+ >
43
47
  <ViewColumn />
44
48
  </IconButton>
45
49
  </Tooltip>
@@ -70,7 +74,6 @@ const ManageColumnView = ({
70
74
  <Checkbox
71
75
  icon={(
72
76
  <CheckBoxBlankIcon
73
- style={{ fontSize: 18 }}
74
77
  className="checkBoxIcon"
75
78
  />
76
79
  )}
@@ -78,9 +81,6 @@ const ManageColumnView = ({
78
81
  checked={column.display}
79
82
  checkedIcon={(
80
83
  <CheckBoxIcon
81
- style={{
82
- fontSize: 18,
83
- }}
84
84
  className="checkBoxIcon"
85
85
  />
86
86
  )}
@@ -88,6 +88,9 @@ const ManageColumnView = ({
88
88
  color="secondary"
89
89
  className="checkBox"
90
90
  />
91
+ {column.icon && (
92
+ <img src={column.icon} alt={column.header} className={column.dataField} />
93
+ )}
91
94
  <Typography>{column.header}</Typography>
92
95
  </ListItem>
93
96
  ))}
@@ -6,3 +6,28 @@ export function formatBytes(bytes, decimals = 2) {
6
6
  const i = Math.floor(Math.log(bytes) / Math.log(1024));
7
7
  return `${parseFloat((bytes / (1024 ** i)).toFixed(dm))} ${sizes[i]}`;
8
8
  }
9
+
10
+ /**
11
+ * convert zero (0) value to custom val
12
+ * @param {*} columns
13
+ * @param {*} data
14
+ * @returns
15
+ */
16
+ export const formatColumnValues = (columns, data) => {
17
+ const formatColumns = columns.filter(({ columnDefaultValues }) => columnDefaultValues);
18
+ if (formatColumns.length > 0) {
19
+ const formatCoumnData = [...data].reduce((acc, item) => {
20
+ const updateRow = { ...item };
21
+ formatColumns.forEach((col) => {
22
+ const { columnDefaultValues, dataField } = col;
23
+ if (columnDefaultValues[item[dataField]]) {
24
+ updateRow[dataField] = columnDefaultValues[item[dataField]];
25
+ }
26
+ });
27
+ acc.push(updateRow);
28
+ return acc;
29
+ }, []);
30
+ return formatCoumnData;
31
+ }
32
+ return data;
33
+ };
@@ -0,0 +1,74 @@
1
+ import { formatBytes, formatColumnValues } from './Dataformat';
2
+ import { actionCellTypes } from './Types';
3
+
4
+ export function createFileName(fileName) {
5
+ const date = new Date();
6
+ const yyyy = date.getFullYear();
7
+ let dd = date.getDate();
8
+ let mm = (date.getMonth() + 1);
9
+
10
+ if (dd < 10) { dd = `0${dd}`; }
11
+
12
+ if (mm < 10) { mm = `0${mm}`; }
13
+
14
+ const todaysDate = `${yyyy}-${mm}-${dd}`;
15
+
16
+ let hours = date.getHours();
17
+ let minutes = date.getMinutes();
18
+ let seconds = date.getSeconds();
19
+
20
+ if (hours < 10) { hours = `0${hours}`; }
21
+
22
+ if (minutes < 10) { minutes = `0${minutes}`; }
23
+
24
+ if (seconds < 10) { seconds = `0${seconds}`; }
25
+
26
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
27
+ }
28
+
29
+ export function convertToCSV(jsonse, keysToInclude, header) {
30
+ const objArray = jsonse;
31
+ // To Do empty object just print headers
32
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
33
+ let str = header.join(',');
34
+ array.map((entry, index) => {
35
+ let line = '';
36
+ keysToInclude.map((keyName) => {
37
+ if (line !== '') line += ',';
38
+ if (keyName === 'file_size') {
39
+ line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
40
+ } else {
41
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
42
+ }
43
+ return line;
44
+ });
45
+ if (index === 0) {
46
+ // str = header.join(',');
47
+ str += `\r\n${line}\r\n`;
48
+ } else {
49
+ str += `${line}\r\n`;
50
+ }
51
+ return str;
52
+ });
53
+ return str;
54
+ }
55
+
56
+ export function downloadJson(tableData, table, downloadFileName) {
57
+ const { columns = [] } = table;
58
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
59
+ const formatDataVal = formatColumnValues(filterColumns, tableData);
60
+ const jsonse = JSON.stringify(formatDataVal);
61
+ const keysToInclude = columns.filter(({ dataField }) => dataField)
62
+ .map(({ dataField }) => dataField);
63
+ const headers = columns.filter(({ dataField }) => dataField).map(({ header }) => header);
64
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
65
+ const exportData = new Blob([csv], { type: 'text/csv' });
66
+ const JsonURL = window.URL.createObjectURL(exportData);
67
+ let tempLink = '';
68
+ tempLink = document.createElement('a');
69
+ tempLink.setAttribute('href', JsonURL);
70
+ tempLink.setAttribute('download', createFileName(downloadFileName || ''));
71
+ document.body.appendChild(tempLink);
72
+ tempLink.click();
73
+ document.body.removeChild(tempLink);
74
+ }