@bento-core/table 1.0.1-ins.0 → 1.0.1-ins.10

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.
@@ -16,16 +16,20 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
16
  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; }
17
17
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
18
  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); }
19
+ const downloadAreaStyle = {
20
+ display: 'flex',
21
+ paddingRight: '41px',
22
+ float: 'right'
23
+ };
19
24
  const ExtendedView = _ref => {
20
25
  let {
21
26
  table,
22
- rows,
23
27
  onColumnViewChange,
24
28
  onRowsPerPageChange,
25
29
  onPageChange,
30
+ numSelected = 0,
26
31
  customTheme,
27
- queryVariables,
28
- server
32
+ queryVariables
29
33
  } = _ref;
30
34
  const {
31
35
  extendedViewConfig
@@ -43,19 +47,16 @@ const ExtendedView = _ref => {
43
47
  });
44
48
  return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
45
49
  theme: themeConfig
46
- }, (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_core.Toolbar, {
47
- className: "downloadAndColumnView"
48
- }, /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
49
- download: download,
50
- rows: rows,
51
- server: server,
52
- table: table,
53
- queryVariables: queryVariables
54
- }), /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
50
+ }, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_core.Toolbar, {
51
+ className: "downloadColumnView"
52
+ }, /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
55
53
  table: table,
56
54
  manageViewColumns: manageViewColumns,
57
55
  onColumnViewChange: onColumnViewChange
58
- })), pagination && /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
56
+ })), pagination && /*#__PURE__*/_react.default.createElement("div", {
57
+ className: "downloadArea",
58
+ style: downloadAreaStyle
59
+ }, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
59
60
  customTheme: customTheme.tblTopPgn,
60
61
  rowsPerPageOptions: [10, 25, 50, 100],
61
62
  component: "div",
@@ -63,8 +64,14 @@ const ExtendedView = _ref => {
63
64
  rowsPerPage: table.rowsPerPage || 10,
64
65
  page: table.page || 0,
65
66
  onPageChange: onPageChange,
66
- onRowsPerPageChange: onRowsPerPageChange
67
- }));
67
+ onRowsPerPageChange: onRowsPerPageChange,
68
+ queryVariables: queryVariables,
69
+ table: table
70
+ }), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
71
+ count: table.totalRowCount || 0,
72
+ queryVariables: queryVariables,
73
+ table: table
74
+ })));
68
75
  };
69
76
  var _default = ExtendedView;
70
77
  exports.default = _default;
package/dist/TableView.js CHANGED
@@ -12,6 +12,7 @@ var _CustomTblBody = _interopRequireDefault(require("./body/CustomTblBody"));
12
12
  var _CustomToolbar = _interopRequireDefault(require("./toolbar/CustomToolbar"));
13
13
  var _DisplayErrMsg = _interopRequireDefault(require("./errMsg/DisplayErrMsg"));
14
14
  var _ExtendedView = _interopRequireDefault(require("./ExtendedView"));
15
+ var _DownloadButtonView = _interopRequireDefault(require("./toolbar/DownloadButtonView"));
15
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17
  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; }
17
18
  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; }
@@ -32,11 +33,15 @@ const CustomTableContainer = props => {
32
33
  component: _core.Paper
33
34
  }, children));
34
35
  };
36
+ const downloadAreaStyle = {
37
+ display: 'flex',
38
+ paddingRight: '41px',
39
+ float: 'right'
40
+ };
35
41
  const TableView = _ref => {
36
42
  var _table$selectedRows, _table$selectedRows2;
37
43
  let {
38
44
  tableRows = [],
39
- totalRows = [],
40
45
  table,
41
46
  onRowsPerPageChange,
42
47
  onPageChange,
@@ -46,13 +51,10 @@ const TableView = _ref => {
46
51
  onSortByColumn,
47
52
  onColumnViewChange,
48
53
  themeConfig = {},
49
- queryVariables,
50
- server
54
+ queryVariables
51
55
  } = _ref;
52
56
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ExtendedView.default, {
53
57
  table: table,
54
- rows: totalRows,
55
- server: server,
56
58
  onColumnViewChange: onColumnViewChange,
57
59
  onRowsPerPageChange: onRowsPerPageChange,
58
60
  onPageChange: onPageChange,
@@ -81,7 +83,10 @@ const TableView = _ref => {
81
83
  }))), tableRows.length === 0 && /*#__PURE__*/_react.default.createElement(_DisplayErrMsg.default, {
82
84
  customTheme: themeConfig.displayErr,
83
85
  table: table
84
- }), /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
86
+ }), /*#__PURE__*/_react.default.createElement("div", {
87
+ className: "downloadArea",
88
+ style: downloadAreaStyle
89
+ }, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
85
90
  customTheme: themeConfig.tblPgn,
86
91
  rowsPerPageOptions: [10, 25, 50, 100],
87
92
  component: "div",
@@ -90,7 +95,11 @@ const TableView = _ref => {
90
95
  page: table.page || 0,
91
96
  onPageChange: onPageChange,
92
97
  onRowsPerPageChange: onRowsPerPageChange
93
- }));
98
+ }), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
99
+ count: table.totalRowCount || 0,
100
+ queryVariables: queryVariables,
101
+ table: table
102
+ })));
94
103
  };
95
104
  var _default = TableView;
96
105
  exports.default = _default;
@@ -44,7 +44,7 @@ const defaultTheme = () => ({
44
44
  MuiLink: {
45
45
  root: {
46
46
  textDecoration: 'none',
47
- color: '#0083c6'
47
+ color: '#7747ff'
48
48
  }
49
49
  },
50
50
  MuiCheckbox: {
@@ -8,6 +8,8 @@ var _react = _interopRequireDefault(require("react"));
8
8
  var _core = require("@material-ui/core");
9
9
  var _Types = require("../util/Types");
10
10
  var _CustomLinkView = _interopRequireDefault(require("./components/CustomLinkView"));
11
+ var _ExternalLinkView = _interopRequireDefault(require("./components/ExternalLinkView"));
12
+ var _ConditionalExternalLinkView = _interopRequireDefault(require("./components/ConditionalExternalLinkView"));
11
13
  var _DataFormatView = _interopRequireDefault(require("./components/DataFormatView"));
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
  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; }
@@ -55,6 +57,16 @@ const ViewCell = _ref2 => {
55
57
  row: row,
56
58
  column: column
57
59
  });
60
+ case _Types.cellTypes.EXTERNAL_LINK:
61
+ return /*#__PURE__*/_react.default.createElement(_ExternalLinkView.default, {
62
+ row: row,
63
+ column: column
64
+ });
65
+ case _Types.cellTypes.CONDITIONAL_EXTERNAL_LINK:
66
+ return /*#__PURE__*/_react.default.createElement(_ConditionalExternalLinkView.default, {
67
+ row: row,
68
+ column: column
69
+ });
58
70
  case _Types.cellTypes.CUSTOM_ELEM:
59
71
  return /*#__PURE__*/_react.default.createElement(CustomComponent, {
60
72
  row: row,
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _core = require("@material-ui/core");
9
+ var _Types = require("../../util/Types");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /* eslint-disable no-console */
12
+
13
+ /**
14
+ * Conditional External Link component
15
+ */
16
+ const ConditionalExternalLinkView = _ref => {
17
+ let {
18
+ column,
19
+ row
20
+ } = _ref;
21
+ const {
22
+ rootPath,
23
+ pathParams
24
+ } = column === null || column === void 0 ? void 0 : column.linkAttr;
25
+ const url = pathParams.map(attr => {
26
+ if (!rootPath) {
27
+ return row[attr];
28
+ }
29
+ return "".concat(rootPath, "/").concat(row[attr]);
30
+ });
31
+ const externalLinkIcon = {
32
+ src: 'https://raw.githubusercontent.com/CBIIT/datacommons-assets/main/bento/images/icons/svgs/externalLinkIcon.svg',
33
+ alt: 'External link icon'
34
+ };
35
+ return !url[0] || url[0] === '' ? '' : /*#__PURE__*/_react.default.createElement(_core.Link, {
36
+ href: url,
37
+ target: "_blank",
38
+ rel: "noopener noreferrer",
39
+ className: _Types.cellTypes.LINK
40
+ }, /*#__PURE__*/_react.default.createElement(_core.Typography, null, row[column === null || column === void 0 ? void 0 : column.dataField], /*#__PURE__*/_react.default.createElement("img", {
41
+ src: externalLinkIcon.src,
42
+ alt: externalLinkIcon.alt,
43
+ style: {
44
+ width: '16px',
45
+ verticalAlign: 'sub',
46
+ marginLeft: '4px'
47
+ }
48
+ })));
49
+ };
50
+ var _default = ConditionalExternalLinkView;
51
+ exports.default = _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _core = require("@material-ui/core");
9
+ var _Types = require("../../util/Types");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /**
12
+ * External Link component
13
+ */
14
+ const ExternalLinkView = _ref => {
15
+ let {
16
+ column,
17
+ row
18
+ } = _ref;
19
+ const {
20
+ rootPath,
21
+ pathParams
22
+ } = column === null || column === void 0 ? void 0 : column.linkAttr;
23
+ const url = pathParams.map(attr => {
24
+ if (!rootPath) {
25
+ return row[attr];
26
+ }
27
+ return "".concat(rootPath, "/").concat(row[attr]);
28
+ });
29
+ const externalLinkIcon = {
30
+ src: 'https://raw.githubusercontent.com/CBIIT/datacommons-assets/main/bento/images/icons/svgs/externalLinkIcon.svg',
31
+ alt: 'External link icon'
32
+ };
33
+ return /*#__PURE__*/_react.default.createElement(_core.Link, {
34
+ href: url,
35
+ target: "_blank",
36
+ rel: "noopener noreferrer",
37
+ className: _Types.cellTypes.LINK
38
+ }, /*#__PURE__*/_react.default.createElement(_core.Typography, null, row[column === null || column === void 0 ? void 0 : column.dataField], /*#__PURE__*/_react.default.createElement("img", {
39
+ src: externalLinkIcon.src,
40
+ alt: externalLinkIcon.alt,
41
+ style: {
42
+ width: '16px',
43
+ verticalAlign: 'sub',
44
+ marginLeft: '4px'
45
+ }
46
+ })));
47
+ };
48
+ var _default = ExternalLinkView;
49
+ exports.default = _default;
@@ -7,12 +7,71 @@ exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _core = require("@material-ui/core");
10
+ var _styles = require("@material-ui/core/styles");
11
+ var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
12
+ var _FirstPage = _interopRequireDefault(require("@material-ui/icons/FirstPage"));
13
+ var _KeyboardArrowLeft = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowLeft"));
14
+ var _KeyboardArrowRight = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowRight"));
15
+ var _LastPage = _interopRequireDefault(require("@material-ui/icons/LastPage"));
10
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
17
  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; }
12
18
  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; }
13
19
  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; }
14
20
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
15
21
  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); }
22
+ const useStyles1 = (0, _styles.makeStyles)(theme => ({
23
+ root: {
24
+ flexShrink: 0,
25
+ marginLeft: theme.spacing(2.5)
26
+ }
27
+ }));
28
+ function TablePaginationActions(props) {
29
+ const classes = useStyles1();
30
+ const theme = (0, _styles.useTheme)();
31
+ const {
32
+ count,
33
+ page,
34
+ rowsPerPage,
35
+ onPageChange
36
+ } = props;
37
+ const handleFirstPageButtonClick = event => {
38
+ onPageChange(event, 0);
39
+ };
40
+ const handleBackButtonClick = event => {
41
+ onPageChange(event, page - 1);
42
+ };
43
+ const handleNextButtonClick = event => {
44
+ onPageChange(event, page + 1);
45
+ };
46
+ const handleLastPageButtonClick = event => {
47
+ onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
48
+ };
49
+ return /*#__PURE__*/_react.default.createElement("div", {
50
+ className: classes.root
51
+ }, /*#__PURE__*/_react.default.createElement(_IconButton.default, {
52
+ onClick: handleFirstPageButtonClick,
53
+ disabled: page === 0,
54
+ "aria-label": "first page"
55
+ }, theme.direction === 'rtl' ? /*#__PURE__*/_react.default.createElement(_LastPage.default, null) : /*#__PURE__*/_react.default.createElement(_FirstPage.default, null)), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
56
+ onClick: handleBackButtonClick,
57
+ disabled: page === 0,
58
+ "aria-label": "previous page"
59
+ }, theme.direction === 'rtl' ? /*#__PURE__*/_react.default.createElement(_KeyboardArrowRight.default, null) : /*#__PURE__*/_react.default.createElement(_KeyboardArrowLeft.default, null)), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
60
+ onClick: handleNextButtonClick,
61
+ disabled: page >= Math.ceil(count / rowsPerPage) - 1,
62
+ "aria-label": "next page"
63
+ }, theme.direction === 'rtl' ? /*#__PURE__*/_react.default.createElement(_KeyboardArrowLeft.default, null) : /*#__PURE__*/_react.default.createElement(_KeyboardArrowRight.default, null)), /*#__PURE__*/_react.default.createElement(_IconButton.default, {
64
+ onClick: handleLastPageButtonClick,
65
+ disabled: page >= Math.ceil(count / rowsPerPage) - 1,
66
+ "aria-label": "last page"
67
+ }, theme.direction === 'rtl' ? /*#__PURE__*/_react.default.createElement(_FirstPage.default, null) : /*#__PURE__*/_react.default.createElement(_LastPage.default, null)));
68
+ }
69
+ TablePaginationActions.propTypes = {
70
+ count: _propTypes.default.number.isRequired,
71
+ onPageChange: _propTypes.default.func.isRequired,
72
+ page: _propTypes.default.number.isRequired,
73
+ rowsPerPage: _propTypes.default.number.isRequired
74
+ };
16
75
  const defaultTheme = {
17
76
  MuiTablePagination: {
18
77
  root: {
@@ -38,6 +97,10 @@ const defaultTheme = {
38
97
  }
39
98
  }
40
99
  };
100
+ const downloadAreaStyle = {
101
+ display: 'flex',
102
+ paddingRight: '41px'
103
+ };
41
104
  const CustomPagination = _ref => {
42
105
  let {
43
106
  rowsPerPageOptions,
@@ -52,6 +115,9 @@ const CustomPagination = _ref => {
52
115
  theme: (0, _core.createTheme)({
53
116
  overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
54
117
  })
118
+ }, /*#__PURE__*/_react.default.createElement("div", {
119
+ className: "downloadArea",
120
+ style: downloadAreaStyle
55
121
  }, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
56
122
  rowsPerPageOptions: rowsPerPageOptions,
57
123
  component: "div",
@@ -59,8 +125,9 @@ const CustomPagination = _ref => {
59
125
  rowsPerPage: rowsPerPage,
60
126
  page: page,
61
127
  onPageChange: onPageChange,
62
- onRowsPerPageChange: onRowsPerPageChange
63
- }));
128
+ onRowsPerPageChange: onRowsPerPageChange,
129
+ ActionsComponent: TablePaginationActions
130
+ })));
64
131
  };
65
132
  CustomPagination.propTypes = {
66
133
  rowsPerPageOptions: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
@@ -16,28 +16,30 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
16
  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; }
17
17
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
18
  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); }
19
+ const downloadButtonStyle = {
20
+ color: '#d1d2d3',
21
+ marginTop: '7px'
22
+ };
19
23
  const DownloadButton = _ref => {
20
24
  let {
21
- download,
22
- rows,
23
- table,
25
+ count,
24
26
  queryVariables,
25
- server
27
+ table
26
28
  } = _ref;
27
- if (!download) {
28
- return null;
29
+ if (count === 0) {
30
+ return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
31
+ className: "disableButton",
32
+ style: downloadButtonStyle
33
+ });
29
34
  }
30
- const {
31
- downloadCsv = 'download',
32
- downloadTable,
33
- downloadFileName
34
- } = download;
35
35
  const client = (0, _client.useApolloClient)();
36
+ const downloadFile = 'INS ';
36
37
  async function downloadSCSVFile() {
37
38
  const {
38
39
  query,
39
40
  paginationAPIField
40
41
  } = table;
42
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
41
43
  const result = await client.query({
42
44
  query,
43
45
  variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
@@ -53,20 +55,13 @@ const DownloadButton = _ref => {
53
55
  (0, _downloadTable.downloadJson)(result, table, downloadFileName);
54
56
  }
55
57
  const downloadTableCSV = (0, _react.useCallback)(() => {
56
- if (downloadTable) {
57
- downloadTable();
58
- } else if (!downloadTable && !server) {
59
- (0, _downloadTable.downloadJson)(rows, table, downloadFileName);
60
- } else {
61
- downloadSCSVFile();
62
- }
58
+ downloadSCSVFile();
63
59
  }, [queryVariables]);
64
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
65
- title: downloadCsv,
66
- className: "download-icon"
60
+ return /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
61
+ title: "Download Full Table As CSV"
67
62
  }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
68
63
  onClick: downloadTableCSV
69
- }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null))));
64
+ }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null)));
70
65
  };
71
66
  var _default = DownloadButton;
72
67
  exports.default = _default;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.actionCellTypes = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.CHECKBOX = void 0;
6
+ exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.actionCellTypes = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.EXTERNAL_LINK = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.CONDITIONAL_EXTERNAL_LINK = exports.CHECKBOX = void 0;
7
7
  const CHECKBOX = 'CHECKBOX';
8
8
  exports.CHECKBOX = CHECKBOX;
9
9
  const DELETE = 'DELETE';
@@ -12,6 +12,10 @@ const CUSTOM_ELEM = 'CUSTOM_ELEM';
12
12
  exports.CUSTOM_ELEM = CUSTOM_ELEM;
13
13
  const LINK = 'LINK';
14
14
  exports.LINK = LINK;
15
+ const EXTERNAL_LINK = 'EXTERNAL_LINK';
16
+ exports.EXTERNAL_LINK = EXTERNAL_LINK;
17
+ const CONDITIONAL_EXTERNAL_LINK = 'CONDITIONAL_EXTERNAL_LINK';
18
+ exports.CONDITIONAL_EXTERNAL_LINK = CONDITIONAL_EXTERNAL_LINK;
15
19
  const DISPLAY = 'DISPLAY';
16
20
  exports.DISPLAY = DISPLAY;
17
21
  const DEFAULT = 'DEFAULT';
@@ -23,6 +27,8 @@ exports.FORMAT_BYTES = FORMAT_BYTES;
23
27
  const cellTypes = {
24
28
  CUSTOM_ELEM,
25
29
  LINK,
30
+ EXTERNAL_LINK,
31
+ CONDITIONAL_EXTERNAL_LINK,
26
32
  DISPLAY,
27
33
  CHECKBOX,
28
34
  DELETE,
@@ -62,9 +62,10 @@ function convertToCSV(jsonse, keysToInclude, header) {
62
62
  }
63
63
  function downloadJson(tableData, table, downloadFileName) {
64
64
  const {
65
- columns = []
65
+ downloadColumns = []
66
66
  } = table;
67
- const filterColumns = columns.filter(_ref => {
67
+ // eslint-disable-next-line max-len
68
+ const filterColumns = downloadColumns.filter(_ref => {
68
69
  let {
69
70
  cellType
70
71
  } = _ref;
@@ -72,7 +73,7 @@ function downloadJson(tableData, table, downloadFileName) {
72
73
  });
73
74
  const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
74
75
  const jsonse = JSON.stringify(formatDataVal);
75
- const keysToInclude = columns.filter(_ref2 => {
76
+ const keysToInclude = downloadColumns.filter(_ref2 => {
76
77
  let {
77
78
  dataField
78
79
  } = _ref2;
@@ -83,7 +84,7 @@ function downloadJson(tableData, table, downloadFileName) {
83
84
  } = _ref3;
84
85
  return dataField;
85
86
  });
86
- const headers = columns.filter(_ref4 => {
87
+ const headers = downloadColumns.filter(_ref4 => {
87
88
  let {
88
89
  dataField
89
90
  } = _ref4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ins.0",
3
+ "version": "1.0.1-ins.10",
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",
@@ -9,21 +9,25 @@ 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
+ paddingRight: '41px',
15
+ float: 'right',
16
+ };
17
+
12
18
  const ExtendedView = ({
13
19
  table,
14
- rows,
15
20
  onColumnViewChange,
16
21
  onRowsPerPageChange,
17
22
  onPageChange,
23
+ numSelected = 0,
18
24
  customTheme,
19
25
  queryVariables,
20
- server,
21
26
  }) => {
22
27
  const { extendedViewConfig } = table;
23
28
  if (!extendedViewConfig) {
24
29
  return null;
25
30
  }
26
-
27
31
  const {
28
32
  download = false,
29
33
  manageViewColumns = false,
@@ -31,41 +35,40 @@ const ExtendedView = ({
31
35
  } = extendedViewConfig;
32
36
 
33
37
  const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
34
-
35
38
  return (
36
39
  <ThemeProvider theme={themeConfig}>
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>
40
+ {(numSelected === 0 && (download || manageViewColumns)) && (
41
+ <Toolbar className="downloadColumnView">
42
+ <ManageColumnView
43
+ table={table}
44
+ manageViewColumns={manageViewColumns}
45
+ onColumnViewChange={onColumnViewChange}
46
+ />
47
+ </Toolbar>
54
48
  )}
55
49
  {
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
- }
50
+ (pagination) && (
51
+ <div className="downloadArea" style={downloadAreaStyle}>
52
+ <CustomPagination
53
+ customTheme={customTheme.tblTopPgn}
54
+ rowsPerPageOptions={[10, 25, 50, 100]}
55
+ component="div"
56
+ count={table.totalRowCount || 0}
57
+ rowsPerPage={table.rowsPerPage || 10}
58
+ page={table.page || 0}
59
+ onPageChange={onPageChange}
60
+ onRowsPerPageChange={onRowsPerPageChange}
61
+ queryVariables={queryVariables}
62
+ table={table}
63
+ />
64
+ <DownloadButton
65
+ count={table.totalRowCount || 0}
66
+ queryVariables={queryVariables}
67
+ table={table}
68
+ />
69
+ </div>
70
+ )
71
+ }
69
72
  </ThemeProvider>
70
73
  );
71
74
  };
package/src/TableView.js CHANGED
@@ -12,6 +12,7 @@ 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;
@@ -25,9 +26,14 @@ const CustomTableContainer = (props) => {
25
26
  );
26
27
  };
27
28
 
29
+ const downloadAreaStyle = {
30
+ display: 'flex',
31
+ paddingRight: '41px',
32
+ float: 'right',
33
+ };
34
+
28
35
  const TableView = ({
29
36
  tableRows = [],
30
- totalRows = [],
31
37
  table,
32
38
  onRowsPerPageChange,
33
39
  onPageChange,
@@ -38,13 +44,10 @@ const TableView = ({
38
44
  onColumnViewChange,
39
45
  themeConfig = {},
40
46
  queryVariables,
41
- server,
42
47
  }) => (
43
48
  <>
44
49
  <ExtendedView
45
50
  table={table}
46
- rows={totalRows}
47
- server={server}
48
51
  onColumnViewChange={onColumnViewChange}
49
52
  onRowsPerPageChange={onRowsPerPageChange}
50
53
  onPageChange={onPageChange}
@@ -84,16 +87,23 @@ const TableView = ({
84
87
  table={table}
85
88
  />
86
89
  )}
87
- <CustomPagination
88
- customTheme={themeConfig.tblPgn}
89
- rowsPerPageOptions={[10, 25, 50, 100]}
90
- component="div"
91
- count={table.totalRowCount || 0}
92
- rowsPerPage={table.rowsPerPage || 10}
93
- page={table.page || 0}
94
- onPageChange={onPageChange}
95
- onRowsPerPageChange={onRowsPerPageChange}
96
- />
90
+ <div className="downloadArea" style={downloadAreaStyle}>
91
+ <CustomPagination
92
+ customTheme={themeConfig.tblPgn}
93
+ rowsPerPageOptions={[10, 25, 50, 100]}
94
+ component="div"
95
+ count={table.totalRowCount || 0}
96
+ rowsPerPage={table.rowsPerPage || 10}
97
+ page={table.page || 0}
98
+ onPageChange={onPageChange}
99
+ onRowsPerPageChange={onRowsPerPageChange}
100
+ />
101
+ <DownloadButton
102
+ count={table.totalRowCount || 0}
103
+ queryVariables={queryVariables}
104
+ table={table}
105
+ />
106
+ </div>
97
107
  </>
98
108
  );
99
109
 
@@ -38,7 +38,7 @@ const defaultTheme = () => ({
38
38
  MuiLink: {
39
39
  root: {
40
40
  textDecoration: 'none',
41
- color: '#0083c6',
41
+ color: '#7747ff',
42
42
  },
43
43
  },
44
44
  MuiCheckbox: {
@@ -5,6 +5,8 @@ import {
5
5
  } from '@material-ui/core';
6
6
  import { cellTypes } from '../util/Types';
7
7
  import CustomLinkView from './components/CustomLinkView';
8
+ import ExternalLinkView from './components/ExternalLinkView';
9
+ import ConditionalExternalLinkView from './components/ConditionalExternalLinkView';
8
10
  import DataFormatView from './components/DataFormatView';
9
11
 
10
12
  /**
@@ -46,6 +48,20 @@ const ViewCell = ({
46
48
  column={column}
47
49
  />
48
50
  );
51
+ case cellTypes.EXTERNAL_LINK:
52
+ return (
53
+ <ExternalLinkView
54
+ row={row}
55
+ column={column}
56
+ />
57
+ );
58
+ case cellTypes.CONDITIONAL_EXTERNAL_LINK:
59
+ return (
60
+ <ConditionalExternalLinkView
61
+ row={row}
62
+ column={column}
63
+ />
64
+ );
49
65
  case cellTypes.CUSTOM_ELEM:
50
66
  return (
51
67
  <CustomComponent
@@ -0,0 +1,43 @@
1
+ /* eslint-disable no-console */
2
+ import React from 'react';
3
+ import {
4
+ Link, Typography,
5
+ } from '@material-ui/core';
6
+ import { cellTypes } from '../../util/Types';
7
+
8
+ /**
9
+ * Conditional External Link component
10
+ */
11
+ const ConditionalExternalLinkView = ({
12
+ column,
13
+ row,
14
+ }) => {
15
+ const { rootPath, pathParams } = column?.linkAttr;
16
+ const url = pathParams.map((attr) => {
17
+ if (!rootPath) {
18
+ return row[attr];
19
+ }
20
+ return `${rootPath}/`.concat(row[attr]);
21
+ });
22
+ const externalLinkIcon = {
23
+ src: 'https://raw.githubusercontent.com/CBIIT/datacommons-assets/main/bento/images/icons/svgs/externalLinkIcon.svg',
24
+ alt: 'External link icon',
25
+ };
26
+ return (
27
+ !url[0] || url[0] === '' ? ''
28
+ : (
29
+ <Link href={url} target="_blank" rel="noopener noreferrer" className={cellTypes.LINK}>
30
+ <Typography>
31
+ {row[column?.dataField]}
32
+ <img
33
+ src={externalLinkIcon.src}
34
+ alt={externalLinkIcon.alt}
35
+ style={{ width: '16px', verticalAlign: 'sub', marginLeft: '4px' }}
36
+ />
37
+ </Typography>
38
+ </Link>
39
+ )
40
+ );
41
+ };
42
+
43
+ export default ConditionalExternalLinkView;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import {
3
+ Link, Typography,
4
+ } from '@material-ui/core';
5
+ import { cellTypes } from '../../util/Types';
6
+
7
+ /**
8
+ * External Link component
9
+ */
10
+ const ExternalLinkView = ({
11
+ column,
12
+ row,
13
+ }) => {
14
+ const { rootPath, pathParams } = column?.linkAttr;
15
+ const url = pathParams.map((attr) => {
16
+ if (!rootPath) {
17
+ return row[attr];
18
+ }
19
+ return `${rootPath}/`.concat(row[attr]);
20
+ });
21
+ const externalLinkIcon = {
22
+ src: 'https://raw.githubusercontent.com/CBIIT/datacommons-assets/main/bento/images/icons/svgs/externalLinkIcon.svg',
23
+ alt: 'External link icon',
24
+ };
25
+ return (
26
+ <Link href={url} target="_blank" rel="noopener noreferrer" className={cellTypes.LINK}>
27
+ <Typography>
28
+ {row[column?.dataField]}
29
+ <img
30
+ src={externalLinkIcon.src}
31
+ alt={externalLinkIcon.alt}
32
+ style={{ width: '16px', verticalAlign: 'sub', marginLeft: '4px' }}
33
+ />
34
+ </Typography>
35
+ </Link>
36
+ );
37
+ };
38
+
39
+ export default ExternalLinkView;
@@ -5,6 +5,79 @@ import {
5
5
  TablePagination,
6
6
  ThemeProvider,
7
7
  } from '@material-ui/core';
8
+ import { makeStyles, useTheme } from '@material-ui/core/styles';
9
+ import IconButton from '@material-ui/core/IconButton';
10
+ import FirstPageIcon from '@material-ui/icons/FirstPage';
11
+ import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft';
12
+ import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight';
13
+ import LastPageIcon from '@material-ui/icons/LastPage';
14
+
15
+ const useStyles1 = makeStyles((theme) => ({
16
+ root: {
17
+ flexShrink: 0,
18
+ marginLeft: theme.spacing(2.5),
19
+ },
20
+ }));
21
+
22
+ function TablePaginationActions(props) {
23
+ const classes = useStyles1();
24
+ const theme = useTheme();
25
+ const {
26
+ count, page, rowsPerPage, onPageChange,
27
+ } = props;
28
+
29
+ const handleFirstPageButtonClick = (event) => {
30
+ onPageChange(event, 0);
31
+ };
32
+
33
+ const handleBackButtonClick = (event) => {
34
+ onPageChange(event, page - 1);
35
+ };
36
+
37
+ const handleNextButtonClick = (event) => {
38
+ onPageChange(event, page + 1);
39
+ };
40
+
41
+ const handleLastPageButtonClick = (event) => {
42
+ onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
43
+ };
44
+
45
+ return (
46
+ <div className={classes.root}>
47
+ <IconButton
48
+ onClick={handleFirstPageButtonClick}
49
+ disabled={page === 0}
50
+ aria-label="first page"
51
+ >
52
+ {theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
53
+ </IconButton>
54
+ <IconButton onClick={handleBackButtonClick} disabled={page === 0} aria-label="previous page">
55
+ {theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
56
+ </IconButton>
57
+ <IconButton
58
+ onClick={handleNextButtonClick}
59
+ disabled={page >= Math.ceil(count / rowsPerPage) - 1}
60
+ aria-label="next page"
61
+ >
62
+ {theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
63
+ </IconButton>
64
+ <IconButton
65
+ onClick={handleLastPageButtonClick}
66
+ disabled={page >= Math.ceil(count / rowsPerPage) - 1}
67
+ aria-label="last page"
68
+ >
69
+ {theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
70
+ </IconButton>
71
+ </div>
72
+ );
73
+ }
74
+
75
+ TablePaginationActions.propTypes = {
76
+ count: PropTypes.number.isRequired,
77
+ onPageChange: PropTypes.func.isRequired,
78
+ page: PropTypes.number.isRequired,
79
+ rowsPerPage: PropTypes.number.isRequired,
80
+ };
8
81
 
9
82
  const defaultTheme = {
10
83
  MuiTablePagination: {
@@ -32,6 +105,11 @@ const defaultTheme = {
32
105
  },
33
106
  };
34
107
 
108
+ const downloadAreaStyle = {
109
+ display: 'flex',
110
+ paddingRight: '41px',
111
+ };
112
+
35
113
  const CustomPagination = ({
36
114
  rowsPerPageOptions,
37
115
  count,
@@ -42,15 +120,18 @@ const CustomPagination = ({
42
120
  customTheme = {},
43
121
  }) => (
44
122
  <ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
45
- <TablePagination
46
- rowsPerPageOptions={rowsPerPageOptions}
47
- component="div"
48
- count={count}
49
- rowsPerPage={rowsPerPage}
50
- page={page}
51
- onPageChange={onPageChange}
52
- onRowsPerPageChange={onRowsPerPageChange}
53
- />
123
+ <div className="downloadArea" style={downloadAreaStyle}>
124
+ <TablePagination
125
+ rowsPerPageOptions={rowsPerPageOptions}
126
+ component="div"
127
+ count={count}
128
+ rowsPerPage={rowsPerPage}
129
+ page={page}
130
+ onPageChange={onPageChange}
131
+ onRowsPerPageChange={onRowsPerPageChange}
132
+ ActionsComponent={TablePaginationActions}
133
+ />
134
+ </div>
54
135
  </ThemeProvider>
55
136
  );
56
137
 
@@ -7,30 +7,32 @@ import {
7
7
  import { CloudDownload } from '@material-ui/icons';
8
8
  import { downloadJson } from '../util/downloadTable';
9
9
 
10
+ const downloadButtonStyle = {
11
+ color: '#d1d2d3',
12
+ marginTop: '7px',
13
+ };
14
+
10
15
  const DownloadButton = ({
11
- download,
12
- rows,
13
- table,
16
+ count,
14
17
  queryVariables,
15
- server,
18
+ table,
16
19
  }) => {
17
- if (!download) {
18
- return null;
20
+ if (count === 0) {
21
+ return <CloudDownload className="disableButton" style={downloadButtonStyle} />;
19
22
  }
20
- const {
21
- downloadCsv = 'download',
22
- downloadTable,
23
- downloadFileName,
24
- } = download;
25
23
 
26
24
  const client = useApolloClient();
27
25
 
26
+ const downloadFile = 'INS ';
27
+
28
28
  async function downloadSCSVFile() {
29
29
  const {
30
30
  query,
31
31
  paginationAPIField,
32
32
  } = table;
33
33
 
34
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
35
+
34
36
  const result = await client.query({
35
37
  query,
36
38
  variables: {
@@ -49,28 +51,17 @@ const DownloadButton = ({
49
51
  }
50
52
 
51
53
  const downloadTableCSV = useCallback(() => {
52
- if (downloadTable) {
53
- downloadTable();
54
- } else if (!downloadTable && !server) {
55
- downloadJson(rows, table, downloadFileName);
56
- } else {
57
- downloadSCSVFile();
58
- }
54
+ downloadSCSVFile();
59
55
  }, [queryVariables]);
60
56
 
61
57
  return (
62
- <>
63
- <Tooltip
64
- title={downloadCsv}
65
- className="download-icon"
58
+ <Tooltip title="Download Full Table As CSV">
59
+ <IconButton
60
+ onClick={downloadTableCSV}
66
61
  >
67
- <IconButton
68
- onClick={downloadTableCSV}
69
- >
70
- <CloudDownload />
71
- </IconButton>
72
- </Tooltip>
73
- </>
62
+ <CloudDownload />
63
+ </IconButton>
64
+ </Tooltip>
74
65
  );
75
66
  };
76
67
 
package/src/util/Types.js CHANGED
@@ -2,6 +2,8 @@ export const CHECKBOX = 'CHECKBOX';
2
2
  export const DELETE = 'DELETE';
3
3
  export const CUSTOM_ELEM = 'CUSTOM_ELEM';
4
4
  export const LINK = 'LINK';
5
+ export const EXTERNAL_LINK = 'EXTERNAL_LINK';
6
+ export const CONDITIONAL_EXTERNAL_LINK = 'CONDITIONAL_EXTERNAL_LINK';
5
7
  export const DISPLAY = 'DISPLAY';
6
8
  export const DEFAULT = 'DEFAULT';
7
9
  export const FORMAT_DATA = 'FORMAT_DATA';
@@ -10,6 +12,8 @@ export const FORMAT_BYTES = 'FORMAT_BYTES';
10
12
  export const cellTypes = {
11
13
  CUSTOM_ELEM,
12
14
  LINK,
15
+ EXTERNAL_LINK,
16
+ CONDITIONAL_EXTERNAL_LINK,
13
17
  DISPLAY,
14
18
  CHECKBOX,
15
19
  DELETE,
@@ -54,13 +54,14 @@ export function convertToCSV(jsonse, keysToInclude, header) {
54
54
  }
55
55
 
56
56
  export function downloadJson(tableData, table, downloadFileName) {
57
- const { columns = [] } = table;
58
- const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
57
+ const { downloadColumns = [] } = table;
58
+ // eslint-disable-next-line max-len
59
+ const filterColumns = downloadColumns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
59
60
  const formatDataVal = formatColumnValues(filterColumns, tableData);
60
61
  const jsonse = JSON.stringify(formatDataVal);
61
- const keysToInclude = columns.filter(({ dataField }) => dataField)
62
+ const keysToInclude = downloadColumns.filter(({ dataField }) => dataField)
62
63
  .map(({ dataField }) => dataField);
63
- const headers = columns.filter(({ dataField }) => dataField).map(({ header }) => header);
64
+ const headers = downloadColumns.filter(({ dataField }) => dataField).map(({ header }) => header);
64
65
  const csv = convertToCSV(jsonse, keysToInclude, headers);
65
66
  const exportData = new Blob([csv], { type: 'text/csv' });
66
67
  const JsonURL = window.URL.createObjectURL(exportData);