@bento-core/table 1.0.1-ccdihub.9 → 1.0.1-ccdihub.91

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.
Files changed (73) hide show
  1. package/dist/DefaultThemConfig.js +1 -1
  2. package/dist/ExtendedView.js +25 -14
  3. package/dist/TableView.js +79 -7
  4. package/dist/body/CustomTblBody.js +5 -2
  5. package/dist/body/DisplayBodyCell.js +17 -3
  6. package/dist/body/components/CPIModal.js +363 -0
  7. package/dist/body/components/CPIView.js +117 -0
  8. package/dist/body/components/ModalStyle.js +121 -0
  9. package/dist/body/components/assets/CPI_icon.svg +22 -0
  10. package/dist/body/components/assets/Cart_Icon.svg +3 -0
  11. package/dist/body/components/assets/Question_Icon.svg +4 -0
  12. package/dist/header/ActionHeaderCell.js +2 -1
  13. package/dist/header/CustomCell.js +11 -3
  14. package/dist/header/CustomTblHeader.js +4 -1
  15. package/dist/header/components/CheckBoxView.js +3 -2
  16. package/dist/index.js +6 -0
  17. package/dist/pagination/CustomPagination.js +11 -2
  18. package/dist/toolbar/DownloadButtonView.js +173 -7
  19. package/dist/toolbar/ManageColumnView.js +115 -25
  20. package/dist/toolbar/assets/Hidden_Column.svg +4 -0
  21. package/dist/toolbar/assets/View_Columns.svg +6 -0
  22. package/dist/util/Dataformat.js +41 -1
  23. package/dist/util/Types.js +22 -2
  24. package/dist/util/downloadTable.js +196 -0
  25. package/dist/wrapper/WrapperService.js +36 -0
  26. package/dist/wrapper/components/AddFiles.js +63 -0
  27. package/dist/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +35 -0
  28. package/dist/wrapper/components/AddToCartDialog/AddToCartDialogController.js +36 -0
  29. package/dist/wrapper/components/AddToCartDialog/AddToCartDialogView.js +43 -0
  30. package/dist/wrapper/components/CPIFilesView/CPIFilesView.js +178 -0
  31. package/dist/wrapper/components/ReduxAddFile.js +27 -0
  32. package/dist/wrapper/components/Snackbar/Snackbar.js +40 -0
  33. package/dist/wrapper/components/Snackbar/SnackbarRedux.js +16 -0
  34. package/dist/wrapper/components/Snackbar/SuccessOutlined.js +17 -0
  35. package/dist/wrapper/components/TextFieldView.js +37 -0
  36. package/dist/wrapper/components/TooltipView.js +40 -0
  37. package/package.json +11 -1
  38. package/src/DefaultThemConfig.js +1 -1
  39. package/src/ExtendedView.js +36 -21
  40. package/src/TableView.js +124 -52
  41. package/src/body/CustomTblBody.js +3 -0
  42. package/src/body/DisplayBodyCell.js +16 -0
  43. package/src/body/components/CPIModal.js +414 -0
  44. package/src/body/components/CPIView.js +135 -0
  45. package/src/body/components/ModalStyle.js +115 -0
  46. package/src/body/components/assets/CPI_icon.svg +22 -0
  47. package/src/body/components/assets/Cart_Icon.svg +3 -0
  48. package/src/body/components/assets/Question_Icon.svg +4 -0
  49. package/src/header/ActionHeaderCell.js +1 -1
  50. package/src/header/CustomCell.js +13 -0
  51. package/src/header/CustomTblHeader.js +1 -0
  52. package/src/header/components/CheckBoxView.js +2 -1
  53. package/src/index.js +1 -0
  54. package/src/pagination/CustomPagination.js +4 -1
  55. package/src/toolbar/DownloadButtonView.js +181 -10
  56. package/src/toolbar/ManageColumnView.js +114 -27
  57. package/src/toolbar/assets/Hidden_Column.svg +4 -0
  58. package/src/toolbar/assets/View_Columns.svg +6 -0
  59. package/src/util/Dataformat.js +25 -0
  60. package/src/util/Types.js +15 -0
  61. package/src/util/downloadTable.js +138 -0
  62. package/src/wrapper/WrapperService.js +25 -0
  63. package/src/wrapper/components/AddFiles.js +62 -0
  64. package/src/wrapper/components/AddToCartDialog/AddToCartDialogAlertView.js +37 -0
  65. package/src/wrapper/components/AddToCartDialog/AddToCartDialogController.js +32 -0
  66. package/src/wrapper/components/AddToCartDialog/AddToCartDialogView.js +57 -0
  67. package/src/wrapper/components/CPIFilesView/CPIFilesView.js +190 -0
  68. package/src/wrapper/components/ReduxAddFile.js +20 -0
  69. package/src/wrapper/components/Snackbar/Snackbar.js +43 -0
  70. package/src/wrapper/components/Snackbar/SnackbarRedux.js +11 -0
  71. package/src/wrapper/components/Snackbar/SuccessOutlined.js +10 -0
  72. package/src/wrapper/components/TextFieldView.js +32 -0
  73. package/src/wrapper/components/TooltipView.js +35 -0
@@ -1,6 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import {
3
3
  Checkbox,
4
+ FormControlLabel,
4
5
  IconButton,
5
6
  List,
6
7
  ListItem,
@@ -8,39 +9,84 @@ import {
8
9
  Tooltip,
9
10
  Typography,
10
11
  withStyles,
12
+ Divider,
11
13
  } from '@material-ui/core';
12
14
  import {
13
- ViewColumn,
14
15
  CheckBox as CheckBoxIcon,
15
16
  CheckBoxOutlineBlank as CheckBoxBlankIcon,
16
17
  Close,
17
18
  } from '@material-ui/icons';
19
+ import KeyboardArrowDownOutlinedIcon from '@material-ui/icons/KeyboardArrowDownOutlined';
18
20
  import { cellTypes } from '../util/Types';
21
+ import viewColumnsIcon from './assets/View_Columns.svg';
22
+ import hiddenColumnsIcon from './assets/Hidden_Column.svg';
19
23
 
20
24
  const ManageColumnView = ({
21
25
  table,
22
26
  onColumnViewChange,
27
+ onAllColumnViewChange,
23
28
  manageViewColumns,
24
29
  }) => {
25
30
  if (!manageViewColumns) {
26
31
  return null;
27
32
  }
33
+ const { columns } = table;
28
34
  const [anchorEl, setAnchorEl] = useState(null);
35
+ const [selectAll, setSelectAll] = useState(false);
36
+
37
+ const viewColumns = columns.filter((col) => col.role === cellTypes.DISPLAY);
38
+
29
39
  const handleClick = (event) => {
30
40
  setAnchorEl(event.currentTarget);
31
41
  };
32
42
 
33
43
  const handleClose = () => setAnchorEl(null);
34
44
 
35
- const open = Boolean(anchorEl);
36
- const { columns } = table;
37
- const viewColumns = columns.filter((col) => col.role === cellTypes.DISPLAY);
45
+ const handleSelectAll = () => {
46
+ const state = selectAll;
47
+ setSelectAll(!selectAll);
48
+ onAllColumnViewChange(!state);
49
+ };
50
+
51
+ const columnDropdown = {
52
+ width: '48px',
53
+ height: '36px',
54
+ paddingLeft: '5px',
55
+ border: '0.75px solid #606060',
56
+ borderRadius: '5px',
57
+ display: 'inline-flex',
58
+ position: 'relative',
59
+ marginTop: '2px',
60
+ marginRight: '7px',
61
+ };
38
62
 
63
+ const displayColumnStyle = {
64
+ position: 'relative',
65
+ right: '20px',
66
+ bottom: '15px',
67
+ scale: '0.5',
68
+ };
69
+
70
+ const viewColumnsStyle = {
71
+ marginTop: '6px',
72
+ height: '24px',
73
+ right: '37px',
74
+ };
75
+
76
+ const arrowdownIcon = {
77
+ fill: '#606060',
78
+ };
79
+
80
+ const open = Boolean(anchorEl);
39
81
  return (
40
- <>
82
+ <div style={columnDropdown}>
83
+ <Tooltip title="Columns may be hidden">
84
+ <img src={hiddenColumnsIcon} alt="hiddenColumnsIcon" style={displayColumnStyle} />
85
+ </Tooltip>
41
86
  <Tooltip title={manageViewColumns.title}>
42
- <IconButton variant="contained" onClick={handleClick}>
43
- <ViewColumn />
87
+ <IconButton variant="contained" onClick={handleClick} style={viewColumnsStyle}>
88
+ <img src={viewColumnsIcon} alt="viewColumnsIcon" />
89
+ <KeyboardArrowDownOutlinedIcon style={arrowdownIcon} />
44
90
  </IconButton>
45
91
  </Tooltip>
46
92
  <Popover
@@ -58,6 +104,7 @@ const ManageColumnView = ({
58
104
  <IconButton
59
105
  onClick={handleClose}
60
106
  className="closeIcon"
107
+ style={{ float: 'right' }}
61
108
  >
62
109
  <Close />
63
110
  </IconButton>
@@ -67,33 +114,73 @@ const ManageColumnView = ({
67
114
  width={1}
68
115
  className="viewColumnListItem"
69
116
  >
70
- <Checkbox
71
- icon={(
72
- <CheckBoxBlankIcon
73
- style={{ fontSize: 18 }}
74
- className="checkBoxIcon"
75
- />
76
- )}
77
- onClick={() => onColumnViewChange(column)}
78
- checked={column.display}
79
- checkedIcon={(
80
- <CheckBoxIcon
81
- style={{
82
- fontSize: 18,
83
- }}
84
- className="checkBoxIcon"
117
+ <FormControlLabel
118
+ control={(
119
+ <Checkbox
120
+ icon={(
121
+ <CheckBoxBlankIcon
122
+ style={{ fontSize: 18 }}
123
+ className="checkBoxIcon"
124
+ />
125
+ )}
126
+ onClick={() => onColumnViewChange(column)}
127
+ checked={column.display}
128
+ checkedIcon={(
129
+ <CheckBoxIcon
130
+ style={{
131
+ fontSize: 18,
132
+ color: column.hideable ? 'rgba(11, 53, 86, 1)' : 'rgba(11, 53, 86, 0.38)',
133
+ }}
134
+ className="checkBoxIcon"
135
+ />
136
+ )}
137
+ disableRipple
138
+ color="secondary"
139
+ className="checkBox"
140
+ disabled={!column.hideable}
85
141
  />
86
142
  )}
87
- disableRipple
88
- color="secondary"
89
- className="checkBox"
143
+ disabled={!column.hideable}
144
+ label={column.header}
90
145
  />
91
- <Typography>{column.header}</Typography>
92
146
  </ListItem>
93
147
  ))}
148
+ <Divider style={{ color: '#375F9A', marginTop: '5px', marginBottom: '5px' }} />
149
+ <ListItem
150
+ width={1}
151
+ className="viewColumnListItem"
152
+ >
153
+ <FormControlLabel
154
+ control={(
155
+ <Checkbox
156
+ icon={(
157
+ <CheckBoxBlankIcon
158
+ style={{ fontSize: 18 }}
159
+ className="checkBoxIcon"
160
+ />
161
+ )}
162
+ onClick={() => handleSelectAll()}
163
+ checked={selectAll}
164
+ checkedIcon={(
165
+ <CheckBoxIcon
166
+ style={{
167
+ fontSize: 18,
168
+ color: 'rgba(11, 53, 86, 1)',
169
+ }}
170
+ className="checkBoxIcon"
171
+ />
172
+ )}
173
+ disableRipple
174
+ color="secondary"
175
+ className="checkBox"
176
+ />
177
+ )}
178
+ label={selectAll ? 'Deselect All' : 'Select All'}
179
+ />
180
+ </ListItem>
94
181
  </List>
95
182
  </Popover>
96
- </>
183
+ </div>
97
184
  );
98
185
  };
99
186
 
@@ -0,0 +1,4 @@
1
+ <svg width="20" height="19" viewBox="0 0 20 19" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="10" y="0.928786" width="12.2783" height="12.2783" rx="2.5" transform="rotate(45 10 0.928786)" fill="#FFEB13" stroke="black"/>
3
+ <path d="M9.99994 7.14529C9.74072 7.14529 9.52354 7.06575 9.3484 6.90667C9.18026 6.74068 9.09619 6.53664 9.09619 6.29457C9.09619 6.05249 9.18026 5.85192 9.3484 5.69284C9.52354 5.52684 9.74072 5.44385 9.99994 5.44385C10.2592 5.44385 10.4728 5.52684 10.641 5.69284C10.8161 5.85192 10.9037 6.05249 10.9037 6.29457C10.9037 6.53664 10.8161 6.74068 10.641 6.90667C10.4728 7.06575 10.2592 7.14529 9.99994 7.14529ZM10.725 7.83001V13.5776H9.25382V7.83001H10.725Z" fill="black"/>
4
+ </svg>
@@ -0,0 +1,6 @@
1
+ <svg width="20" height="18" viewBox="0 0 20 18" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M2.88892 1.40607H17.1116C17.6636 1.40633 18.1116 1.85394 18.1116 2.40607V15.5936C18.1116 16.1457 17.6636 16.5933 17.1116 16.5936H2.88892C2.33663 16.5936 1.88892 16.1459 1.88892 15.5936V2.40607C1.88892 1.85378 2.33663 1.40607 2.88892 1.40607Z" fill="white" stroke="#606060" stroke-width="2"/>
3
+ <line x1="1.79956" y1="6.08969" x2="19.1106" y2="6.08969" stroke="#606060" stroke-width="2"/>
4
+ <line x1="13.2661" y1="7.09055" x2="13.2661" y2="17.5941" stroke="#606060" stroke-width="2"/>
5
+ <line x1="7.6936" y1="7.0903" x2="7.6936" y2="17.5939" stroke="#606060" stroke-width="2"/>
6
+ </svg>
@@ -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
+ };
package/src/util/Types.js CHANGED
@@ -5,7 +5,12 @@ export const LINK = 'LINK';
5
5
  export const DISPLAY = 'DISPLAY';
6
6
  export const DEFAULT = 'DEFAULT';
7
7
  export const FORMAT_DATA = 'FORMAT_DATA';
8
+ export const CPI = 'CPI';
8
9
  export const FORMAT_BYTES = 'FORMAT_BYTES';
10
+ export const TRANSFORM = 'TRANSFORM';
11
+ export const STUDY_DOWNLOAD = 'STUDY_DOWNLOAD';
12
+ export const EXPAND = 'EXPAND';
13
+ export const DBGAP = 'DBGAP';
9
14
 
10
15
  export const cellTypes = {
11
16
  CUSTOM_ELEM,
@@ -15,10 +20,20 @@ export const cellTypes = {
15
20
  DELETE,
16
21
  DEFAULT,
17
22
  FORMAT_DATA,
23
+ CPI,
24
+ };
25
+
26
+ export const cellStyles = {
27
+ TRANSFORM,
28
+ EXPAND,
29
+ DBGAP,
30
+ STUDY_DOWNLOAD,
18
31
  };
19
32
 
20
33
  export const actionCellTypes = [CHECKBOX, DELETE];
21
34
 
35
+ export const notIncludedCellStyle = [STUDY_DOWNLOAD];
36
+
22
37
  export const FORMAT_DATA_CELLS = [FORMAT_BYTES];
23
38
 
24
39
  export const dataFormatTypes = {
@@ -0,0 +1,138 @@
1
+ import { formatBytes, formatColumnValues } from './Dataformat';
2
+ import { actionCellTypes, notIncludedCellStyle } from './Types';
3
+
4
+ export function createFileName(fileName, type) {
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
+ if (type === 'csv') {
27
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
28
+ }
29
+ return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.json'}`;
30
+ }
31
+
32
+ export function convertToCSV(jsonse, keysToInclude, header) {
33
+ const objArray = jsonse;
34
+ // To Do empty object just print headers
35
+ const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
36
+ let str = header.join(',');
37
+ array.map((entry, index) => {
38
+ let line = '';
39
+ keysToInclude.map((keyName) => {
40
+ if (line !== '') line += ',';
41
+ if (keyName === 'file_size') {
42
+ line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
43
+ } else if (keyName === 'age_at_diagnosis' || keyName === 'participant_age_at_collection') {
44
+ if (entry[keyName] === -999) {
45
+ line += 'Not Reported';
46
+ } else {
47
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
48
+ }
49
+ } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category') {
50
+ if (!entry[keyName] || entry[keyName] === '[]') {
51
+ line += '';
52
+ } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
53
+ line += `"${entry[keyName].toString().substring(1, entry[keyName].length - 1)}"`;
54
+ } else {
55
+ line += `"${entry[keyName]}"`;
56
+ }
57
+ } else {
58
+ line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
59
+ }
60
+ return line;
61
+ });
62
+ if (index === 0) {
63
+ // str = header.join(',');
64
+ str += `\r\n${line}\r\n`;
65
+ } else {
66
+ str += `${line}\r\n`;
67
+ }
68
+ return str;
69
+ });
70
+ return str;
71
+ }
72
+
73
+ export function downloadCSV(tableData, table, downloadFileName) {
74
+ const { columns = [] } = table;
75
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType))
76
+ .filter(({ cellStyle }) => !notIncludedCellStyle.includes(cellStyle))
77
+ .filter(({ display }) => display);
78
+ const formatDataVal = formatColumnValues(filterColumns, tableData);
79
+ const jsonse = JSON.stringify(formatDataVal);
80
+ const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
81
+ .map(({ dataField }) => dataField);
82
+ const headers = filterColumns.filter(({ dataField }) => dataField)
83
+ .map(({ header, downloadHeader }) => (downloadHeader || header));
84
+ const csv = convertToCSV(jsonse, keysToInclude, headers);
85
+ const exportData = new Blob([csv], { type: 'text/csv' });
86
+ const JsonURL = window.URL.createObjectURL(exportData);
87
+ let tempLink = '';
88
+ tempLink = document.createElement('a');
89
+ tempLink.setAttribute('href', JsonURL);
90
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'csv'));
91
+ document.body.appendChild(tempLink);
92
+ tempLink.click();
93
+ document.body.removeChild(tempLink);
94
+ }
95
+
96
+ export function downloadJson(tableData, table, downloadFileName) {
97
+ const { columns = [] } = table;
98
+ const toDelete = columns.filter((e) => !e.display);
99
+ const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType))
100
+ .filter(({ display }) => display);
101
+ let formatDataVal = formatColumnValues(filterColumns, tableData);
102
+ formatDataVal = formatDataVal.map((entry) => {
103
+ let survivalStatus = entry.last_known_survival_status;
104
+ let sampleId = entry.sample_id;
105
+ let dataCategory = entry.data_category;
106
+ const toReturn = { ...entry };
107
+
108
+ if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
109
+ survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
110
+ toReturn['Last Known Survival Status'] = survivalStatus;
111
+ }
112
+ if (sampleId && sampleId.toString().charAt(0) === '[' && sampleId.toString().charAt(sampleId.toString().length - 1) === ']') {
113
+ sampleId = sampleId.toString().substring(1, sampleId.length - 1);
114
+ toReturn['Sample Id'] = sampleId;
115
+ }
116
+ if (dataCategory && dataCategory.toString().charAt(0) === '[' && dataCategory.toString().charAt(dataCategory.toString().length - 1) === ']') {
117
+ dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
118
+ toReturn['Data Category'] = dataCategory;
119
+ }
120
+ toDelete.forEach((column) => delete toReturn[column.dataField]);
121
+ return toReturn;
122
+ });
123
+ filterColumns.forEach((column) => {
124
+ formatDataVal = JSON.parse(
125
+ JSON.stringify(formatDataVal).split(`"${column.dataField}":`).join(`"${column.header}":`),
126
+ );
127
+ });
128
+ const jsonse = JSON.stringify(formatDataVal);
129
+ const exportData = new Blob([jsonse], { type: 'application/json' });
130
+ const JsonURL = window.URL.createObjectURL(exportData);
131
+ let tempLink = '';
132
+ tempLink = document.createElement('a');
133
+ tempLink.setAttribute('href', JsonURL);
134
+ tempLink.setAttribute('download', createFileName(downloadFileName || '', 'json'));
135
+ document.body.appendChild(tempLink);
136
+ tempLink.click();
137
+ document.body.removeChild(tempLink);
138
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * query varibales to fetch all the selected files id
3
+ */
4
+ export const getQueryVariables = (variables) => {
5
+ const queryVariables = { ...variables };
6
+ queryVariables.first = 200000;
7
+ return queryVariables;
8
+ };
9
+
10
+ export const getFilesID = ({
11
+ client,
12
+ variables,
13
+ query,
14
+ }) => {
15
+ const queryVariables = getQueryVariables(variables);
16
+ return async function getFileIDs() {
17
+ const fetchResult = await client
18
+ .query({
19
+ query,
20
+ variables: queryVariables,
21
+ })
22
+ .then((response) => response.data);
23
+ return fetchResult;
24
+ };
25
+ };
@@ -0,0 +1,62 @@
1
+ import React, { useState } from 'react';
2
+ import { useApolloClient } from '@apollo/client';
3
+ import CPIFilesView from './CPIFilesView/CPIFilesView';
4
+ import SnackbarView from './Snackbar/Snackbar';
5
+ import AlertView from './AddToCartDialog/AddToCartDialogAlertView';
6
+
7
+ export const btnTypes = {
8
+ ADD_ALL_FILES: 'ADD_ALL_FILES',
9
+ ADD_SELECTED_FILES: 'ADD_SELECTED_FILES',
10
+ DOWNLOAD_MANIFEST: 'DOWNLOAD_MANIFEST',
11
+ };
12
+ /**
13
+ * customize button based on configuration
14
+ * refer config table (wrapper component config)
15
+ */
16
+ const AddFilesView = (props) => {
17
+ const {
18
+ count,
19
+ alertMessage,
20
+ cartFiles,
21
+ buttonStyle,
22
+ } = props;
23
+ /**
24
+ * snackbar state
25
+ */
26
+ const [openSnackbar, setOpenSnackbar] = useState(false);
27
+
28
+ /**
29
+ * conditionally display max file Alter/Error dialog view
30
+ */
31
+ const [displayAlter, setAlterDisplay] = useState(false);
32
+ /**
33
+ * acess bento app client via ApolloProvider
34
+ */
35
+ const client = useApolloClient();
36
+ return (
37
+ <>
38
+ <CPIFilesView
39
+ {...props}
40
+ client={client}
41
+ setAlterDisplay={setAlterDisplay}
42
+ setOpenSnackbar={setOpenSnackbar}
43
+ cartFiles={cartFiles}
44
+ buttonStyle={buttonStyle}
45
+ />
46
+ <SnackbarView
47
+ open={openSnackbar}
48
+ count={count}
49
+ onClose={() => setOpenSnackbar(false)}
50
+ />
51
+ {(displayAlter) && (
52
+ <AlertView
53
+ alertMessage={alertMessage}
54
+ open={displayAlter}
55
+ onClose={() => setAlterDisplay(false)}
56
+ />
57
+ )}
58
+ </>
59
+ );
60
+ };
61
+
62
+ export default AddFilesView;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import {
3
+ Dialog, DialogContent, DialogContentText,
4
+ } from '@material-ui/core';
5
+
6
+ function AddToCartDialogAlertView(props) {
7
+ const {
8
+ open,
9
+ onClose,
10
+ alertMessage,
11
+ } = props;
12
+ const closeAlertModelTimer = 4000;
13
+
14
+ const AlertDialog = (
15
+ <>
16
+ <Dialog
17
+ open={open}
18
+ aria-labelledby="alert-dialog-title"
19
+ aria-describedby="alert-dialog-description"
20
+ >
21
+ <DialogContent className="alter-content">
22
+ <DialogContentText id="alert-dialog-description">
23
+ {alertMessage}
24
+ </DialogContentText>
25
+ </DialogContent>
26
+ </Dialog>
27
+ </>
28
+ );
29
+
30
+ if (open) {
31
+ // close the Dialog after 3 seconds.
32
+ setTimeout(() => { onClose(); }, closeAlertModelTimer);
33
+ }
34
+ return AlertDialog;
35
+ }
36
+
37
+ export default AddToCartDialogAlertView;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import Dialog from './AddToCartDialogView';
3
+ import Alert from './AddToCartDialogAlertView';
4
+
5
+ const AddToCartDialogController = (props) => {
6
+ const [open, setOpen] = React.useState(false);
7
+
8
+ const handleClose = () => {
9
+ setOpen(false);
10
+ };
11
+
12
+ const {
13
+ cartWillFull = false,
14
+ numberOfFilesSelected,
15
+ onYesClick,
16
+ onNoClick,
17
+ } = props;
18
+
19
+ if (cartWillFull) {
20
+ return <Alert open={open} onClose={handleClose} />;
21
+ }
22
+ return (
23
+ <Dialog
24
+ open={open}
25
+ numberOfFilesSelected={numberOfFilesSelected}
26
+ onYesClick={onYesClick}
27
+ onNoClick={onNoClick}
28
+ />
29
+ );
30
+ };
31
+
32
+ export default AddToCartDialogController;
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import {
3
+ Dialog, DialogActions, DialogContent, DialogContentText, Button,
4
+ } from '@material-ui/core';
5
+ import Alert from './AddToCartDialogAlertView';
6
+
7
+ function AddToCartDialogView(props) {
8
+ const {
9
+ open,
10
+ numberOfFilesSelected,
11
+ onYesClick,
12
+ onNoClick,
13
+ cartWillFull = false,
14
+ alertMessage,
15
+ dialogText,
16
+ } = props;
17
+
18
+ if (cartWillFull) {
19
+ return (
20
+ <Alert
21
+ alertMessage={alertMessage}
22
+ open={open}
23
+ onClose={() => onNoClick()}
24
+ />
25
+ );
26
+ }
27
+
28
+ return (
29
+ <>
30
+ <Dialog
31
+ open={open}
32
+ aria-labelledby="alert-dialog-title"
33
+ aria-describedby="alert-dialog-description"
34
+ >
35
+ <DialogContent>
36
+ <DialogContentText id="alert-dialog-description">
37
+ {dialogText}
38
+ {' '}
39
+ {numberOfFilesSelected}
40
+ {' '}
41
+ to cart
42
+ </DialogContentText>
43
+ </DialogContent>
44
+ <DialogActions>
45
+ <Button className="yesBtn" onClick={() => onYesClick()}>
46
+ Yes
47
+ </Button>
48
+ <Button className="noBtn" onClick={() => onNoClick()}>
49
+ No
50
+ </Button>
51
+ </DialogActions>
52
+ </Dialog>
53
+ </>
54
+ );
55
+ }
56
+
57
+ export default AddToCartDialogView;