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 5b451fa commit 0e82dac
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 6 deletions.
11 changes: 9 additions & 2 deletions js/components/datasets/datasetFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ export const DatasetFilter = memo(
return scoreDatasetList[Object.keys(scoreDatasetList).find(attrName => attrName === attr)];
};

const handleFilterChange = (newFilterProperties, newFilterSettings, key) => {
const handleFilterChange = (newFilterProperties, newFilterSettings, key, prio, oldPrio) => {
Object.keys(scoreDatasetList).forEach(attrKey => {
if (newFilterProperties[attrKey].priority === undefined || newFilterProperties[attrKey].priority === '') {
newFilterProperties[attrKey].priority = 0;
}
if (attrKey === key && prio !== undefined && prio !== null) {
newFilterProperties[attrKey].newPrio = prio;
newFilterProperties[attrKey].oldPrio = oldPrio;
}
});
dispatch(setDatasetFilter(datasetID, newFilterProperties, newFilterSettings, key));
dispatch(setFilterProperties(datasetID, newFilterProperties));
Expand All @@ -126,7 +130,10 @@ export const DatasetFilter = memo(
newFilterSettings.priorityOrder = localPriorityOrder;
newFilterSettings.active = true;

handleFilterChange(filterProperties, newFilterSettings, key);
let oldPrio = index;
let newPrio = index + inc;
let newFilterProperties = { ...filterProperties };
handleFilterChange(newFilterProperties, newFilterSettings, key, newPrio, oldPrio);
}
};

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 @@ -250,6 +250,11 @@ export const updateFilterShowedScoreProperties = ({ datasetID, scoreList = [] })
payload: { datasetID, scoreList }
});

export const setFilterShowedScoreProperties = ({ datasetID, scoreList = [], oldScoreList, isChecked, scoreName }) => ({
type: constants.SET_FILTER_SHOWED_SCORE_PROPERTIES,
payload: { datasetID, scoreList, isChecked, scoreName, oldScoreList }
});

export const removeFromFilterShowedScoreProperties = datasetID => ({
type: constants.REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES,
payload: datasetID
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 @@ -42,6 +42,7 @@ export const constants = {
APPEND_TO_SCORE_COMPOUND_MAP_BY_SCORE_CATEGORY: prefix + 'APPEND_TO_SCORE_COMPOUND_MAP_BY_SCORE_CATEGORY',
CLEAR_SCORE_COMPOUND_MAP: prefix + 'CLEAR_SCORE_COMPOUND_MAP',

SET_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'SET_FILTER_SHOWED_SCORE_PROPERTIES',
UPDATE_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'UPDATE_FILTER_SHOWED_SCORE_PROPERTIES',
REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES',

Expand Down
7 changes: 7 additions & 0 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
appendToScoreDatasetMap,
appendToScoreCompoundMapByScoreCategory,
updateFilterShowedScoreProperties,
setFilterShowedScoreProperties,
setFilterProperties,
setIsLoadingInspirationListOfMolecules,
appendToInspirationMoleculeDataList,
Expand Down Expand Up @@ -339,6 +340,8 @@ export const selectScoreProperty = ({ isChecked, datasetID, scoreName }) => (dis
const state = getState();
const filteredScorePropertiesOfDataset = state.datasetsReducers.filteredScoreProperties[datasetID];
const scoreDatasetMap = state.datasetsReducers.scoreDatasetMap[datasetID];
let scoreList = [];
let oldScoreList = [...filteredScorePropertiesOfDataset];

if (isChecked === true) {
if (filteredScorePropertiesOfDataset.length === COUNT_OF_VISIBLE_SCORES) {
Expand All @@ -348,20 +351,24 @@ export const selectScoreProperty = ({ isChecked, datasetID, scoreName }) => (dis
// 2. select new property
const selectedProperty = scoreDatasetMap[scoreName];
filteredScorePropertiesOfDataset.push(selectedProperty);
scoreList = filteredScorePropertiesOfDataset;
dispatch(
updateFilterShowedScoreProperties({
datasetID,
scoreList: filteredScorePropertiesOfDataset
})
);
} else {
scoreList = filteredScorePropertiesOfDataset.filter(item => item.name !== scoreName);
dispatch(
updateFilterShowedScoreProperties({
datasetID,
scoreList: filteredScorePropertiesOfDataset.filter(item => item.name !== scoreName)
})
);
}

dispatch(setFilterShowedScoreProperties({ datasetID, scoreList, oldScoreList, isChecked, scoreName }));
};

export const loadInspirationMoleculesDataList = (inspirationList = []) => (dispatch, getState) => {
Expand Down
1 change: 1 addition & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const actionType = {
TAB: 'TAB',
DATASET_INDEX: 'DATASET_INDEX',
DATASET_FILTER: 'DATASET_FILTER',
DATASET_FILTER_SCORE: 'DATASET_FILTER_SCORE',
ALL_HIDE: 'ALL_HIDE',
ALL_TURNED_ON: 'ALL_TURNED_ON',
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
Expand Down
46 changes: 44 additions & 2 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
removeAllSelectedMolTypes,
hideAllSelectedMolecules
} from '../../components/preview/molecule/redux/dispatchActions';
import { setSortDialogOpen } from '../../components/preview/molecule/redux/actions';
import {
handleBuyList,
handleBuyListAll,
Expand All @@ -58,7 +59,8 @@ import {
moveSelectedMoleculeSettings,
moveSelectedInspirations,
moveMoleculeInspirationsSettings,
getInspirationsForMol
getInspirationsForMol,
selectScoreProperty
} from '../../components/datasets/redux/dispatchActions';
import {
appendMoleculeToCompoundsOfDatasetToBuy,
Expand All @@ -68,7 +70,9 @@ import {
setSelectedDatasetIndex,
setDatasetFilter,
setFilterProperties,
setFilterSettings
setFilterSettings,
updateFilterShowedScoreProperties,
setFilterShowedScoreProperties
} from '../../components/datasets/redux/actions';
import { setAllMolLists } from '../api/actions';
import { getUrl, loadAllMolsFromMolGroup } from '../../../js/utils/genericList';
Expand Down Expand Up @@ -343,6 +347,7 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d
getCommonLastActionByType(orderedActionList, actionType.TAB, currentActions);
getCommonLastActionByType(orderedActionList, actionType.DATASET_INDEX, currentActions);
getCommonLastActionByType(orderedActionList, actionType.DATASET_FILTER, currentActions);
getCommonLastActionByType(orderedActionList, actionType.DATASET_FILTER_SCORE, currentActions);

if (nglViewList) {
let nglStateList = nglViewList.map(nglView => {
Expand Down Expand Up @@ -1036,6 +1041,27 @@ const restoreTabActions = moleculesAction => (dispatch, getState) => {
dispatch(setFilterProperties(datasetID, newFilterProperties));
dispatch(setFilterSettings(datasetID, newFilterSettings));
}

let filterScoreAction = moleculesAction.find(action => action.type === actionType.DATASET_FILTER_SCORE);
if (filterScoreAction) {
let datasetID = filterScoreAction.dataset_id;
dispatch(
updateFilterShowedScoreProperties({
datasetID,
scoreList: filterScoreAction.newScoreList
})
);

dispatch(
setFilterShowedScoreProperties({
datasetID,
scoreList: filterScoreAction.newScoreList,
oldScoreList: filterScoreAction.oldScoreList,
isChecked: filterScoreAction.isChecked,
scoreName: filterScoreAction.object_name
})
);
}
};

const restoreSnapshotImageActions = projectID => async (dispatch, getState) => {
Expand Down Expand Up @@ -1409,6 +1435,9 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {
case actionType.DATASET_FILTER:
dispatch(handleFilterAction(action, false));
break;
case actionType.DATASET_FILTER_SCORE:
dispatch(handleFilterScoreAction(action, false));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, false, majorView));
break;
Expand Down Expand Up @@ -1564,6 +1593,9 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {
case actionType.DATASET_FILTER:
dispatch(handleFilterAction(action, true));
break;
case actionType.DATASET_FILTER_SCORE:
dispatch(handleFilterScoreAction(action, true));
break;
case actionType.REPRESENTATION_VISIBILITY_UPDATED:
dispatch(handleUpdateRepresentationVisibilityAction(action, true, majorView));
break;
Expand Down Expand Up @@ -1855,6 +1887,7 @@ const handleTabAction = (action, isSelected) => (dispatch, getState) => {
if (action.type === actionType.DATASET_INDEX) {
dispatch(setSelectedDatasetIndex(oldValue, newValue, name, oldName));
} else {
dispatch(setSortDialogOpen(false));
dispatch(setTabValue(oldValue, newValue, name, oldName));
}
}
Expand All @@ -1871,6 +1904,15 @@ const handleFilterAction = (action, isSelected) => (dispatch, getState) => {
}
};

const handleFilterScoreAction = (action, isSelected) => (dispatch, getState) => {
if (action) {
let datasetID = action.dataset_id;
let isChecked = isSelected === true ? action.isChecked : !action.isChecked;
let scoreName = action.object_name;
dispatch(selectScoreProperty({ isChecked, datasetID, scoreName }));
}
};

const handleCompoundAction = (action, isSelected) => (dispatch, getState) => {
const state = getState();
if (action) {
Expand Down
102 changes: 100 additions & 2 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,11 @@ export const findTrackAction = (action, state) => {

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

let objectType = actionObjectType.COMPOUND;
let key = action.payload.key;
let descriptionProperties = getFilterKeyChange(filterPropertiesOfDataset[key], newProperties[key]);

trackAction = {
type: actionType.DATASET_FILTER,
Expand All @@ -893,13 +895,32 @@ export const findTrackAction = (action, state) => {
object_type: objectType,
oldProperties: filterPropertiesOfDataset,
oldSettings: filterSettingsOfDataset,
newProperties: action.payload.properties,
newProperties: newProperties,
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}`
: `Filter parameter: ${action.payload.key} ${actionDescription.CHANGED} of dataset: ${action.payload.datasetID}. ${descriptionProperties}`
};
}
} else if (action.type === customDatasetConstants.SET_FILTER_SHOWED_SCORE_PROPERTIES) {
if (action.payload) {
let objectType = actionObjectType.COMPOUND;
let valueDescription = action.payload.isChecked === true ? actionDescription.VISIBLE : actionDescription.HIDDEN;

trackAction = {
type: actionType.DATASET_FILTER_SCORE,
annotation: actionAnnotation.CHECK,
timestamp: Date.now(),
username: username,
object_type: objectType,
object_name: action.payload.scoreName,
isChecked: action.payload.isChecked,
oldScoreList: action.payload.oldScoreList,
newScoreList: action.payload.scoreList,
dataset_id: action.payload.datasetID,
text: `Filter parameter: ${action.payload.scoreName} ${actionDescription.CHANGED} to ${valueDescription} of dataset: ${action.payload.datasetID}`
};
}
} else if (action.type === nglConstants.UPDATE_COMPONENT_REPRESENTATION_VISIBILITY) {
Expand Down Expand Up @@ -1222,6 +1243,83 @@ const getClipCenterChange = (oldValue, newValue) => {
return description;
};

const getFilterKeyChange = (oldValue, newValue) => {
let description = '';
if (oldValue && newValue) {
if (oldValue.order !== newValue.order) {
description +=
' from value: order:' +
getOrderDescription(oldValue.order) +
' to value: order:' +
getOrderDescription(newValue.order);
return description;
} else if (oldValue.newPrio !== newValue.newPrio) {
description +=
' from value: priority: ' + (newValue.oldPrio + 1) + ' to value: priority: ' + (newValue.newPrio + 1);
return description;
} else {
if (oldValue.isBoolean === true) {
if (oldValue.minValue !== newValue.minValue) {
return (
' from value: ' +
getBooleanDescription(oldValue.minValue) +
' to value: ' +
getBooleanDescription(newValue.minValue)
);
} else if (oldValue.maxValue !== newValue.maxValue) {
return (
' from value: ' +
getBooleanDescription(oldValue.maxValue) +
' to value: ' +
getBooleanDescription(newValue.maxValue)
);
} else {
return ' to value: ignore';
}
} else {
if (oldValue.minValue !== newValue.minValue) {
return ' from value: ' + oldValue.minValue + ' to value: ' + newValue.minValue;
} else if (oldValue.maxValue !== newValue.maxValue) {
return ' from value: max: ' + oldValue.maxValue + ' to value: max: ' + newValue.maxValue;
}
}
}
}
return description;
};

const getOrderDescription = order => {
let description = '';
if (order === 1) {
return 'up';
}

if (order === -1) {
return 'down';
}

if (order === 0) {
return 'ignore';
}
return description;
};

const getBooleanDescription = value => {
let description = '';
if (value === 1) {
return 'false';
}

if (value === 50) {
return 'ignore';
}

if (value === 100) {
return 'true';
}
return description;
};

export const createInitAction = target_on => (dispatch, getState) => {
const state = getState();
const username = DJANGO_CONTEXT['username'];
Expand Down

0 comments on commit 0e82dac

Please sign in to comment.