@bento-core/table 1.0.1-ccdihub.9 → 1.0.1-ctdc.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.
package/package.json CHANGED
@@ -1,32 +1,30 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdihub.9",
3
+ "version": "1.0.1-ctdc.1",
4
+ "description": "",
4
5
  "main": "dist/index.js",
5
6
  "scripts": {
6
7
  "build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
7
8
  "test": "echo \"Error: no test specified\" && exit 1",
8
9
  "lint": "eslint src"
9
10
  },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/CBIIT/bento-frontend.git"
13
- },
11
+ "repository": "https://github.com/CBIIT/bento-frontend",
14
12
  "publishConfig": {
15
13
  "access": "public"
16
14
  },
15
+ "dependencies": {
16
+ "@bento-core/util": "^1.0.0"
17
+ },
17
18
  "peerDependencies": {
18
19
  "@material-ui/core": "^4.12.4",
19
20
  "@material-ui/icons": "^4.9.1",
20
21
  "prop-types": "^15.7.2",
21
22
  "react": "^17.0.2",
22
23
  "react-dom": "^17.0.0",
23
- "react-redux": "^7.2.1"
24
+ "react-redux": "^7.2.1",
25
+ "@apollo/client": "^3.6.9",
26
+ "clsx": "^1.2.1"
24
27
  },
25
28
  "author": "CTOS Bento Team",
26
- "license": "ISC",
27
- "bugs": {
28
- "url": "https://github.com/CBIIT/bento-frontend/issues"
29
- },
30
- "homepage": "https://github.com/CBIIT/bento-frontend#readme",
31
- "description": ""
29
+ "license": "ISC"
32
30
  }
@@ -11,16 +11,19 @@ import DownloadButton from './toolbar/DownloadButtonView';
11
11
 
12
12
  const ExtendedView = ({
13
13
  table,
14
+ rows,
14
15
  onColumnViewChange,
15
16
  onRowsPerPageChange,
16
17
  onPageChange,
17
- numSelected = 0,
18
18
  customTheme,
19
+ queryVariables,
20
+ server,
19
21
  }) => {
20
22
  const { extendedViewConfig } = table;
21
23
  if (!extendedViewConfig) {
22
24
  return null;
23
25
  }
26
+
24
27
  const {
25
28
  download = false,
26
29
  manageViewColumns = false,
@@ -28,34 +31,41 @@ const ExtendedView = ({
28
31
  } = extendedViewConfig;
29
32
 
30
33
  const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
34
+
31
35
  return (
32
36
  <ThemeProvider theme={themeConfig}>
33
- {(numSelected === 0 && (download || manageViewColumns)) && (
34
- <Toolbar className="downloadColumnView">
35
- <DownloadButton
36
- download={download}
37
- />
38
- <ManageColumnView
39
- table={table}
40
- manageViewColumns={manageViewColumns}
41
- onColumnViewChange={onColumnViewChange}
42
- />
43
- </Toolbar>
37
+ {(download || manageViewColumns) && (
38
+ <Toolbar
39
+ className="downloadAndColumnView"
40
+ >
41
+ <DownloadButton
42
+ download={download}
43
+ rows={rows}
44
+ server={server}
45
+ table={table}
46
+ queryVariables={queryVariables}
47
+ />
48
+ <ManageColumnView
49
+ table={table}
50
+ manageViewColumns={manageViewColumns}
51
+ onColumnViewChange={onColumnViewChange}
52
+ />
53
+ </Toolbar>
44
54
  )}
45
55
  {
46
- (pagination) && (
47
- <CustomPagination
48
- customTheme={customTheme.tblTopPgn}
49
- rowsPerPageOptions={[10, 25, 50, 100]}
50
- component="div"
51
- count={table.totalRowCount || 0}
52
- rowsPerPage={table.rowsPerPage || 10}
53
- page={table.page || 0}
54
- onPageChange={onPageChange}
55
- onRowsPerPageChange={onRowsPerPageChange}
56
- />
57
- )
58
- }
56
+ (pagination) && (
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
+ />
67
+ )
68
+ }
59
69
  </ThemeProvider>
60
70
  );
61
71
  };
package/src/TableView.js CHANGED
@@ -27,6 +27,7 @@ const CustomTableContainer = (props) => {
27
27
 
28
28
  const TableView = ({
29
29
  tableRows = [],
30
+ totalRows = [],
30
31
  table,
31
32
  onRowsPerPageChange,
32
33
  onPageChange,
@@ -36,15 +37,20 @@ const TableView = ({
36
37
  onSortByColumn,
37
38
  onColumnViewChange,
38
39
  themeConfig = {},
40
+ queryVariables,
41
+ server,
39
42
  }) => (
40
43
  <>
41
44
  <ExtendedView
42
45
  table={table}
46
+ rows={totalRows}
47
+ server={server}
43
48
  onColumnViewChange={onColumnViewChange}
44
49
  onRowsPerPageChange={onRowsPerPageChange}
45
50
  onPageChange={onPageChange}
46
51
  numSelected={table?.selectedRows?.length || 0}
47
52
  customTheme={themeConfig.extendedView}
53
+ queryVariables={queryVariables}
48
54
  />
49
55
  <CustomToolbar
50
56
  numSelected={table?.selectedRows?.length || 0}
@@ -12,6 +12,7 @@ import DisplayCell from './DisplayBodyCell';
12
12
  import defaultTheme from './DefaultThemConfig';
13
13
  import { actionCellTypes } from '../util/Types';
14
14
  import ActionCell from './ActionBodyCell';
15
+ import { formatColumnValues } from '../util/Dataformat';
15
16
 
16
17
  /**
17
18
  * 1. Returns cell associated with action (checkbox / delete view)
@@ -24,13 +25,14 @@ const CustomTableBody = ({
24
25
  customTheme = {},
25
26
  }) => {
26
27
  const { columns } = table;
28
+ const formatRows = formatColumnValues(columns, rows);
27
29
  const displayColunms = columns.filter((col) => col.display);
28
30
  const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
29
31
 
30
32
  return (
31
33
  <ThemeProvider theme={themeConfig}>
32
34
  <TableBody>
33
- {rows
35
+ {formatRows
34
36
  .map((row) => (
35
37
  <TableRow>
36
38
  {
@@ -4,15 +4,12 @@ import {
4
4
  TableCell,
5
5
  } from '@material-ui/core';
6
6
 
7
- const label = { inputProps: { 'aria-label': 'Checkbox item' } };
8
-
9
7
  const CheckboxView = ({
10
8
  row,
11
9
  onRowSelectChange,
12
10
  }) => (
13
11
  <TableCell padding="checkbox">
14
12
  <Checkbox
15
- {...label}
16
13
  disableRipple
17
14
  onClick={(event) => onRowSelectChange(event, row)}
18
15
  checked={row.isChecked}
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import {
3
+ TableRow,
4
+ TableCell,
5
+ Typography,
6
+ } from '@material-ui/core';
7
+
8
+ const ColumnGrouping = ({
9
+ columnGroups = [],
10
+ columns = [],
11
+ }) => {
12
+ if (columnGroups.length === 0) {
13
+ return null;
14
+ }
15
+
16
+ const getColSpan = (indexes = [0, 0]) => {
17
+ const startIndex = indexes[0];
18
+ const endIndex = indexes[1];
19
+ const displayGroupCols = columns
20
+ .map((col, index) => ((startIndex <= index && index <= endIndex) && col.display))
21
+ .filter((item) => item);
22
+ return displayGroupCols.length;
23
+ };
24
+
25
+ return (
26
+ <TableRow className="column_grouping">
27
+ {columnGroups.map((group) => {
28
+ const {
29
+ title,
30
+ customViewRender,
31
+ clsName,
32
+ columnIndexes,
33
+ } = group;
34
+ if (!columnIndexes) {
35
+ return (
36
+ <Typography variant="subtitle1" color="error" size="sm">
37
+ Missing columnIndexes [startColIndex, endColIndex]
38
+ </Typography>
39
+ );
40
+ }
41
+ const colSpan = getColSpan(columnIndexes);
42
+ if (colSpan > 0) {
43
+ return (
44
+ <TableCell colSpan={colSpan} className={clsName}>
45
+ {customViewRender ? customViewRender() : title}
46
+ </TableCell>
47
+ );
48
+ }
49
+ return null;
50
+ })}
51
+ </TableRow>
52
+ );
53
+ };
54
+
55
+ export default ColumnGrouping;
@@ -50,6 +50,7 @@ const CustomHeaderCell = ({
50
50
  scope="col"
51
51
  active={sortBy === dataField}
52
52
  direction={sortOrder}
53
+ className={dataField}
53
54
  >
54
55
  <Tooltip>
55
56
  <TableSortLabel
@@ -12,6 +12,7 @@ import HeaderCell from './CustomCell';
12
12
  import defaultTheme from './DefaultThemConfig';
13
13
  import { actionCellTypes } from '../util/Types';
14
14
  import ActionHeaderCell from './ActionHeaderCell';
15
+ import ColumnGrouping from './ColumnGrouping';
15
16
 
16
17
  const CustomTableHeader = ({
17
18
  table,
@@ -27,6 +28,7 @@ const CustomTableHeader = ({
27
28
  selectedRows = [],
28
29
  sortBy,
29
30
  sortOrder,
31
+ columnGroups,
30
32
  } = table;
31
33
  const Ids = rows.map((row) => row[table.dataKey]);
32
34
  const includeSelectedIds = Ids.some((id) => selectedRows.includes(id));
@@ -40,6 +42,7 @@ const CustomTableHeader = ({
40
42
  return (
41
43
  <ThemeProvider theme={themeConfig}>
42
44
  <TableHead>
45
+ <ColumnGrouping columnGroups={columnGroups} columns={columns} />
43
46
  <TableRow>
44
47
  {
45
48
  displayColunms.map((column) => {
@@ -2,23 +2,24 @@ import React from 'react';
2
2
  import {
3
3
  TableCell,
4
4
  Checkbox,
5
+ FormControlLabel,
5
6
  } from '@material-ui/core';
6
7
 
7
- const label = { inputProps: { 'aria-label': 'Select all checkbox' } };
8
-
9
8
  const CheckboxView = ({
10
9
  includeSelectedIds,
11
10
  toggleSelectAll,
12
11
  Ids,
13
12
  }) => (
14
13
  <TableCell padding="checkbox">
15
- <span style={{ display: 'none' }}>Select all</span>
16
- <Checkbox
17
- {...label}
18
- color="primary"
19
- indeterminate={includeSelectedIds}
20
- checked={includeSelectedIds}
21
- onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds)}
14
+ <FormControlLabel
15
+ control={(
16
+ <Checkbox
17
+ color="primary"
18
+ indeterminate={includeSelectedIds}
19
+ checked={includeSelectedIds}
20
+ onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds)}
21
+ />
22
+ )}
22
23
  />
23
24
  </TableCell>
24
25
  );
@@ -28,34 +28,51 @@ const DeleteCellView = ({
28
28
  }) => {
29
29
  const [displayDialog, setDisplay] = useState(false);
30
30
  const toggleDialogDisplay = () => setDisplay(!displayDialog);
31
+ const testTrigger = () => {
32
+ setDisplay(true);
33
+ };
34
+ const { customColHeaderRender, customModalMessage } = column;
31
35
  return (
32
- <TableCell
33
- scope="col"
34
- className="del_all_row"
35
- >
36
- <Typography className="del_all_row_text">
37
- Remove
38
- </Typography>
39
- <Tooltip
40
- id="del_all_row_tooltip"
41
- className="del_all_row_tooltip"
42
- title={TooltipContent()}
43
- renderComponent={TooltipContent()}
36
+ <>
37
+ <TableCell
38
+ scope="col"
39
+ className="del_all_row"
44
40
  >
45
- <IconButton aria-label="help" className="del_all_row_btn">
46
- <ArrowDropDownIcon
47
- className="del_all_row_btn_icon"
48
- onClick={toggleDialogDisplay}
49
- />
50
- </IconButton>
51
- </Tooltip>
52
- <RemoveAllDialogView
53
- open={displayDialog}
54
- removeAllFiles={column.headerEventHandler}
55
- count={count}
56
- toggleDisplay={toggleDialogDisplay}
57
- />
58
- </TableCell>
41
+ {
42
+ customColHeaderRender ? (
43
+ <>
44
+ {customColHeaderRender(testTrigger)}
45
+ </>
46
+ ) : (
47
+ <>
48
+ <Typography className="del_all_row_text">
49
+ Remove
50
+ </Typography>
51
+ <Tooltip
52
+ id="del_all_row_tooltip"
53
+ className="del_all_row_tooltip"
54
+ title={TooltipContent()}
55
+ renderComponent={TooltipContent()}
56
+ >
57
+ <IconButton aria-label="help" className="del_all_row_btn">
58
+ <ArrowDropDownIcon
59
+ className="del_all_row_btn_icon"
60
+ onClick={toggleDialogDisplay}
61
+ />
62
+ </IconButton>
63
+ </Tooltip>
64
+ </>
65
+ )
66
+ }
67
+ <RemoveAllDialogView
68
+ open={displayDialog}
69
+ removeAllFiles={column.headerEventHandler}
70
+ count={count}
71
+ toggleDisplay={toggleDialogDisplay}
72
+ customModalMessage={customModalMessage}
73
+ />
74
+ </TableCell>
75
+ </>
59
76
  );
60
77
  };
61
78
 
@@ -13,11 +13,31 @@ function RemoveAllDialogView(props) {
13
13
  toggleDisplay,
14
14
  count,
15
15
  removeAllFiles,
16
+ customModalMessage,
16
17
  } = props;
17
18
  const deleteAllFiles = () => {
18
19
  removeAllFiles();
19
20
  toggleDisplay();
20
21
  };
22
+
23
+ const generateModalMessage = (countValue) => {
24
+ if (customModalMessage) {
25
+ return customModalMessage(countValue);
26
+ }
27
+ return (
28
+ <>
29
+ Remove
30
+ {' '}
31
+ <b>
32
+ All files
33
+ {' ('}
34
+ {countValue}
35
+ {') '}
36
+ </b>
37
+ From Cart
38
+ </>
39
+ );
40
+ };
21
41
  return (
22
42
  <>
23
43
  <Dialog
@@ -27,15 +47,7 @@ function RemoveAllDialogView(props) {
27
47
  >
28
48
  <DialogContent>
29
49
  <DialogContentText id="alert-dialog-description">
30
- Remove
31
- {' '}
32
- <b>
33
- All files
34
- {' ('}
35
- {count}
36
- {') '}
37
- </b>
38
- From Cart
50
+ {generateModalMessage(count)}
39
51
  </DialogContentText>
40
52
  </DialogContent>
41
53
  <DialogActions>
@@ -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
+ };