@bento-core/table 1.0.1-ccdihub.99 → 1.0.1-ccdiintegrated.10
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 +135 -8
- package/dist/TableView.js +25 -7
- package/dist/body/CustomTblBody.js +2 -1
- package/dist/body/DefaultThemConfig.js +1 -1
- package/dist/body/DisplayBodyCell.js +24 -2
- package/dist/body/components/CPIMappingView.js +221 -0
- package/dist/body/components/CPIModal.js +440 -94
- package/dist/body/components/CPIView.js +64 -10
- package/dist/body/components/CustomLinkView.js +2 -1
- package/dist/body/components/DataFormatView.js +1 -1
- package/dist/body/components/StudiesDataAvailabilityView.js +125 -0
- package/dist/body/components/assets/CPI_Icon_Dataset.svg +6 -0
- package/dist/body/components/assets/CPI_Icon_Multi.svg +6 -0
- package/dist/body/components/assets/CPI_Icon_Single.svg +4 -0
- package/dist/body/components/assets/CPI_Icon_Study.svg +11 -0
- package/dist/body/components/assets/Participant_Files.svg +17 -0
- package/dist/body/components/assets/Publications.svg +15 -0
- package/dist/body/components/assets/Sample_Files.svg +16 -0
- package/dist/body/components/assets/Study_Files.svg +21 -0
- package/dist/body/components/assets/download.svg +3 -0
- package/dist/header/CustomCell.js +4 -3
- package/dist/header/CustomTblHeader.js +16 -3
- package/dist/index.js +25 -0
- package/dist/toolbar/DownloadButtonView.js +30 -4
- package/dist/toolbar/SearchBar.js +92 -0
- package/dist/toolbar/assets/Search_Icon.svg +3 -0
- package/dist/util/Dataformat.js +50 -2
- package/dist/util/Types.js +16 -4
- package/dist/util/downloadTable.js +77 -53
- package/dist/wrapper/components/AddFiles.js +6 -14
- package/dist/wrapper/components/AddToCart/AddToCartView.js +128 -0
- package/dist/wrapper/components/AddToCart/ReduxAddToCart.js +28 -0
- package/dist/wrapper/components/CPIFilesView/CPIFilesView.js +12 -6
- package/dist/wrapper/components/ReduxAddFile.js +1 -0
- package/dist/wrapper/components/Snackbar/CartToast.js +96 -0
- package/dist/wrapper/components/Snackbar/Snackbar.js +12 -1
- package/dist/wrapper/components/Snackbar/SnackbarRedux.js +2 -1
- package/package.json +23 -22
- package/src/ExtendedView.js +147 -8
- package/src/TableView.js +29 -8
- package/src/body/CustomTblBody.js +2 -1
- package/src/body/DefaultThemConfig.js +1 -1
- package/src/body/DisplayBodyCell.js +40 -2
- package/src/body/components/CPIMappingView.js +260 -0
- package/src/body/components/CPIModal.js +468 -101
- package/src/body/components/CPIView.js +75 -22
- package/src/body/components/CustomLinkView.js +4 -1
- package/src/body/components/DataFormatView.js +4 -2
- package/src/body/components/StudiesDataAvailabilityView.js +121 -0
- package/src/body/components/assets/CPI_Icon_Dataset.svg +6 -0
- package/src/body/components/assets/CPI_Icon_Multi.svg +6 -0
- package/src/body/components/assets/CPI_Icon_Single.svg +4 -0
- package/src/body/components/assets/CPI_Icon_Study.svg +11 -0
- package/src/body/components/assets/Participant_Files.svg +17 -0
- package/src/body/components/assets/Publications.svg +15 -0
- package/src/body/components/assets/Sample_Files.svg +16 -0
- package/src/body/components/assets/Study_Files.svg +21 -0
- package/src/body/components/assets/download.svg +3 -0
- package/src/header/CustomCell.js +4 -3
- package/src/header/CustomTblHeader.js +13 -1
- package/src/index.js +7 -1
- package/src/toolbar/DownloadButtonView.js +20 -4
- package/src/toolbar/SearchBar.js +90 -0
- package/src/toolbar/assets/Search_Icon.svg +3 -0
- package/src/util/Dataformat.js +47 -0
- package/src/util/Types.js +10 -1
- package/src/util/downloadTable.js +75 -34
- package/src/wrapper/components/AddFiles.js +7 -14
- package/src/wrapper/components/AddToCart/AddToCartView.js +134 -0
- package/src/wrapper/components/AddToCart/ReduxAddToCart.js +21 -0
- package/src/wrapper/components/CPIFilesView/CPIFilesView.js +15 -9
- package/src/wrapper/components/ReduxAddFile.js +1 -0
- package/src/wrapper/components/Snackbar/CartToast.js +99 -0
- package/src/wrapper/components/Snackbar/Snackbar.js +8 -3
- package/src/wrapper/components/Snackbar/SnackbarRedux.js +2 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
IconButton,
|
|
4
|
+
InputBase,
|
|
5
|
+
makeStyles,
|
|
6
|
+
} from '@material-ui/core';
|
|
7
|
+
import SearchIcon from './assets/Search_Icon.svg';
|
|
8
|
+
|
|
9
|
+
const SearchBar = ({ onSearch }) => {
|
|
10
|
+
const [searchValue, setSearchValue] = useState('');
|
|
11
|
+
|
|
12
|
+
const handleSearchClick = () => {
|
|
13
|
+
if (onSearch) {
|
|
14
|
+
onSearch(searchValue);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const handleKeyPress = (event) => {
|
|
19
|
+
if (event.key === 'Enter') {
|
|
20
|
+
handleSearchClick();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const handleChange = (event) => {
|
|
25
|
+
setSearchValue(event.target.value);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const useStyles = makeStyles({
|
|
29
|
+
searchContainer: {
|
|
30
|
+
display: 'flex',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
border: '0.75px solid #606060',
|
|
33
|
+
borderRadius: '5px',
|
|
34
|
+
backgroundColor: '#ffffff',
|
|
35
|
+
height: '36px',
|
|
36
|
+
width: '300px',
|
|
37
|
+
paddingLeft: '12px',
|
|
38
|
+
paddingRight: '4px',
|
|
39
|
+
marginTop: '8px',
|
|
40
|
+
marginBottom: '8px',
|
|
41
|
+
marginLeft: '-28px',
|
|
42
|
+
float: 'left',
|
|
43
|
+
},
|
|
44
|
+
inputBase: {
|
|
45
|
+
flex: 1,
|
|
46
|
+
fontFamily: 'Poppins',
|
|
47
|
+
fontSize: '14px',
|
|
48
|
+
color: '#000000',
|
|
49
|
+
'& input::placeholder': {
|
|
50
|
+
color: '#9B9B9B',
|
|
51
|
+
opacity: 1,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
searchButton: {
|
|
55
|
+
padding: '6px',
|
|
56
|
+
backgroundColor: 'transparent',
|
|
57
|
+
'&:hover': {
|
|
58
|
+
backgroundColor: 'rgba(0, 0, 0, 0.04)',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
searchIcon: {
|
|
62
|
+
width: '15px',
|
|
63
|
+
height: '15px',
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const classes = useStyles();
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className={classes.searchContainer}>
|
|
71
|
+
<InputBase
|
|
72
|
+
className={classes.inputBase}
|
|
73
|
+
placeholder="Search..."
|
|
74
|
+
value={searchValue}
|
|
75
|
+
onChange={handleChange}
|
|
76
|
+
onKeyPress={handleKeyPress}
|
|
77
|
+
inputProps={{ 'aria-label': 'search' }}
|
|
78
|
+
/>
|
|
79
|
+
<IconButton
|
|
80
|
+
className={classes.searchButton}
|
|
81
|
+
onClick={handleSearchClick}
|
|
82
|
+
aria-label="search"
|
|
83
|
+
>
|
|
84
|
+
<img src={SearchIcon} alt="search" className={classes.searchIcon} />
|
|
85
|
+
</IconButton>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default SearchBar;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M6.4134 1C3.43007 1 1 3.43007 1 6.4134C1 9.39672 3.43007 11.8268 6.4134 11.8268C7.71072 11.8268 8.90214 11.3661 9.83589 10.6014L13.0681 13.8336C13.118 13.8855 13.1777 13.927 13.2438 13.9556C13.3099 13.9841 13.3811 13.9992 13.4531 14C13.5251 14.0007 13.5966 13.9871 13.6632 13.9598C13.7299 13.9326 13.7905 13.8924 13.8414 13.8414C13.8924 13.7905 13.9326 13.7299 13.9598 13.6632C13.9871 13.5966 14.0007 13.5251 14 13.4531C13.9992 13.3811 13.9841 13.3099 13.9556 13.2438C13.927 13.1777 13.8855 13.118 13.8336 13.0681L10.6014 9.83589C11.3661 8.90214 11.8268 7.71072 11.8268 6.4134C11.8268 3.43007 9.39672 1 6.4134 1ZM6.4134 2.08268C8.8116 2.08268 10.7441 4.0152 10.7441 6.4134C10.7441 8.8116 8.8116 10.7441 6.4134 10.7441C4.0152 10.7441 2.08268 8.8116 2.08268 6.4134C2.08268 4.0152 4.0152 2.08268 6.4134 2.08268Z" fill="#4D889E" stroke="#4D889E"/>
|
|
3
|
+
</svg>
|
package/src/util/Dataformat.js
CHANGED
|
@@ -31,3 +31,50 @@ export const formatColumnValues = (columns, data) => {
|
|
|
31
31
|
}
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Column flag `stripSurroundingBrackets: false` disables OpenSearch
|
|
37
|
+
* bracket-stripping for that column. Default (undefined/true) is enabled.
|
|
38
|
+
*/
|
|
39
|
+
export const isBracketStripEnabled = (column = {}) => (
|
|
40
|
+
column.stripSurroundingBrackets !== false
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Remove wrapping square brackets from OpenSearch array-as-string values.
|
|
45
|
+
* "[Complete Response]" => "Complete Response"; "[]" => "".
|
|
46
|
+
*/
|
|
47
|
+
export const stripSurroundingBrackets = (value) => {
|
|
48
|
+
if (value == null) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.map((item) => stripSurroundingBrackets(item));
|
|
53
|
+
}
|
|
54
|
+
if (typeof value !== 'string') {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const text = value.trim();
|
|
58
|
+
if (text === '[]') {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
if (text.startsWith('[') && text.endsWith(']')) {
|
|
62
|
+
return text.slice(1, -1).trim();
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Display helper: strip wrapping brackets and join arrays. */
|
|
68
|
+
export const formatValueForDisplay = (value) => {
|
|
69
|
+
const stripped = stripSurroundingBrackets(value);
|
|
70
|
+
if (Array.isArray(stripped)) {
|
|
71
|
+
return stripped
|
|
72
|
+
.map((item) => (item == null ? '' : String(item)))
|
|
73
|
+
.filter(Boolean)
|
|
74
|
+
.join(', ');
|
|
75
|
+
}
|
|
76
|
+
if (stripped == null) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
return String(stripped);
|
|
80
|
+
};
|
package/src/util/Types.js
CHANGED
|
@@ -6,11 +6,16 @@ export const DISPLAY = 'DISPLAY';
|
|
|
6
6
|
export const DEFAULT = 'DEFAULT';
|
|
7
7
|
export const FORMAT_DATA = 'FORMAT_DATA';
|
|
8
8
|
export const CPI = 'CPI';
|
|
9
|
+
export const CPI_MAPPING = 'CPI_MAPPING';
|
|
9
10
|
export const FORMAT_BYTES = 'FORMAT_BYTES';
|
|
10
11
|
export const TRANSFORM = 'TRANSFORM';
|
|
11
12
|
export const STUDY_DOWNLOAD = 'STUDY_DOWNLOAD';
|
|
12
13
|
export const EXPAND = 'EXPAND';
|
|
13
14
|
export const DBGAP = 'DBGAP';
|
|
15
|
+
export const MODAL = 'MODAL';
|
|
16
|
+
export const EXCLUDE_FROM_DOWNLOAD = 'EXCLUDE_FROM_DOWNLOAD';
|
|
17
|
+
|
|
18
|
+
export const STUDIES = 'STUDIES';
|
|
14
19
|
|
|
15
20
|
export const cellTypes = {
|
|
16
21
|
CUSTOM_ELEM,
|
|
@@ -21,6 +26,8 @@ export const cellTypes = {
|
|
|
21
26
|
DEFAULT,
|
|
22
27
|
FORMAT_DATA,
|
|
23
28
|
CPI,
|
|
29
|
+
CPI_MAPPING,
|
|
30
|
+
STUDIES,
|
|
24
31
|
};
|
|
25
32
|
|
|
26
33
|
export const cellStyles = {
|
|
@@ -28,11 +35,13 @@ export const cellStyles = {
|
|
|
28
35
|
EXPAND,
|
|
29
36
|
DBGAP,
|
|
30
37
|
STUDY_DOWNLOAD,
|
|
38
|
+
MODAL,
|
|
39
|
+
EXCLUDE_FROM_DOWNLOAD,
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
export const actionCellTypes = [CHECKBOX, DELETE];
|
|
34
43
|
|
|
35
|
-
export const notIncludedCellStyle = [STUDY_DOWNLOAD];
|
|
44
|
+
export const notIncludedCellStyle = [STUDY_DOWNLOAD, EXCLUDE_FROM_DOWNLOAD];
|
|
36
45
|
|
|
37
46
|
export const FORMAT_DATA_CELLS = [FORMAT_BYTES];
|
|
38
47
|
|
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
1
|
+
import { formatBytes, formatColumnValues, stripSurroundingBrackets } from './Dataformat';
|
|
2
2
|
import { actionCellTypes, notIncludedCellStyle } from './Types';
|
|
3
3
|
|
|
4
|
+
const AGE_FIELDS = new Set([
|
|
5
|
+
'age_at_diagnosis',
|
|
6
|
+
'participant_age_at_collection',
|
|
7
|
+
'age_at_treatment_start',
|
|
8
|
+
'age_at_treatment_end',
|
|
9
|
+
'age_at_response',
|
|
10
|
+
'age_at_last_known_survival_status',
|
|
11
|
+
'age_at_event_free_survival_status',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sentinel OpenSearch age values (-999) become "Not Reported" for CSV/JSON download.
|
|
16
|
+
* Supports scalars, arrays (files table), and bracketed strings.
|
|
17
|
+
*/
|
|
18
|
+
export function formatAgeForDownload(value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
if (value.length === 0) {
|
|
21
|
+
return 'Not Reported';
|
|
22
|
+
}
|
|
23
|
+
return value.map((item) => formatAgeForDownload(item)).join('; ');
|
|
24
|
+
}
|
|
25
|
+
if (value === -999 || value === '-999' || value == null || value === '') {
|
|
26
|
+
return 'Not Reported';
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'string' && value.startsWith('[') && value.endsWith(']')) {
|
|
29
|
+
const inner = value.slice(1, -1).trim();
|
|
30
|
+
if (!inner) {
|
|
31
|
+
return 'Not Reported';
|
|
32
|
+
}
|
|
33
|
+
return inner.split(',').map((item) => formatAgeForDownload(item.trim())).join('; ');
|
|
34
|
+
}
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
4
38
|
export function createFileName(fileName, type) {
|
|
5
39
|
const date = new Date();
|
|
6
40
|
const yyyy = date.getFullYear();
|
|
@@ -40,22 +74,25 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
40
74
|
if (line !== '') line += ',';
|
|
41
75
|
if (keyName === 'file_size') {
|
|
42
76
|
line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
|
|
43
|
-
} else if (keyName
|
|
44
|
-
if (entry[keyName]
|
|
45
|
-
line += '
|
|
77
|
+
} else if (AGE_FIELDS.has(keyName)) {
|
|
78
|
+
if (entry[keyName] == null) {
|
|
79
|
+
line += ' ';
|
|
46
80
|
} else {
|
|
47
|
-
line +=
|
|
81
|
+
line += `"${formatAgeForDownload(entry[keyName])}"`;
|
|
48
82
|
}
|
|
49
|
-
} else
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
line += `"${entry[keyName].toString().substring(1, entry[keyName].length - 1)}"`;
|
|
83
|
+
} else {
|
|
84
|
+
const raw = entry[keyName];
|
|
85
|
+
if (raw == null) {
|
|
86
|
+
line += ' ';
|
|
54
87
|
} else {
|
|
55
|
-
|
|
88
|
+
const stripped = stripSurroundingBrackets(raw);
|
|
89
|
+
if (stripped === '' || stripped === '[]') {
|
|
90
|
+
line += '';
|
|
91
|
+
} else {
|
|
92
|
+
const display = Array.isArray(stripped) ? stripped.join(', ') : stripped;
|
|
93
|
+
line += `"${display}"`;
|
|
94
|
+
}
|
|
56
95
|
}
|
|
57
|
-
} else {
|
|
58
|
-
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
59
96
|
}
|
|
60
97
|
return line;
|
|
61
98
|
});
|
|
@@ -70,11 +107,18 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
70
107
|
return str;
|
|
71
108
|
}
|
|
72
109
|
|
|
110
|
+
/** Columns shown in the table, or marked downloadOnly (hidden in the UI, included in export). */
|
|
111
|
+
const isIncludedInDownload = ({ display, downloadOnly }) => Boolean(display || downloadOnly);
|
|
112
|
+
|
|
113
|
+
export function getDownloadColumns(columns = []) {
|
|
114
|
+
return columns.filter(({ cellType }) => !actionCellTypes.includes(cellType))
|
|
115
|
+
.filter(({ cellStyle }) => !notIncludedCellStyle.includes(cellStyle))
|
|
116
|
+
.filter(isIncludedInDownload);
|
|
117
|
+
}
|
|
118
|
+
|
|
73
119
|
export function downloadCSV(tableData, table, downloadFileName) {
|
|
74
120
|
const { columns = [] } = table;
|
|
75
|
-
const filterColumns = columns
|
|
76
|
-
.filter(({ cellStyle }) => !notIncludedCellStyle.includes(cellStyle))
|
|
77
|
-
.filter(({ display }) => display);
|
|
121
|
+
const filterColumns = getDownloadColumns(columns);
|
|
78
122
|
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
79
123
|
const jsonse = JSON.stringify(formatDataVal);
|
|
80
124
|
const keysToInclude = filterColumns.filter(({ dataField }) => dataField)
|
|
@@ -95,28 +139,25 @@ export function downloadCSV(tableData, table, downloadFileName) {
|
|
|
95
139
|
|
|
96
140
|
export function downloadJson(tableData, table, downloadFileName) {
|
|
97
141
|
const { columns = [] } = table;
|
|
98
|
-
const toDelete = columns.filter((e) => !e.display);
|
|
99
|
-
const filterColumns = columns
|
|
100
|
-
.filter(({ display }) => display);
|
|
142
|
+
const toDelete = columns.filter((e) => !e.display && !e.downloadOnly);
|
|
143
|
+
const filterColumns = getDownloadColumns(columns);
|
|
101
144
|
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
102
145
|
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
146
|
const toReturn = { ...entry };
|
|
107
147
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
toReturn[
|
|
119
|
-
}
|
|
148
|
+
AGE_FIELDS.forEach((field) => {
|
|
149
|
+
if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
|
|
150
|
+
toReturn[field] = formatAgeForDownload(entry[field]);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
Object.keys(toReturn).forEach((key) => {
|
|
155
|
+
if (AGE_FIELDS.has(key)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
toReturn[key] = stripSurroundingBrackets(toReturn[key]);
|
|
159
|
+
});
|
|
160
|
+
|
|
120
161
|
toDelete.forEach((column) => delete toReturn[column.dataField]);
|
|
121
162
|
return toReturn;
|
|
122
163
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { useApolloClient } from '@apollo/client';
|
|
3
3
|
import CPIFilesView from './CPIFilesView/CPIFilesView';
|
|
4
|
-
import
|
|
4
|
+
import CartToast from './Snackbar/CartToast';
|
|
5
5
|
import AlertView from './AddToCartDialog/AddToCartDialogAlertView';
|
|
6
6
|
|
|
7
7
|
export const btnTypes = {
|
|
@@ -10,29 +10,21 @@ export const btnTypes = {
|
|
|
10
10
|
DOWNLOAD_MANIFEST: 'DOWNLOAD_MANIFEST',
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Explore CPI add-files button. Uses CartToast (body portal) instead of the
|
|
14
|
+
* Global Search MUI Snackbar so the toast stays visible above the Explore Modal.
|
|
15
15
|
*/
|
|
16
16
|
const AddFilesView = (props) => {
|
|
17
17
|
const {
|
|
18
18
|
count,
|
|
19
|
+
alreadyInCartCount,
|
|
19
20
|
alertMessage,
|
|
20
21
|
cartFiles,
|
|
21
22
|
buttonStyle,
|
|
22
23
|
} = props;
|
|
23
|
-
/**
|
|
24
|
-
* snackbar state
|
|
25
|
-
*/
|
|
26
24
|
const [openSnackbar, setOpenSnackbar] = useState(false);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* conditionally display max file Alter/Error dialog view
|
|
30
|
-
*/
|
|
31
25
|
const [displayAlter, setAlterDisplay] = useState(false);
|
|
32
|
-
/**
|
|
33
|
-
* acess bento app client via ApolloProvider
|
|
34
|
-
*/
|
|
35
26
|
const client = useApolloClient();
|
|
27
|
+
|
|
36
28
|
return (
|
|
37
29
|
<>
|
|
38
30
|
<CPIFilesView
|
|
@@ -43,9 +35,10 @@ const AddFilesView = (props) => {
|
|
|
43
35
|
cartFiles={cartFiles}
|
|
44
36
|
buttonStyle={buttonStyle}
|
|
45
37
|
/>
|
|
46
|
-
<
|
|
38
|
+
<CartToast
|
|
47
39
|
open={openSnackbar}
|
|
48
40
|
count={count}
|
|
41
|
+
alreadyInCartCount={alreadyInCartCount}
|
|
49
42
|
onClose={() => setOpenSnackbar(false)}
|
|
50
43
|
/>
|
|
51
44
|
{(displayAlter) && (
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import ToolTip from '@bento-core/tool-tip';
|
|
3
|
+
import { Button } from '@material-ui/core';
|
|
4
|
+
import SnackbarView from '../Snackbar/Snackbar';
|
|
5
|
+
import AlertView from '../AddToCartDialog/AddToCartDialogAlertView';
|
|
6
|
+
|
|
7
|
+
const customTooltip = {
|
|
8
|
+
border: '#03A383 1px solid',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const customArrow = {
|
|
12
|
+
'&::before': {
|
|
13
|
+
border: '#03A383 1px solid',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const iconStyle = {
|
|
18
|
+
paddingRight: '20px',
|
|
19
|
+
paddingBottom: '20px',
|
|
20
|
+
paddingLeft: '5px',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const ToolTipView = (props) => {
|
|
24
|
+
const {
|
|
25
|
+
section,
|
|
26
|
+
tooltipCofig,
|
|
27
|
+
} = props;
|
|
28
|
+
const {
|
|
29
|
+
icon,
|
|
30
|
+
src,
|
|
31
|
+
alt,
|
|
32
|
+
arrow = false,
|
|
33
|
+
tooltipText,
|
|
34
|
+
} = tooltipCofig;
|
|
35
|
+
return (
|
|
36
|
+
<ToolTip
|
|
37
|
+
placement="top"
|
|
38
|
+
title={tooltipText || `${tooltipCofig[section]}`}
|
|
39
|
+
arrow={arrow}
|
|
40
|
+
classes={{
|
|
41
|
+
tooltip: customTooltip,
|
|
42
|
+
arrow: customArrow,
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<img src={icon || src} alt={alt} style={iconStyle} />
|
|
46
|
+
</ToolTip>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// const checkDuplicate = (cartFiles, ids) => {
|
|
51
|
+
// const newIds = [];
|
|
52
|
+
// for (let i = 0; i < ids.length; i += 1) {
|
|
53
|
+
// if (!cartFiles.includes(ids[i])) {
|
|
54
|
+
// newIds.push(ids[i]);
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
57
|
+
// return newIds;
|
|
58
|
+
// };
|
|
59
|
+
|
|
60
|
+
const checkDuplicate = (cartFiles, ids) => (ids.filter((id) => !cartFiles[id]));
|
|
61
|
+
|
|
62
|
+
const AddToCartView = (props) => {
|
|
63
|
+
const {
|
|
64
|
+
cartFiles,
|
|
65
|
+
fileId,
|
|
66
|
+
buttonStyle,
|
|
67
|
+
addFiles,
|
|
68
|
+
count,
|
|
69
|
+
alreadyInCartCount,
|
|
70
|
+
} = props;
|
|
71
|
+
|
|
72
|
+
// const [isDataloading, setIsDataloading] = useState(false);
|
|
73
|
+
const [openSnackbar, setOpenSnackbar] = useState(false);
|
|
74
|
+
const [displayAlter, setAlterDisplay] = useState(false);
|
|
75
|
+
|
|
76
|
+
const cartFilesDict = {};
|
|
77
|
+
cartFiles.forEach((file) => { cartFilesDict[file] = true; });
|
|
78
|
+
|
|
79
|
+
// const backdropCls = {
|
|
80
|
+
// width: '100%',
|
|
81
|
+
// zIndex: 99999,
|
|
82
|
+
// background: 'rgba(0, 0, 0, 0.1)',
|
|
83
|
+
// };
|
|
84
|
+
/**
|
|
85
|
+
* verify and set file ids
|
|
86
|
+
*/
|
|
87
|
+
const addAllFiles = () => {
|
|
88
|
+
const idsInitial = fileId || [];
|
|
89
|
+
const ids = Array.isArray(idsInitial) ? idsInitial : [idsInitial];
|
|
90
|
+
const fileCount = ids.length;
|
|
91
|
+
const upperLimit = 200000;
|
|
92
|
+
const cartCount = cartFiles.length;
|
|
93
|
+
if (fileCount <= upperLimit && cartCount < upperLimit) {
|
|
94
|
+
const newIds = checkDuplicate(cartFiles, ids);
|
|
95
|
+
if (cartCount + newIds.length <= upperLimit) {
|
|
96
|
+
addFiles(ids);
|
|
97
|
+
setOpenSnackbar(true);
|
|
98
|
+
} else {
|
|
99
|
+
setAlterDisplay(true);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
setAlterDisplay(true);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<>
|
|
108
|
+
<Button
|
|
109
|
+
variant="outlined"
|
|
110
|
+
onClick={addAllFiles}
|
|
111
|
+
disableRipple
|
|
112
|
+
style={buttonStyle}
|
|
113
|
+
disabled={false}
|
|
114
|
+
>
|
|
115
|
+
ADD TO CART
|
|
116
|
+
</Button>
|
|
117
|
+
<SnackbarView
|
|
118
|
+
open={openSnackbar}
|
|
119
|
+
count={count}
|
|
120
|
+
alreadyInCartCount={alreadyInCartCount}
|
|
121
|
+
onClose={() => setOpenSnackbar(false)}
|
|
122
|
+
/>
|
|
123
|
+
{displayAlter && (
|
|
124
|
+
<AlertView
|
|
125
|
+
alertMessage="The cart is limited to 200,000 files. Please narrow the search criteria or remove some files from the cart to add more."
|
|
126
|
+
open={displayAlter}
|
|
127
|
+
onClose={() => setAlterDisplay(false)}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default AddToCartView;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { connect } from 'react-redux';
|
|
3
|
+
import { onAddCartFiles } from '@bento-core/cart';
|
|
4
|
+
import AddToCartView from './AddToCartView';
|
|
5
|
+
|
|
6
|
+
const AddToCartRedux = (props) => <AddToCartView {...props} />;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* create query variable with actie filters
|
|
10
|
+
*/
|
|
11
|
+
const mapStateToProps = (state) => ({
|
|
12
|
+
count: state.cartReducer && state.cartReducer.count,
|
|
13
|
+
alreadyInCartCount: state.cartReducer && state.cartReducer.alreadyInCartCount,
|
|
14
|
+
cartFiles: state.cartReducer && state.cartReducer.filesId,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const mapDispatchToProps = (dispatch) => ({
|
|
18
|
+
addFiles: (files) => { dispatch(onAddCartFiles(files)); },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default connect(mapStateToProps, mapDispatchToProps)(AddToCartRedux);
|
|
@@ -62,12 +62,12 @@ export const ToolTipView = (props) => {
|
|
|
62
62
|
const checkDuplicate = (cartFiles, ids) => (ids.filter((id) => !cartFiles[id]));
|
|
63
63
|
|
|
64
64
|
const addFileQuery = gql`
|
|
65
|
-
query search (
|
|
66
|
-
$
|
|
65
|
+
query search (
|
|
66
|
+
$pid: [String],
|
|
67
67
|
){
|
|
68
|
-
fileIDsFromList (
|
|
69
|
-
|
|
70
|
-
)
|
|
68
|
+
fileIDsFromList (
|
|
69
|
+
pid: $pid,
|
|
70
|
+
)
|
|
71
71
|
}
|
|
72
72
|
`;
|
|
73
73
|
|
|
@@ -86,6 +86,7 @@ const CPIFilesComponent = (props) => {
|
|
|
86
86
|
participantIds,
|
|
87
87
|
buttonStyle,
|
|
88
88
|
rowID,
|
|
89
|
+
onOptionClick,
|
|
89
90
|
} = props;
|
|
90
91
|
/**
|
|
91
92
|
* conditionally display dialog view
|
|
@@ -108,20 +109,25 @@ const CPIFilesComponent = (props) => {
|
|
|
108
109
|
* verify and set file ids
|
|
109
110
|
*/
|
|
110
111
|
const addAllFiles = () => {
|
|
112
|
+
if (typeof onOptionClick === 'function') {
|
|
113
|
+
onOptionClick();
|
|
114
|
+
}
|
|
111
115
|
let toAdd = [];
|
|
112
116
|
if (btnType === 'ADD_ALL_FILES') {
|
|
117
|
+
// Always include the modal participant pid plus any internal CPI-mapped ids.
|
|
118
|
+
toAdd = rowID ? [rowID] : [];
|
|
113
119
|
participantIds.forEach((e) => {
|
|
114
120
|
if (e.data_type === 'internal' && e.p_id) {
|
|
115
121
|
toAdd = toAdd.concat(e.p_id);
|
|
116
122
|
}
|
|
117
|
-
toAdd = toAdd.concat(rowID);
|
|
118
123
|
});
|
|
119
124
|
} else {
|
|
120
|
-
toAdd =
|
|
125
|
+
toAdd = (rowID ? [rowID] : []).concat(participantIds);
|
|
121
126
|
}
|
|
127
|
+
toAdd = [...new Set(toAdd.filter((id) => typeof id === 'string' && id))];
|
|
122
128
|
const fileIds = getFilesID({
|
|
123
129
|
client,
|
|
124
|
-
variables: {
|
|
130
|
+
variables: { pid: toAdd },
|
|
125
131
|
query: addFileQuery,
|
|
126
132
|
});
|
|
127
133
|
const upperLimit = 200000;
|
|
@@ -136,7 +142,7 @@ const CPIFilesComponent = (props) => {
|
|
|
136
142
|
setOpen(true);
|
|
137
143
|
setAddFilesId(ids);
|
|
138
144
|
} else {
|
|
139
|
-
const newIds = checkDuplicate(
|
|
145
|
+
const newIds = checkDuplicate(cartFilesDict, ids);
|
|
140
146
|
if (cartCount + newIds.length <= upperLimit) {
|
|
141
147
|
setOpen(true);
|
|
142
148
|
setAddFilesId(newIds);
|
|
@@ -10,6 +10,7 @@ const AddFilesRedux = (props) => <AddFiles {...props} />;
|
|
|
10
10
|
*/
|
|
11
11
|
const mapStateToProps = (state) => ({
|
|
12
12
|
count: state.cartReducer && state.cartReducer.count,
|
|
13
|
+
alreadyInCartCount: state.cartReducer && state.cartReducer.alreadyInCartCount,
|
|
13
14
|
cartFiles: state.cartReducer && state.cartReducer.filesId,
|
|
14
15
|
});
|
|
15
16
|
|