Skip to content

Commit cda548a

Browse files
author
Adriána Kohanová
committed
#533 RHS tab and filters not preserved in snapshot
1 parent 5b48a2e commit cda548a

File tree

8 files changed

+184
-112
lines changed

8 files changed

+184
-112
lines changed

js/components/datasets/datasetSelectorMenuButton.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Popper from '@material-ui/core/Popper';
66
import MenuItem from '@material-ui/core/MenuItem';
77
import MenuList from '@material-ui/core/MenuList';
88
import { makeStyles } from '@material-ui/core';
9+
import { useDispatch } from 'react-redux';
910

1011
const useStyles = makeStyles(theme => ({
1112
dropDown: {
@@ -21,9 +22,10 @@ export const DatasetSelectorMenuButton = ({
2122
setSelectedDatasetIndex
2223
}) => {
2324
const classes = useStyles();
25+
const dispatch = useDispatch();
2426

2527
const handleMenuItemClick = (event, index) => {
26-
setSelectedDatasetIndex(index);
28+
dispatch(setSelectedDatasetIndex(index));
2729
setOpen(false);
2830
event.stopPropagation();
2931
};

js/components/datasets/redux/actions.js

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export const setMoleculeListIsLoading = isLoading => ({
2626
payload: isLoading
2727
});
2828

29+
export const setSelectedDatasetIndex = selectedIndex => ({
30+
type: constants.SET_SELECTED_DATASET_INDEX,
31+
payload: selectedIndex
32+
});
33+
34+
export const setTabValue = (oldValue, tabValue, tabName, oldName) => ({
35+
type: constants.SET_TAB_VALUE,
36+
payload: { oldValue: oldValue, value: tabValue, name: tabName, oldName: oldName }
37+
});
38+
2939
export const replaceAllMoleculeLists = allMoleculeLists => ({
3040
type: constants.REPLACE_ALL_MOLECULELISTS,
3141
payload: allMoleculeLists

js/components/datasets/redux/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const constants = {
77
ADD_MOLECULELIST: prefix + 'ADD_MOLECULELIST',
88
REMOVE_MOLECULELIST: prefix + 'REMOVE_MOLECULELIST',
99
SET_IS_LOADING_MOLECULE_LIST: prefix + 'SET_IS_LOADING_MOLECULE_LIST',
10+
SET_SELECTED_DATASET_INDEX: prefix + 'SET_SELECTED_DATASET_INDEX',
11+
SET_TAB_VALUE: prefix + 'SET_TAB_VALUE',
1012

1113
SET_FILTER_SETTINGS: prefix + 'SET_FILTER_SETTINGS',
1214
SET_FILTER_PROPERTIES: prefix + 'SET_FILTER_PROPERTIES',

js/components/datasets/redux/reducer.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const INITIAL_STATE = {
77
scoreDatasetMap: {}, // map of $datasetID and its $scoreList
88
scoreCompoundMap: {}, // map of $compoundID and its $scoreList
99

10+
selectedDatasetIndex: 0,
11+
tabValue: 0,
12+
1013
// filter
1114
filterDatasetMap: {}, // map of $datasetID and its $filterSettings
1215
filterPropertiesDatasetMap: {}, // map of $datasetID and its $filterProperties
@@ -138,7 +141,7 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
138141
return Object.assign({}, state, { datasets: action.payload });
139142

140143
case constants.REPLACE_ALL_MOLECULELISTS:
141-
return {...state, moleculeLists: action.payload};
144+
return { ...state, moleculeLists: action.payload };
142145

143146
case constants.ADD_MOLECULELIST:
144147
// initialize also control containers
@@ -161,6 +164,12 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
161164
case constants.SET_IS_LOADING_MOLECULE_LIST:
162165
return Object.assign({}, state, { isLoadingMoleculeList: action.payload });
163166

167+
case constants.SET_SELECTED_DATASET_INDEX:
168+
return Object.assign({}, state, { selectedDatasetIndex: action.payload });
169+
170+
case constants.SET_TAB_VALUE:
171+
return Object.assign({}, state, { tabValue: action.payload.value });
172+
164173
case constants.SET_FILTER_SETTINGS:
165174
const { datasetID, filter } = action.payload;
166175
return { ...state, filterDatasetMap: { ...state.filterDatasetMap, [datasetID]: filter } };
@@ -347,7 +356,7 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
347356
return Object.assign({}, state, { inspirationFragmentList: [...diminishedInspirationFragmentList] });
348357

349358
case constants.SET_ALL_INSPIRATIONS:
350-
return {...state, allInspirations: action.payload};
359+
return { ...state, allInspirations: action.payload };
351360

352361
case constants.APPEND_MOLECULE_TO_COMPOUNDS_TO_BUY_OF_DATASET:
353362
const setOfMolecules = new Set(state.compoundsToBuyDatasetMap[action.payload.datasetID]);

js/components/preview/Preview.js

+37-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ import { loadDatasetCompoundsWithScores, loadDataSets } from '../datasets/redux/
3131
import { SelectedCompoundList } from '../datasets/selectedCompoundsList';
3232
import { DatasetSelectorMenuButton } from '../datasets/datasetSelectorMenuButton';
3333
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
34-
import { setMoleculeListIsLoading, setAllInspirations } from '../datasets/redux/actions';
34+
import {
35+
setMoleculeListIsLoading,
36+
setSelectedDatasetIndex,
37+
setTabValue,
38+
setAllInspirations
39+
} from '../datasets/redux/actions';
3540

3641
const hitNavigatorWidth = 504;
3742

@@ -91,14 +96,15 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
9196
const dispatch = useDispatch();
9297

9398
const customDatasets = useSelector(state => state.datasetsReducers.datasets);
94-
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState(0);
99+
const selectedDatasetIndex = useSelector(state => state.datasetsReducers.selectedDatasetIndex);
95100
const currentDataset = customDatasets[selectedDatasetIndex];
96101
const target_on = useSelector(state => state.apiReducers.target_on);
97102
const isTrackingRestoring = useSelector(state => state.trackingReducers.isTrackingCompoundsRestoring);
98103

99104
const all_mol_lists = useSelector(state => state.apiReducers.all_mol_lists);
100105
const moleculeLists = useSelector(state => state.datasetsReducers.moleculeLists);
101106
const isLoadingMoleculeList = useSelector(state => state.datasetsReducers.isLoadingMoleculeList);
107+
const tabValue = useSelector(state => state.datasetsReducers.tabValue);
102108

103109
/*
104110
Loading datasets
@@ -109,7 +115,7 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
109115
dispatch(loadDataSets(target_on))
110116
.then(results => {
111117
if (Array.isArray(results) && results.length > 0) {
112-
setSelectedDatasetIndex(0);
118+
dispatch(setSelectedDatasetIndex(0));
113119
}
114120
return dispatch(loadDatasetCompoundsWithScores());
115121
})
@@ -189,14 +195,26 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
189195
)}px - ${summaryViewHeight}px - ${projectHistoryHeight}px - ${TABS_HEADER_HEIGHT}px )`;
190196
const [showHistory, setShowHistory] = useState(false);
191197

192-
const [tabValue, setTabValue] = useState(0);
193198
const getTabValue = () => {
194199
if (tabValue === 2) {
195200
return tabValue + selectedDatasetIndex;
196201
}
197202
return tabValue;
198203
};
199204

205+
const getTabName = () => {
206+
if (tabValue === 0) {
207+
return 'Vector selector';
208+
}
209+
if (tabValue === 1) {
210+
return 'Selected compounds';
211+
}
212+
if (tabValue >= 2) {
213+
return currentDataset?.title;
214+
}
215+
return '';
216+
};
217+
200218
useEffect(() => {
201219
// Unmount Preview - reset NGL state
202220
return () => {
@@ -253,13 +271,25 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
253271
aria-label="outlined primary button group"
254272
className={classes.tabButtonGroup}
255273
>
256-
<Button size="small" variant={getTabValue() === 0 ? 'contained' : 'text'} onClick={() => setTabValue(0)}>
274+
<Button
275+
size="small"
276+
variant={getTabValue() === 0 ? 'contained' : 'text'}
277+
onClick={() => dispatch(setTabValue(tabValue, 0, 'Vector selector', getTabName()))}
278+
>
257279
Vector selector
258280
</Button>
259-
<Button size="small" variant={getTabValue() === 1 ? 'contained' : 'text'} onClick={() => setTabValue(1)}>
281+
<Button
282+
size="small"
283+
variant={getTabValue() === 1 ? 'contained' : 'text'}
284+
onClick={() => dispatch(setTabValue(tabValue, 1, 'Selected compounds', getTabName()))}
285+
>
260286
Selected compounds
261287
</Button>
262-
<Button size="small" variant={getTabValue() >= 2 ? 'contained' : 'text'} onClick={() => setTabValue(2)}>
288+
<Button
289+
size="small"
290+
variant={getTabValue() >= 2 ? 'contained' : 'text'}
291+
onClick={() => dispatch(setTabValue(tabValue, 2, currentDataset?.title, getTabName()))}
292+
>
263293
{currentDataset?.title}
264294
</Button>
265295
<Button

js/reducers/tracking/constants.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export const actionType = {
5959
REDO: 'REDO',
6060
ARROW_NAVIGATION: 'ARROW_NAVIGATION',
6161
SNAPSHOT: 'SNAPSHOT',
62+
TAB: 'TAB',
63+
DATASET_INDEX: 'DATASET_INDEX',
64+
DATASET_FILTER: 'DATASET_FILTER',
6265
ALL_HIDE: 'ALL_HIDE',
6366
ALL_TURNED_ON: 'ALL_TURNED_ON',
6467
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
@@ -103,7 +106,8 @@ export const actionDescription = {
103106
TARGET: 'Target',
104107
ALL: 'All',
105108
LIGANDS: 'Ligands',
106-
SIDECHAINS: 'Sidechains'
109+
SIDECHAINS: 'Sidechains',
110+
TAB: 'Tab'
107111
};
108112

109113
export const actionObjectType = {

0 commit comments

Comments
 (0)