@bento-core/table 1.0.0-c3dc.3 → 1.0.0-c3dc.30
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 +9 -11
- package/dist/TableView.js +7 -4
- package/dist/assets/cpi_icon.svg +22 -0
- package/dist/assets/downArrow.svg +3 -0
- package/dist/assets/leftArrow.svg +3 -0
- package/dist/assets/rightArrow.svg +3 -0
- package/dist/body/CustomTblBody.js +9 -4
- package/dist/body/DisplayBodyCell.js +18 -3
- package/dist/body/components/CPIModal.js +210 -0
- package/dist/body/components/CPIView.js +115 -0
- package/dist/body/components/CustomLinkView.js +1 -1
- package/dist/body/components/ModalStyle.js +121 -0
- package/dist/header/ActionHeaderCell.js +2 -1
- package/dist/header/CustomCell.js +8 -5
- package/dist/header/CustomTblHeader.js +3 -1
- package/dist/header/components/CheckBoxView.js +3 -2
- package/dist/pagination/CustomPagination.js +84 -28
- package/dist/toolbar/DownloadButtonView.js +152 -45
- package/dist/util/Types.js +8 -2
- package/dist/util/downloadTable.js +72 -37
- package/package.json +2 -2
- package/src/ExtendedView.js +34 -33
- package/src/TableView.js +11 -8
- package/src/assets/cpi_icon.svg +22 -0
- package/src/assets/downArrow.svg +3 -0
- package/src/assets/leftArrow.svg +3 -0
- package/src/assets/rightArrow.svg +3 -0
- package/src/body/CustomTblBody.js +6 -1
- package/src/body/DisplayBodyCell.js +23 -0
- package/src/body/components/CPIModal.js +245 -0
- package/src/body/components/CPIView.js +133 -0
- package/src/body/components/CustomLinkView.js +1 -1
- package/src/body/components/ModalStyle.js +115 -0
- package/src/header/ActionHeaderCell.js +1 -0
- package/src/header/CustomCell.js +6 -3
- package/src/header/CustomTblHeader.js +3 -1
- package/src/header/components/CheckBoxView.js +2 -1
- package/src/pagination/CustomPagination.js +97 -40
- package/src/toolbar/DownloadButtonView.js +168 -55
- package/src/util/Types.js +4 -0
- package/src/util/downloadTable.js +51 -17
|
@@ -25,7 +25,8 @@ const ActionHeaderCell = _ref => {
|
|
|
25
25
|
return /*#__PURE__*/_react.default.createElement(_CheckBoxView.default, {
|
|
26
26
|
includeSelectedIds: includeSelectedIds,
|
|
27
27
|
toggleSelectAll: toggleSelectAll,
|
|
28
|
-
Ids: Ids
|
|
28
|
+
Ids: Ids,
|
|
29
|
+
rows: rows
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
if (_Types.cellTypes.DELETE === cellType) {
|
|
@@ -22,13 +22,15 @@ const CustomHeaderCell = _ref => {
|
|
|
22
22
|
sortBy,
|
|
23
23
|
column,
|
|
24
24
|
components = {},
|
|
25
|
-
toggleSort
|
|
25
|
+
toggleSort,
|
|
26
|
+
style
|
|
26
27
|
} = _ref;
|
|
27
28
|
const {
|
|
28
29
|
dataField,
|
|
29
30
|
tooltipText,
|
|
30
31
|
header,
|
|
31
32
|
headerType,
|
|
33
|
+
sortField,
|
|
32
34
|
customColHeaderRender,
|
|
33
35
|
sortable
|
|
34
36
|
} = column;
|
|
@@ -59,11 +61,12 @@ const CustomHeaderCell = _ref => {
|
|
|
59
61
|
return /*#__PURE__*/_react.default.createElement(_TableCell.default, {
|
|
60
62
|
scope: "col",
|
|
61
63
|
active: sortBy === dataField,
|
|
62
|
-
direction: sortOrder
|
|
64
|
+
direction: sortOrder,
|
|
65
|
+
style: style
|
|
63
66
|
}, /*#__PURE__*/_react.default.createElement(Tooltip, null, /*#__PURE__*/_react.default.createElement(_TableSortLabel.default, {
|
|
64
|
-
active: sortBy === dataField,
|
|
65
|
-
hideSortIcon: sortBy !== dataField,
|
|
66
|
-
direction: sortBy === dataField ? sortOrder : 'asc',
|
|
67
|
+
active: sortBy === (sortField ? sortField : dataField),
|
|
68
|
+
hideSortIcon: sortBy !== (sortField ? sortField : dataField),
|
|
69
|
+
direction: sortBy === (sortField ? sortField : dataField) ? sortOrder : 'asc',
|
|
67
70
|
onClick: toggleSort
|
|
68
71
|
}, headerType === _Types.headerTypes.CUSTOM_ELEM && customColHeaderRender ? customColHeaderRender(column) : header)));
|
|
69
72
|
};
|
|
@@ -66,7 +66,9 @@ const CustomTableHeader = _ref => {
|
|
|
66
66
|
column: column,
|
|
67
67
|
sortBy: sortBy,
|
|
68
68
|
sortOrder: sortOrder,
|
|
69
|
-
toggleSort: () =>
|
|
69
|
+
toggleSort: () => {
|
|
70
|
+
sortByColumn(column.sortField ? column.sortField : column.dataField, sortOrder);
|
|
71
|
+
}
|
|
70
72
|
});
|
|
71
73
|
}))));
|
|
72
74
|
};
|
|
@@ -17,7 +17,8 @@ const CheckboxView = _ref => {
|
|
|
17
17
|
let {
|
|
18
18
|
includeSelectedIds,
|
|
19
19
|
toggleSelectAll,
|
|
20
|
-
Ids
|
|
20
|
+
Ids,
|
|
21
|
+
rows
|
|
21
22
|
} = _ref;
|
|
22
23
|
return /*#__PURE__*/_react.default.createElement(_core.TableCell, {
|
|
23
24
|
padding: "checkbox"
|
|
@@ -29,7 +30,7 @@ const CheckboxView = _ref => {
|
|
|
29
30
|
color: "primary",
|
|
30
31
|
indeterminate: includeSelectedIds,
|
|
31
32
|
checked: includeSelectedIds,
|
|
32
|
-
onChange: event => toggleSelectAll(event, Ids, includeSelectedIds)
|
|
33
|
+
onChange: event => toggleSelectAll(event, Ids, includeSelectedIds, rows)
|
|
33
34
|
})));
|
|
34
35
|
};
|
|
35
36
|
var _default = CheckboxView;
|
|
@@ -7,38 +7,58 @@ 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
|
|
10
|
+
var _icons = require("@material-ui/icons");
|
|
11
|
+
var _rightArrow = _interopRequireDefault(require("../assets/rightArrow.svg"));
|
|
12
|
+
var _leftArrow = _interopRequireDefault(require("../assets/leftArrow.svg"));
|
|
11
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
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; }
|
|
13
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; }
|
|
14
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; }
|
|
15
17
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
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); }
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
toolbar: {
|
|
24
|
-
minHeight: '45px'
|
|
25
|
-
}
|
|
19
|
+
const useStyles = (0, _core.makeStyles)(() => ({
|
|
20
|
+
paginationRoot: {
|
|
21
|
+
display: 'flex',
|
|
22
|
+
justifyContent: 'flex-end',
|
|
23
|
+
// Moves pagination to the right
|
|
24
|
+
paddingRight: '10px' // Optional spacing
|
|
26
25
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
|
|
27
|
+
actionsContainer: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
justifyContent: 'flex-end' // Align pagination buttons to the right
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
const defaultTheme = (0, _core.createMuiTheme)({
|
|
34
|
+
overrides: {
|
|
35
|
+
MuiTablePagination: {
|
|
36
|
+
root: {
|
|
37
|
+
paddingRight: '50px',
|
|
38
|
+
width: '100%'
|
|
39
|
+
},
|
|
40
|
+
toolbar: {
|
|
41
|
+
minHeight: '45px',
|
|
42
|
+
display: 'flex',
|
|
43
|
+
alignItems: 'center'
|
|
44
|
+
}
|
|
31
45
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
MuiTypography: {
|
|
47
|
+
body2: {
|
|
48
|
+
fontSize: '14px',
|
|
49
|
+
textTransform: 'uppercase'
|
|
50
|
+
},
|
|
51
|
+
root: {
|
|
52
|
+
fontSize: '14px'
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
MuiIconButton: {
|
|
56
|
+
root: {
|
|
57
|
+
padding: '2px'
|
|
58
|
+
}
|
|
39
59
|
}
|
|
40
60
|
}
|
|
41
|
-
};
|
|
61
|
+
});
|
|
42
62
|
const CustomPagination = _ref => {
|
|
43
63
|
let {
|
|
44
64
|
rowsPerPageOptions,
|
|
@@ -49,12 +69,15 @@ const CustomPagination = _ref => {
|
|
|
49
69
|
onRowsPerPageChange,
|
|
50
70
|
customTheme = {}
|
|
51
71
|
} = _ref;
|
|
72
|
+
const classes = useStyles();
|
|
52
73
|
return /*#__PURE__*/_react.default.createElement(_core.ThemeProvider, {
|
|
53
|
-
theme: (0, _core.
|
|
54
|
-
overrides: _objectSpread(_objectSpread({}, defaultTheme), customTheme)
|
|
74
|
+
theme: (0, _core.createMuiTheme)({
|
|
75
|
+
overrides: _objectSpread(_objectSpread({}, defaultTheme.overrides), customTheme)
|
|
55
76
|
})
|
|
56
77
|
}, /*#__PURE__*/_react.default.createElement(_core.TablePagination, {
|
|
57
|
-
labelRowsPerPage: "
|
|
78
|
+
labelRowsPerPage: /*#__PURE__*/_react.default.createElement("span", {
|
|
79
|
+
id: "rows-per-page-label"
|
|
80
|
+
}, "Rows per page:"),
|
|
58
81
|
rowsPerPageOptions: rowsPerPageOptions,
|
|
59
82
|
component: "div",
|
|
60
83
|
count: count,
|
|
@@ -63,11 +86,44 @@ const CustomPagination = _ref => {
|
|
|
63
86
|
onPageChange: onPageChange,
|
|
64
87
|
onRowsPerPageChange: onRowsPerPageChange,
|
|
65
88
|
SelectProps: {
|
|
66
|
-
IconComponent:
|
|
89
|
+
IconComponent: _icons.ArrowDropDown,
|
|
67
90
|
inputProps: {
|
|
68
|
-
'aria-label': 'Selection dropdown for displaying the number of results per page'
|
|
91
|
+
'aria-label': 'Selection dropdown for displaying the number of results per page',
|
|
92
|
+
'aria-labelledby': 'rows-per-page-label',
|
|
93
|
+
style: {
|
|
94
|
+
visibility: 'hidden'
|
|
95
|
+
}
|
|
69
96
|
}
|
|
70
|
-
}
|
|
97
|
+
},
|
|
98
|
+
nextIconButtonProps: {
|
|
99
|
+
'aria-label': 'Next page'
|
|
100
|
+
},
|
|
101
|
+
backIconButtonProps: {
|
|
102
|
+
'aria-label': 'Previous page'
|
|
103
|
+
},
|
|
104
|
+
ActionsComponent: () => /*#__PURE__*/_react.default.createElement("div", {
|
|
105
|
+
className: classes.actionsContainer
|
|
106
|
+
}, /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
107
|
+
onClick: event => onPageChange(event, page - 1),
|
|
108
|
+
disabled: page === 0,
|
|
109
|
+
"aria-label": "Previous page"
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
111
|
+
src: _leftArrow.default,
|
|
112
|
+
style: {
|
|
113
|
+
opacity: page === 0 ? 0.2 : 1
|
|
114
|
+
},
|
|
115
|
+
alt: "Left Arrow"
|
|
116
|
+
})), /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
117
|
+
onClick: event => onPageChange(event, page + 1),
|
|
118
|
+
disabled: page >= Math.ceil(count / rowsPerPage) - 1,
|
|
119
|
+
"aria-label": "Next page"
|
|
120
|
+
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
121
|
+
src: _rightArrow.default,
|
|
122
|
+
style: {
|
|
123
|
+
opacity: page >= Math.ceil(count / rowsPerPage) - 1 ? 0.2 : 1
|
|
124
|
+
},
|
|
125
|
+
alt: "Right Arrow"
|
|
126
|
+
})))
|
|
71
127
|
}));
|
|
72
128
|
};
|
|
73
129
|
CustomPagination.propTypes = {
|
|
@@ -7,8 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _client = require("@apollo/client");
|
|
9
9
|
var _core = require("@material-ui/core");
|
|
10
|
+
var _KeyboardArrowDownOutlined = _interopRequireDefault(require("@material-ui/icons/KeyboardArrowDownOutlined"));
|
|
10
11
|
var _icons = require("@material-ui/icons");
|
|
11
12
|
var _downloadTable = require("../util/downloadTable");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
14
|
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
15
|
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
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,43 +18,57 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
18
|
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
19
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
20
|
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
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
21
|
+
// const downloadButtonStyle = {
|
|
22
|
+
// color: '#d1d2d3',
|
|
23
|
+
// marginTop: '7px',
|
|
24
|
+
// };
|
|
23
25
|
|
|
24
|
-
// Default style for Download Button with Text.
|
|
25
|
-
const DEFAULT_BUTTON_STYLE = {
|
|
26
|
-
width: '223px',
|
|
27
|
-
height: '41px',
|
|
28
|
-
borderRadius: '5px',
|
|
29
|
-
backgroundColor: '#2A6E93',
|
|
30
|
-
color: '#fff',
|
|
31
|
-
marginTop: '10px',
|
|
32
|
-
fontFamily: 'poppins',
|
|
33
|
-
'& #cloudIcon': {
|
|
34
|
-
margin: '10px',
|
|
35
|
-
marginTop: '6px'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
26
|
const DownloadButton = _ref => {
|
|
39
27
|
let {
|
|
40
28
|
count,
|
|
41
29
|
queryVariables,
|
|
42
|
-
table
|
|
43
|
-
buttonConfig = {},
|
|
44
|
-
isIcon = false
|
|
30
|
+
table
|
|
45
31
|
} = _ref;
|
|
32
|
+
const [listDisplay, setListDisplay] = (0, _react.useState)('none');
|
|
33
|
+
const dropdownSelection = (0, _react.useRef)(null);
|
|
34
|
+
const useOutsideAlerter = ref => {
|
|
35
|
+
(0, _react.useEffect)(() => {
|
|
36
|
+
function handleClickOutside(event) {
|
|
37
|
+
if (!(event.target.getAttribute('id') && event.target.getAttribute('id').includes('dropdownListItem'))) {
|
|
38
|
+
setListDisplay('none');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
44
|
+
};
|
|
45
|
+
}, [ref]);
|
|
46
|
+
};
|
|
47
|
+
useOutsideAlerter(dropdownSelection);
|
|
46
48
|
if (table.paginationAPIField === 'filesInList') {
|
|
47
49
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const client = (0, _client.useApolloClient)();
|
|
52
|
+
function cleanData(result) {
|
|
53
|
+
function hasHTMLTags(str) {
|
|
54
|
+
const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
|
|
55
|
+
return htmlTagPattern.test(str);
|
|
56
|
+
}
|
|
57
|
+
const cleanedResult = result.map(res => {
|
|
58
|
+
const newObj = {};
|
|
59
|
+
Object.keys(res).forEach(key => {
|
|
60
|
+
if (hasHTMLTags(res[key])) {
|
|
61
|
+
const div = document.createElement('div');
|
|
62
|
+
div.innerHTML = res[key];
|
|
63
|
+
newObj[key] = div.textContent || div.innerText || res[key];
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = res[key];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return newObj;
|
|
53
69
|
});
|
|
70
|
+
return cleanedResult;
|
|
54
71
|
}
|
|
55
|
-
const client = (0, _client.useApolloClient)();
|
|
56
72
|
async function downloadSCSVFile() {
|
|
57
73
|
const {
|
|
58
74
|
query,
|
|
@@ -62,7 +78,30 @@ const DownloadButton = _ref => {
|
|
|
62
78
|
query,
|
|
63
79
|
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
64
80
|
page: 0,
|
|
65
|
-
first: 10000
|
|
81
|
+
first: 10000,
|
|
82
|
+
order_by: table.sortBy,
|
|
83
|
+
sort_direction: table.sortOrder
|
|
84
|
+
})
|
|
85
|
+
}).then(response => {
|
|
86
|
+
if (paginationAPIField && response && response.data) {
|
|
87
|
+
return response.data[paginationAPIField];
|
|
88
|
+
}
|
|
89
|
+
return response.data;
|
|
90
|
+
});
|
|
91
|
+
(0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'csv');
|
|
92
|
+
}
|
|
93
|
+
async function downloadJsonFile() {
|
|
94
|
+
const {
|
|
95
|
+
query,
|
|
96
|
+
paginationAPIField
|
|
97
|
+
} = table;
|
|
98
|
+
const result = await client.query({
|
|
99
|
+
query,
|
|
100
|
+
variables: _objectSpread(_objectSpread({}, queryVariables), {}, {
|
|
101
|
+
page: 0,
|
|
102
|
+
first: 10000,
|
|
103
|
+
order_by: table.sortBy,
|
|
104
|
+
sort_direction: table.sortOrder
|
|
66
105
|
})
|
|
67
106
|
}).then(response => {
|
|
68
107
|
if (paginationAPIField && response && response.data) {
|
|
@@ -70,29 +109,97 @@ const DownloadButton = _ref => {
|
|
|
70
109
|
}
|
|
71
110
|
return response.data;
|
|
72
111
|
});
|
|
73
|
-
(0, _downloadTable.
|
|
112
|
+
(0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'json');
|
|
74
113
|
}
|
|
75
114
|
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
76
115
|
downloadSCSVFile();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
116
|
+
setListDisplay('none');
|
|
117
|
+
}, [queryVariables, table]);
|
|
118
|
+
const downloadTableJson = (0, _react.useCallback)(() => {
|
|
119
|
+
downloadJsonFile();
|
|
120
|
+
setListDisplay('none');
|
|
121
|
+
}, [queryVariables, table]);
|
|
122
|
+
const handleClickButton = () => {
|
|
123
|
+
if (listDisplay === 'none') {
|
|
124
|
+
setListDisplay('block');
|
|
125
|
+
} else {
|
|
126
|
+
setListDisplay('none');
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const useStyles = (0, _core.makeStyles)({
|
|
130
|
+
dropdown: {
|
|
131
|
+
width: '60px',
|
|
132
|
+
height: '25px',
|
|
133
|
+
marginTop: '8px',
|
|
134
|
+
paddingLeft: '5px',
|
|
135
|
+
border: '0.75px solid #606060',
|
|
136
|
+
borderRadius: '5px',
|
|
137
|
+
display: 'inline-block',
|
|
138
|
+
position: 'relative',
|
|
139
|
+
alignSelf: 'center'
|
|
140
|
+
},
|
|
141
|
+
dropdownList: {
|
|
142
|
+
display: 'block',
|
|
143
|
+
position: 'absolute',
|
|
144
|
+
width: '60px',
|
|
145
|
+
marginTop: '3px',
|
|
146
|
+
marginLeft: '-5px',
|
|
147
|
+
overflow: 'auto',
|
|
148
|
+
zIndex: '20',
|
|
149
|
+
border: '1.5px solid #41545E',
|
|
150
|
+
borderRadius: '5px',
|
|
151
|
+
background: '#ffffff'
|
|
152
|
+
},
|
|
153
|
+
dropdownListItem: {
|
|
154
|
+
padding: '2px 4px',
|
|
155
|
+
font: 'Poppins',
|
|
156
|
+
fontSize: '14px',
|
|
157
|
+
fontWeight: 400,
|
|
158
|
+
lineHeight: '21px',
|
|
159
|
+
'&:hover': {
|
|
160
|
+
background: '#D7D7D7',
|
|
161
|
+
cursor: 'pointer'
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
arrowdownIcon: {
|
|
165
|
+
marginLeft: '5px',
|
|
166
|
+
fill: '#606060'
|
|
167
|
+
},
|
|
168
|
+
arrowdownIconDisabled: {
|
|
169
|
+
marginLeft: '5px',
|
|
170
|
+
fill: '#00000042'
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const classes = useStyles();
|
|
174
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
175
|
+
className: classes.dropdown
|
|
176
|
+
}, /*#__PURE__*/_react.default.createElement(_core.Tooltip, {
|
|
177
|
+
title: table.downloadButtonTooltipText || 'Download filtered results'
|
|
178
|
+
}, count !== 0 ? /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
179
|
+
onClick: handleClickButton,
|
|
92
180
|
style: {
|
|
93
|
-
|
|
181
|
+
padding: '0'
|
|
94
182
|
}
|
|
95
|
-
})
|
|
183
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
|
|
184
|
+
className: classes.arrowdownIcon
|
|
185
|
+
})) : /*#__PURE__*/_react.default.createElement(_core.IconButton, {
|
|
186
|
+
disabled: true
|
|
187
|
+
}, /*#__PURE__*/_react.default.createElement(_icons.CloudDownload, null), /*#__PURE__*/_react.default.createElement(_KeyboardArrowDownOutlined.default, {
|
|
188
|
+
className: classes.arrowdownIconDisabled
|
|
189
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
190
|
+
className: classes.dropdownList,
|
|
191
|
+
style: {
|
|
192
|
+
display: listDisplay
|
|
193
|
+
}
|
|
194
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
195
|
+
id: "dropdownListItemCSV",
|
|
196
|
+
className: classes.dropdownListItem,
|
|
197
|
+
onClick: downloadTableCSV
|
|
198
|
+
}, "CSV"), /*#__PURE__*/_react.default.createElement("div", {
|
|
199
|
+
id: "dropdownListItemJSON",
|
|
200
|
+
className: classes.dropdownListItem,
|
|
201
|
+
onClick: downloadTableJson
|
|
202
|
+
}, "JSON")));
|
|
96
203
|
};
|
|
97
204
|
var _default = DownloadButton;
|
|
98
205
|
exports.default = _default;
|
package/dist/util/Types.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.cellStyles = exports.actionCellTypes = exports.TRANSFORM = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.EXPAND = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.CHECKBOX = void 0;
|
|
6
|
+
exports.headerTypes = exports.dataFormatTypes = exports.cellTypes = exports.cellStyles = exports.actionCellTypes = exports.TRANSFORM = exports.LINK = exports.FORMAT_DATA_CELLS = exports.FORMAT_DATA = exports.FORMAT_BYTES = exports.EXPAND = exports.DISPLAY = exports.DELETE = exports.DEFAULT = exports.ComponentTypes = exports.CUSTOM_ELEM = exports.CPI = exports.COMMA = exports.CHECKBOX = void 0;
|
|
7
7
|
const CHECKBOX = 'CHECKBOX';
|
|
8
8
|
exports.CHECKBOX = CHECKBOX;
|
|
9
9
|
const DELETE = 'DELETE';
|
|
@@ -24,6 +24,10 @@ const TRANSFORM = 'TRANSFORM';
|
|
|
24
24
|
exports.TRANSFORM = TRANSFORM;
|
|
25
25
|
const EXPAND = 'EXPAND';
|
|
26
26
|
exports.EXPAND = EXPAND;
|
|
27
|
+
const COMMA = 'COMMA';
|
|
28
|
+
exports.COMMA = COMMA;
|
|
29
|
+
const CPI = 'CPI';
|
|
30
|
+
exports.CPI = CPI;
|
|
27
31
|
const cellTypes = {
|
|
28
32
|
CUSTOM_ELEM,
|
|
29
33
|
LINK,
|
|
@@ -31,7 +35,9 @@ const cellTypes = {
|
|
|
31
35
|
CHECKBOX,
|
|
32
36
|
DELETE,
|
|
33
37
|
DEFAULT,
|
|
34
|
-
FORMAT_DATA
|
|
38
|
+
FORMAT_DATA,
|
|
39
|
+
COMMA,
|
|
40
|
+
CPI
|
|
35
41
|
};
|
|
36
42
|
exports.cellTypes = cellTypes;
|
|
37
43
|
const cellStyles = {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertToCSV = convertToCSV;
|
|
7
7
|
exports.createFileName = createFileName;
|
|
8
|
-
exports.
|
|
8
|
+
exports.downloadData = downloadData;
|
|
9
9
|
var _Dataformat = require("./Dataformat");
|
|
10
10
|
var _Types = require("./Types");
|
|
11
11
|
function createFileName(fileName) {
|
|
@@ -32,7 +32,7 @@ function createFileName(fileName) {
|
|
|
32
32
|
if (seconds < 10) {
|
|
33
33
|
seconds = "0".concat(seconds);
|
|
34
34
|
}
|
|
35
|
-
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds
|
|
35
|
+
return "".concat(fileName, " ").concat(todaysDate, " ").concat(hours, "-").concat(minutes, "-").concat(seconds);
|
|
36
36
|
}
|
|
37
37
|
function convertToCSV(jsonse, keysToInclude, header) {
|
|
38
38
|
const objArray = jsonse;
|
|
@@ -51,8 +51,11 @@ function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
51
51
|
} else {
|
|
52
52
|
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
53
53
|
}
|
|
54
|
+
} else if (keyName === 'participant') {
|
|
55
|
+
line += entry[keyName].participant_id;
|
|
54
56
|
} else {
|
|
55
|
-
|
|
57
|
+
const newLine = entry[keyName] !== null ? String(entry[keyName]).replace(/"/g, '""') : '';
|
|
58
|
+
line += "\"".concat(newLine, "\"");
|
|
56
59
|
}
|
|
57
60
|
return line;
|
|
58
61
|
});
|
|
@@ -66,49 +69,81 @@ function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
66
69
|
});
|
|
67
70
|
return str;
|
|
68
71
|
}
|
|
69
|
-
function
|
|
72
|
+
function downloadData(tableData, table, downloadFileName) {
|
|
73
|
+
let format = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'csv';
|
|
70
74
|
const {
|
|
71
75
|
columns = []
|
|
72
76
|
} = table;
|
|
73
77
|
const filterColumns = columns.filter(_ref => {
|
|
74
78
|
let {
|
|
75
|
-
cellType
|
|
79
|
+
cellType,
|
|
80
|
+
doNotDownload
|
|
76
81
|
} = _ref;
|
|
77
|
-
return !_Types.actionCellTypes.includes(cellType);
|
|
82
|
+
return !_Types.actionCellTypes.includes(cellType) && !doNotDownload;
|
|
78
83
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} = _ref3;
|
|
90
|
-
return dataField;
|
|
91
|
-
});
|
|
92
|
-
const headers = columns.filter(_ref4 => {
|
|
93
|
-
let {
|
|
94
|
-
dataField
|
|
95
|
-
} = _ref4;
|
|
96
|
-
return dataField;
|
|
97
|
-
}).map(_ref5 => {
|
|
98
|
-
let {
|
|
99
|
-
header,
|
|
100
|
-
downloadHeader
|
|
101
|
-
} = _ref5;
|
|
102
|
-
return downloadHeader || header;
|
|
84
|
+
let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
85
|
+
formatDataVal = formatDataVal.map(item => {
|
|
86
|
+
const updatedItem = {};
|
|
87
|
+
filterColumns.forEach(_ref2 => {
|
|
88
|
+
let {
|
|
89
|
+
dataField
|
|
90
|
+
} = _ref2;
|
|
91
|
+
updatedItem[dataField] = item[dataField];
|
|
92
|
+
});
|
|
93
|
+
return updatedItem;
|
|
103
94
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
let fileContent;
|
|
96
|
+
let fileType;
|
|
97
|
+
if (format === 'json') {
|
|
98
|
+
filterColumns.forEach(column => {
|
|
99
|
+
const mapData = data => {
|
|
100
|
+
var _dataObject$column$da;
|
|
101
|
+
const dataObject = data;
|
|
102
|
+
if (dataObject !== null && dataObject !== void 0 && (_dataObject$column$da = dataObject[column.dataField]) !== null && _dataObject$column$da !== void 0 && _dataObject$column$da.participant_id) {
|
|
103
|
+
var _dataObject$column$da2;
|
|
104
|
+
dataObject[column.dataField] = dataObject === null || dataObject === void 0 ? void 0 : (_dataObject$column$da2 = dataObject[column.dataField]) === null || _dataObject$column$da2 === void 0 ? void 0 : _dataObject$column$da2.participant_id;
|
|
105
|
+
}
|
|
106
|
+
return dataObject;
|
|
107
|
+
};
|
|
108
|
+
formatDataVal = formatDataVal.map(mapData);
|
|
109
|
+
formatDataVal = JSON.parse(JSON.stringify(formatDataVal).split("\"".concat(column.dataField, "\":")).join("\"".concat(column.header, "\":")));
|
|
110
|
+
});
|
|
111
|
+
fileContent = JSON.stringify(formatDataVal);
|
|
112
|
+
fileType = 'application/json';
|
|
113
|
+
} else {
|
|
114
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
115
|
+
const keysToInclude = filterColumns.filter(_ref3 => {
|
|
116
|
+
let {
|
|
117
|
+
dataField
|
|
118
|
+
} = _ref3;
|
|
119
|
+
return dataField;
|
|
120
|
+
}).map(_ref4 => {
|
|
121
|
+
let {
|
|
122
|
+
dataField
|
|
123
|
+
} = _ref4;
|
|
124
|
+
return dataField;
|
|
125
|
+
});
|
|
126
|
+
const headers = filterColumns.filter(_ref5 => {
|
|
127
|
+
let {
|
|
128
|
+
dataField
|
|
129
|
+
} = _ref5;
|
|
130
|
+
return dataField;
|
|
131
|
+
}).map(_ref6 => {
|
|
132
|
+
let {
|
|
133
|
+
header,
|
|
134
|
+
downloadHeader
|
|
135
|
+
} = _ref6;
|
|
136
|
+
return downloadHeader || header;
|
|
137
|
+
});
|
|
138
|
+
fileContent = convertToCSV(jsonse, keysToInclude, headers);
|
|
139
|
+
fileType = 'text/csv';
|
|
140
|
+
}
|
|
141
|
+
const exportData = new Blob([fileContent], {
|
|
142
|
+
type: fileType
|
|
107
143
|
});
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
tempLink
|
|
111
|
-
tempLink.setAttribute('href', JsonURL);
|
|
144
|
+
const fileURL = window.URL.createObjectURL(exportData);
|
|
145
|
+
const tempLink = document.createElement('a');
|
|
146
|
+
tempLink.setAttribute('href', fileURL);
|
|
112
147
|
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
113
148
|
document.body.appendChild(tempLink);
|
|
114
149
|
tempLink.click();
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/table",
|
|
3
|
-
"version": "1.0.0-c3dc.
|
|
3
|
+
"version": "1.0.0-c3dc.30",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "
|
|
6
|
+
"build": "cross-env-shell rm -rf dist && NODE_ENV=production BABEL_ENV=es babel src --out-dir dist --copy-files",
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
8
|
"lint": "eslint src"
|
|
9
9
|
},
|