Skip to content

Commit

Permalink
#533 RHS tab and filters not preserved in snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Feb 3, 2021
1 parent cda548a commit 33ff8b9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 9 deletions.
4 changes: 3 additions & 1 deletion js/components/datasets/datasetSelectorMenuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const DatasetSelectorMenuButton = ({
const dispatch = useDispatch();

const handleMenuItemClick = (event, index) => {
dispatch(setSelectedDatasetIndex(index));
let oldDataset = customDatasets[selectedDatasetIndex]?.title;
let newDataset = customDatasets[index]?.title;
dispatch(setSelectedDatasetIndex(selectedDatasetIndex, index, newDataset, oldDataset));
setOpen(false);
event.stopPropagation();
};
Expand Down
5 changes: 3 additions & 2 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export const setMoleculeListIsLoading = isLoading => ({
payload: isLoading
});

export const setSelectedDatasetIndex = selectedIndex => ({
export const setSelectedDatasetIndex = (oldValue, tabValue, tabName, oldName, skipTracking = false) => ({
type: constants.SET_SELECTED_DATASET_INDEX,
payload: selectedIndex
payload: { oldValue: oldValue, value: tabValue, name: tabName, oldName: oldName },
skipTracking: skipTracking
});

export const setTabValue = (oldValue, tabValue, tabName, oldName) => ({
Expand Down
2 changes: 1 addition & 1 deletion js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, { isLoadingMoleculeList: action.payload });

case constants.SET_SELECTED_DATASET_INDEX:
return Object.assign({}, state, { selectedDatasetIndex: action.payload });
return Object.assign({}, state, { selectedDatasetIndex: action.payload.value });

case constants.SET_TAB_VALUE:
return Object.assign({}, state, { tabValue: action.payload.value });
Expand Down
3 changes: 2 additions & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
dispatch(loadDataSets(target_on))
.then(results => {
if (Array.isArray(results) && results.length > 0) {
dispatch(setSelectedDatasetIndex(0));
let defaultDataset = results[0]?.unique_name;
dispatch(setSelectedDatasetIndex(0, 0, defaultDataset, defaultDataset, true));
}
return dispatch(loadDatasetCompoundsWithScores());
})
Expand Down
3 changes: 2 additions & 1 deletion js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export const actionDescription = {
ALL: 'All',
LIGANDS: 'Ligands',
SIDECHAINS: 'Sidechains',
TAB: 'Tab'
TAB: 'Tab',
DATASET: 'Dataset'
};

export const actionObjectType = {
Expand Down
30 changes: 27 additions & 3 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ import {
appendMoleculeToCompoundsOfDatasetToBuy,
removeMoleculeFromCompoundsOfDatasetToBuy,
setMoleculeListIsLoading,
setTabValue
setTabValue,
setSelectedDatasetIndex
} from '../../components/datasets/redux/actions';
import { setAllMolLists } from '../api/actions';
import { getUrl, loadAllMolsFromMolGroup } from '../../../js/utils/genericList';
Expand Down Expand Up @@ -1008,7 +1009,19 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
const restoreTabActions = moleculesAction => (dispatch, getState) => {
let action = moleculesAction.find(action => action.type === actionType.TAB);
if (action) {
dispatch(setTabValue(action.oldObjectId, action.object_id, action.object_name));
dispatch(setTabValue(action.oldObjectId, action.object_id, action.object_name, action.oldObjectName));
}

let indexAction = moleculesAction.find(action => action.type === actionType.DATASET_INDEX);
if (indexAction) {
dispatch(
setSelectedDatasetIndex(
indexAction.oldObjectId,
indexAction.object_id,
indexAction.object_name,
indexAction.oldObjectName
)
);
}
};

Expand Down Expand Up @@ -1377,6 +1390,9 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
case actionType.TAB:
dispatch(handleTabAction(action, false));
break;
case actionType.DATASET_INDEX:
dispatch(handleTabAction(action, false));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, false, majorView));
break;
Expand Down Expand Up @@ -1526,6 +1542,9 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
case actionType.TAB:
dispatch(handleTabAction(action, true));
break;
case actionType.DATASET_INDEX:
dispatch(handleTabAction(action, true));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, true, majorView));
break;
Expand Down Expand Up @@ -1813,7 +1832,12 @@ const handleTabAction = (action, isSelected) => (dispatch, getState) => {
let oldValue = isSelected === true ? action.oldObjectId : action.object_id;
let name = isSelected === true ? action.object_name : action.oldObjectName;
let oldName = isSelected === true ? action.oldObjectName : action.object_name;
dispatch(setTabValue(oldValue, newValue, name, oldName));

if (action.type === actionType.DATASET_INDEX) {
dispatch(setSelectedDatasetIndex(oldValue, newValue, name, oldName));
} else {
dispatch(setTabValue(oldValue, newValue, name, oldName));
}
}
};

Expand Down
21 changes: 21 additions & 0 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,27 @@ export const findTrackAction = (action, state) => {
text: `${actionDescription.TAB} ${objectName} ${actionDescription.SELECTED}`
};
}
} else if (action.type === customDatasetConstants.SET_SELECTED_DATASET_INDEX) {
if (action.payload) {
let objectType = actionObjectType.COMPOUND;
let objectName = action.payload.name;
let objectId = action.payload.value;
let oldObjectId = action.payload.oldValue;
let oldObjectName = action.payload.oldName;

trackAction = {
type: actionType.DATASET_INDEX,
annotation: actionAnnotation.CHECK,
timestamp: Date.now(),
username: username,
object_type: objectType,
object_name: objectName,
object_id: objectId,
oldObjectId: oldObjectId,
oldObjectName: oldObjectName,
text: `${actionDescription.DATASET} ${objectName} ${actionDescription.SELECTED}`
};
}
} else if (action.type === nglConstants.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY) {
let objectType = actionObjectType.REPRESENTATION;
let value = action.newVisibility;
Expand Down

0 comments on commit 33ff8b9

Please sign in to comment.