@bento-core/table 1.0.1-ccdihub.32 → 1.0.1-ccdihub.34

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,6 +16,9 @@ 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
+ };
19
22
  const ExtendedView = _ref => {
20
23
  let {
21
24
  table,
@@ -44,13 +47,14 @@ const ExtendedView = _ref => {
44
47
  theme: themeConfig
45
48
  }, numSelected === 0 && (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_core.Toolbar, {
46
49
  className: "downloadColumnView"
47
- }, /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
48
- download: download
49
- }), /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
50
+ }, /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
50
51
  table: table,
51
52
  manageViewColumns: manageViewColumns,
52
53
  onColumnViewChange: onColumnViewChange
53
- })), pagination && /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
54
+ })), pagination && /*#__PURE__*/_react.default.createElement("div", {
55
+ className: "downloadArea",
56
+ style: downloadAreaStyle
57
+ }, /*#__PURE__*/_react.default.createElement(_CustomPagination.default, {
54
58
  customTheme: customTheme.tblTopPgn,
55
59
  rowsPerPageOptions: [10, 25, 50, 100],
56
60
  component: "div",
@@ -61,7 +65,11 @@ const ExtendedView = _ref => {
61
65
  onRowsPerPageChange: onRowsPerPageChange,
62
66
  queryVariables: queryVariables,
63
67
  table: table
64
- }));
68
+ }), /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
69
+ count: table.totalRowCount || 0,
70
+ queryVariables: queryVariables,
71
+ table: table
72
+ })));
65
73
  };
66
74
  var _default = ExtendedView;
67
75
  exports.default = _default;
@@ -7,7 +7,6 @@ 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 _DownloadButton = _interopRequireDefault(require("./components/DownloadButton"));
11
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
11
  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
12
  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; }
@@ -39,12 +38,6 @@ const defaultTheme = {
39
38
  }
40
39
  }
41
40
  };
42
- const downloadAreaStyle = {
43
- display: 'flex',
44
- borderTop: '1px solid #8A7F7C',
45
- borderBottom: '1px solid #8A7F7C',
46
- paddingRight: '41px'
47
- };
48
41
  const CustomPagination = _ref => {
49
42
  let {
50
43
  rowsPerPageOptions,
@@ -53,17 +46,12 @@ const CustomPagination = _ref => {
53
46
  page,
54
47
  onPageChange,
55
48
  onRowsPerPageChange,
56
- customTheme = {},
57
- queryVariables,
58
- table
49
+ customTheme = {}
59
50
  } = _ref;
60
51
  return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
61
52
  theme: (0, _core.createTheme)({
62
53
  overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
63
54
  })
64
- }, /*#__PURE__*/_react.default.createElement("div", {
65
- className: "downloadArea",
66
- style: downloadAreaStyle
67
55
  }, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
68
56
  rowsPerPageOptions: rowsPerPageOptions,
69
57
  component: "div",
@@ -78,11 +66,7 @@ const CustomPagination = _ref => {
78
66
  },
79
67
  native: true
80
68
  }
81
- }), /*#__PURE__*/_react.default.createElement(_DownloadButton.default, {
82
- count: count,
83
- queryVariables: queryVariables,
84
- table: table
85
- })));
69
+ }));
86
70
  };
87
71
  CustomPagination.propTypes = {
88
72
  rowsPerPageOptions: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
@@ -36,10 +36,9 @@ const DownloadButton = _ref => {
36
36
  async function downloadSCSVFile() {
37
37
  const {
38
38
  query,
39
- paginationAPIField,
40
- name
39
+ paginationAPIField
41
40
  } = table;
42
- const downloadFileName = downloadFile.concat(name, ' download');
41
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
43
42
  const result = await client.query({
44
43
  query,
45
44
  variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
@@ -4,20 +4,63 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _client = require("@apollo/client");
8
9
  var _core = require("@material-ui/core");
9
10
  var _icons = require("@material-ui/icons");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ var _downloadTable = require("../util/downloadTable");
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ 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; }
15
+ 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; }
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
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
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
+ };
11
23
  const DownloadButton = _ref => {
12
24
  let {
13
- download
25
+ count,
26
+ queryVariables,
27
+ table
14
28
  } = _ref;
15
- if (!download) {
16
- return null;
29
+ if (count === 0) {
30
+ return /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, {
31
+ style: downloadButtonStyle
32
+ });
33
+ }
34
+ const client = (0, _client.useApolloClient)();
35
+ const downloadFile = 'CCDI Inventory ';
36
+ async function downloadSCSVFile() {
37
+ const {
38
+ query,
39
+ paginationAPIField
40
+ } = table;
41
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
42
+ const result = await client.query({
43
+ query,
44
+ variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
45
+ page: 0,
46
+ first: 25000
47
+ })
48
+ }).then(response => {
49
+ if (paginationAPIField && response && response.data) {
50
+ return response.data[paginationAPIField];
51
+ }
52
+ return response.data;
53
+ });
54
+ (0, _downloadTable.downloadJson)(result, table, downloadFileName);
17
55
  }
18
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
19
- title: download.downloadCsv
20
- }, /*#__PURE__*/_react.default.createElement(_core.IconButton, null, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null))));
56
+ const downloadTableCSV = (0, _react.useCallback)(() => {
57
+ downloadSCSVFile();
58
+ }, [queryVariables]);
59
+ return /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
60
+ title: "Download filtered results as a CSV"
61
+ }, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
62
+ onClick: downloadTableCSV
63
+ }, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null)));
21
64
  };
22
65
  var _default = DownloadButton;
23
66
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdihub.32",
3
+ "version": "1.0.1-ccdihub.34",
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,6 +9,10 @@ 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
+ };
15
+
12
16
  const ExtendedView = ({
13
17
  table,
14
18
  onColumnViewChange,
@@ -33,9 +37,9 @@ const ExtendedView = ({
33
37
  <ThemeProvider theme={themeConfig}>
34
38
  {(numSelected === 0 && (download || manageViewColumns)) && (
35
39
  <Toolbar className="downloadColumnView">
36
- <DownloadButton
40
+ {/* <DownloadButton
37
41
  download={download}
38
- />
42
+ /> */}
39
43
  <ManageColumnView
40
44
  table={table}
41
45
  manageViewColumns={manageViewColumns}
@@ -45,18 +49,25 @@ const ExtendedView = ({
45
49
  )}
46
50
  {
47
51
  (pagination) && (
48
- <CustomPagination
49
- customTheme={customTheme.tblTopPgn}
50
- rowsPerPageOptions={[10, 25, 50, 100]}
51
- component="div"
52
- count={table.totalRowCount || 0}
53
- rowsPerPage={table.rowsPerPage || 10}
54
- page={table.page || 0}
55
- onPageChange={onPageChange}
56
- onRowsPerPageChange={onRowsPerPageChange}
57
- queryVariables={queryVariables}
58
- table={table}
59
- />
52
+ <div className="downloadArea" style={downloadAreaStyle}>
53
+ <CustomPagination
54
+ customTheme={customTheme.tblTopPgn}
55
+ rowsPerPageOptions={[10, 25, 50, 100]}
56
+ component="div"
57
+ count={table.totalRowCount || 0}
58
+ rowsPerPage={table.rowsPerPage || 10}
59
+ page={table.page || 0}
60
+ onPageChange={onPageChange}
61
+ onRowsPerPageChange={onRowsPerPageChange}
62
+ queryVariables={queryVariables}
63
+ table={table}
64
+ />
65
+ <DownloadButton
66
+ count={table.totalRowCount || 0}
67
+ queryVariables={queryVariables}
68
+ table={table}
69
+ />
70
+ </div>
60
71
  )
61
72
  }
62
73
  </ThemeProvider>
@@ -5,7 +5,6 @@ import {
5
5
  TablePagination,
6
6
  ThemeProvider,
7
7
  } from '@material-ui/core';
8
- import DownloadButton from './components/DownloadButton';
9
8
 
10
9
  const defaultTheme = {
11
10
  MuiTablePagination: {
@@ -33,13 +32,6 @@ const defaultTheme = {
33
32
  },
34
33
  };
35
34
 
36
- const downloadAreaStyle = {
37
- display: 'flex',
38
- borderTop: '1px solid #8A7F7C',
39
- borderBottom: '1px solid #8A7F7C',
40
- paddingRight: '41px',
41
- };
42
-
43
35
  const CustomPagination = ({
44
36
  rowsPerPageOptions,
45
37
  count,
@@ -48,30 +40,21 @@ const CustomPagination = ({
48
40
  onPageChange,
49
41
  onRowsPerPageChange,
50
42
  customTheme = {},
51
- queryVariables,
52
- table,
53
43
  }) => (
54
44
  <ThemeProvider theme={createTheme({ overrides: { ...defaultTheme, ...customTheme } })}>
55
- <div className="downloadArea" style={downloadAreaStyle}>
56
- <TablePagination
57
- rowsPerPageOptions={rowsPerPageOptions}
58
- component="div"
59
- count={count}
60
- rowsPerPage={rowsPerPage}
61
- page={page}
62
- onPageChange={onPageChange}
63
- onRowsPerPageChange={onRowsPerPageChange}
64
- SelectProps={{
65
- inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
66
- native: true,
67
- }}
68
- />
69
- <DownloadButton
70
- count={count}
71
- queryVariables={queryVariables}
72
- table={table}
73
- />
74
- </div>
45
+ <TablePagination
46
+ rowsPerPageOptions={rowsPerPageOptions}
47
+ component="div"
48
+ count={count}
49
+ rowsPerPage={rowsPerPage}
50
+ page={page}
51
+ onPageChange={onPageChange}
52
+ onRowsPerPageChange={onRowsPerPageChange}
53
+ SelectProps={{
54
+ inputProps: { 'aria-label': 'Selection dropdown for displaying the number of results per page' },
55
+ native: true,
56
+ }}
57
+ />
75
58
  </ThemeProvider>
76
59
  );
77
60
 
@@ -29,10 +29,9 @@ const DownloadButton = ({
29
29
  const {
30
30
  query,
31
31
  paginationAPIField,
32
- name,
33
32
  } = table;
34
33
 
35
- const downloadFileName = downloadFile.concat(name, ' download');
34
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
36
35
 
37
36
  const result = await client.query({
38
37
  query,
@@ -1,25 +1,67 @@
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';
9
+
10
+ const downloadButtonStyle = {
11
+ color: '#d1d2d3',
12
+ marginTop: '7px',
13
+ };
7
14
 
8
15
  const DownloadButton = ({
9
- download,
16
+ count,
17
+ queryVariables,
18
+ table,
10
19
  }) => {
11
- if (!download) {
12
- return null;
20
+ if (count === 0) {
21
+ return <CloudDownload style={downloadButtonStyle} />;
13
22
  }
14
23
 
24
+ const client = useApolloClient();
25
+
26
+ const downloadFile = 'CCDI Inventory ';
27
+
28
+ async function downloadSCSVFile() {
29
+ const {
30
+ query,
31
+ paginationAPIField,
32
+ } = table;
33
+
34
+ const downloadFileName = downloadFile.concat(paginationAPIField.replace('Overview', ''), ' download');
35
+
36
+ const result = await client.query({
37
+ query,
38
+ variables: {
39
+ ...queryVariables,
40
+ page: 0,
41
+ first: 25000,
42
+ },
43
+ })
44
+ .then((response) => {
45
+ if (paginationAPIField && response && response.data) {
46
+ return response.data[paginationAPIField];
47
+ }
48
+ return response.data;
49
+ });
50
+ downloadJson(result, table, downloadFileName);
51
+ }
52
+
53
+ const downloadTableCSV = useCallback(() => {
54
+ downloadSCSVFile();
55
+ }, [queryVariables]);
56
+
15
57
  return (
16
- <>
17
- <Tooltip title={download.downloadCsv}>
18
- <IconButton>
19
- <CloudDownload />
20
- </IconButton>
21
- </Tooltip>
22
- </>
58
+ <Tooltip title="Download filtered results as a CSV">
59
+ <IconButton
60
+ onClick={downloadTableCSV}
61
+ >
62
+ <CloudDownload />
63
+ </IconButton>
64
+ </Tooltip>
23
65
  );
24
66
  };
25
67