@bento-core/table 1.0.1-ccdihub.7 → 1.0.1-ccdihub.71

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.
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertToCSV = convertToCSV;
7
+ exports.createFileName = createFileName;
8
+ exports.downloadCSV = downloadCSV;
9
+ exports.downloadJson = downloadJson;
10
+ var _Dataformat = require("./Dataformat");
11
+ var _Types = require("./Types");
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ function createFileName(fileName, type) {
18
+ const date = new Date();
19
+ const yyyy = date.getFullYear();
20
+ let dd = date.getDate();
21
+ let mm = date.getMonth() + 1;
22
+ if (dd < 10) {
23
+ dd = "0".concat(dd);
24
+ }
25
+ if (mm < 10) {
26
+ mm = "0".concat(mm);
27
+ }
28
+ const todaysDate = "".concat(yyyy, "-").concat(mm, "-").concat(dd);
29
+ let hours = date.getHours();
30
+ let minutes = date.getMinutes();
31
+ let seconds = date.getSeconds();
32
+ if (hours < 10) {
33
+ hours = "0".concat(hours);
34
+ }
35
+ if (minutes < 10) {
36
+ minutes = "0".concat(minutes);
37
+ }
38
+ if (seconds < 10) {
39
+ seconds = "0".concat(seconds);
40
+ }
41
+ if (type === 'csv') {
42
+ return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
43
+ }
44
+ return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.json');
45
+ }
46
+ function convertToCSV(jsonse, keysToInclude, header) {
47
+ const objArray = jsonse;
48
+ // To Do empty object just print headers
49
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
50
+ let str = header.join(',');
51
+ array.map((entry, index) => {
52
+ let line = '';
53
+ keysToInclude.map(keyName => {
54
+ if (line !== '') line += ',';
55
+ if (keyName === 'file_size') {
56
+ line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
57
+ } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
58
+ if (entry[keyName] === -999) {
59
+ line += 'Not Reported';
60
+ } else {
61
+ line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
62
+ }
63
+ } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id') {
64
+ if (!entry[keyName] || entry[keyName] === '[]') {
65
+ line += '';
66
+ } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
67
+ line += "\"".concat(entry[keyName].toString().substring(1, entry[keyName].length - 1), "\"");
68
+ } else {
69
+ line += "\"".concat(entry[keyName], "\"");
70
+ }
71
+ } else {
72
+ line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
73
+ }
74
+ return line;
75
+ });
76
+ if (index === 0) {
77
+ // str = header.join(',');
78
+ str += "\r\n".concat(line, "\r\n");
79
+ } else {
80
+ str += "".concat(line, "\r\n");
81
+ }
82
+ return str;
83
+ });
84
+ return str;
85
+ }
86
+ function downloadCSV(tableData, table, downloadFileName) {
87
+ const {
88
+ columns = []
89
+ } = table;
90
+ const filterColumns = columns.filter(_ref => {
91
+ let {
92
+ cellType
93
+ } = _ref;
94
+ return !_Types.actionCellTypes.includes(cellType);
95
+ }).filter(_ref2 => {
96
+ let {
97
+ cellStyle
98
+ } = _ref2;
99
+ return !_Types.notIncludedCellStyle.includes(cellStyle);
100
+ });
101
+ const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
102
+ const jsonse = JSON.stringify(formatDataVal);
103
+ const keysToInclude = filterColumns.filter(_ref3 => {
104
+ let {
105
+ dataField
106
+ } = _ref3;
107
+ return dataField;
108
+ }).map(_ref4 => {
109
+ let {
110
+ dataField
111
+ } = _ref4;
112
+ return dataField;
113
+ });
114
+ const headers = filterColumns.filter(_ref5 => {
115
+ let {
116
+ dataField
117
+ } = _ref5;
118
+ return dataField;
119
+ }).map(_ref6 => {
120
+ let {
121
+ header,
122
+ downloadHeader
123
+ } = _ref6;
124
+ return downloadHeader || header;
125
+ });
126
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
127
+ const exportData = new Blob([csv], {
128
+ type: 'text/csv'
129
+ });
130
+ const JsonURL = window.URL.createObjectURL(exportData);
131
+ let tempLink = '';
132
+ tempLink = document.createElement('a');
133
+ tempLink.setAttribute('href', JsonURL);
134
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'csv'));
135
+ document.body.appendChild(tempLink);
136
+ tempLink.click();
137
+ document.body.removeChild(tempLink);
138
+ }
139
+ function downloadJson(tableData, table, downloadFileName) {
140
+ const {
141
+ columns = []
142
+ } = table;
143
+ const filterColumns = columns.filter(_ref7 => {
144
+ let {
145
+ cellType
146
+ } = _ref7;
147
+ return !_Types.actionCellTypes.includes(cellType);
148
+ });
149
+ let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
150
+ formatDataVal = formatDataVal.map(entry => {
151
+ let survivalStatus = entry.last_known_survival_status;
152
+ let sampleId = entry.sample_id;
153
+ if (!survivalStatus || survivalStatus === '[]') {
154
+ survivalStatus = '';
155
+ } else if (survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
156
+ survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
157
+ }
158
+ if (!sampleId || sampleId === '[]') {
159
+ sampleId = '';
160
+ } else if (sampleId.toString().charAt(0) === '[' && sampleId.toString().charAt(sampleId.toString().length - 1) === ']') {
161
+ sampleId = sampleId.toString().substring(1, sampleId.length - 1);
162
+ }
163
+ return _objectSpread(_objectSpread({}, entry), {}, {
164
+ last_known_survival_status: survivalStatus,
165
+ sample_id: sampleId
166
+ });
167
+ });
168
+ filterColumns.forEach(column => {
169
+ formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
170
+ });
171
+ const jsonse = JSON.stringify(formatDataVal);
172
+ const exportData = new Blob([jsonse], {
173
+ type: 'application/json'
174
+ });
175
+ const JsonURL = window.URL.createObjectURL(exportData);
176
+ let tempLink = '';
177
+ tempLink = document.createElement('a');
178
+ tempLink.setAttribute('href', JsonURL);
179
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'json'));
180
+ document.body.appendChild(tempLink);
181
+ tempLink.click();
182
+ document.body.removeChild(tempLink);
183
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdihub.7",
3
+ "version": "1.0.1-ccdihub.71",
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",
@@ -28,5 +28,8 @@
28
28
  "url": "https://github.com/CBIIT/bento-frontend/issues"
29
29
  },
30
30
  "homepage": "https://github.com/CBIIT/bento-frontend#readme",
31
+ "dependencies": {
32
+ "@apollo/client": "^3.8.3"
33
+ },
31
34
  "description": ""
32
35
  }
@@ -9,6 +9,12 @@ import ManageColumnView from './toolbar/ManageColumnView';
9
9
  import defaultTheme from './DefaultThemConfig';
10
10
  import DownloadButton from './toolbar/DownloadButtonView';
11
11
 
12
+ const downloadAreaStyle = {
13
+ display: 'flex',
14
+ borderTop: '1px solid #8A7F7C',
15
+ paddingRight: '41px',
16
+ };
17
+
12
18
  const ExtendedView = ({
13
19
  table,
14
20
  onColumnViewChange,
@@ -16,6 +22,7 @@ const ExtendedView = ({
16
22
  onPageChange,
17
23
  numSelected = 0,
18
24
  customTheme,
25
+ queryVariables,
19
26
  }) => {
20
27
  const { extendedViewConfig } = table;
21
28
  if (!extendedViewConfig) {
@@ -32,9 +39,9 @@ const ExtendedView = ({
32
39
  <ThemeProvider theme={themeConfig}>
33
40
  {(numSelected === 0 && (download || manageViewColumns)) && (
34
41
  <Toolbar className="downloadColumnView">
35
- <DownloadButton
42
+ {/* <DownloadButton
36
43
  download={download}
37
- />
44
+ /> */}
38
45
  <ManageColumnView
39
46
  table={table}
40
47
  manageViewColumns={manageViewColumns}
@@ -44,16 +51,25 @@ const ExtendedView = ({
44
51
  )}
45
52
  {
46
53
  (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
- />
54
+ <div className="downloadArea" style={downloadAreaStyle}>
55
+ <CustomPagination
56
+ customTheme={customTheme.tblTopPgn}
57
+ rowsPerPageOptions={[10, 25, 50, 100]}
58
+ component="div"
59
+ count={table.totalRowCount || 0}
60
+ rowsPerPage={table.rowsPerPage || 10}
61
+ page={table.page || 0}
62
+ onPageChange={onPageChange}
63
+ onRowsPerPageChange={onRowsPerPageChange}
64
+ queryVariables={queryVariables}
65
+ table={table}
66
+ />
67
+ <DownloadButton
68
+ count={table.totalRowCount || 0}
69
+ queryVariables={queryVariables}
70
+ table={table}
71
+ />
72
+ </div>
57
73
  )
58
74
  }
59
75
  </ThemeProvider>
package/src/TableView.js CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import {
3
3
  Paper,
4
4
  Table,
@@ -12,19 +12,45 @@ import CustomTableBody from './body/CustomTblBody';
12
12
  import CustomToolbar from './toolbar/CustomToolbar';
13
13
  import DisplayErrMsg from './errMsg/DisplayErrMsg';
14
14
  import ExtendedView from './ExtendedView';
15
+ import DownloadButton from './toolbar/DownloadButtonView';
15
16
 
16
17
  const CustomTableContainer = (props) => {
17
18
  const { children, customTheme } = props;
18
19
  const themeConfig = createTheme({ overrides: { ...customTheme } });
19
20
  return (
20
21
  <ThemeProvider theme={themeConfig}>
21
- <TableContainer component={Paper}>
22
+ <TableContainer id="tableContainer" component={Paper}>
22
23
  {children}
23
24
  </TableContainer>
24
25
  </ThemeProvider>
25
26
  );
26
27
  };
27
28
 
29
+ const downloadAreaStyle = {
30
+ display: 'flex',
31
+ borderTop: '1px solid #8A7F7C',
32
+ borderBottom: '1px solid #8A7F7C',
33
+ paddingRight: '41px',
34
+ };
35
+
36
+ const cartDownloadAreaStyle = {
37
+ display: 'flex',
38
+ borderTop: '5px solid #e7e5e5',
39
+ borderBottom: '3px solid #e7e5e5',
40
+ paddingRight: '40px',
41
+ };
42
+
43
+ const addScrollContainerStyle = {
44
+ overflowX: 'auto',
45
+ overflowY: 'hidden',
46
+ width: '100%',
47
+ height: '14px',
48
+ };
49
+
50
+ const addScrollStyle = {
51
+ height: '14px',
52
+ };
53
+
28
54
  const TableView = ({
29
55
  tableRows = [],
30
56
  table,
@@ -36,59 +62,91 @@ const TableView = ({
36
62
  onSortByColumn,
37
63
  onColumnViewChange,
38
64
  themeConfig = {},
39
- }) => (
40
- <>
41
- <ExtendedView
42
- table={table}
43
- onColumnViewChange={onColumnViewChange}
44
- onRowsPerPageChange={onRowsPerPageChange}
45
- onPageChange={onPageChange}
46
- numSelected={table?.selectedRows?.length || 0}
47
- customTheme={themeConfig.extendedView}
48
- />
49
- <CustomToolbar
50
- numSelected={table?.selectedRows?.length || 0}
51
- table={table}
52
- onColumnViewChange={onColumnViewChange}
53
- customTheme={themeConfig.toolbar}
54
- />
55
- <CustomTableContainer
56
- customTheme={themeConfig.tblContainer || {}}
57
- >
58
- <Table>
59
- <TableHeader
60
- customTheme={themeConfig.tblHeader}
65
+ queryVariables,
66
+ }) => {
67
+ useEffect(() => {
68
+ const tableContainer = document.getElementById('tableContainer');
69
+ const addScrollContainer = document.getElementById('addScrollContainer');
70
+ const targetTable = tableContainer.firstChild;
71
+ const addScroll = addScrollContainer.firstChild;
72
+ const tableWidth = targetTable.clientWidth;
73
+ addScroll.style.width = `${tableWidth}px`;
74
+ tableContainer.onscroll = () => {
75
+ addScrollContainer.scrollLeft = tableContainer.scrollLeft;
76
+ };
77
+ addScrollContainer.onscroll = () => {
78
+ tableContainer.scrollLeft = addScrollContainer.scrollLeft;
79
+ };
80
+ if (!(tableWidth > tableContainer.clientWidth)) {
81
+ addScrollContainer.style.height = '0px';
82
+ }
83
+ });
84
+
85
+ return (
86
+ <>
87
+ <ExtendedView
88
+ table={table}
89
+ onColumnViewChange={onColumnViewChange}
90
+ onRowsPerPageChange={onRowsPerPageChange}
91
+ onPageChange={onPageChange}
92
+ numSelected={table?.selectedRows?.length || 0}
93
+ customTheme={themeConfig.extendedView}
94
+ queryVariables={queryVariables}
95
+ />
96
+ <CustomToolbar
97
+ numSelected={table?.selectedRows?.length || 0}
98
+ table={table}
99
+ onColumnViewChange={onColumnViewChange}
100
+ customTheme={themeConfig.toolbar}
101
+ />
102
+ <CustomTableContainer
103
+ customTheme={themeConfig.tblContainer || {}}
104
+ >
105
+ <Table>
106
+ <TableHeader
107
+ customTheme={themeConfig.tblHeader}
108
+ table={table}
109
+ rows={tableRows}
110
+ count={totalRowCount}
111
+ toggleSelectAll={onToggleSelectAll}
112
+ sortByColumn={onSortByColumn}
113
+ />
114
+ <CustomTableBody
115
+ customTheme={themeConfig.tblBody}
116
+ rows={tableRows}
117
+ table={table}
118
+ onRowSelectChange={onRowSelectChange}
119
+ />
120
+ </Table>
121
+ </CustomTableContainer>
122
+ <div id="addScrollContainer" style={addScrollContainerStyle}>
123
+ <div style={addScrollStyle} />
124
+ </div>
125
+ {tableRows.length === 0 && (
126
+ <DisplayErrMsg
127
+ customTheme={themeConfig.displayErr}
61
128
  table={table}
62
- rows={tableRows}
63
- count={totalRowCount}
64
- toggleSelectAll={onToggleSelectAll}
65
- sortByColumn={onSortByColumn}
66
129
  />
67
- <CustomTableBody
68
- customTheme={themeConfig.tblBody}
69
- rows={tableRows}
130
+ )}
131
+ <div className="downloadArea" style={table.paginationAPIField === 'filesInList' ? cartDownloadAreaStyle : downloadAreaStyle}>
132
+ <CustomPagination
133
+ customTheme={themeConfig.tblPgn}
134
+ rowsPerPageOptions={[10, 25, 50, 100]}
135
+ component="div"
136
+ count={table.totalRowCount || 0}
137
+ rowsPerPage={table.rowsPerPage || 10}
138
+ page={table.page || 0}
139
+ onPageChange={onPageChange}
140
+ onRowsPerPageChange={onRowsPerPageChange}
141
+ />
142
+ <DownloadButton
143
+ count={table.totalRowCount || 0}
144
+ queryVariables={queryVariables}
70
145
  table={table}
71
- onRowSelectChange={onRowSelectChange}
72
146
  />
73
- </Table>
74
- </CustomTableContainer>
75
- {tableRows.length === 0 && (
76
- <DisplayErrMsg
77
- customTheme={themeConfig.displayErr}
78
- table={table}
79
- />
80
- )}
81
- <CustomPagination
82
- customTheme={themeConfig.tblPgn}
83
- rowsPerPageOptions={[10, 25, 50, 100]}
84
- component="div"
85
- count={table.totalRowCount || 0}
86
- rowsPerPage={table.rowsPerPage || 10}
87
- page={table.page || 0}
88
- onPageChange={onPageChange}
89
- onRowsPerPageChange={onRowsPerPageChange}
90
- />
91
- </>
92
- );
147
+ </div>
148
+ </>
149
+ );
150
+ };
93
151
 
94
152
  export default TableView;
@@ -4,7 +4,7 @@ import {
4
4
  Checkbox,
5
5
  } from '@material-ui/core';
6
6
 
7
- const label = { inputProps: { 'aria-label': 'Checkbox item' } };
7
+ const label = { inputProps: { 'aria-label': 'Select all checkbox' } };
8
8
 
9
9
  const CheckboxView = ({
10
10
  includeSelectedIds,
@@ -12,6 +12,7 @@ const CheckboxView = ({
12
12
  Ids,
13
13
  }) => (
14
14
  <TableCell padding="checkbox">
15
+ <span style={{ display: 'none' }}>Select all</span>
15
16
  <Checkbox
16
17
  {...label}
17
18
  color="primary"
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as TableView } from './TableView';
2
2
  export {
3
3
  cellTypes,
4
+ cellStyles,
4
5
  headerTypes,
5
6
  ComponentTypes,
6
7
  dataFormatTypes,
@@ -5,6 +5,7 @@ import {
5
5
  TablePagination,
6
6
  ThemeProvider,
7
7
  } from '@material-ui/core';
8
+ import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
8
9
 
9
10
  const defaultTheme = {
10
11
  MuiTablePagination: {
@@ -43,6 +44,7 @@ const CustomPagination = ({
43
44
  }) => (
44
45
  <ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
45
46
  <TablePagination
47
+ labelRowsPerPage="Results per Page:"
46
48
  rowsPerPageOptions={rowsPerPageOptions}
47
49
  component="div"
48
50
  count={count}
@@ -51,8 +53,8 @@ const CustomPagination = ({
51
53
  onPageChange={onPageChange}
52
54
  onRowsPerPageChange={onRowsPerPageChange}
53
55
  SelectProps={{
56
+ IconComponent: KeyboardArrowDownOutlinedIcon,
54
57
  inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
55
- native: true,
56
58
  }}
57
59
  />
58
60
  </ThemeProvider>