@bento-core/table 1.0.0-alpha.0 → 1.0.1-icdc.0
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/dist/ExtendedView.js +11 -5
- package/dist/TableView.js +8 -2
- package/dist/body/CustomTblBody.js +3 -1
- package/dist/header/ColumnGrouping.js +52 -0
- package/dist/header/CustomCell.js +2 -1
- package/dist/header/CustomTblHeader.js +7 -2
- package/dist/header/components/DeleteCellView.js +10 -4
- package/dist/toolbar/DownloadButtonView.js +54 -5
- package/dist/toolbar/ManageColumnView.js +7 -8
- package/dist/util/Dataformat.js +41 -1
- package/dist/util/downloadTable.js +109 -0
- package/package.json +16 -5
- package/src/ExtendedView.js +35 -25
- package/src/TableView.js +6 -0
- package/src/body/CustomTblBody.js +3 -1
- package/src/header/ColumnGrouping.js +55 -0
- package/src/header/CustomCell.js +1 -0
- package/src/header/CustomTblHeader.js +3 -0
- package/src/header/components/DeleteCellView.js +42 -26
- package/src/toolbar/DownloadButtonView.js +54 -3
- package/src/toolbar/ManageColumnView.js +9 -6
- package/src/util/Dataformat.js +25 -0
- package/src/util/downloadTable.js +74 -0
package/dist/ExtendedView.js
CHANGED
|
@@ -19,11 +19,13 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
19
19
|
const ExtendedView = _ref => {
|
|
20
20
|
let {
|
|
21
21
|
table,
|
|
22
|
+
rows,
|
|
22
23
|
onColumnViewChange,
|
|
23
24
|
onRowsPerPageChange,
|
|
24
25
|
onPageChange,
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
customTheme,
|
|
27
|
+
queryVariables,
|
|
28
|
+
server
|
|
27
29
|
} = _ref;
|
|
28
30
|
const {
|
|
29
31
|
extendedViewConfig
|
|
@@ -41,10 +43,14 @@ const ExtendedView = _ref => {
|
|
|
41
43
|
});
|
|
42
44
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
43
45
|
theme: themeConfig
|
|
44
|
-
},
|
|
45
|
-
className: "
|
|
46
|
+
}, (download || manageViewColumns) && /*#__PURE__*/_react.default.createElement(_core.Toolbar, {
|
|
47
|
+
className: "downloadAndColumnView"
|
|
46
48
|
}, /*#__PURE__*/_react.default.createElement(_DownloadButtonView.default, {
|
|
47
|
-
download: download
|
|
49
|
+
download: download,
|
|
50
|
+
rows: rows,
|
|
51
|
+
server: server,
|
|
52
|
+
table: table,
|
|
53
|
+
queryVariables: queryVariables
|
|
48
54
|
}), /*#__PURE__*/_react.default.createElement(_ManageColumnView.default, {
|
|
49
55
|
table: table,
|
|
50
56
|
manageViewColumns: manageViewColumns,
|
package/dist/TableView.js
CHANGED
|
@@ -36,6 +36,7 @@ const TableView = _ref => {
|
|
|
36
36
|
var _table$selectedRows, _table$selectedRows2;
|
|
37
37
|
let {
|
|
38
38
|
tableRows = [],
|
|
39
|
+
totalRows = [],
|
|
39
40
|
table,
|
|
40
41
|
onRowsPerPageChange,
|
|
41
42
|
onPageChange,
|
|
@@ -44,15 +45,20 @@ const TableView = _ref => {
|
|
|
44
45
|
totalRowCount,
|
|
45
46
|
onSortByColumn,
|
|
46
47
|
onColumnViewChange,
|
|
47
|
-
themeConfig = {}
|
|
48
|
+
themeConfig = {},
|
|
49
|
+
queryVariables,
|
|
50
|
+
server
|
|
48
51
|
} = _ref;
|
|
49
52
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ExtendedView.default, {
|
|
50
53
|
table: table,
|
|
54
|
+
rows: totalRows,
|
|
55
|
+
server: server,
|
|
51
56
|
onColumnViewChange: onColumnViewChange,
|
|
52
57
|
onRowsPerPageChange: onRowsPerPageChange,
|
|
53
58
|
onPageChange: onPageChange,
|
|
54
59
|
numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows = table.selectedRows) === null || _table$selectedRows === void 0 ? void 0 : _table$selectedRows.length) || 0,
|
|
55
|
-
customTheme: themeConfig.extendedView
|
|
60
|
+
customTheme: themeConfig.extendedView,
|
|
61
|
+
queryVariables: queryVariables
|
|
56
62
|
}), /*#__PURE__*/_react.default.createElement(_CustomToolbar.default, {
|
|
57
63
|
numSelected: (table === null || table === void 0 ? void 0 : (_table$selectedRows2 = table.selectedRows) === null || _table$selectedRows2 === void 0 ? void 0 : _table$selectedRows2.length) || 0,
|
|
58
64
|
table: table,
|
|
@@ -11,6 +11,7 @@ var _DisplayBodyCell = _interopRequireDefault(require("./DisplayBodyCell"));
|
|
|
11
11
|
var _DefaultThemConfig = _interopRequireDefault(require("./DefaultThemConfig"));
|
|
12
12
|
var _Types = require("../util/Types");
|
|
13
13
|
var _ActionBodyCell = _interopRequireDefault(require("./ActionBodyCell"));
|
|
14
|
+
var _Dataformat = require("../util/Dataformat");
|
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
16
|
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; }
|
|
16
17
|
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; }
|
|
@@ -31,13 +32,14 @@ const CustomTableBody = _ref => {
|
|
|
31
32
|
const {
|
|
32
33
|
columns
|
|
33
34
|
} = table;
|
|
35
|
+
const formatRows = (0, _Dataformat.formatColumnValues)(columns, rows);
|
|
34
36
|
const displayColunms = columns.filter(col => col.display);
|
|
35
37
|
const themeConfig = (0, _core.createTheme)({
|
|
36
38
|
overrides: _objectSpread(_objectSpread({}, (0, _DefaultThemConfig.default)()), customTheme)
|
|
37
39
|
});
|
|
38
40
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
39
41
|
theme: themeConfig
|
|
40
|
-
}, /*#__PURE__*/_react.default.createElement(_core.TableBody, null,
|
|
42
|
+
}, /*#__PURE__*/_react.default.createElement(_core.TableBody, null, formatRows.map(row => /*#__PURE__*/_react.default.createElement(_core.TableRow, null, displayColunms.map(column => {
|
|
41
43
|
const {
|
|
42
44
|
cellType
|
|
43
45
|
} = column;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const ColumnGrouping = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
columnGroups = [],
|
|
13
|
+
columns = []
|
|
14
|
+
} = _ref;
|
|
15
|
+
if (columnGroups.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const getColSpan = function getColSpan() {
|
|
19
|
+
let indexes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
|
|
20
|
+
const startIndex = indexes[0];
|
|
21
|
+
const endIndex = indexes[1];
|
|
22
|
+
const displayGroupCols = columns.map((col, index) => startIndex <= index && index <= endIndex && col.display).filter(item => item);
|
|
23
|
+
return displayGroupCols.length;
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement(_core.TableRow, {
|
|
26
|
+
className: "column_grouping"
|
|
27
|
+
}, columnGroups.map(group => {
|
|
28
|
+
const {
|
|
29
|
+
title,
|
|
30
|
+
customViewRender,
|
|
31
|
+
clsName,
|
|
32
|
+
columnIndexes
|
|
33
|
+
} = group;
|
|
34
|
+
if (!columnIndexes) {
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_core.Typography, {
|
|
36
|
+
variant: "subtitle1",
|
|
37
|
+
color: "error",
|
|
38
|
+
size: "sm"
|
|
39
|
+
}, "Missing columnIndexes [startColIndex, endColIndex]");
|
|
40
|
+
}
|
|
41
|
+
const colSpan = getColSpan(columnIndexes);
|
|
42
|
+
if (colSpan > 0) {
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_core.TableCell, {
|
|
44
|
+
colSpan: colSpan,
|
|
45
|
+
className: clsName
|
|
46
|
+
}, customViewRender ? customViewRender() : title);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
var _default = ColumnGrouping;
|
|
52
|
+
exports.default = _default;
|
|
@@ -53,7 +53,8 @@ const CustomHeaderCell = _ref => {
|
|
|
53
53
|
return /*#__PURE__*/_react.default.createElement(_TableCell.default, {
|
|
54
54
|
scope: "col",
|
|
55
55
|
active: sortBy === dataField,
|
|
56
|
-
direction: sortOrder
|
|
56
|
+
direction: sortOrder,
|
|
57
|
+
className: dataField
|
|
57
58
|
}, /*#__PURE__*/_react.default.createElement(Tooltip, null, /*#__PURE__*/_react.default.createElement(_TableSortLabel.default, {
|
|
58
59
|
active: sortBy === dataField,
|
|
59
60
|
hideSortIcon: sortBy !== dataField,
|
|
@@ -11,6 +11,7 @@ var _CustomCell = _interopRequireDefault(require("./CustomCell"));
|
|
|
11
11
|
var _DefaultThemConfig = _interopRequireDefault(require("./DefaultThemConfig"));
|
|
12
12
|
var _Types = require("../util/Types");
|
|
13
13
|
var _ActionHeaderCell = _interopRequireDefault(require("./ActionHeaderCell"));
|
|
14
|
+
var _ColumnGrouping = _interopRequireDefault(require("./ColumnGrouping"));
|
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
16
|
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; }
|
|
16
17
|
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; }
|
|
@@ -31,7 +32,8 @@ const CustomTableHeader = _ref => {
|
|
|
31
32
|
columns,
|
|
32
33
|
selectedRows = [],
|
|
33
34
|
sortBy,
|
|
34
|
-
sortOrder
|
|
35
|
+
sortOrder,
|
|
36
|
+
columnGroups
|
|
35
37
|
} = table;
|
|
36
38
|
const Ids = rows.map(row => row[table.dataKey]);
|
|
37
39
|
const includeSelectedIds = Ids.some(id => selectedRows.includes(id));
|
|
@@ -46,7 +48,10 @@ const CustomTableHeader = _ref => {
|
|
|
46
48
|
});
|
|
47
49
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
48
50
|
theme: themeConfig
|
|
49
|
-
}, /*#__PURE__*/_react.default.createElement(_core.TableHead, null, /*#__PURE__*/_react.default.createElement(
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement(_core.TableHead, null, /*#__PURE__*/_react.default.createElement(_ColumnGrouping.default, {
|
|
52
|
+
columnGroups: columnGroups,
|
|
53
|
+
columns: columns
|
|
54
|
+
}), /*#__PURE__*/_react.default.createElement(_core.TableRow, null, displayColunms.map(column => {
|
|
50
55
|
const {
|
|
51
56
|
cellType
|
|
52
57
|
} = column;
|
|
@@ -21,10 +21,16 @@ const DeleteCellView = _ref => {
|
|
|
21
21
|
} = _ref;
|
|
22
22
|
const [displayDialog, setDisplay] = (0, _react.useState)(false);
|
|
23
23
|
const toggleDialogDisplay = () => setDisplay(!displayDialog);
|
|
24
|
-
|
|
24
|
+
const testTrigger = () => {
|
|
25
|
+
setDisplay(true);
|
|
26
|
+
};
|
|
27
|
+
const {
|
|
28
|
+
customColHeaderRender
|
|
29
|
+
} = column;
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.TableCell, {
|
|
25
31
|
scope: "col",
|
|
26
32
|
className: "del_all_row"
|
|
27
|
-
}, /*#__PURE__*/_react.default.createElement(_core.Typography, {
|
|
33
|
+
}, customColHeaderRender ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, customColHeaderRender(testTrigger)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Typography, {
|
|
28
34
|
className: "del_all_row_text"
|
|
29
35
|
}, "Remove"), /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
30
36
|
id: "del_all_row_tooltip",
|
|
@@ -37,12 +43,12 @@ const DeleteCellView = _ref => {
|
|
|
37
43
|
}, /*#__PURE__*/_react.default.createElement(_icons.ArrowDropDown, {
|
|
38
44
|
className: "del_all_row_btn_icon",
|
|
39
45
|
onClick: toggleDialogDisplay
|
|
40
|
-
}))), /*#__PURE__*/_react.default.createElement(_RemoveAllDialog.default, {
|
|
46
|
+
})))), /*#__PURE__*/_react.default.createElement(_RemoveAllDialog.default, {
|
|
41
47
|
open: displayDialog,
|
|
42
48
|
removeAllFiles: column.headerEventHandler,
|
|
43
49
|
count: count,
|
|
44
50
|
toggleDisplay: toggleDialogDisplay
|
|
45
|
-
}));
|
|
51
|
+
})));
|
|
46
52
|
};
|
|
47
53
|
var _default = DeleteCellView;
|
|
48
54
|
exports.default = _default;
|
|
@@ -4,20 +4,69 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _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
|
-
|
|
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); }
|
|
11
19
|
const DownloadButton = _ref => {
|
|
12
20
|
let {
|
|
13
|
-
download
|
|
21
|
+
download,
|
|
22
|
+
rows,
|
|
23
|
+
table,
|
|
24
|
+
queryVariables,
|
|
25
|
+
server
|
|
14
26
|
} = _ref;
|
|
15
27
|
if (!download) {
|
|
16
28
|
return null;
|
|
17
29
|
}
|
|
30
|
+
const {
|
|
31
|
+
downloadCsv = 'download',
|
|
32
|
+
downloadTable,
|
|
33
|
+
downloadFileName
|
|
34
|
+
} = download;
|
|
35
|
+
const client = (0, _client.useApolloClient)();
|
|
36
|
+
async function downloadSCSVFile() {
|
|
37
|
+
const {
|
|
38
|
+
query,
|
|
39
|
+
paginationAPIField
|
|
40
|
+
} = table;
|
|
41
|
+
const result = await client.query({
|
|
42
|
+
query,
|
|
43
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
44
|
+
page: 0,
|
|
45
|
+
first: 10000
|
|
46
|
+
})
|
|
47
|
+
}).then(response => {
|
|
48
|
+
if (paginationAPIField && response && response.data) {
|
|
49
|
+
return response.data[paginationAPIField];
|
|
50
|
+
}
|
|
51
|
+
return response.data;
|
|
52
|
+
});
|
|
53
|
+
(0, _downloadTable.downloadJson)(result, table, downloadFileName);
|
|
54
|
+
}
|
|
55
|
+
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
|
+
}
|
|
63
|
+
}, [queryVariables]);
|
|
18
64
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
19
|
-
title:
|
|
20
|
-
|
|
65
|
+
title: downloadCsv,
|
|
66
|
+
className: "download-icon"
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
68
|
+
onClick: downloadTableCSV
|
|
69
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null))));
|
|
21
70
|
};
|
|
22
71
|
var _default = DownloadButton;
|
|
23
72
|
exports.default = _default;
|
|
@@ -20,7 +20,7 @@ const ManageColumnView = _ref => {
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
|
|
23
|
-
const
|
|
23
|
+
const toggleDisplay = event => {
|
|
24
24
|
setAnchorEl(event.currentTarget);
|
|
25
25
|
};
|
|
26
26
|
const handleClose = () => setAnchorEl(null);
|
|
@@ -33,7 +33,8 @@ const ManageColumnView = _ref => {
|
|
|
33
33
|
title: manageViewColumns.title
|
|
34
34
|
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
35
35
|
variant: "contained",
|
|
36
|
-
onClick:
|
|
36
|
+
onClick: toggleDisplay,
|
|
37
|
+
className: "manageViewColumnBtn"
|
|
37
38
|
}, /*#__PURE__*/_react.default.createElement(_icons.ViewColumn, null))), /*#__PURE__*/_react.default.createElement(_core.Popover, {
|
|
38
39
|
open: open,
|
|
39
40
|
anchorEl: anchorEl,
|
|
@@ -55,22 +56,20 @@ const ManageColumnView = _ref => {
|
|
|
55
56
|
className: "viewColumnListItem"
|
|
56
57
|
}, /*#__PURE__*/_react.default.createElement(_core.Checkbox, {
|
|
57
58
|
icon: /*#__PURE__*/_react.default.createElement(_icons.CheckBoxOutlineBlank, {
|
|
58
|
-
style: {
|
|
59
|
-
fontSize: 18
|
|
60
|
-
},
|
|
61
59
|
className: "checkBoxIcon"
|
|
62
60
|
}),
|
|
63
61
|
onClick: () => onColumnViewChange(column),
|
|
64
62
|
checked: column.display,
|
|
65
63
|
checkedIcon: /*#__PURE__*/_react.default.createElement(_icons.CheckBox, {
|
|
66
|
-
style: {
|
|
67
|
-
fontSize: 18
|
|
68
|
-
},
|
|
69
64
|
className: "checkBoxIcon"
|
|
70
65
|
}),
|
|
71
66
|
disableRipple: true,
|
|
72
67
|
color: "secondary",
|
|
73
68
|
className: "checkBox"
|
|
69
|
+
}), column.icon && /*#__PURE__*/_react.default.createElement("img", {
|
|
70
|
+
src: column.icon,
|
|
71
|
+
alt: column.header,
|
|
72
|
+
className: column.dataField
|
|
74
73
|
}), /*#__PURE__*/_react.default.createElement(_core.Typography, null, column.header))))));
|
|
75
74
|
};
|
|
76
75
|
const styles = () => ({
|
package/dist/util/Dataformat.js
CHANGED
|
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatBytes = formatBytes;
|
|
7
|
+
exports.formatColumnValues = void 0;
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
7
13
|
/* eslint-disable import/prefer-default-export */
|
|
8
14
|
function formatBytes(bytes) {
|
|
9
15
|
let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
@@ -12,4 +18,38 @@ function formatBytes(bytes) {
|
|
|
12
18
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
13
19
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
14
20
|
return "".concat(parseFloat((bytes / 1024 ** i).toFixed(dm)), " ").concat(sizes[i]);
|
|
15
|
-
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* convert zero (0) value to custom val
|
|
25
|
+
* @param {*} columns
|
|
26
|
+
* @param {*} data
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
const formatColumnValues = (columns, data) => {
|
|
30
|
+
const formatColumns = columns.filter(_ref => {
|
|
31
|
+
let {
|
|
32
|
+
columnDefaultValues
|
|
33
|
+
} = _ref;
|
|
34
|
+
return columnDefaultValues;
|
|
35
|
+
});
|
|
36
|
+
if (formatColumns.length > 0) {
|
|
37
|
+
const formatCoumnData = [...data].reduce((acc, item) => {
|
|
38
|
+
const updateRow = _objectSpread({}, item);
|
|
39
|
+
formatColumns.forEach(col => {
|
|
40
|
+
const {
|
|
41
|
+
columnDefaultValues,
|
|
42
|
+
dataField
|
|
43
|
+
} = col;
|
|
44
|
+
if (columnDefaultValues[item[dataField]]) {
|
|
45
|
+
updateRow[dataField] = columnDefaultValues[item[dataField]];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
acc.push(updateRow);
|
|
49
|
+
return acc;
|
|
50
|
+
}, []);
|
|
51
|
+
return formatCoumnData;
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
};
|
|
55
|
+
exports.formatColumnValues = formatColumnValues;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertToCSV = convertToCSV;
|
|
7
|
+
exports.createFileName = createFileName;
|
|
8
|
+
exports.downloadJson = downloadJson;
|
|
9
|
+
var _Dataformat = require("./Dataformat");
|
|
10
|
+
var _Types = require("./Types");
|
|
11
|
+
function createFileName(fileName) {
|
|
12
|
+
const date = new Date();
|
|
13
|
+
const yyyy = date.getFullYear();
|
|
14
|
+
let dd = date.getDate();
|
|
15
|
+
let mm = date.getMonth() + 1;
|
|
16
|
+
if (dd < 10) {
|
|
17
|
+
dd = "0".concat(dd);
|
|
18
|
+
}
|
|
19
|
+
if (mm < 10) {
|
|
20
|
+
mm = "0".concat(mm);
|
|
21
|
+
}
|
|
22
|
+
const todaysDate = "".concat(yyyy, "-").concat(mm, "-").concat(dd);
|
|
23
|
+
let hours = date.getHours();
|
|
24
|
+
let minutes = date.getMinutes();
|
|
25
|
+
let seconds = date.getSeconds();
|
|
26
|
+
if (hours < 10) {
|
|
27
|
+
hours = "0".concat(hours);
|
|
28
|
+
}
|
|
29
|
+
if (minutes < 10) {
|
|
30
|
+
minutes = "0".concat(minutes);
|
|
31
|
+
}
|
|
32
|
+
if (seconds < 10) {
|
|
33
|
+
seconds = "0".concat(seconds);
|
|
34
|
+
}
|
|
35
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds, '.csv');
|
|
36
|
+
}
|
|
37
|
+
function convertToCSV(jsonse, keysToInclude, header) {
|
|
38
|
+
const objArray = jsonse;
|
|
39
|
+
// To Do empty object just print headers
|
|
40
|
+
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
|
|
41
|
+
let str = header.join(',');
|
|
42
|
+
array.map((entry, index) => {
|
|
43
|
+
let line = '';
|
|
44
|
+
keysToInclude.map(keyName => {
|
|
45
|
+
if (line !== '') line += ',';
|
|
46
|
+
if (keyName === 'file_size') {
|
|
47
|
+
line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
|
|
48
|
+
} else {
|
|
49
|
+
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
50
|
+
}
|
|
51
|
+
return line;
|
|
52
|
+
});
|
|
53
|
+
if (index === 0) {
|
|
54
|
+
// str = header.join(',');
|
|
55
|
+
str += "\r\n".concat(line, "\r\n");
|
|
56
|
+
} else {
|
|
57
|
+
str += "".concat(line, "\r\n");
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
});
|
|
61
|
+
return str;
|
|
62
|
+
}
|
|
63
|
+
function downloadJson(tableData, table, downloadFileName) {
|
|
64
|
+
const {
|
|
65
|
+
columns = []
|
|
66
|
+
} = table;
|
|
67
|
+
const filterColumns = columns.filter(_ref => {
|
|
68
|
+
let {
|
|
69
|
+
cellType
|
|
70
|
+
} = _ref;
|
|
71
|
+
return !_Types.actionCellTypes.includes(cellType);
|
|
72
|
+
});
|
|
73
|
+
const formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
74
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
75
|
+
const keysToInclude = columns.filter(_ref2 => {
|
|
76
|
+
let {
|
|
77
|
+
dataField
|
|
78
|
+
} = _ref2;
|
|
79
|
+
return dataField;
|
|
80
|
+
}).map(_ref3 => {
|
|
81
|
+
let {
|
|
82
|
+
dataField
|
|
83
|
+
} = _ref3;
|
|
84
|
+
return dataField;
|
|
85
|
+
});
|
|
86
|
+
const headers = columns.filter(_ref4 => {
|
|
87
|
+
let {
|
|
88
|
+
dataField
|
|
89
|
+
} = _ref4;
|
|
90
|
+
return dataField;
|
|
91
|
+
}).map(_ref5 => {
|
|
92
|
+
let {
|
|
93
|
+
header
|
|
94
|
+
} = _ref5;
|
|
95
|
+
return header;
|
|
96
|
+
});
|
|
97
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
98
|
+
const exportData = new Blob([csv], {
|
|
99
|
+
type: 'text/csv'
|
|
100
|
+
});
|
|
101
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
102
|
+
let tempLink = '';
|
|
103
|
+
tempLink = document.createElement('a');
|
|
104
|
+
tempLink.setAttribute('href', JsonURL);
|
|
105
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
106
|
+
document.body.appendChild(tempLink);
|
|
107
|
+
tempLink.click();
|
|
108
|
+
document.body.removeChild(tempLink);
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/table",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.1-icdc.0",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"build": "npm run lint && cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
|
|
8
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
8
|
"lint": "eslint src"
|
|
10
9
|
},
|
|
11
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/CBIIT/bento-frontend.git"
|
|
13
|
+
},
|
|
12
14
|
"publishConfig": {
|
|
13
15
|
"access": "public"
|
|
14
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@bento-core/util": "^1.0.0"
|
|
19
|
+
},
|
|
15
20
|
"peerDependencies": {
|
|
16
21
|
"@material-ui/core": "^4.12.4",
|
|
17
22
|
"@material-ui/icons": "^4.9.1",
|
|
18
23
|
"prop-types": "^15.7.2",
|
|
19
24
|
"react": "^17.0.2",
|
|
20
25
|
"react-dom": "^17.0.0",
|
|
21
|
-
"react-redux": "^7.2.1"
|
|
26
|
+
"react-redux": "^7.2.1",
|
|
27
|
+
"@apollo/client": "^3.6.9",
|
|
28
|
+
"clsx": "^1.2.1"
|
|
22
29
|
},
|
|
23
30
|
"author": "CTOS Bento Team",
|
|
24
31
|
"license": "ISC",
|
|
25
|
-
"
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/CBIIT/bento-frontend/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/CBIIT/bento-frontend#readme",
|
|
36
|
+
"description": ""
|
|
26
37
|
}
|
package/src/ExtendedView.js
CHANGED
|
@@ -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
|
-
{(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
{
|
|
35
|
+
{formatRows
|
|
34
36
|
.map((row) => (
|
|
35
37
|
<TableRow>
|
|
36
38
|
{
|
|
@@ -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;
|
package/src/header/CustomCell.js
CHANGED
|
@@ -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) => {
|
|
@@ -28,34 +28,50 @@ 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 } = column;
|
|
31
35
|
return (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
+
/>
|
|
73
|
+
</TableCell>
|
|
74
|
+
</>
|
|
59
75
|
);
|
|
60
76
|
};
|
|
61
77
|
|
|
@@ -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
|
|
18
|
-
|
|
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
|
|
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
|
|
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
|
))}
|
package/src/util/Dataformat.js
CHANGED
|
@@ -6,3 +6,28 @@ export function formatBytes(bytes, decimals = 2) {
|
|
|
6
6
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
7
7
|
return `${parseFloat((bytes / (1024 ** i)).toFixed(dm))} ${sizes[i]}`;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* convert zero (0) value to custom val
|
|
12
|
+
* @param {*} columns
|
|
13
|
+
* @param {*} data
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export const formatColumnValues = (columns, data) => {
|
|
17
|
+
const formatColumns = columns.filter(({ columnDefaultValues }) => columnDefaultValues);
|
|
18
|
+
if (formatColumns.length > 0) {
|
|
19
|
+
const formatCoumnData = [...data].reduce((acc, item) => {
|
|
20
|
+
const updateRow = { ...item };
|
|
21
|
+
formatColumns.forEach((col) => {
|
|
22
|
+
const { columnDefaultValues, dataField } = col;
|
|
23
|
+
if (columnDefaultValues[item[dataField]]) {
|
|
24
|
+
updateRow[dataField] = columnDefaultValues[item[dataField]];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
acc.push(updateRow);
|
|
28
|
+
return acc;
|
|
29
|
+
}, []);
|
|
30
|
+
return formatCoumnData;
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
2
|
+
import { actionCellTypes } from './Types';
|
|
3
|
+
|
|
4
|
+
export function createFileName(fileName) {
|
|
5
|
+
const date = new Date();
|
|
6
|
+
const yyyy = date.getFullYear();
|
|
7
|
+
let dd = date.getDate();
|
|
8
|
+
let mm = (date.getMonth() + 1);
|
|
9
|
+
|
|
10
|
+
if (dd < 10) { dd = `0${dd}`; }
|
|
11
|
+
|
|
12
|
+
if (mm < 10) { mm = `0${mm}`; }
|
|
13
|
+
|
|
14
|
+
const todaysDate = `${yyyy}-${mm}-${dd}`;
|
|
15
|
+
|
|
16
|
+
let hours = date.getHours();
|
|
17
|
+
let minutes = date.getMinutes();
|
|
18
|
+
let seconds = date.getSeconds();
|
|
19
|
+
|
|
20
|
+
if (hours < 10) { hours = `0${hours}`; }
|
|
21
|
+
|
|
22
|
+
if (minutes < 10) { minutes = `0${minutes}`; }
|
|
23
|
+
|
|
24
|
+
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
|
+
|
|
26
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
30
|
+
const objArray = jsonse;
|
|
31
|
+
// To Do empty object just print headers
|
|
32
|
+
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
|
|
33
|
+
let str = header.join(',');
|
|
34
|
+
array.map((entry, index) => {
|
|
35
|
+
let line = '';
|
|
36
|
+
keysToInclude.map((keyName) => {
|
|
37
|
+
if (line !== '') line += ',';
|
|
38
|
+
if (keyName === 'file_size') {
|
|
39
|
+
line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
|
|
40
|
+
} else {
|
|
41
|
+
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
42
|
+
}
|
|
43
|
+
return line;
|
|
44
|
+
});
|
|
45
|
+
if (index === 0) {
|
|
46
|
+
// str = header.join(',');
|
|
47
|
+
str += `\r\n${line}\r\n`;
|
|
48
|
+
} else {
|
|
49
|
+
str += `${line}\r\n`;
|
|
50
|
+
}
|
|
51
|
+
return str;
|
|
52
|
+
});
|
|
53
|
+
return str;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function downloadJson(tableData, table, downloadFileName) {
|
|
57
|
+
const { columns = [] } = table;
|
|
58
|
+
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
59
|
+
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
60
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
61
|
+
const keysToInclude = columns.filter(({ dataField }) => dataField)
|
|
62
|
+
.map(({ dataField }) => dataField);
|
|
63
|
+
const headers = columns.filter(({ dataField }) => dataField).map(({ header }) => header);
|
|
64
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
65
|
+
const exportData = new Blob([csv], { type: 'text/csv' });
|
|
66
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
67
|
+
let tempLink = '';
|
|
68
|
+
tempLink = document.createElement('a');
|
|
69
|
+
tempLink.setAttribute('href', JsonURL);
|
|
70
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
71
|
+
document.body.appendChild(tempLink);
|
|
72
|
+
tempLink.click();
|
|
73
|
+
document.body.removeChild(tempLink);
|
|
74
|
+
}
|