Skip to content

Commit

Permalink
#479 Vector selector actions (RHS clicks) are not captured
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Jan 20, 2021
1 parent bc7ee58 commit 1e5921d
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 27 deletions.
21 changes: 13 additions & 8 deletions js/components/preview/compounds/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ 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 => ({
type: constants.RESET_COMPOUND_CLASSES,
payload: compoundClasses
});

export const setCurrentCompoundClass = currentCompoundClass => {
export const setCurrentCompoundClass = (currentCompoundClass, oldCompoundClass) => {
return {
type: constants.SET_CURRENT_COMPOUND_CLASS,
payload: currentCompoundClass
payload: currentCompoundClass,
oldCompoundClass: oldCompoundClass
};
};

Expand All @@ -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) => ({
Expand Down
33 changes: 25 additions & 8 deletions js/components/preview/compounds/redux/dispatchActions.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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]) {
Expand All @@ -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) => {
Expand All @@ -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));
}
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 20 additions & 4 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};

Expand Down
2 changes: 2 additions & 0 deletions js/reducers/selection/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -73,6 +79,8 @@ export const actionDescription = {
SIDECHAIN: 'Sidechain',
INTERACTION: 'Interaction',
VECTOR: 'Vector',
COMPOUND: 'Compound',
CLASS: 'Compound colour',
SURFACE: 'Surface',
SITE: 'Site',
TARGET: 'Target',
Expand Down
123 changes: 116 additions & 7 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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)) {
Expand All @@ -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;
Expand Down

0 comments on commit 1e5921d

Please sign in to comment.