From 1e5921d48ddddefd79286447f6655730dcaf1e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1na=20Kohanov=C3=A1?= Date: Wed, 20 Jan 2021 07:36:00 +0100 Subject: [PATCH 1/2] #479 Vector selector actions (RHS clicks) are not captured --- .../preview/compounds/redux/actions.js | 21 +-- .../compounds/redux/dispatchActions.js | 33 +++-- js/reducers/selection/actions.js | 24 +++- js/reducers/selection/constants.js | 2 + js/reducers/tracking/constants.js | 8 ++ js/reducers/tracking/trackingActions.js | 123 +++++++++++++++++- 6 files changed, 184 insertions(+), 27 deletions(-) diff --git a/js/components/preview/compounds/redux/actions.js b/js/components/preview/compounds/redux/actions.js index 208d124ce..fe5898927 100644 --- a/js/components/preview/compounds/redux/actions.js +++ b/js/components/preview/compounds/redux/actions.js @@ -29,9 +29,11 @@ export const updateCurrentCompound = ({ id, key, value }) => ({ } }); -export const setCompoundClasses = compoundClasses => ({ +export const setCompoundClasses = (compoundClasses, oldCompoundClasses, newClassDescription) => ({ type: constants.SET_COMPOUND_CLASSES, - payload: compoundClasses + payload: compoundClasses, + oldCompoundClasses: oldCompoundClasses, + newClassDescription: newClassDescription }); export const resetCompoundClasses = compoundClasses => ({ @@ -39,10 +41,11 @@ export const resetCompoundClasses = compoundClasses => ({ payload: compoundClasses }); -export const setCurrentCompoundClass = currentCompoundClass => { +export const setCurrentCompoundClass = (currentCompoundClass, oldCompoundClass) => { return { type: constants.SET_CURRENT_COMPOUND_CLASS, - payload: currentCompoundClass + payload: currentCompoundClass, + oldCompoundClass: oldCompoundClass }; }; @@ -57,14 +60,16 @@ export const setShowedCompoundList = compounds => ({ payload: compounds }); -export const addShowedCompoundToList = compoundId => ({ +export const addShowedCompoundToList = (compoundId, item) => ({ type: constants.APPEND_SHOWED_COMPOUND_LIST, - payload: compoundId + payload: compoundId, + item: item }); -export const removeShowedCompoundFromList = compoundId => ({ +export const removeShowedCompoundFromList = (compoundId, item) => ({ type: constants.REMOVE_SHOWED_COMPOUND_LIST, - payload: compoundId + payload: compoundId, + item: item }); export const addSelectedCompoundClass = (classID, compoundID) => ({ diff --git a/js/components/preview/compounds/redux/dispatchActions.js b/js/components/preview/compounds/redux/dispatchActions.js index 658820fa5..43f32b358 100644 --- a/js/components/preview/compounds/redux/dispatchActions.js +++ b/js/components/preview/compounds/redux/dispatchActions.js @@ -1,4 +1,10 @@ -import { appendToBuyList, removeFromToBuyList, setToBuyList } from '../../../../reducers/selection/actions'; +import { + appendToBuyList, + removeFromToBuyList, + setToBuyList, + appendToBuyListAll, + removeFromToBuyListAll +} from '../../../../reducers/selection/actions'; import { setCompoundClasses, setCurrentPage, @@ -32,6 +38,7 @@ export const selectAllCompounds = () => (dispatch, getState) => { const moleculeOfVector = getMoleculeOfCurrentVector(state); const smiles = moleculeOfVector && moleculeOfVector.smiles; const currentCompoundClass = state.previewReducers.compounds.currentCompoundClass; + let items = []; for (let key in currentVectorCompoundsFiltered) { for (let index in currentVectorCompoundsFiltered[key]) { @@ -43,12 +50,15 @@ export const selectAllCompounds = () => (dispatch, getState) => { mol: smiles, class: parseInt(currentCompoundClass) }; - dispatch(appendToBuyList(thisObj)); + items.push(thisObj); + dispatch(appendToBuyList(thisObj, true)); dispatch(addSelectedCompoundClass(currentCompoundClass, parseInt(indexOfCompound))); } } } } + + dispatch(appendToBuyListAll(items)); }; export const onChangeCompoundClassValue = event => (dispatch, getState) => { @@ -59,16 +69,20 @@ export const onChangeCompoundClassValue = event => (dispatch, getState) => { }); // const compoundClasses = state.previewReducers.compounds.compoundClasses; + let oldCompoundClass = Object.assign({}, compoundClasses); const newClassDescription = { [event.target.id]: event.target.value }; const descriptionToSet = Object.assign(compoundClasses, newClassDescription); - dispatch(setCompoundClasses(descriptionToSet)); + dispatch(setCompoundClasses(descriptionToSet, oldCompoundClass, newClassDescription)); }; -export const onKeyDownCompoundClass = event => dispatch => { +export const onKeyDownCompoundClass = event => (dispatch, getState) => { + const state = getState(); + // on Enter if (event.keyCode === 13) { - dispatch(setCurrentCompoundClass(event.target.id)); + let oldCompoundClass = state.previewReducers.compounds.currentCompoundClass; + dispatch(setCurrentCompoundClass(event.target.id, oldCompoundClass)); } }; @@ -131,8 +145,11 @@ const showCompoundNglView = ({ majorViewStage, data, index }) => (dispatch, getS }; export const clearAllSelectedCompounds = majorViewStage => (dispatch, getState) => { - dispatch(setToBuyList([])); const state = getState(); + + let to_buy_list = state.selectionReducers.to_buy_list; + dispatch(removeFromToBuyListAll(to_buy_list)); + dispatch(setToBuyList([])); // reset objects from nglView and showedCompoundList const currentCompounds = state.previewReducers.compounds.currentCompounds; const showedCompoundList = state.previewReducers.compounds.showedCompoundList; @@ -164,9 +181,9 @@ export const handleClickOnCompound = ({ event, data, majorViewStage, index }) => if (event.shiftKey) { await dispatch(showCompoundNglView({ majorViewStage, data, index })); if (showedCompoundList.find(item => item === index) !== undefined) { - dispatch(removeShowedCompoundFromList(index)); + dispatch(removeShowedCompoundFromList(index, data)); } else { - dispatch(addShowedCompoundToList(index)); + dispatch(addShowedCompoundToList(index, data)); } } else { let isSelectedID; diff --git a/js/reducers/selection/actions.js b/js/reducers/selection/actions.js index d1b9a5479..18eac4abc 100644 --- a/js/reducers/selection/actions.js +++ b/js/reducers/selection/actions.js @@ -11,17 +11,33 @@ export const setToBuyList = function(to_buy_list) { }; }; -export const appendToBuyList = function(item) { +export const appendToBuyList = function(item, skipTracking = false) { return { type: constants.APPEND_TO_BUY_LIST, - item: item + item: item, + skipTracking: skipTracking }; }; -export const removeFromToBuyList = function(item) { +export const removeFromToBuyList = function(item, skipTracking = false) { return { type: constants.REMOVE_FROM_TO_BUY_LIST, - item: item + item: item, + skipTracking: skipTracking + }; +}; + +export const appendToBuyListAll = function(items) { + return { + type: constants.APPEND_TO_BUY_LIST_ALL, + items: items + }; +}; + +export const removeFromToBuyListAll = function(items) { + return { + type: constants.REMOVE_FROM_BUY_LIST_ALL, + items: items }; }; diff --git a/js/reducers/selection/constants.js b/js/reducers/selection/constants.js index 24269ecef..d91a8af26 100644 --- a/js/reducers/selection/constants.js +++ b/js/reducers/selection/constants.js @@ -7,7 +7,9 @@ export const constants = { SET_TO_BUY_LIST: prefix + 'SET_TO_BUY_LIST', APPEND_TO_BUY_LIST: prefix + 'APPEND_TO_BUY_LIST', + APPEND_TO_BUY_LIST_ALL: prefix + 'APPEND_TO_BUY_LIST_ALL', REMOVE_FROM_TO_BUY_LIST: prefix + 'REMOVE_FROM_TO_BUY_LIST', + REMOVE_FROM_BUY_LIST_ALL: prefix + 'REMOVE_FROM_BUY_LIST_ALL', SET_VECTOR_LIST: prefix + 'SET_VECTOR_LIST', SET_CURRENT_VECTOR: prefix + 'SET_CURRENT_VECTOR', SET_FRAGMENT_DISPLAY_LIST: prefix + 'SET_FRAGMENT_DISPLAY_LIST', diff --git a/js/reducers/tracking/constants.js b/js/reducers/tracking/constants.js index 102534f05..b4770d24b 100644 --- a/js/reducers/tracking/constants.js +++ b/js/reducers/tracking/constants.js @@ -34,10 +34,16 @@ export const actionType = { SURFACE_TURNED_OFF: 'SURFACE_TURNED_OFF', VECTORS_TURNED_ON: 'VECTORS_TURNED_ON', VECTORS_TURNED_OFF: 'VECTORS_TURNED_OFF', + CLASS_SELECTED: 'CLASS_SELECTED', + CLASS_UPDATED: 'CLASS_UPDATED', VECTOR_SELECTED: 'VECTOR_SELECTED', VECTOR_DESELECTED: 'VECTOR_DESELECTED', MOLECULE_ADDED_TO_SHOPPING_CART: 'MOLECULE_ADDED_TO_SHOPPING_CART', + MOLECULE_ADDED_TO_SHOPPING_CART_ALL: 'MOLECULE_ADDED_TO_SHOPPING_CART_ALL', MOLECULE_REMOVED_FROM_SHOPPING_CART: 'MOLECULE_REMOVED_FROM_SHOPPING_CART', + MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL: 'MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL', + VECTOR_COUMPOUND_ADDED: 'VECTOR_COUMPOUND_ADDED', + VECTOR_COUMPOUND_REMOVED: 'VECTOR_COUMPOUND_REMOVED', COMPOUND_SELECTED: 'COMPOUND_SELECTED', COMPOUND_DESELECTED: 'COMPOUND_DESELECTED', REPRESENTATION_UPDATED: 'REPRESENTATION_UPDATED', @@ -73,6 +79,8 @@ export const actionDescription = { SIDECHAIN: 'Sidechain', INTERACTION: 'Interaction', VECTOR: 'Vector', + COMPOUND: 'Compound', + CLASS: 'Compound colour', SURFACE: 'Surface', SITE: 'Site', TARGET: 'Target', diff --git a/js/reducers/tracking/trackingActions.js b/js/reducers/tracking/trackingActions.js index 1a513c81d..38707b4fc 100644 --- a/js/reducers/tracking/trackingActions.js +++ b/js/reducers/tracking/trackingActions.js @@ -1,6 +1,7 @@ import { actionType, actionObjectType, actionDescription, actionAnnotation } from './constants'; import { constants as apiConstants } from '../api/constants'; import { CONSTANTS as nglConstants } from '../ngl/constants'; +import { constants as previewCompoundConstants } from '../../components/preview/compounds/redux/constants'; import { constants as selectionConstants } from '../selection/constants'; import { constants as customDatasetConstants } from '../../components/datasets/redux/constants'; import { DJANGO_CONTEXT } from '../../utils/djangoContext'; @@ -357,27 +358,27 @@ export const findTrackAction = (action, state) => { )}` }; } - } else if (action.type.includes(selectionConstants.APPEND_TO_BUY_LIST)) { + } else if (action.type === selectionConstants.APPEND_TO_BUY_LIST) { if (action.item) { let objectType = actionObjectType.MOLECULE; - let objectName = action.vector; + let objectName = action.item && action.item.vector; trackAction = { type: actionType.MOLECULE_ADDED_TO_SHOPPING_CART, annotation: actionAnnotation.CHECK, timestamp: Date.now(), username: username, - object_type: actionObjectType.MOLECULE, + object_type: objectType, object_name: objectName, object_id: objectName, item: action.item, - text: `${objectType} ${objectName} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` + text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` }; } - } else if (action.type.includes(selectionConstants.REMOVE_FROM_TO_BUY_LIST)) { + } else if (action.type === selectionConstants.REMOVE_FROM_TO_BUY_LIST) { if (action.item) { let objectType = actionObjectType.MOLECULE; - let objectName = action.vector; + let objectName = action.item && action.item.vector; trackAction = { type: actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART, @@ -388,7 +389,71 @@ export const findTrackAction = (action, state) => { object_name: objectName, object_id: objectName, item: action.item, - text: `${objectType} ${objectName} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` + text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` + }; + } + } else if (action.type === selectionConstants.APPEND_TO_BUY_LIST_ALL) { + if (action.items) { + let items = action.items; + let objectType = actionObjectType.COMPOUND; + + trackAction = { + type: actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL, + annotation: actionAnnotation.CHECK, + timestamp: Date.now(), + username: username, + object_type: objectType, + items: items, + text: `${actionDescription.ALL} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` + }; + } + } else if (action.type === selectionConstants.REMOVE_FROM_BUY_LIST_ALL) { + if (action.items) { + let items = action.items; + let objectType = actionObjectType.COMPOUND; + + trackAction = { + type: actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL, + annotation: actionAnnotation.CLEAR, + timestamp: Date.now(), + username: username, + object_type: objectType, + items: items, + text: `${actionDescription.ALL} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` + }; + } + } else if (action.type === previewCompoundConstants.APPEND_SHOWED_COMPOUND_LIST) { + if (action.item && action.payload) { + let objectType = actionObjectType.COMPOUND; + let objectName = action.item && action.item.vector; + + trackAction = { + type: actionType.VECTOR_COUMPOUND_ADDED, + annotation: actionAnnotation.CHECK, + timestamp: Date.now(), + username: username, + object_type: objectType, + object_name: objectName, + object_id: action.payload, + item: action.item, + text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.ADDED}` + }; + } + } else if (action.type === previewCompoundConstants.REMOVE_SHOWED_COMPOUND_LIST) { + if (action.item && action.payload) { + let objectType = actionObjectType.COMPOUND; + let objectName = action.item && action.item.vector; + + trackAction = { + type: actionType.VECTOR_COUMPOUND_REMOVED, + annotation: actionAnnotation.CLEAR, + timestamp: Date.now(), + username: username, + object_type: objectType, + object_name: objectName, + object_id: action.payload, + item: action.item, + text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.REMOVED}` }; } } else if (action.type.includes(selectionConstants.SET_CURRENT_VECTOR)) { @@ -407,6 +472,50 @@ export const findTrackAction = (action, state) => { text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.SELECTED}` }; } + } else if (action.type === previewCompoundConstants.SET_CURRENT_COMPOUND_CLASS) { + if (action.payload) { + let objectType = actionObjectType.COMPOUND; + let objectName = action.payload; + let oldObjectName = action.oldCompoundClass; + + trackAction = { + type: actionType.CLASS_SELECTED, + annotation: actionAnnotation.CHECK, + timestamp: Date.now(), + username: username, + object_type: objectType, + object_name: objectName, + object_id: objectName, + oldObjectName: oldObjectName, + text: `${actionDescription.CLASS} ${objectName} ${actionDescription.SELECTED}` + }; + } + } else if (action.type === previewCompoundConstants.SET_COMPOUND_CLASSES) { + if (action.payload) { + let objectType = actionObjectType.COMPOUND; + let newClassDescription = action.payload; + let objectName = JSON.stringify(action.newClassDescription); + let oldClassDescription = action.oldCompoundClasses; + + var regex = new RegExp('"', 'g'); + objectName = objectName + .replace(regex, '') + .replace('{', '') + .replace('}', ''); + + trackAction = { + type: actionType.CLASS_UPDATED, + annotation: actionAnnotation.CHECK, + timestamp: Date.now(), + username: username, + object_type: objectType, + object_name: objectName, + object_id: objectName, + oldClassDescription: oldClassDescription, + newClassDescription: newClassDescription, + text: `${actionDescription.CLASS} value ${actionDescription.UPDATED}: ${objectName}` + }; + } } else if (action.type.includes(customDatasetConstants.APPEND_MOLECULE_TO_COMPOUNDS_TO_BUY_OF_DATASET)) { if (action.payload) { let objectType = actionObjectType.COMPOUND; From c157a7e6e79daacaa3ed7bd0d8e9de11f9d134b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1na=20Kohanov=C3=A1?= Date: Wed, 20 Jan 2021 14:03:10 +0100 Subject: [PATCH 2/2] #479 Vector selector actions (RHS clicks) are not captured --- .../preview/compounds/redux/actions.js | 10 +- .../compounds/redux/dispatchActions.js | 64 ++++++++-- js/reducers/selection/actions.js | 6 +- js/reducers/selection/dispatchActions.js | 7 +- js/reducers/tracking/dispatchActions.js | 117 ++++++++++++++++-- js/reducers/tracking/trackingActions.js | 85 +++++++------ 6 files changed, 219 insertions(+), 70 deletions(-) diff --git a/js/components/preview/compounds/redux/actions.js b/js/components/preview/compounds/redux/actions.js index fe5898927..74b157dcf 100644 --- a/js/components/preview/compounds/redux/actions.js +++ b/js/components/preview/compounds/redux/actions.js @@ -29,11 +29,12 @@ export const updateCurrentCompound = ({ id, key, value }) => ({ } }); -export const setCompoundClasses = (compoundClasses, oldCompoundClasses, newClassDescription) => ({ +export const setCompoundClasses = (compoundClasses, oldCompoundClasses, value, id) => ({ type: constants.SET_COMPOUND_CLASSES, payload: compoundClasses, oldCompoundClasses: oldCompoundClasses, - newClassDescription: newClassDescription + value: value, + id: id }); export const resetCompoundClasses = compoundClasses => ({ @@ -41,11 +42,12 @@ export const resetCompoundClasses = compoundClasses => ({ payload: compoundClasses }); -export const setCurrentCompoundClass = (currentCompoundClass, oldCompoundClass) => { +export const setCurrentCompoundClass = (currentCompoundClass, oldCompoundClass, skipTracking) => { return { type: constants.SET_CURRENT_COMPOUND_CLASS, payload: currentCompoundClass, - oldCompoundClass: oldCompoundClass + oldCompoundClass: oldCompoundClass, + skipTracking: skipTracking }; }; diff --git a/js/components/preview/compounds/redux/dispatchActions.js b/js/components/preview/compounds/redux/dispatchActions.js index 43f32b358..e84c9b2a7 100644 --- a/js/components/preview/compounds/redux/dispatchActions.js +++ b/js/components/preview/compounds/redux/dispatchActions.js @@ -48,10 +48,12 @@ export const selectAllCompounds = () => (dispatch, getState) => { smiles: currentVectorCompoundsFiltered[key][index][indexOfCompound].end, vector: currentVectorCompoundsFiltered[key].vector.split('_')[0], mol: smiles, - class: parseInt(currentCompoundClass) + class: parseInt(currentCompoundClass), + indexOfCompound: indexOfCompound, + index: index }; items.push(thisObj); - dispatch(appendToBuyList(thisObj, true)); + dispatch(appendToBuyList(thisObj, index, true)); dispatch(addSelectedCompoundClass(currentCompoundClass, parseInt(indexOfCompound))); } } @@ -69,11 +71,13 @@ export const onChangeCompoundClassValue = event => (dispatch, getState) => { }); // const compoundClasses = state.previewReducers.compounds.compoundClasses; - let oldCompoundClass = Object.assign({}, compoundClasses); - const newClassDescription = { [event.target.id]: event.target.value }; + let id = event.target.id; + let value = event.target.value; + let oldDescriptionToSet = Object.assign({}, compoundClasses); + const newClassDescription = { [id]: value }; const descriptionToSet = Object.assign(compoundClasses, newClassDescription); - dispatch(setCompoundClasses(descriptionToSet, oldCompoundClass, newClassDescription)); + dispatch(setCompoundClasses(descriptionToSet, oldDescriptionToSet, value, id)); }; export const onKeyDownCompoundClass = event => (dispatch, getState) => { @@ -148,7 +152,13 @@ export const clearAllSelectedCompounds = majorViewStage => (dispatch, getState) const state = getState(); let to_buy_list = state.selectionReducers.to_buy_list; - dispatch(removeFromToBuyListAll(to_buy_list)); + dispatch(clearCompounds(to_buy_list, majorViewStage)); +}; + +const clearCompounds = (items, majorViewStage) => (dispatch, getState) => { + const state = getState(); + + dispatch(removeFromToBuyListAll(items)); dispatch(setToBuyList([])); // reset objects from nglView and showedCompoundList const currentCompounds = state.previewReducers.compounds.currentCompounds; @@ -167,7 +177,7 @@ export const clearAllSelectedCompounds = majorViewStage => (dispatch, getState) // reset configuration dispatch(resetConfiguration()); // reset current compound class - dispatch(dispatch(setCurrentCompoundClass(compoundsColors.blue.key))); + dispatch(dispatch(setCurrentCompoundClass(compoundsColors.blue.key, compoundsColors.blue.key, true))); }; export const handleClickOnCompound = ({ event, data, majorViewStage, index }) => async (dispatch, getState) => { @@ -197,11 +207,47 @@ export const handleClickOnCompound = ({ event, data, majorViewStage, index }) => if (isSelectedID !== undefined) { await dispatch(removeSelectedCompoundClass(index)); - dispatch(removeFromToBuyList(data)); + dispatch(removeFromToBuyList(data, index)); } else { await dispatch(addSelectedCompoundClass(currentCompoundClass, index)); - dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass }))); + dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass })), index); + } + } +}; + +export const handleBuyList = ({ isSelected, data, index }) => async (dispatch, getState) => { + const state = getState(); + const currentCompoundClass = state.previewReducers.compounds.currentCompoundClass; + + dispatch(setHighlightedCompoundId(index)); + + if (isSelected === false) { + await dispatch(removeSelectedCompoundClass(index)); + dispatch(removeFromToBuyList(data, index, true)); + } else { + await dispatch(addSelectedCompoundClass(currentCompoundClass, index)); + dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass }), index, true)); + } +}; + +export const handleBuyListAll = ({ isSelected, items, majorViewStage }) => async (dispatch, getState) => { + if (isSelected === false) { + dispatch(clearCompounds(items, majorViewStage)); + } else { + for (var item in items) { + dispatch(appendToBuyList(item, item.index, true)); + dispatch(addSelectedCompoundClass(item.class, item.indexOfCompound)); } + dispatch(appendToBuyListAll(items)); + } +}; + +export const handleShowVectorCompound = ({ isSelected, data, index, majorViewStage }) => async (dispatch, getState) => { + await dispatch(showCompoundNglView({ majorViewStage, data, index })); + if (isSelected === false) { + dispatch(removeShowedCompoundFromList(index, data)); + } else { + dispatch(addShowedCompoundToList(index, data)); } }; diff --git a/js/reducers/selection/actions.js b/js/reducers/selection/actions.js index 18eac4abc..9055a1112 100644 --- a/js/reducers/selection/actions.js +++ b/js/reducers/selection/actions.js @@ -11,18 +11,20 @@ export const setToBuyList = function(to_buy_list) { }; }; -export const appendToBuyList = function(item, skipTracking = false) { +export const appendToBuyList = function(item, index, skipTracking = false) { return { type: constants.APPEND_TO_BUY_LIST, item: item, + index: index, skipTracking: skipTracking }; }; -export const removeFromToBuyList = function(item, skipTracking = false) { +export const removeFromToBuyList = function(item, index, skipTracking = false) { return { type: constants.REMOVE_FROM_TO_BUY_LIST, item: item, + index: index, skipTracking: skipTracking }; }; diff --git a/js/reducers/selection/dispatchActions.js b/js/reducers/selection/dispatchActions.js index 29560a7ee..269ec78d8 100644 --- a/js/reducers/selection/dispatchActions.js +++ b/js/reducers/selection/dispatchActions.js @@ -4,8 +4,13 @@ import { getAllCompoundsList } from './selectors'; import { MOL_ATTRIBUTES } from '../../components/preview/molecule/redux/constants'; export const selectVectorAndResetCompounds = vectorSmile => async (dispatch, getState) => { + const state = getState(); + let currentVector = state.selectionReducers.currentVector; + if (currentVector !== vectorSmile) { + await dispatch(setCurrentVector(vectorSmile)); + } + await dispatch(resetCurrentCompoundsSettings(false)); - await dispatch(setCurrentVector(vectorSmile)); const currentCompoundsList = getAllCompoundsList(getState()); dispatch(setCurrentCompounds(currentCompoundsList)); }; diff --git a/js/reducers/tracking/dispatchActions.js b/js/reducers/tracking/dispatchActions.js index 00b6cc9ba..a41eefc01 100644 --- a/js/reducers/tracking/dispatchActions.js +++ b/js/reducers/tracking/dispatchActions.js @@ -7,7 +7,7 @@ import { import { createInitAction } from './trackingActions'; import { actionType, actionObjectType, NUM_OF_SECONDS_TO_IGNORE_MERGE } from './constants'; import { VIEWS } from '../../../js/constants/constants'; -import { setCurrentVector, appendToBuyList, removeFromToBuyList, setHideAll } from '../selection/actions'; +import { setCurrentVector, appendToBuyList, setHideAll } from '../selection/actions'; import { resetReducersForRestoringActions, shouldLoadProtein, @@ -33,6 +33,12 @@ import { removeSurface, removeVector } from '../../components/preview/molecule/redux/dispatchActions'; +import { + handleBuyList, + handleBuyListAll, + handleShowVectorCompound +} from '../../components/preview/compounds/redux/dispatchActions'; +import { setCurrentCompoundClass, setCompoundClasses } from '../../components/preview/compounds/redux/actions'; import { colourList } from '../../components/preview/molecule/moleculeView'; import { addDatasetComplex, @@ -61,7 +67,12 @@ import { } from '../../../js/reducers/ngl/actions'; import * as listType from '../../constants/listTypes'; import { assignRepresentationToComp } from '../../components/nglView/generatingObjects'; -import { deleteObject, setOrientation, setNglBckGrndColor, setNglClipNear } from '../../../js/reducers/ngl/dispatchActions'; +import { + deleteObject, + setOrientation, + setNglBckGrndColor, + setNglClipNear +} from '../../../js/reducers/ngl/dispatchActions'; import { setSendActionsList, setIsActionsSending, @@ -95,6 +106,7 @@ import { setSelectedAllByType as setSelectedAllByTypeOfDataset, setDeselectedAllByType as setDeselectedAllByTypeOfDataset } from '../../components/datasets/redux/actions'; +import { selectVectorAndResetCompounds } from '../../../js/reducers/selection/dispatchActions'; export const addCurrentActionsListToSnapshot = (snapshot, project, nglViewList) => async (dispatch, getState) => { let projectID = project && project.projectID; @@ -1258,10 +1270,22 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => { dispatch(handleMoleculeAction(action, 'vector', true, majorViewStage, state)); break; case actionType.VECTOR_SELECTED: - dispatch(setCurrentVector(undefined)); + dispatch(handleVectorAction(action, false)); break; case actionType.VECTOR_DESELECTED: - dispatch(setCurrentVector(action.object_name)); + dispatch(handleVectorAction(action, true)); + break; + case actionType.VECTOR_COUMPOUND_ADDED: + dispatch(handleVectorCompoundAction(action, false, majorViewStage)); + break; + case actionType.VECTOR_COUMPOUND_REMOVED: + dispatch(handleVectorCompoundAction(action, true, majorViewStage)); + break; + case actionType.CLASS_SELECTED: + dispatch(handleClassSelectedAction(action, false)); + break; + case actionType.CLASS_UPDATED: + dispatch(handleClassUpdatedAction(action, false)); break; case actionType.TARGET_LOADED: dispatch(handleTargetAction(action, false)); @@ -1278,6 +1302,13 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => { case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART: dispatch(handleShoppingCartAction(action, true)); break; + case actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL: + dispatch(handleShoppingCartAllAction(action, false)); + break; + case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL: + dispatch(handleShoppingCartAllAction(action, true)); + break; + case actionType.COMPOUND_SELECTED: dispatch(handleCompoundAction(action, false)); break; @@ -1365,10 +1396,22 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => { dispatch(handleMoleculeAction(action, 'vector', false, majorViewStage, state)); break; case actionType.VECTOR_SELECTED: - dispatch(setCurrentVector(action.object_name)); + dispatch(handleVectorAction(action, true)); break; case actionType.VECTOR_DESELECTED: - dispatch(setCurrentVector(undefined)); + dispatch(handleVectorAction(action, false)); + break; + case actionType.VECTOR_COUMPOUND_ADDED: + dispatch(handleVectorCompoundAction(action, true)); + break; + case actionType.VECTOR_COUMPOUND_REMOVED: + dispatch(handleVectorCompoundAction(action, false)); + break; + case actionType.CLASS_SELECTED: + dispatch(handleClassSelectedAction(action, true)); + break; + case actionType.CLASS_UPDATED: + dispatch(handleClassUpdatedAction(action, true)); break; case actionType.TARGET_LOADED: dispatch(handleTargetAction(action, true)); @@ -1385,6 +1428,12 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => { case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART: dispatch(handleShoppingCartAction(action, false)); break; + case actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL: + dispatch(handleShoppingCartAllAction(action, true)); + break; + case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL: + dispatch(handleShoppingCartAllAction(action, false)); + break; case actionType.COMPOUND_SELECTED: dispatch(handleCompoundAction(action, true)); break; @@ -1602,6 +1651,43 @@ const handleAllAction = (action, isSelected, majorViewStage, state) => (dispatch } }; +const handleVectorAction = (action, isSelected) => (dispatch, getState) => { + if (action) { + if (isSelected === false) { + dispatch(selectVectorAndResetCompounds(undefined)); + } else { + dispatch(selectVectorAndResetCompounds(action.object_name)); + } + } +}; + +const handleVectorCompoundAction = (action, isSelected, majorViewStage) => (dispatch, getState) => { + if (action) { + let data = action.item; + let index = action.index; + dispatch(handleShowVectorCompound({ isSelected, data, index, majorViewStage: majorViewStage })); + } +}; + +const handleClassSelectedAction = (action, isAdd) => (dispatch, getState) => { + if (action) { + let value = isAdd ? action.value : action.oldValue; + let oldValue = isAdd ? action.oldValue : action.value; + dispatch(setCurrentCompoundClass(value, oldValue)); + } +}; + +const handleClassUpdatedAction = (action, isAdd) => (dispatch, getState) => { + if (action) { + let id = action.object_id; + let newValue = isAdd ? action.newCompoundClasses : action.oldCompoundClasses; + let oldValue = isAdd ? action.oldCompoundClasses : action.newCompoundClasses; + let value = isAdd ? action.object_name : action.oldCompoundClasses[id]; + value = value !== undefined ? value : ''; + dispatch(setCompoundClasses(newValue, oldValue, value, id)); + } +}; + const handleTargetAction = (action, isSelected, stages) => (dispatch, getState) => { const state = getState(); if (action) { @@ -1634,10 +1720,19 @@ const handleCompoundAction = (action, isSelected) => (dispatch, getState) => { const handleShoppingCartAction = (action, isAdd) => (dispatch, getState) => { if (action) { let data = action.item; - if (isAdd) { - dispatch(appendToBuyList(data)); - } else { - dispatch(removeFromToBuyList(data)); + let index = action.index; + + if (data) { + dispatch(handleBuyList({ isSelected: isAdd, data, index })); + } + } +}; + +const handleShoppingCartAllAction = (action, isAdd) => (dispatch, getState) => { + if (action) { + let data = action.items; + if (data) { + dispatch(handleBuyListAll({ isSelected: isAdd, data })); } } }; @@ -1888,7 +1983,7 @@ export const mergeActions = (trackAction, list) => { } }; -const needsToBeMerged = (trackAction) => { +const needsToBeMerged = trackAction => { return trackAction.merge !== undefined ? trackAction.merge : false; }; diff --git a/js/reducers/tracking/trackingActions.js b/js/reducers/tracking/trackingActions.js index 29ea0e624..0f386b26d 100644 --- a/js/reducers/tracking/trackingActions.js +++ b/js/reducers/tracking/trackingActions.js @@ -5,7 +5,7 @@ import { constants as previewCompoundConstants } from '../../components/preview/ import { constants as selectionConstants } from '../selection/constants'; import { constants as customDatasetConstants } from '../../components/datasets/redux/constants'; import { DJANGO_CONTEXT } from '../../utils/djangoContext'; -import {NGL_PARAMS, BACKGROUND_COLOR} from '../../components/nglView/constants/index'; +import { NGL_PARAMS, BACKGROUND_COLOR } from '../../components/nglView/constants/index'; export const findTrackAction = (action, state) => { const username = DJANGO_CONTEXT['username']; @@ -373,6 +373,7 @@ export const findTrackAction = (action, state) => { object_type: objectType, object_name: objectName, object_id: objectName, + index: action.index, item: action.item, text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` }; @@ -390,40 +391,37 @@ export const findTrackAction = (action, state) => { object_type: objectType, object_name: objectName, object_id: objectName, + index: action.index, item: action.item, text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` }; } } else if (action.type === selectionConstants.APPEND_TO_BUY_LIST_ALL) { - if (action.items) { - let items = action.items; - let objectType = actionObjectType.COMPOUND; + let items = action.items; + let objectType = actionObjectType.COMPOUND; - trackAction = { - type: actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL, - annotation: actionAnnotation.CHECK, - timestamp: Date.now(), - username: username, - object_type: objectType, - items: items, - text: `${actionDescription.ALL} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` - }; - } + trackAction = { + type: actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL, + annotation: actionAnnotation.CHECK, + timestamp: Date.now(), + username: username, + object_type: objectType, + items: items, + text: `${actionDescription.ALL} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` + }; } else if (action.type === selectionConstants.REMOVE_FROM_BUY_LIST_ALL) { - if (action.items) { - let items = action.items; - let objectType = actionObjectType.COMPOUND; + let items = action.items; + let objectType = actionObjectType.COMPOUND; - trackAction = { - type: actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL, - annotation: actionAnnotation.CLEAR, - timestamp: Date.now(), - username: username, - object_type: objectType, - items: items, - text: `${actionDescription.ALL} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` - }; - } + trackAction = { + type: actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL, + annotation: actionAnnotation.CLEAR, + timestamp: Date.now(), + username: username, + object_type: objectType, + items: items, + text: `${actionDescription.ALL} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` + }; } else if (action.type === previewCompoundConstants.APPEND_SHOWED_COMPOUND_LIST) { if (action.item && action.payload) { let objectType = actionObjectType.COMPOUND; @@ -438,6 +436,7 @@ export const findTrackAction = (action, state) => { object_name: objectName, object_id: action.payload, item: action.item, + index: action.payload, text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.ADDED}` }; } @@ -455,6 +454,7 @@ export const findTrackAction = (action, state) => { object_name: objectName, object_id: action.payload, item: action.item, + index: action.payload, text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.REMOVED}` }; } @@ -488,22 +488,14 @@ export const findTrackAction = (action, state) => { object_type: objectType, object_name: objectName, object_id: objectName, - oldObjectName: oldObjectName, + oldValue: oldObjectName, + value: objectName, text: `${actionDescription.CLASS} ${objectName} ${actionDescription.SELECTED}` }; } } else if (action.type === previewCompoundConstants.SET_COMPOUND_CLASSES) { if (action.payload) { let objectType = actionObjectType.COMPOUND; - let newClassDescription = action.payload; - let objectName = JSON.stringify(action.newClassDescription); - let oldClassDescription = action.oldCompoundClasses; - - var regex = new RegExp('"', 'g'); - objectName = objectName - .replace(regex, '') - .replace('{', '') - .replace('}', ''); trackAction = { type: actionType.CLASS_UPDATED, @@ -511,11 +503,11 @@ export const findTrackAction = (action, state) => { timestamp: Date.now(), username: username, object_type: objectType, - object_name: objectName, - object_id: objectName, - oldClassDescription: oldClassDescription, - newClassDescription: newClassDescription, - text: `${actionDescription.CLASS} value ${actionDescription.UPDATED}: ${objectName}` + object_name: action.value, + object_id: action.id, + newCompoundClasses: action.payload, + oldCompoundClasses: action.oldCompoundClasses, + text: `${actionDescription.CLASS} value ${actionDescription.UPDATED}: ${action.id}:${action.value}` }; } } else if (action.type.includes(customDatasetConstants.APPEND_MOLECULE_TO_COMPOUNDS_TO_BUY_OF_DATASET)) { @@ -871,7 +863,14 @@ export const findTrackAction = (action, state) => { oldSetting: oldSetting, newSetting: newSetting, getText: function() { - return "Clip near of NGL " + actionDescription.CHANGED + " from value: " + this.oldSetting + " to value: " + this.newSetting; + return ( + 'Clip near of NGL ' + + actionDescription.CHANGED + + ' from value: ' + + this.oldSetting + + ' to value: ' + + this.newSetting + ); }, text: `Clip near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}` };