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 aa3a832 commit c157a7e
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 70 deletions.
10 changes: 6 additions & 4 deletions js/components/preview/compounds/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ 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 => ({
type: constants.RESET_COMPOUND_CLASSES,
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
};
};

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

Expand Down
6 changes: 4 additions & 2 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
Expand Down
7 changes: 6 additions & 1 deletion js/reducers/selection/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down
117 changes: 106 additions & 11 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }));
}
}
};
Expand Down Expand Up @@ -1888,7 +1983,7 @@ export const mergeActions = (trackAction, list) => {
}
};

const needsToBeMerged = (trackAction) => {
const needsToBeMerged = trackAction => {
return trackAction.merge !== undefined ? trackAction.merge : false;
};

Expand Down
Loading

0 comments on commit c157a7e

Please sign in to comment.