From fc1b3535c6d39685f96a054727755db916761a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1na=20Kohanov=C3=A1?= Date: Fri, 22 Jan 2021 09:13:03 +0100 Subject: [PATCH] #479 Vector selector actions (RHS clicks) are not captured --- .../compounds/redux/dispatchActions.js | 27 ++++---- js/reducers/tracking/dispatchActions.js | 24 +++---- js/reducers/tracking/trackingActions.js | 64 +++++++++---------- 3 files changed, 54 insertions(+), 61 deletions(-) diff --git a/js/components/preview/compounds/redux/dispatchActions.js b/js/components/preview/compounds/redux/dispatchActions.js index e84c9b2a7..fc3c82fca 100644 --- a/js/components/preview/compounds/redux/dispatchActions.js +++ b/js/components/preview/compounds/redux/dispatchActions.js @@ -44,17 +44,17 @@ export const selectAllCompounds = () => (dispatch, getState) => { for (let index in currentVectorCompoundsFiltered[key]) { if (index !== 'vector') { for (let indexOfCompound in currentVectorCompoundsFiltered[key][index]) { + let compoundId = parseInt(indexOfCompound); var thisObj = { smiles: currentVectorCompoundsFiltered[key][index][indexOfCompound].end, vector: currentVectorCompoundsFiltered[key].vector.split('_')[0], mol: smiles, class: parseInt(currentCompoundClass), - indexOfCompound: indexOfCompound, - index: index + compoundId: compoundId }; items.push(thisObj); - dispatch(appendToBuyList(thisObj, index, true)); - dispatch(addSelectedCompoundClass(currentCompoundClass, parseInt(indexOfCompound))); + dispatch(appendToBuyList(thisObj, compoundId, true)); + dispatch(addSelectedCompoundClass(currentCompoundClass, compoundId)); } } } @@ -215,28 +215,29 @@ export const handleClickOnCompound = ({ event, data, majorViewStage, index }) => } }; -export const handleBuyList = ({ isSelected, data, index }) => async (dispatch, getState) => { +export const handleBuyList = ({ isSelected, data, compoundId }) => (dispatch, getState) => { const state = getState(); const currentCompoundClass = state.previewReducers.compounds.currentCompoundClass; - dispatch(setHighlightedCompoundId(index)); + dispatch(setHighlightedCompoundId(compoundId)); if (isSelected === false) { - await dispatch(removeSelectedCompoundClass(index)); - dispatch(removeFromToBuyList(data, index, true)); + dispatch(removeSelectedCompoundClass(compoundId)); + dispatch(removeFromToBuyList(data, compoundId, true)); } else { - await dispatch(addSelectedCompoundClass(currentCompoundClass, index)); - dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass }), index, true)); + dispatch(addSelectedCompoundClass(currentCompoundClass, compoundId)); + dispatch(appendToBuyList(Object.assign({}, data, { class: currentCompoundClass }), compoundId, true)); } }; -export const handleBuyListAll = ({ isSelected, items, majorViewStage }) => async (dispatch, getState) => { +export const handleBuyListAll = ({ isSelected, items, majorViewStage }) => (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)); + let index = item.compoundId; + dispatch(appendToBuyList(item, index, true)); + dispatch(addSelectedCompoundClass(item.class, index)); } dispatch(appendToBuyListAll(items)); } diff --git a/js/reducers/tracking/dispatchActions.js b/js/reducers/tracking/dispatchActions.js index a41eefc01..9488a38d2 100644 --- a/js/reducers/tracking/dispatchActions.js +++ b/js/reducers/tracking/dispatchActions.js @@ -1303,12 +1303,11 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => { dispatch(handleShoppingCartAction(action, true)); break; case actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL: - dispatch(handleShoppingCartAllAction(action, false)); + dispatch(handleShoppingCartAllAction(action, false, majorViewStage)); break; case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL: - dispatch(handleShoppingCartAllAction(action, true)); + dispatch(handleShoppingCartAllAction(action, true, majorViewStage)); break; - case actionType.COMPOUND_SELECTED: dispatch(handleCompoundAction(action, false)); break; @@ -1429,10 +1428,10 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => { dispatch(handleShoppingCartAction(action, false)); break; case actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL: - dispatch(handleShoppingCartAllAction(action, true)); + dispatch(handleShoppingCartAllAction(action, true, majorViewStage)); break; case actionType.MOLECULE_REMOVED_FROM_SHOPPING_CART_ALL: - dispatch(handleShoppingCartAllAction(action, false)); + dispatch(handleShoppingCartAllAction(action, false, majorViewStage)); break; case actionType.COMPOUND_SELECTED: dispatch(handleCompoundAction(action, true)); @@ -1664,8 +1663,8 @@ const handleVectorAction = (action, isSelected) => (dispatch, getState) => { const handleVectorCompoundAction = (action, isSelected, majorViewStage) => (dispatch, getState) => { if (action) { let data = action.item; - let index = action.index; - dispatch(handleShowVectorCompound({ isSelected, data, index, majorViewStage: majorViewStage })); + let compoundId = action.compoundId; + dispatch(handleShowVectorCompound({ isSelected, data, index: compoundId, majorViewStage: majorViewStage })); } }; @@ -1720,20 +1719,17 @@ const handleCompoundAction = (action, isSelected) => (dispatch, getState) => { const handleShoppingCartAction = (action, isAdd) => (dispatch, getState) => { if (action) { let data = action.item; - let index = action.index; + let compoundId = action.compoundId; if (data) { - dispatch(handleBuyList({ isSelected: isAdd, data, index })); + dispatch(handleBuyList({ isSelected: isAdd, data, compoundId })); } } }; -const handleShoppingCartAllAction = (action, isAdd) => (dispatch, getState) => { +const handleShoppingCartAllAction = (action, isAdd, majorViewStage) => (dispatch, getState) => { if (action) { - let data = action.items; - if (data) { - dispatch(handleBuyListAll({ isSelected: isAdd, data })); - } + dispatch(handleBuyListAll({ isSelected: isAdd, items: action.items, majorViewStage: majorViewStage })); } }; diff --git a/js/reducers/tracking/trackingActions.js b/js/reducers/tracking/trackingActions.js index 0f386b26d..4c775736f 100644 --- a/js/reducers/tracking/trackingActions.js +++ b/js/reducers/tracking/trackingActions.js @@ -373,7 +373,7 @@ export const findTrackAction = (action, state) => { object_type: objectType, object_name: objectName, object_id: objectName, - index: action.index, + compoundId: action.item.compoundId, item: action.item, text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.ADDED} ${actionDescription.TO_SHOPPING_CART}` }; @@ -391,7 +391,7 @@ export const findTrackAction = (action, state) => { object_type: objectType, object_name: objectName, object_id: objectName, - index: action.index, + compoundId: action.item.compoundId, item: action.item, text: `${actionDescription.VECTOR} ${objectName} ${actionDescription.REMOVED} ${actionDescription.FROM_SHOPPING_CART}` }; @@ -423,41 +423,37 @@ export const findTrackAction = (action, state) => { 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; + 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, - index: action.payload, - text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.ADDED}` - }; - } + 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, + compoundId: action.payload, + 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; + 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, - index: action.payload, - text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.REMOVED}` - }; - } + 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, + compoundId: action.payload, + text: `${actionDescription.COMPOUND} ${objectName} ${actionDescription.REMOVED}` + }; } else if (action.type.includes(selectionConstants.SET_CURRENT_VECTOR)) { if (action.payload) { let objectType = actionObjectType.MOLECULE;