Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#479' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Jan 21, 2021
2 parents 1e0e019 + c157a7e commit 0ccbf33
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 46 deletions.
23 changes: 15 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,25 @@ export const updateCurrentCompound = ({ id, key, value }) => ({
}
});

export const setCompoundClasses = compoundClasses => ({
export const setCompoundClasses = (compoundClasses, oldCompoundClasses, value, id) => ({
type: constants.SET_COMPOUND_CLASSES,
payload: compoundClasses
payload: compoundClasses,
oldCompoundClasses: oldCompoundClasses,
value: value,
id: id
});

export const resetCompoundClasses = compoundClasses => ({
type: constants.RESET_COMPOUND_CLASSES,
payload: compoundClasses
});

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

Expand All @@ -57,14 +62,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
89 changes: 76 additions & 13 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 @@ -41,14 +48,19 @@ 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
};
dispatch(appendToBuyList(thisObj));
items.push(thisObj);
dispatch(appendToBuyList(thisObj, index, true));
dispatch(addSelectedCompoundClass(currentCompoundClass, parseInt(indexOfCompound)));
}
}
}
}

dispatch(appendToBuyListAll(items));
};

export const onChangeCompoundClassValue = event => (dispatch, getState) => {
Expand All @@ -59,16 +71,22 @@ export const onChangeCompoundClassValue = event => (dispatch, getState) => {
});
// const compoundClasses = state.previewReducers.compounds.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));
dispatch(setCompoundClasses(descriptionToSet, oldDescriptionToSet, value, id));
};

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 +149,17 @@ 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(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;
const showedCompoundList = state.previewReducers.compounds.showedCompoundList;
Expand All @@ -150,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 All @@ -164,9 +191,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 All @@ -180,14 +207,50 @@ 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));
}
};

export const loadCompoundImageData = ({ width, height, onCancel, data, setImage }) => {
let url = undefined;
let key = undefined;
Expand Down
26 changes: 22 additions & 4 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,35 @@ export const setToBuyList = function(to_buy_list) {
};
};

export const appendToBuyList = function(item) {
export const appendToBuyList = function(item, index, skipTracking = false) {
return {
type: constants.APPEND_TO_BUY_LIST,
item: item
item: item,
index: index,
skipTracking: skipTracking
};
};

export const removeFromToBuyList = function(item) {
export const removeFromToBuyList = function(item, index, skipTracking = false) {
return {
type: constants.REMOVE_FROM_TO_BUY_LIST,
item: item
item: item,
index: index,
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
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
8 changes: 8 additions & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,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 @@ -81,6 +87,8 @@ export const actionDescription = {
SIDECHAIN: 'Sidechain',
INTERACTION: 'Interaction',
VECTOR: 'Vector',
COMPOUND: 'Compound',
CLASS: 'Compound colour',
SURFACE: 'Surface',
SITE: 'Site',
TARGET: 'Target',
Expand Down
Loading

0 comments on commit 0ccbf33

Please sign in to comment.