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 4, 2021
1 parent 33ff8b9 commit 5b451fa
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
10 changes: 6 additions & 4 deletions js/components/datasets/datasetFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setFilterDialogOpen,
setFilterProperties,
setFilterSettings,
setDatasetFilter,
setFilterWithInspirations
} from './redux/actions';
import {
Expand Down Expand Up @@ -96,20 +97,21 @@ export const DatasetFilter = memo(
return scoreDatasetList[Object.keys(scoreDatasetList).find(attrName => attrName === attr)];
};

const handleFilterChange = (newFilterProperties, newFilterSettings) => {
const handleFilterChange = (newFilterProperties, newFilterSettings, key) => {
Object.keys(scoreDatasetList).forEach(attrKey => {
if (newFilterProperties[attrKey].priority === undefined || newFilterProperties[attrKey].priority === '') {
newFilterProperties[attrKey].priority = 0;
}
});
dispatch(setDatasetFilter(datasetID, newFilterProperties, newFilterSettings, key));
dispatch(setFilterProperties(datasetID, newFilterProperties));
dispatch(setFilterSettings(datasetID, newFilterSettings));
};

const handleItemChange = key => setting => {
const newFilterSettings = createFilterSettingsObject({ active: true, predefined, priorityOrder });
const newFilterProperties = { ...filterProperties, [key]: setting };
handleFilterChange(newFilterProperties, newFilterSettings);
handleFilterChange(newFilterProperties, newFilterSettings, key);
};

const handlePrioChange = key => inc => () => {
Expand All @@ -124,13 +126,13 @@ export const DatasetFilter = memo(
newFilterSettings.priorityOrder = localPriorityOrder;
newFilterSettings.active = true;

handleFilterChange(filterProperties, newFilterSettings);
handleFilterChange(filterProperties, newFilterSettings, key);
}
};

const handleClear = () => {
setPredefinedFilter('none');
handleFilterChange(defaultFilterProperties, defaultFilterSettings);
handleFilterChange(defaultFilterProperties, defaultFilterSettings, 'clear');
};

// Check for multiple attributes with same sorting priority
Expand Down
5 changes: 5 additions & 0 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const setFilterProperties = (datasetID, properties) => ({
payload: { datasetID, properties }
});

export const setDatasetFilter = (datasetID, properties, settings, key) => ({
type: constants.SET_DATASET_FILTER,
payload: { datasetID, properties, settings, key }
});

export const setFilterDialogOpen = filterDialogOpen => ({
type: constants.SET_FILTER_DIALOG_OPEN,
payload: filterDialogOpen
Expand Down
1 change: 1 addition & 0 deletions js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const constants = {
SET_FILTER_PROPERTIES: prefix + 'SET_FILTER_PROPERTIES',
SET_FILTER_DIALOG_OPEN: prefix + 'SET_FILTER_DIALOG_OPEN',
SET_FILTER_WITH_INSPIRATIONS: prefix + 'SET_FILTER_WITH_INSPIRATIONS',
SET_DATASET_FILTER: prefix + 'SET_DATASET_FILTER',

SET_LIGAND_LIST: prefix + 'SET_LIGAND_LIST',
APPEND_LIGAND_LIST: prefix + 'APPEND_LIGAND_LIST',
Expand Down
32 changes: 31 additions & 1 deletion js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ import {
removeMoleculeFromCompoundsOfDatasetToBuy,
setMoleculeListIsLoading,
setTabValue,
setSelectedDatasetIndex
setSelectedDatasetIndex,
setDatasetFilter,
setFilterProperties,
setFilterSettings
} from '../../components/datasets/redux/actions';
import { setAllMolLists } from '../api/actions';
import { getUrl, loadAllMolsFromMolGroup } from '../../../js/utils/genericList';
Expand Down Expand Up @@ -1023,6 +1026,16 @@ const restoreTabActions = moleculesAction => (dispatch, getState) => {
)
);
}

let filterAction = moleculesAction.find(action => action.type === actionType.DATASET_FILTER);
if (filterAction) {
let datasetID = filterAction.dataset_id;
let newFilterProperties = filterAction.newProperties;
let newFilterSettings = filterAction.newSettings;
dispatch(setDatasetFilter(datasetID, newFilterProperties, newFilterSettings, filterAction.key));
dispatch(setFilterProperties(datasetID, newFilterProperties));
dispatch(setFilterSettings(datasetID, newFilterSettings));
}
};

const restoreSnapshotImageActions = projectID => async (dispatch, getState) => {
Expand Down Expand Up @@ -1393,6 +1406,9 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
case actionType.DATASET_INDEX:
dispatch(handleTabAction(action, false));
break;
case actionType.DATASET_FILTER:
dispatch(handleFilterAction(action, false));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, false, majorView));
break;
Expand Down Expand Up @@ -1545,6 +1561,9 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
case actionType.DATASET_INDEX:
dispatch(handleTabAction(action, true));
break;
case actionType.DATASET_FILTER:
dispatch(handleFilterAction(action, true));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, true, majorView));
break;
Expand Down Expand Up @@ -1841,6 +1860,17 @@ const handleTabAction = (action, isSelected) => (dispatch, getState) => {
}
};

const handleFilterAction = (action, isSelected) => (dispatch, getState) => {
if (action) {
let datasetID = action.dataset_id;
let newFilterProperties = isSelected === true ? action.newProperties : action.oldProperties;
let newFilterSettings = isSelected === true ? action.newSettings : action.oldSettings;
dispatch(setDatasetFilter(datasetID, newFilterProperties, newFilterSettings, action.key));
dispatch(setFilterProperties(datasetID, newFilterProperties));
dispatch(setFilterSettings(datasetID, newFilterSettings));
}
};

const handleCompoundAction = (action, isSelected) => (dispatch, getState) => {
const state = getState();
if (action) {
Expand Down
28 changes: 28 additions & 0 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,34 @@ export const findTrackAction = (action, state) => {
text: `${actionDescription.DATASET} ${objectName} ${actionDescription.SELECTED}`
};
}
} else if (action.type === customDatasetConstants.SET_DATASET_FILTER) {
if (action.payload) {
const filterProperties = state.datasetsReducers.filterPropertiesDatasetMap;
const filterSettings = state.datasetsReducers.filterDatasetMap;

let filterPropertiesOfDataset = filterProperties[action.payload.datasetID];
let filterSettingsOfDataset = filterSettings[action.payload.datasetID];

let objectType = actionObjectType.COMPOUND;
let key = action.payload.key;

trackAction = {
type: actionType.DATASET_FILTER,
annotation: actionAnnotation.CHECK,
timestamp: Date.now(),
username: username,
object_type: objectType,
oldProperties: filterPropertiesOfDataset,
oldSettings: filterSettingsOfDataset,
newProperties: action.payload.properties,
newSettings: action.payload.settings,
dataset_id: action.payload.datasetID,
text:
key === 'clear'
? `Filter ${actionDescription.CHANGED} to default values of dataset: ${action.payload.datasetID}`
: `Filter parameter: ${action.payload.key} ${actionDescription.CHANGED} of dataset: ${action.payload.datasetID}`
};
}
} else if (action.type === nglConstants.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY) {
let objectType = actionObjectType.REPRESENTATION;
let value = action.newVisibility;
Expand Down

0 comments on commit 5b451fa

Please sign in to comment.