@bento-core/table 1.0.0-alpha.0 → 1.0.1-CDS.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 +13 -3
- package/dist/body/ActionBodyCell.js +4 -1
- package/dist/body/CustomTblBody.js +6 -2
- package/dist/body/components/CheckBoxView.js +7 -3
- package/dist/body/components/DeleteCellView.js +6 -2
- package/dist/header/ActionHeaderCell.js +3 -1
- package/dist/header/ColumnGrouping.js +52 -0
- package/dist/header/CustomCell.js +2 -1
- package/dist/header/CustomTblHeader.js +10 -3
- package/dist/header/components/DeleteCellView.js +11 -6
- package/dist/header/components/RemoveAllDialog.js +3 -1
- package/dist/toolbar/DownloadButtonView.js +57 -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 +7 -2
- package/src/ExtendedView.js +35 -25
- package/src/TableView.js +10 -0
- package/src/body/ActionBodyCell.js +3 -0
- package/src/body/CustomTblBody.js +5 -1
- package/src/body/components/CheckBoxView.js +23 -9
- package/src/body/components/DeleteCellView.js +28 -16
- package/src/header/ActionHeaderCell.js +2 -0
- package/src/header/ColumnGrouping.js +55 -0
- package/src/header/CustomCell.js +1 -0
- package/src/header/CustomTblHeader.js +5 -0
- package/src/header/components/DeleteCellView.js +41 -26
- package/src/header/components/RemoveAllDialog.js +2 -0
- package/src/toolbar/DownloadButtonView.js +57 -3
- package/src/toolbar/ManageColumnView.js +9 -6
- package/src/util/Dataformat.js +25 -0
- package/src/util/downloadTable.js +74 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento-core/table",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-CDS.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@bento-core/util": "^1.0.0"
|
|
17
|
+
},
|
|
15
18
|
"peerDependencies": {
|
|
19
|
+
"@apollo/client": "^3.6.9",
|
|
16
20
|
"@material-ui/core": "^4.12.4",
|
|
17
21
|
"@material-ui/icons": "^4.9.1",
|
|
22
|
+
"clsx": "^1.2.1",
|
|
18
23
|
"prop-types": "^15.7.2",
|
|
19
24
|
"react": "^17.0.2",
|
|
20
25
|
"react-dom": "^17.0.0",
|
|
@@ -22,5 +27,5 @@
|
|
|
22
27
|
},
|
|
23
28
|
"author": "CTOS Bento Team",
|
|
24
29
|
"license": "ISC",
|
|
25
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "6bf5d5f8401ae0e964127a5d8880ef633732a0f1"
|
|
26
31
|
}
|
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,
|
|
@@ -35,16 +36,23 @@ const TableView = ({
|
|
|
35
36
|
totalRowCount,
|
|
36
37
|
onSortByColumn,
|
|
37
38
|
onColumnViewChange,
|
|
39
|
+
onDeleteRow,
|
|
40
|
+
onDeleteAllFiles,
|
|
38
41
|
themeConfig = {},
|
|
42
|
+
queryVariables,
|
|
43
|
+
server,
|
|
39
44
|
}) => (
|
|
40
45
|
<>
|
|
41
46
|
<ExtendedView
|
|
42
47
|
table={table}
|
|
48
|
+
rows={totalRows}
|
|
49
|
+
server={server}
|
|
43
50
|
onColumnViewChange={onColumnViewChange}
|
|
44
51
|
onRowsPerPageChange={onRowsPerPageChange}
|
|
45
52
|
onPageChange={onPageChange}
|
|
46
53
|
numSelected={table?.selectedRows?.length || 0}
|
|
47
54
|
customTheme={themeConfig.extendedView}
|
|
55
|
+
queryVariables={queryVariables}
|
|
48
56
|
/>
|
|
49
57
|
<CustomToolbar
|
|
50
58
|
numSelected={table?.selectedRows?.length || 0}
|
|
@@ -62,6 +70,7 @@ const TableView = ({
|
|
|
62
70
|
rows={tableRows}
|
|
63
71
|
count={totalRowCount}
|
|
64
72
|
toggleSelectAll={onToggleSelectAll}
|
|
73
|
+
onDeleteAllFiles={onDeleteAllFiles}
|
|
65
74
|
sortByColumn={onSortByColumn}
|
|
66
75
|
/>
|
|
67
76
|
<CustomTableBody
|
|
@@ -69,6 +78,7 @@ const TableView = ({
|
|
|
69
78
|
rows={tableRows}
|
|
70
79
|
table={table}
|
|
71
80
|
onRowSelectChange={onRowSelectChange}
|
|
81
|
+
onDeleteRow={onDeleteRow}
|
|
72
82
|
/>
|
|
73
83
|
</Table>
|
|
74
84
|
</CustomTableContainer>
|
|
@@ -7,6 +7,7 @@ import { cellTypes } from '../util/Types';
|
|
|
7
7
|
const ActionCell = ({
|
|
8
8
|
row,
|
|
9
9
|
onRowSelectChange,
|
|
10
|
+
onDeleteRow,
|
|
10
11
|
column,
|
|
11
12
|
}) => {
|
|
12
13
|
const { cellType } = column;
|
|
@@ -15,6 +16,7 @@ const ActionCell = ({
|
|
|
15
16
|
return (
|
|
16
17
|
<CheckboxView
|
|
17
18
|
row={row}
|
|
19
|
+
column={column}
|
|
18
20
|
onRowSelectChange={onRowSelectChange}
|
|
19
21
|
/>
|
|
20
22
|
);
|
|
@@ -25,6 +27,7 @@ const ActionCell = ({
|
|
|
25
27
|
<DeleteCellView
|
|
26
28
|
row={row}
|
|
27
29
|
column={column}
|
|
30
|
+
onDeleteRow={onDeleteRow}
|
|
28
31
|
/>
|
|
29
32
|
);
|
|
30
33
|
}
|
|
@@ -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)
|
|
@@ -21,16 +22,18 @@ const CustomTableBody = ({
|
|
|
21
22
|
rows = [],
|
|
22
23
|
table,
|
|
23
24
|
onRowSelectChange,
|
|
25
|
+
onDeleteRow,
|
|
24
26
|
customTheme = {},
|
|
25
27
|
}) => {
|
|
26
28
|
const { columns } = table;
|
|
29
|
+
const formatRows = formatColumnValues(columns, rows);
|
|
27
30
|
const displayColunms = columns.filter((col) => col.display);
|
|
28
31
|
const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
|
|
29
32
|
|
|
30
33
|
return (
|
|
31
34
|
<ThemeProvider theme={themeConfig}>
|
|
32
35
|
<TableBody>
|
|
33
|
-
{
|
|
36
|
+
{formatRows
|
|
34
37
|
.map((row) => (
|
|
35
38
|
<TableRow>
|
|
36
39
|
{
|
|
@@ -43,6 +46,7 @@ const CustomTableBody = ({
|
|
|
43
46
|
row={row}
|
|
44
47
|
column={column}
|
|
45
48
|
onRowSelectChange={onRowSelectChange}
|
|
49
|
+
onDeleteRow={onDeleteRow}
|
|
46
50
|
/>
|
|
47
51
|
);
|
|
48
52
|
}
|
|
@@ -7,14 +7,28 @@ import {
|
|
|
7
7
|
const CheckboxView = ({
|
|
8
8
|
row,
|
|
9
9
|
onRowSelectChange,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
10
|
+
column,
|
|
11
|
+
}) => {
|
|
12
|
+
const { customCellRender } = column;
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{
|
|
16
|
+
customCellRender ? (
|
|
17
|
+
<>
|
|
18
|
+
{customCellRender(row, onRowSelectChange)}
|
|
19
|
+
</>
|
|
20
|
+
) : (
|
|
21
|
+
<TableCell padding="checkbox">
|
|
22
|
+
<Checkbox
|
|
23
|
+
disableRipple
|
|
24
|
+
onClick={(event) => onRowSelectChange(event, row)}
|
|
25
|
+
checked={row.isChecked}
|
|
26
|
+
/>
|
|
27
|
+
</TableCell>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
19
33
|
|
|
20
34
|
export default CheckboxView;
|
|
@@ -10,22 +10,34 @@ import {
|
|
|
10
10
|
const DeleteCellView = ({
|
|
11
11
|
column,
|
|
12
12
|
row,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
className="del_row_btn"
|
|
21
|
-
onClick={() => column.cellEventHandler(row)}
|
|
13
|
+
onDeleteRow,
|
|
14
|
+
}) => {
|
|
15
|
+
const { customCellRender } = column;
|
|
16
|
+
return (
|
|
17
|
+
<TableCell
|
|
18
|
+
scope="col"
|
|
19
|
+
className="delete_row"
|
|
22
20
|
>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
{
|
|
22
|
+
customCellRender ? (
|
|
23
|
+
<>
|
|
24
|
+
{customCellRender(row, onDeleteRow)}
|
|
25
|
+
</>
|
|
26
|
+
) : (
|
|
27
|
+
<IconButton
|
|
28
|
+
disableRipple
|
|
29
|
+
className="del_row_btn"
|
|
30
|
+
onClick={() => column.cellEventHandler(row)}
|
|
31
|
+
>
|
|
32
|
+
<DeleteOutlineIcon
|
|
33
|
+
className="del_row_btn_icon"
|
|
34
|
+
fontSize="small"
|
|
35
|
+
/>
|
|
36
|
+
</IconButton>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
</TableCell>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
30
42
|
|
|
31
43
|
export default DeleteCellView;
|
|
@@ -6,6 +6,7 @@ import DeleteCellView from './components/DeleteCellView';
|
|
|
6
6
|
const ActionHeaderCell = ({
|
|
7
7
|
includeSelectedIds,
|
|
8
8
|
toggleSelectAll,
|
|
9
|
+
onDeleteAllFiles,
|
|
9
10
|
Ids,
|
|
10
11
|
count,
|
|
11
12
|
rows,
|
|
@@ -29,6 +30,7 @@ const ActionHeaderCell = ({
|
|
|
29
30
|
rows={rows}
|
|
30
31
|
count={count}
|
|
31
32
|
column={column}
|
|
33
|
+
onDeleteAllFiles={onDeleteAllFiles}
|
|
32
34
|
/>
|
|
33
35
|
);
|
|
34
36
|
}
|
|
@@ -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,
|
|
@@ -21,12 +22,14 @@ const CustomTableHeader = ({
|
|
|
21
22
|
components = {},
|
|
22
23
|
customTheme = {},
|
|
23
24
|
count,
|
|
25
|
+
onDeleteAllFiles,
|
|
24
26
|
}) => {
|
|
25
27
|
const {
|
|
26
28
|
columns,
|
|
27
29
|
selectedRows = [],
|
|
28
30
|
sortBy,
|
|
29
31
|
sortOrder,
|
|
32
|
+
columnGroups,
|
|
30
33
|
} = table;
|
|
31
34
|
const Ids = rows.map((row) => row[table.dataKey]);
|
|
32
35
|
const includeSelectedIds = Ids.some((id) => selectedRows.includes(id));
|
|
@@ -40,6 +43,7 @@ const CustomTableHeader = ({
|
|
|
40
43
|
return (
|
|
41
44
|
<ThemeProvider theme={themeConfig}>
|
|
42
45
|
<TableHead>
|
|
46
|
+
<ColumnGrouping columnGroups={columnGroups} columns={columns} />
|
|
43
47
|
<TableRow>
|
|
44
48
|
{
|
|
45
49
|
displayColunms.map((column) => {
|
|
@@ -51,6 +55,7 @@ const CustomTableHeader = ({
|
|
|
51
55
|
<ActionHeaderCell
|
|
52
56
|
includeSelectedIds={includeSelectedIds}
|
|
53
57
|
toggleSelectAll={toggleSelectAll}
|
|
58
|
+
onDeleteAllFiles={onDeleteAllFiles}
|
|
54
59
|
Ids={Ids}
|
|
55
60
|
rows={rows}
|
|
56
61
|
count={count}
|
|
@@ -25,37 +25,52 @@ const TooltipContent = () => (
|
|
|
25
25
|
const DeleteCellView = ({
|
|
26
26
|
column,
|
|
27
27
|
count,
|
|
28
|
+
onDeleteAllFiles,
|
|
28
29
|
}) => {
|
|
29
30
|
const [displayDialog, setDisplay] = useState(false);
|
|
30
31
|
const toggleDialogDisplay = () => setDisplay(!displayDialog);
|
|
32
|
+
const { customColHeaderRender } = column;
|
|
31
33
|
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()}
|
|
34
|
+
<>
|
|
35
|
+
<TableCell
|
|
36
|
+
scope="col"
|
|
37
|
+
className="del_all_row"
|
|
44
38
|
>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
39
|
+
{
|
|
40
|
+
customColHeaderRender ? (
|
|
41
|
+
<>
|
|
42
|
+
{customColHeaderRender(toggleDialogDisplay)}
|
|
43
|
+
</>
|
|
44
|
+
) : (
|
|
45
|
+
<>
|
|
46
|
+
<Typography className="del_all_row_text">
|
|
47
|
+
Remove
|
|
48
|
+
</Typography>
|
|
49
|
+
<Tooltip
|
|
50
|
+
id="del_all_row_tooltip"
|
|
51
|
+
className="del_all_row_tooltip"
|
|
52
|
+
title={TooltipContent()}
|
|
53
|
+
renderComponent={TooltipContent()}
|
|
54
|
+
>
|
|
55
|
+
<IconButton aria-label="help" className="del_all_row_btn">
|
|
56
|
+
<ArrowDropDownIcon
|
|
57
|
+
className="del_all_row_btn_icon"
|
|
58
|
+
onClick={toggleDialogDisplay}
|
|
59
|
+
/>
|
|
60
|
+
</IconButton>
|
|
61
|
+
</Tooltip>
|
|
62
|
+
</>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
<RemoveAllDialogView
|
|
66
|
+
open={displayDialog}
|
|
67
|
+
removeAllFiles={column.headerEventHandler}
|
|
68
|
+
count={count}
|
|
69
|
+
toggleDisplay={toggleDialogDisplay}
|
|
70
|
+
onDeleteAllFiles={onDeleteAllFiles}
|
|
71
|
+
/>
|
|
72
|
+
</TableCell>
|
|
73
|
+
</>
|
|
59
74
|
);
|
|
60
75
|
};
|
|
61
76
|
|
|
@@ -1,21 +1,75 @@
|
|
|
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
|
+
// custom download from bento app
|
|
53
|
+
if (downloadTable) {
|
|
54
|
+
downloadTable(queryVariables);
|
|
55
|
+
} else if (!downloadTable && !server) {
|
|
56
|
+
// download client table
|
|
57
|
+
downloadJson(rows, table, downloadFileName);
|
|
58
|
+
} else {
|
|
59
|
+
// donwload server table
|
|
60
|
+
downloadSCSVFile();
|
|
61
|
+
}
|
|
62
|
+
}, [queryVariables]);
|
|
14
63
|
|
|
15
64
|
return (
|
|
16
65
|
<>
|
|
17
|
-
<Tooltip
|
|
18
|
-
|
|
66
|
+
<Tooltip
|
|
67
|
+
title={downloadCsv}
|
|
68
|
+
className="download-icon"
|
|
69
|
+
>
|
|
70
|
+
<IconButton
|
|
71
|
+
onClick={downloadTableCSV}
|
|
72
|
+
>
|
|
19
73
|
<CloudDownload />
|
|
20
74
|
</IconButton>
|
|
21
75
|
</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
|
+
};
|