From 99591ac60f9b64a912c9c094eda3d216d7dd9d8d Mon Sep 17 00:00:00 2001 From: ag-m2ms Date: Thu, 10 Dec 2020 14:05:24 +0100 Subject: [PATCH] Adjusted tracking behaviour for turned off sites --- .../moleculeGroups/redux/dispatchActions.js | 33 +++++++++++++++---- js/reducers/api/actions.js | 8 +++++ js/reducers/api/constants.js | 1 + js/reducers/selection/actions.js | 25 ++++++++------ js/reducers/tracking/dispatchActions.js | 16 ++++++++- js/reducers/tracking/trackingActions.js | 27 ++++++++------- 6 files changed, 78 insertions(+), 32 deletions(-) diff --git a/js/components/preview/moleculeGroups/redux/dispatchActions.js b/js/components/preview/moleculeGroups/redux/dispatchActions.js index 47cc081ae..d152f4d41 100644 --- a/js/components/preview/moleculeGroups/redux/dispatchActions.js +++ b/js/components/preview/moleculeGroups/redux/dispatchActions.js @@ -27,7 +27,7 @@ import { setVectorOnList } from '../../../../reducers/selection/actions'; import { setCountOfRemainingMoleculeGroups, setMoleculeOrientations } from '../../../../reducers/ngl/actions'; -import { setMolGroupList, setMolGroupOn } from '../../../../reducers/api/actions'; +import { setMolGroupList, setMolGroupOn, setMolGroupOff } from '../../../../reducers/api/actions'; import { getUrl, loadFromServer } from '../../../../utils/genericList'; import { OBJECT_TYPE } from '../../../nglView/constants'; import { setSortDialogOpen } from '../../molecule/redux/actions'; @@ -43,7 +43,13 @@ export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup let site; const state = getState(); - const vector_list = state.selectionReducers.vector_list; + const { fragmentDisplayList, complexList, proteinList, surfaceList, vectorOnList, vector_list } = state.selectionReducers; + + const actionFragmentDisplayList = []; + const actionComplexList = []; + const actionProteinList = []; + const actionSurfaceList = []; + const actionVectorOnList = []; // loop through all molecules selectJoinedMoleculeList(state).forEach(mol => { @@ -69,7 +75,20 @@ export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup ) ); }); + + if (fragmentDisplayList.find(ligand => ligand === mol.id)) actionFragmentDisplayList.push(mol); + if (complexList.find(ligand => ligand === mol.id)) actionComplexList.push(mol); + if (proteinList.find(ligand => ligand === mol.id)) actionProteinList.push(mol); + if (surfaceList.find(ligand => ligand === mol.id)) actionSurfaceList.push(mol); + if (vectorOnList.find(ligand => ligand === mol.id)) actionVectorOnList.push(mol); }); + dispatch(setMolGroupOff(molGroupId, { + ligand: actionFragmentDisplayList, + protein: actionProteinList, + complex: actionComplexList, + surface: actionSurfaceList, + vector: actionVectorOnList + })); // remove all Vectors vector_list @@ -87,15 +106,15 @@ export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup currentMolGroup.mol_id.forEach(moleculeID => { // remove Ligand, Complex, Vectors from selection //Ligand - dispatch(removeFromFragmentDisplayList({ id: moleculeID })); + dispatch(removeFromFragmentDisplayList({ id: moleculeID }, true)); // Complex - dispatch(removeFromComplexList({ id: moleculeID })); + dispatch(removeFromComplexList({ id: moleculeID }, true)); // Protein - dispatch(removeFromProteinList({ id: moleculeID })); + dispatch(removeFromProteinList({ id: moleculeID }, true)); // Surface - dispatch(removeFromSurfaceList({ id: moleculeID })); + dispatch(removeFromSurfaceList({ id: moleculeID }, true)); // Vectors - dispatch(removeFromVectorOnList({ id: moleculeID })); + dispatch(removeFromVectorOnList({ id: moleculeID }, true)); }); }; diff --git a/js/reducers/api/actions.js b/js/reducers/api/actions.js index 925e9b56a..d384e30e4 100644 --- a/js/reducers/api/actions.js +++ b/js/reducers/api/actions.js @@ -59,6 +59,14 @@ export const setMolGroupOn = function(mol_group_id) { }; }; +export const setMolGroupOff = function(mol_group_id, selectionGroups) { + return { + type: constants.SET_MOL_GROUP_OFF, + mol_group_off: mol_group_id, + selectionGroups + }; +}; + export const setMolGroupList = function(mol_group_list) { return { type: constants.SET_MOL_GROUP_LIST, diff --git a/js/reducers/api/constants.js b/js/reducers/api/constants.js index b15a46d25..00208acbc 100644 --- a/js/reducers/api/constants.js +++ b/js/reducers/api/constants.js @@ -11,6 +11,7 @@ export const constants = { SET_PANNDA_EVENT_ON: prefix + 'SET_PANNDA_EVENT_ON', SET_MOL_GROUP_ON: prefix + 'SET_MOL_GROUP_ON', + SET_MOL_GROUP_OFF: prefix + 'SET_MOL_GROUP_OFF', SET_MOL_GROUP_LIST: prefix + 'SET_MOL_GROUP_LIST', SET_MOLECULE_LIST: prefix + 'SET_MOLECULE_LIST', SET_CACHED_MOL_LISTS: prefix + 'SET_CACHED_MOL_LISTS', diff --git a/js/reducers/selection/actions.js b/js/reducers/selection/actions.js index 9c154498c..d1b9a5479 100644 --- a/js/reducers/selection/actions.js +++ b/js/reducers/selection/actions.js @@ -39,10 +39,11 @@ export const setCurrentVector = vectorSmile => { }; }; -export const setFragmentDisplayList = function(fragmentDisplayList) { +export const setFragmentDisplayList = function(fragmentDisplayList, skipTracking = false) { return { type: constants.SET_FRAGMENT_DISPLAY_LIST, - fragmentDisplayList: fragmentDisplayList + fragmentDisplayList: fragmentDisplayList, + skipTracking }; }; @@ -62,10 +63,11 @@ export const removeFromFragmentDisplayList = function(item, skipTracking = false }; }; -export const setProteinList = function(proteinList) { +export const setProteinList = function(proteinList, skipTracking = false) { return { type: constants.SET_PROTEIN_LIST, - proteinList: proteinList + proteinList: proteinList, + skipTracking }; }; @@ -84,10 +86,11 @@ export const removeFromProteinList = function(item, skipTracking = false) { skipTracking: skipTracking }; }; -export const setComplexList = function(complexList) { +export const setComplexList = function(complexList, skipTracking = false) { return { type: constants.SET_COMPLEX_LIST, - complexList: complexList + complexList: complexList, + skipTracking }; }; @@ -107,10 +110,11 @@ export const removeFromComplexList = function(item, skipTracking = false) { }; }; -export const setSurfaceList = function(surfaceList) { +export const setSurfaceList = function(surfaceList, skipTracking = false) { return { type: constants.SET_SURFACE_LIST, - surfaceList: surfaceList + surfaceList: surfaceList, + skipTracking }; }; @@ -151,10 +155,11 @@ export const removeFromDensityList = function(item) { }; }; -export const setVectorOnList = function(vectorOnList) { +export const setVectorOnList = function(vectorOnList, skipTracking = false) { return { type: constants.SET_VECTOR_ON_LIST, - vectorOnList: vectorOnList + vectorOnList: vectorOnList, + skipTracking }; }; diff --git a/js/reducers/tracking/dispatchActions.js b/js/reducers/tracking/dispatchActions.js index 93b2b353e..fc8aee47c 100644 --- a/js/reducers/tracking/dispatchActions.js +++ b/js/reducers/tracking/dispatchActions.js @@ -1513,10 +1513,24 @@ const removeRepresentation = (parentKey, representation, nglView) => (dispatch, const handleMoleculeGroupAction = (action, isSelected, stageSummaryView, majorViewStage) => (dispatch, getState) => { const state = getState(); if (action) { - let moleculeGroup = getMolGroup(action.object_name, state); + const { selectionGroups, object_name } = action; + let moleculeGroup = getMolGroup(object_name, state); if (moleculeGroup) { if (isSelected === true) { dispatch(selectMoleculeGroup(moleculeGroup, stageSummaryView)); + + for (const type in selectionGroups) { + if (selectionGroups.hasOwnProperty(type)) { + const typeGroup = selectionGroups[type]; + for (const mol of typeGroup) { + if (type === 'ligand') { + dispatch(addType[type](majorViewStage, mol, colourList[mol.id % colourList.length], true, true)); + } else { + dispatch(addType[type](majorViewStage, mol, colourList[mol.id % colourList.length], true)); + } + } + } + } } else { dispatch(onDeselectMoleculeGroup({ moleculeGroup, stageSummaryView, majorViewStage })); } diff --git a/js/reducers/tracking/trackingActions.js b/js/reducers/tracking/trackingActions.js index 963671514..5d359a6b5 100644 --- a/js/reducers/tracking/trackingActions.js +++ b/js/reducers/tracking/trackingActions.js @@ -42,20 +42,19 @@ export const findTrackAction = (action, state) => { }; } } - } else if (action.type.includes(selectionConstants.SET_OBJECT_SELECTION)) { - let objectId = action.payload && action.payload[0]; - if (objectId) { - let molGroupName = getMolGroupName(objectId, state); - trackAction = { - type: actionType.SITE_TURNED_OFF, - timestamp: Date.now(), - username: username, - object_type: actionObjectType.SITE, - object_name: molGroupName, - object_id: objectId, - text: `${actionDescription.SITE} ${molGroupName} ${actionDescription.TURNED_OFF}` - }; - } + } else if (action.type.includes(apiConstants.SET_MOL_GROUP_OFF)) { + const { mol_group_off, selectionGroups } = action; + let molGroupName = getMolGroupName(mol_group_off, state); + trackAction = { + type: actionType.SITE_TURNED_OFF, + timestamp: Date.now(), + username: username, + object_type: actionObjectType.SITE, + object_name: molGroupName, + object_id: mol_group_off, + selectionGroups, + text: `${actionDescription.SITE} ${molGroupName} ${actionDescription.TURNED_OFF}` + }; } else if (action.type === selectionConstants.SET_HIDE_ALL) { if (action.data) { let objectType = actionObjectType.MOLECULE;