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] #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;