@bento-core/paginated-table 0.2.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/babel.config.json +20 -0
- package/dist/index.js +104 -0
- package/dist/table/ClientController.js +64 -0
- package/dist/table/ContextProvider.js +31 -0
- package/dist/table/PaginatedTable.js +190 -0
- package/dist/table/README.md +253 -0
- package/dist/table/ServerController.js +42 -0
- package/dist/table/TableService.js +103 -0
- package/dist/table/state/Actions.js +57 -0
- package/dist/table/state/Reducer.js +53 -0
- package/dist/wrapper/Wrapper.js +167 -0
- package/dist/wrapper/WrapperService.js +36 -0
- package/dist/wrapper/components/AddAllFiles/AddAllView.js +88 -0
- package/dist/wrapper/components/AddFiles.js +65 -0
- package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +68 -0
- package/dist/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +62 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +35 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogController.js +36 -0
- package/dist/wrapper/components/AddToCartDialog/AddToCartDialogView.js +42 -0
- package/dist/wrapper/components/ButtonView.js +22 -0
- package/dist/wrapper/components/DownloadManifestBtn.js +71 -0
- package/dist/wrapper/components/ReduxAddFile.js +26 -0
- package/dist/wrapper/components/Snackbar/Snackbar.js +40 -0
- package/dist/wrapper/components/Snackbar/SnackbarRedux.js +16 -0
- package/dist/wrapper/components/Snackbar/SuccessOutlined.js +17 -0
- package/dist/wrapper/components/TextFieldView.js +34 -0
- package/dist/wrapper/components/TooltipView.js +40 -0
- package/package.json +28 -0
- package/src/index.js +18 -0
- package/src/table/ClientController.js +64 -0
- package/src/table/ContextProvider.js +27 -0
- package/src/table/PaginatedTable.js +185 -0
- package/src/table/README.md +253 -0
- package/src/table/ServerController.js +40 -0
- package/src/table/TableService.js +80 -0
- package/src/table/state/Actions.js +50 -0
- package/src/table/state/Reducer.js +49 -0
- package/src/wrapper/Wrapper.js +163 -0
- package/src/wrapper/WrapperService.js +25 -0
- package/src/wrapper/components/AddAllFiles/AddAllView.js +88 -0
- package/src/wrapper/components/AddFiles.js +75 -0
- package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesController.js +69 -0
- package/src/wrapper/components/AddSelectedFiles/AddSelectedFilesView.js +65 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +37 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogController.js +32 -0
- package/src/wrapper/components/AddToCartDialog/AddToCartDialogView.js +56 -0
- package/src/wrapper/components/ButtonView.js +24 -0
- package/src/wrapper/components/DownloadManifestBtn.js +64 -0
- package/src/wrapper/components/ReduxAddFile.js +19 -0
- package/src/wrapper/components/Snackbar/Snackbar.js +43 -0
- package/src/wrapper/components/Snackbar/SnackbarRedux.js +11 -0
- package/src/wrapper/components/Snackbar/SuccessOutlined.js +10 -0
- package/src/wrapper/components/TextFieldView.js +31 -0
- package/src/wrapper/components/TooltipView.js +35 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useReducer } from 'react';
|
|
2
|
+
import ServerTableView from './ServerController';
|
|
3
|
+
import ClientTableView from './ClientController';
|
|
4
|
+
import {
|
|
5
|
+
onRowsPerPageChange,
|
|
6
|
+
onPageChange,
|
|
7
|
+
onRowSeclect,
|
|
8
|
+
setTotalRowCount,
|
|
9
|
+
onColumnSort,
|
|
10
|
+
onPageAndTotalCountChange,
|
|
11
|
+
onColumnViewChange,
|
|
12
|
+
} from './state/Actions';
|
|
13
|
+
import { TableContext } from './ContextProvider';
|
|
14
|
+
import reducer from './state/Reducer';
|
|
15
|
+
|
|
16
|
+
const PaginatedTable = ({
|
|
17
|
+
queryVariables = {},
|
|
18
|
+
themeConfig = {},
|
|
19
|
+
totalRowCount = 0,
|
|
20
|
+
initState,
|
|
21
|
+
activeTab = true,
|
|
22
|
+
server = true,
|
|
23
|
+
tblRows = [],
|
|
24
|
+
}) => {
|
|
25
|
+
/**
|
|
26
|
+
* Initailize useReducer state
|
|
27
|
+
* 1. table: state (Note: table includes cofiguration in addition to pagination state)
|
|
28
|
+
* 2. dispatch: dispatch action (as redux action) to update pagination state
|
|
29
|
+
* 3. Add all btn / Add file button also dispatch action to update table state
|
|
30
|
+
*/
|
|
31
|
+
const [table, dispatch] = useReducer(reducer, {}, initState);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* use context to provide table state to wrapper component
|
|
35
|
+
*/
|
|
36
|
+
const tableContext = useContext(TableContext);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
/**
|
|
40
|
+
* set table context
|
|
41
|
+
* 1. provide table state to other component (wrapper comp -> Add file button)
|
|
42
|
+
* 2. provide table dispatch action to other component (wrapper comp)
|
|
43
|
+
*/
|
|
44
|
+
tableContext.setContext({ ...table, dispatch });
|
|
45
|
+
}, [table]);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* update state to props change
|
|
49
|
+
*/
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const { page, rowsPerPage } = table;
|
|
52
|
+
// validate table state - curr rowCount should be less than total row count after filter
|
|
53
|
+
// above validation steps when page is zero
|
|
54
|
+
// prevent currentRows denominator to be zero (newPage -> Nan)
|
|
55
|
+
if (page > 0 && totalRowCount <= page * rowsPerPage) {
|
|
56
|
+
const adjustRow = (page === 1) ? 1 : 0;
|
|
57
|
+
const currentRows = (page * rowsPerPage) + adjustRow;
|
|
58
|
+
const newPage = Math.floor(totalRowCount / currentRows);
|
|
59
|
+
dispatch(onPageAndTotalCountChange({
|
|
60
|
+
page: newPage,
|
|
61
|
+
totalRowCount,
|
|
62
|
+
}));
|
|
63
|
+
} else {
|
|
64
|
+
dispatch(setTotalRowCount(totalRowCount));
|
|
65
|
+
}
|
|
66
|
+
}, [totalRowCount]);
|
|
67
|
+
|
|
68
|
+
const handleChangeRowsPerPage = (event) => {
|
|
69
|
+
const noOfRows = parseInt(event.target.value, 10);
|
|
70
|
+
|
|
71
|
+
dispatch(onRowsPerPageChange({ rowsPerPage: noOfRows, page:0}));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleChangePage = (event, newPage) => {
|
|
75
|
+
dispatch(onPageChange({ pageNumb: newPage }));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* update selected Ids
|
|
80
|
+
* @param {*} event
|
|
81
|
+
* @param {*} row
|
|
82
|
+
*/
|
|
83
|
+
const onRowSelectHandler = (event, row) => {
|
|
84
|
+
event.stopPropagation();
|
|
85
|
+
let selectedIds = [...table.selectedRows];
|
|
86
|
+
const selectedId = row[table.dataKey];
|
|
87
|
+
if (!row.isChecked) {
|
|
88
|
+
selectedIds.push(selectedId);
|
|
89
|
+
} else {
|
|
90
|
+
selectedIds = selectedIds.reduce((acc, id) => {
|
|
91
|
+
if (selectedId !== id) {
|
|
92
|
+
acc.push(id);
|
|
93
|
+
}
|
|
94
|
+
return acc;
|
|
95
|
+
}, []);
|
|
96
|
+
}
|
|
97
|
+
dispatch(onRowSeclect(selectedIds));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleToggleSelectAll = (event, Ids, includeIds) => {
|
|
101
|
+
if (event.target.checked && !includeIds) {
|
|
102
|
+
const selecedIds = Ids.concat(table.selectedRows);
|
|
103
|
+
dispatch(onRowSeclect(selecedIds));
|
|
104
|
+
} else {
|
|
105
|
+
const filterIds = table.selectedRows.filter((id) => !Ids.includes(id));
|
|
106
|
+
dispatch(onRowSeclect(filterIds));
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const handleSortByColumn = (column, order) => {
|
|
111
|
+
const { sortBy } = table;
|
|
112
|
+
const sort = (order === 'asc' && sortBy === column) ? 'desc' : 'asc';
|
|
113
|
+
dispatch(onColumnSort({ sort, column }));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* manage columns view change
|
|
118
|
+
* hide/display columns from table
|
|
119
|
+
*/
|
|
120
|
+
const handleColumnViewChange = (column) => {
|
|
121
|
+
const columns = table.columns.map((col) => {
|
|
122
|
+
const updateColumnView = { ...col };
|
|
123
|
+
if (col.dataField === column.dataField) {
|
|
124
|
+
updateColumnView.display = !column.display;
|
|
125
|
+
}
|
|
126
|
+
return updateColumnView;
|
|
127
|
+
});
|
|
128
|
+
dispatch(onColumnViewChange({
|
|
129
|
+
...table,
|
|
130
|
+
columns,
|
|
131
|
+
}));
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A. client table
|
|
135
|
+
* table data provide by bento app (tblRows)
|
|
136
|
+
* Rows display & column sorting by ClientController
|
|
137
|
+
*/
|
|
138
|
+
if (!server) {
|
|
139
|
+
return (
|
|
140
|
+
<>
|
|
141
|
+
<ClientTableView
|
|
142
|
+
tblRows={tblRows}
|
|
143
|
+
table={table}
|
|
144
|
+
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
145
|
+
onPageChange={handleChangePage}
|
|
146
|
+
onRowSelectChange={onRowSelectHandler}
|
|
147
|
+
onToggleSelectAll={handleToggleSelectAll}
|
|
148
|
+
onSortByColumn={handleSortByColumn}
|
|
149
|
+
onColumnViewChange={handleColumnViewChange}
|
|
150
|
+
themeConfig={themeConfig}
|
|
151
|
+
/>
|
|
152
|
+
</>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* B. server table
|
|
158
|
+
* bento-core makes http call base on table state
|
|
159
|
+
*/
|
|
160
|
+
/**
|
|
161
|
+
* prevent loading data except for active tab
|
|
162
|
+
*/
|
|
163
|
+
if (!activeTab) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<>
|
|
169
|
+
<ServerTableView
|
|
170
|
+
queryVariables={queryVariables}
|
|
171
|
+
totalRowCount={totalRowCount}
|
|
172
|
+
table={table}
|
|
173
|
+
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
174
|
+
onPageChange={handleChangePage}
|
|
175
|
+
onRowSelectChange={onRowSelectHandler}
|
|
176
|
+
onToggleSelectAll={handleToggleSelectAll}
|
|
177
|
+
onSortByColumn={handleSortByColumn}
|
|
178
|
+
onColumnViewChange={handleColumnViewChange}
|
|
179
|
+
themeConfig={themeConfig}
|
|
180
|
+
/>
|
|
181
|
+
</>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export default PaginatedTable;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# PAGINATED TABLE COMPONENT DESIGN
|
|
2
|
+
|
|
3
|
+
### Bento core paginated table design:
|
|
4
|
+
|
|
5
|
+
* Use of UseReducer to track table state and local state to display dialog component
|
|
6
|
+
* use of useContext to access table state
|
|
7
|
+
* Limit use of props drilling
|
|
8
|
+
* Core layout defined by Bento Core table component
|
|
9
|
+
* Build on top of Mui table (demo - https://mui.com/material-ui/react-table/#custom-pagination-actions)
|
|
10
|
+
* Apply SOLID principles in react (https://konstantinlebedev.com/solid-in-react/)
|
|
11
|
+
|
|
12
|
+
## 1 UseReducer configuration
|
|
13
|
+
|
|
14
|
+
### Generate and integrate redux dispatch actions
|
|
15
|
+
```
|
|
16
|
+
const initTblState = (initailState) => ({
|
|
17
|
+
...initailState,
|
|
18
|
+
title: config.name,
|
|
19
|
+
query: config.api,
|
|
20
|
+
dataKey: config.dataKey,
|
|
21
|
+
columns: configColumn(config.columns),
|
|
22
|
+
count: dashboardStats[config.count],
|
|
23
|
+
selectedRows: [],
|
|
24
|
+
tableMsg: config.tableMsg,
|
|
25
|
+
paginationAPIField: config.paginationAPIField,
|
|
26
|
+
sortBy: config.defaultSortField,
|
|
27
|
+
sortOrder: config.defaultSortDirection,
|
|
28
|
+
rowsPerPage: 10,
|
|
29
|
+
page: 0,
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
**Paginated Table Init State TABLE-1**
|
|
33
|
+
| Table State | Required | description | Configuration |
|
|
34
|
+
| :--- | :----:| :----: | ----: |
|
|
35
|
+
| title | TRUE | table name (Case, Sample, Files), required for class name | |
|
|
36
|
+
| query | TRUE | GraphQL Query for paginated Table (e.g. GET_CASES_OVERVIEW_QUERY) | api |
|
|
37
|
+
| dataKey | TRUE | Tracking selected rows (case - dataKey: 'subject_id') | dashboardTabData/tabContainers |
|
|
38
|
+
| columns | TRUE | columns defined by dashboardTabData (tabContainers) | add fucntion attribut customCellRender/customColHeaderRender to configure custom cell (see bento frontend) |
|
|
39
|
+
| count | TRUE | Total row cound for (Cases, Samples, Files), update based on filter event | |
|
|
40
|
+
| selectedRows | TRUE | Tracks selected Rows | |
|
|
41
|
+
| tableMsg | TRUE | Display noMatch Msg | dashboardTabData/tabContainers/tableMsg |
|
|
42
|
+
| theme | FALSE | override style with themeprovider use ClassName provided by bento-core table to apply style (refer to class name table) | |
|
|
43
|
+
| paginationAPIField | TRUE | Access http response data - defined by dashboardTabData (tabContainers) | ```paginationAPIField: 'subjectOverview'```|
|
|
44
|
+
| sortBy | TRUE | default sort column | defaultSortField: 'subject_id',|
|
|
45
|
+
| sortOrder | FALSE | default sort column 'ASC' | ```defaultSortDirection: 'asc',```|
|
|
46
|
+
| rowsPerPage | FALSE | default 10 | |
|
|
47
|
+
| page | FALSE | 0 | |
|
|
48
|
+
| extendedViewConfig | FALSE | extended view of table header component | refer bento-frontend tabContainers, dashboardTabData.js |
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### 2 Importing Component and Configuration
|
|
52
|
+
```
|
|
53
|
+
import TableView from 'bento-core/PaginationTable/PaginatedTable';
|
|
54
|
+
// active filter json structure
|
|
55
|
+
<TableView
|
|
56
|
+
initState={initTblState}
|
|
57
|
+
themeConfig={themeConfig}
|
|
58
|
+
activeFilters={activeFilters}
|
|
59
|
+
totalRowCount={dashboardStats[config.count]}
|
|
60
|
+
activeTab={activeTab}
|
|
61
|
+
/>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Paginated Table Props Config TABLE-2**
|
|
65
|
+
| Table | Required | description | Configuration |
|
|
66
|
+
| :--- | :----:| :----: | ----: |
|
|
67
|
+
| table state | TRUE | as describe on TABLE-1 | |
|
|
68
|
+
| viewConfig | FALSE | (Optional) table view config, set hide/diaply pagination above table header | |
|
|
69
|
+
| themeConfig | FALSE | override style with themeprovider use ClassName provided by bento-core table to apply style (refer to class name table) | |
|
|
70
|
+
| totalRowCount | TRUE | Total row cound for (Cases, Samples, Files), update based on filter event | |
|
|
71
|
+
| activeTab | TRUE | prevents http call for inactive tabs (dashboard) /set true to myFile cart | |
|
|
72
|
+
|
|
73
|
+
## 3 Table component themeConfig Configuration
|
|
74
|
+
```
|
|
75
|
+
export const tblHeader = {
|
|
76
|
+
MuiTableSortLabel: {
|
|
77
|
+
root: {
|
|
78
|
+
...define style
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const tblPgn = {
|
|
84
|
+
MuiTablePagination: {
|
|
85
|
+
root: {
|
|
86
|
+
paddingRight: '50px',
|
|
87
|
+
borderTop: '5px solid #e7e5e5',
|
|
88
|
+
borderBottom: '3px solid #e7e5e5',
|
|
89
|
+
},
|
|
90
|
+
toolbar: {
|
|
91
|
+
minHeight: '45px',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
// define mui styles for table component
|
|
96
|
+
export const themeConfig = {
|
|
97
|
+
tblHeader,
|
|
98
|
+
tblTopPgn,
|
|
99
|
+
tblPgn,
|
|
100
|
+
tblBody,
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 3 Table state Context provider Configuration
|
|
105
|
+
```
|
|
106
|
+
Reference - TabPanel.js (bento-frontend)
|
|
107
|
+
|
|
108
|
+
import {
|
|
109
|
+
TableContextProvider,
|
|
110
|
+
TableView,
|
|
111
|
+
Wrapper,
|
|
112
|
+
} from '@bento-core/paginated-table';
|
|
113
|
+
|
|
114
|
+
const initTblState = (initailState) => ({
|
|
115
|
+
...initailState,
|
|
116
|
+
title: config.name,
|
|
117
|
+
query: config.api,
|
|
118
|
+
paginationAPIField: config.paginationAPIField,
|
|
119
|
+
dataKey: config.dataKey,
|
|
120
|
+
columns: configColumn(config.columns),
|
|
121
|
+
count: dashboardStats[config.count],
|
|
122
|
+
selectedRows: [],
|
|
123
|
+
enableRowSelection: config.enableRowSelection,
|
|
124
|
+
tableMsg: config.tableMsg,
|
|
125
|
+
sortBy: config.defaultSortField,
|
|
126
|
+
sortOrder: config.defaultSortDirection,
|
|
127
|
+
extendedViewConfig: config.extendedViewConfig,
|
|
128
|
+
rowsPerPage: 10,
|
|
129
|
+
page: 0,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
<TableContextProvider>
|
|
133
|
+
<Wrapper
|
|
134
|
+
wrapConfig={configWrapper(config, wrapperConfig)}
|
|
135
|
+
customTheme={customTheme}
|
|
136
|
+
classes={classes}
|
|
137
|
+
section={config.name}
|
|
138
|
+
>
|
|
139
|
+
<Grid container>
|
|
140
|
+
<Grid item xs={12} id={config.tableID}>
|
|
141
|
+
<TableView
|
|
142
|
+
initState={initTblState}
|
|
143
|
+
themeConfig={themeConfig}
|
|
144
|
+
queryVariables={activeFilters}
|
|
145
|
+
totalRowCount={dashboardStats[config.count]}
|
|
146
|
+
activeTab={activeTab}
|
|
147
|
+
/>
|
|
148
|
+
</Grid>
|
|
149
|
+
</Grid>
|
|
150
|
+
</Wrapper>
|
|
151
|
+
</TableContextProvider>
|
|
152
|
+
|
|
153
|
+
//child component
|
|
154
|
+
|
|
155
|
+
import { TableContext } from 'bento-core';
|
|
156
|
+
|
|
157
|
+
const tableContext = useContext(TableContext);
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
TableContextProvider provides table state to Wrapper Component or it can be used in higher parent component as needed.
|
|
161
|
+
|
|
162
|
+
####
|
|
163
|
+
|
|
164
|
+
## 4 Wrapper Configuration:
|
|
165
|
+
Wrapper component around table compnent.
|
|
166
|
+
1. ADD ALL FILES button
|
|
167
|
+
2. ADD SELECTED ROWS button
|
|
168
|
+
3. Go to My File link
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
/**
|
|
172
|
+
* Configuration display component based on index
|
|
173
|
+
* CAUTION: If table is in wrapper component provide position of table component
|
|
174
|
+
*/
|
|
175
|
+
export const wrapperConfig = [{
|
|
176
|
+
container: 'buttons',
|
|
177
|
+
size: 'xl',
|
|
178
|
+
clsName: 'container_header',
|
|
179
|
+
items: [
|
|
180
|
+
{
|
|
181
|
+
title: 'ADD ALL FILES',
|
|
182
|
+
clsName: 'add_all_button',
|
|
183
|
+
type: types.BUTTON,
|
|
184
|
+
role: btnTypes.ADD_ALL_FILES,
|
|
185
|
+
btnType: btnTypes.ADD_ALL_FILES,
|
|
186
|
+
conditional: false,
|
|
187
|
+
alertMessage,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
title: 'ADD SELECTED FILES',
|
|
191
|
+
clsName: 'add_selected_button',
|
|
192
|
+
type: types.BUTTON,
|
|
193
|
+
role: btnTypes.ADD_SELECTED_FILES,
|
|
194
|
+
btnType: btnTypes.ADD_SELECTED_FILES,
|
|
195
|
+
tooltipCofig: tooltipContent,
|
|
196
|
+
conditional: true,
|
|
197
|
+
}],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
container: 'paginatedTable',
|
|
201
|
+
paginatedTable: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
container: 'buttons',
|
|
205
|
+
size: 'xl',
|
|
206
|
+
clsName: 'container_footer',
|
|
207
|
+
items: [
|
|
208
|
+
{
|
|
209
|
+
title: 'ADD SELECTED FILES',
|
|
210
|
+
clsName: 'add_selected_button',
|
|
211
|
+
type: types.BUTTON,
|
|
212
|
+
role: btnTypes.ADD_SELECTED_FILES,
|
|
213
|
+
btnType: btnTypes.ADD_SELECTED_FILES,
|
|
214
|
+
tooltipCofig: tooltipContent,
|
|
215
|
+
conditional: true,
|
|
216
|
+
}],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
container: 'buttons',
|
|
220
|
+
size: 'xl',
|
|
221
|
+
clsName: 'container_footer_link',
|
|
222
|
+
items: [
|
|
223
|
+
{
|
|
224
|
+
title: 'Go to Cart >',
|
|
225
|
+
clsName: 'go_to_cart',
|
|
226
|
+
url: '#/fileCentricCart',
|
|
227
|
+
type: types.LINK,
|
|
228
|
+
}],
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Each item in headerConfig and footerConfig represent container
|
|
234
|
+
**container Config TABLE-3**
|
|
235
|
+
headerConfig - upper component on the table
|
|
236
|
+
footerConfig - button component on the table
|
|
237
|
+
| Attris | Required | description | Configuration |
|
|
238
|
+
| :--- | :----:| :----: | ----: |
|
|
239
|
+
| container | TRUE | describe container | |
|
|
240
|
+
| size | TRUE | container size | xl, md, sm |
|
|
241
|
+
| clsName | TRUE | class name to apply style using themeprovider | |
|
|
242
|
+
| item | TRUE | number of button component ***(refer to table 4)*** | |
|
|
243
|
+
|
|
244
|
+
**Button component Config TABLE-4**
|
|
245
|
+
headerConfig - upper component on the table
|
|
246
|
+
| Attris | Required | description | Configuration |
|
|
247
|
+
| :--- | :----:| :----: | ----: |
|
|
248
|
+
| title | TRUE | button label | 'ADD SELECTED FILES' |
|
|
249
|
+
| clsName | TRUE | class name to apply style using themeprovider | |
|
|
250
|
+
| type | TRUE | add all files or add selected files| btnTypes.ADD_SELECTED_FILES |
|
|
251
|
+
| tooltipCofig | FALSE | appears on side of the refers button | dashboardTabData/ tooltipContent |
|
|
252
|
+
|
|
253
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
CircularProgress,
|
|
4
|
+
Container,
|
|
5
|
+
} from '@material-ui/core';
|
|
6
|
+
import { TableView } from '@bento-core/table';
|
|
7
|
+
import {
|
|
8
|
+
getTableData,
|
|
9
|
+
setSelectedRows,
|
|
10
|
+
} from './TableService';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Updates table row when table state is changed 1. (paginated action) and 2. filter action
|
|
14
|
+
*/
|
|
15
|
+
const TableController = ((props) => {
|
|
16
|
+
const { queryVariables, table } = props;
|
|
17
|
+
const { tableData } = getTableData({ queryVariables, table });
|
|
18
|
+
if (!tableData) {
|
|
19
|
+
return (
|
|
20
|
+
<Container maxWidth="xl">
|
|
21
|
+
<CircularProgress />
|
|
22
|
+
</Container>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* update rows
|
|
27
|
+
* set selected rows isChecked to TRUE
|
|
28
|
+
*/
|
|
29
|
+
const updateRows = setSelectedRows(tableData, table);
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<TableView
|
|
33
|
+
{...props}
|
|
34
|
+
tableRows={updateRows}
|
|
35
|
+
/>
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export default TableController;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useApolloClient } from '@apollo/client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* set true to checked items
|
|
6
|
+
* @param {*} rows
|
|
7
|
+
* @param {*} table
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const setSelectedRows = (rows = [], table) => {
|
|
11
|
+
const { selectedRows, dataKey } = table;
|
|
12
|
+
const updateRows = [...rows].map((row) => {
|
|
13
|
+
const isChecked = dataKey
|
|
14
|
+
? (selectedRows.indexOf(row[dataKey]) !== -1) : false;
|
|
15
|
+
return { ...row, isChecked };
|
|
16
|
+
}, []);
|
|
17
|
+
return updateRows;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* update query variable (eg active filters / files ids)
|
|
22
|
+
* with table pagination state
|
|
23
|
+
*/
|
|
24
|
+
const getPaginatedQueryVariables = (queryVariables, table) => {
|
|
25
|
+
const variables = { ...queryVariables };
|
|
26
|
+
const {
|
|
27
|
+
page,
|
|
28
|
+
rowsPerPage,
|
|
29
|
+
sortBy,
|
|
30
|
+
sortOrder,
|
|
31
|
+
} = table;
|
|
32
|
+
const offset = page * rowsPerPage;
|
|
33
|
+
variables.offset = offset;
|
|
34
|
+
variables.order_by = sortBy;
|
|
35
|
+
variables.first = rowsPerPage;
|
|
36
|
+
variables.sort_direction = sortOrder;
|
|
37
|
+
return variables;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {*} queryVariables
|
|
42
|
+
* @param {*} table (table state)
|
|
43
|
+
* @param {*} tab (tab)
|
|
44
|
+
* @returns table data
|
|
45
|
+
*/
|
|
46
|
+
export const getTableData = ({ queryVariables, table }) => {
|
|
47
|
+
const client = useApolloClient();
|
|
48
|
+
const {
|
|
49
|
+
page,
|
|
50
|
+
rowsPerPage,
|
|
51
|
+
sortOrder,
|
|
52
|
+
query,
|
|
53
|
+
sortBy
|
|
54
|
+
} = table;
|
|
55
|
+
async function getData() {
|
|
56
|
+
const paginatedqueryVariable = getPaginatedQueryVariables(queryVariables, table);
|
|
57
|
+
const result = await client.query({
|
|
58
|
+
query,
|
|
59
|
+
variables: paginatedqueryVariable,
|
|
60
|
+
})
|
|
61
|
+
.then((response) => response.data);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
const [tableData, setTableData] = useState(null);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
getData().then((result) => {
|
|
68
|
+
if (table.paginationAPIField && result[table.paginationAPIField]) {
|
|
69
|
+
setTableData(result[table.paginationAPIField]);
|
|
70
|
+
} else {
|
|
71
|
+
setTableData(result);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
// cancel the request before component unmounts
|
|
76
|
+
controller.abort();
|
|
77
|
+
};
|
|
78
|
+
}, [queryVariables, page, rowsPerPage, sortOrder, sortBy]);
|
|
79
|
+
return { tableData };
|
|
80
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const actionTypes = {
|
|
2
|
+
VIEW_COLUMN_CHANGE: 'VIEW_COLUMN_CHANGE',
|
|
3
|
+
ON_COLUMN_SORT: 'ON_COLUMN_SORT',
|
|
4
|
+
ON_SORT_ORDER_CHANGE: 'ON_SORT_ORDER_CHANGE',
|
|
5
|
+
ON_ROWS_PER_PAGE_CHANGE: 'ON_ROWS_PER_PAGE_CHANGE',
|
|
6
|
+
ON_PAGE_CHANGE: 'ON_PAGE_CHANGE',
|
|
7
|
+
ON_ROW_SELECT: 'ON_ROW_SELECT',
|
|
8
|
+
SET_TOTAL_ROW_COUNT: 'SET_TOTAL_ROW_COUNT',
|
|
9
|
+
ON_PAGE_AND_TOTAL_COUNT_CHANGE: 'ON_PAGE_AND_TOTAL_COUNT_CHANGE',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const onColumnViewChange = (columns) => ({
|
|
13
|
+
type: actionTypes.VIEW_COLUMN_CHANGE,
|
|
14
|
+
payload: columns,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const onColumnSort = (value) => ({
|
|
18
|
+
type: actionTypes.ON_COLUMN_SORT,
|
|
19
|
+
payload: value,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const onChangeSortDirection = (sortOrder) => ({
|
|
23
|
+
type: actionTypes.ON_COLUMN_SORT,
|
|
24
|
+
payload: sortOrder,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const onRowsPerPageChange = (value) => ({
|
|
28
|
+
type: actionTypes.ON_ROWS_PER_PAGE_CHANGE,
|
|
29
|
+
payload: value,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const onPageAndTotalCountChange = (value) => ({
|
|
33
|
+
type: actionTypes.ON_PAGE_AND_TOTAL_COUNT_CHANGE,
|
|
34
|
+
payload: value,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const onPageChange = (pageNumb) => ({
|
|
38
|
+
type: actionTypes.ON_PAGE_CHANGE,
|
|
39
|
+
payload: pageNumb,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const onRowSeclect = (rows) => ({
|
|
43
|
+
type: actionTypes.ON_ROW_SELECT,
|
|
44
|
+
payload: rows,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const setTotalRowCount = (count) => ({
|
|
48
|
+
type: actionTypes.SET_TOTAL_ROW_COUNT,
|
|
49
|
+
payload: count,
|
|
50
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { actionTypes } from './Actions';
|
|
2
|
+
|
|
3
|
+
const reducer = (state, action) => {
|
|
4
|
+
const { type, payload } = action;
|
|
5
|
+
switch (type) {
|
|
6
|
+
case actionTypes.ON_COLUMN_SORT:
|
|
7
|
+
return {
|
|
8
|
+
...state,
|
|
9
|
+
sortOrder: payload.sort,
|
|
10
|
+
sortBy: payload.column,
|
|
11
|
+
};
|
|
12
|
+
case actionTypes.ON_PAGE_CHANGE:
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
page: payload.pageNumb,
|
|
16
|
+
};
|
|
17
|
+
case actionTypes.ON_ROWS_PER_PAGE_CHANGE:
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
rowsPerPage: payload.rowsPerPage,
|
|
21
|
+
page: payload.page,
|
|
22
|
+
};
|
|
23
|
+
case actionTypes.VIEW_COLUMN_CHANGE:
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
...payload,
|
|
27
|
+
};
|
|
28
|
+
case actionTypes.ON_ROW_SELECT:
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
selectedRows: payload,
|
|
32
|
+
};
|
|
33
|
+
case actionTypes.ON_PAGE_AND_TOTAL_COUNT_CHANGE:
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
totalRowCount: payload.totalRowCount,
|
|
37
|
+
page: payload.page,
|
|
38
|
+
};
|
|
39
|
+
case actionTypes.SET_TOTAL_ROW_COUNT:
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
totalRowCount: payload,
|
|
43
|
+
};
|
|
44
|
+
default:
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default reducer;
|