Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#453' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Dec 1, 2020
2 parents e84f58d + 75bf86d commit 9d6f428
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 20 deletions.
46 changes: 34 additions & 12 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
updateVectorCompounds,
updateBondColorMapOfCompounds,
resetBondColorMapOfVectors,
setCurrentVector
setCurrentVector,
setHideAll
} from '../../../../reducers/selection/actions';
import { base_url } from '../../../routes/constants';
import {
Expand Down Expand Up @@ -115,11 +116,11 @@ const handleVector = (json, stage, data) => (dispatch, getState) => {
dispatch(updateBondColorMapOfCompounds(data.smiles, vectorBondColorMap));
};

export const addVector = (stage, data) => async (dispatch, getState) => {
export const addVector = (stage, data, skipTracking = false) => async (dispatch, getState) => {
const currentVector = getState().selectionReducers.currentVector;

dispatch(incrementCountOfPendingVectorLoadRequests());
dispatch(appendVectorOnList(generateMoleculeId(data)));
dispatch(appendVectorOnList(generateMoleculeId(data), skipTracking));
dispatch(selectVectorAndResetCompounds(currentVector));

return api({ url: getViewUrl('graph', data) })
Expand Down Expand Up @@ -226,7 +227,7 @@ export const removeComplex = (stage, data, colourToggle, skipTracking = false) =
dispatch(removeFromComplexList(generateMoleculeId(data), skipTracking));
};

export const addSurface = (stage, data, colourToggle) => dispatch => {
export const addSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
dispatch(
loadObject({
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
Expand All @@ -237,17 +238,17 @@ export const addSurface = (stage, data, colourToggle) => dispatch => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
});
dispatch(appendSurfaceList(generateMoleculeId(data)));
dispatch(appendSurfaceList(generateMoleculeId(data), skipTracking));
};

export const removeSurface = (stage, data, colourToggle) => dispatch => {
export const removeSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
dispatch(
deleteObject(
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
stage
)
);
dispatch(removeFromSurfaceList(generateMoleculeId(data)));
dispatch(removeFromSurfaceList(generateMoleculeId(data), skipTracking));
};

export const addDensity = (stage, data, colourToggle) => dispatch => {
Expand Down Expand Up @@ -330,39 +331,51 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
const vectorOnList = state.selectionReducers.vectorOnList;
const surfaceList = state.selectionReducers.surfaceList;
const proteinList = state.selectionReducers.proteinList;
const vectorList = state.selectionReducers.vector_list;

let ligandDataList = [];
let complexDataList = [];
let vectorOnDataList = [];
let surfaceDataList = [];
let proteinDataList = [];

fragmentDisplayList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeLigand(stage, data));
ligandDataList.push(data);
dispatch(removeLigand(stage, data, true));
}
});
complexList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeComplex(stage, data, colourList[0]));
complexDataList.push(data);
dispatch(removeComplex(stage, data, colourList[0], true));
}
});
vectorOnList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeVector(stage, data));
vectorOnDataList.push(data);
dispatch(removeVector(stage, data, true));
}
});

// remove Surface
surfaceList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeSurface(stage, data));
surfaceDataList.push(data);
dispatch(removeSurface(stage, data, colourList[0], true));
}
});

// remove Protein
proteinList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeHitProtein(stage, data));
proteinDataList.push(data);
dispatch(removeHitProtein(stage, data, colourList[0], true));
}
});

Expand All @@ -371,6 +384,15 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
dispatch(resetCompoundsOfVectors());
dispatch(resetBondColorMapOfVectors());
dispatch(setCompoundImage(noCompoundImage));

let data = {
ligandList: ligandDataList,
proteinList: proteinDataList,
complexList: complexDataList,
surfaceList: surfaceDataList,
vectorOnList: vectorOnDataList
};
dispatch(setHideAll(data));
};

export const searchMoleculeGroupByMoleculeID = moleculeID => (dispatch, getState) =>
Expand Down
21 changes: 15 additions & 6 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ export const setSurfaceList = function(surfaceList) {
};
};

export const appendSurfaceList = function(item) {
export const appendSurfaceList = function(item, skipTracking = false) {
return {
type: constants.APPEND_SURFACE_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

export const removeFromSurfaceList = function(item) {
export const removeFromSurfaceList = function(item, skipTracking = false) {
return {
type: constants.REMOVE_FROM_SURFACE_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

Expand Down Expand Up @@ -156,10 +158,11 @@ export const setVectorOnList = function(vectorOnList) {
};
};

export const appendVectorOnList = function(item) {
export const appendVectorOnList = function(item, skipTracking = false) {
return {
type: constants.APPEND_VECTOR_ON_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

Expand Down Expand Up @@ -253,3 +256,9 @@ export const setDeselectedAllByType = (type, items, isInspiration) => ({
type: constants.SET_DESELECTED_ALL_BY_TYPE,
payload: { type, items, isInspiration }
});

export const setHideAll = (data, isHide = true) => ({
type: constants.SET_HIDE_ALL,
isHide: isHide,
data: data
});
1 change: 1 addition & 0 deletions js/reducers/selection/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const constants = {
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',
SET_SELECTED_ALL_BY_TYPE: prefix + 'SET_SELECTED_ALL_BY_TYPE',
SET_DESELECTED_ALL_BY_TYPE: prefix + 'SET_DESELECTED_ALL_BY_TYPE',
SET_HIDE_ALL: prefix + 'SET_HIDE_ALL',

RESET_COMPOUNDS_OF_VECTORS: prefix + 'RESET_COMPOUNDS_OF_VECTORS',
UPDATE_VECTOR_COMPOUNDS: prefix + 'UPDATE_VECTOR_COMPOUNDS',
Expand Down
4 changes: 4 additions & 0 deletions js/reducers/selection/selectionReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
return Object.assign({}, state, {
moleculeAllTypeSelection: action.payload.type
});

case constants.SET_HIDE_ALL:
return state;

// Cases like: @@redux/INIT
default:
return state;
Expand Down
3 changes: 3 additions & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const actionType = {
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
UNDO: 'UNDO',
REDO: 'REDO',
ALL_HIDE: 'ALL_HIDE',
ALL_TURNED_ON: 'ALL_TURNED_ON',
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
ALL_TURNED_ON_BY_TYPE: 'ALL_TURNED_ON_BY_TYPE',
Expand All @@ -54,6 +55,8 @@ export const actionDescription = {
TURNED_OFF: 'was turned off',
SELECTED: 'was selected',
DESELECTED: 'was deselected',
HIDDEN: 'hidden',
CANCELED: 'canceled',
ADDED: 'was added',
REMOVED: 'was removed',
CHANGED: 'was changed',
Expand Down
79 changes: 78 additions & 1 deletion js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from './actions';
import { actionType, actionObjectType } from './constants';
import { VIEWS } from '../../../js/constants/constants';
import { setCurrentVector, appendToBuyList, removeFromToBuyList } from '../selection/actions';
import { setCurrentVector, appendToBuyList, removeFromToBuyList, setHideAll } from '../selection/actions';
import { unmountPreviewComponent, shouldLoadProtein } from '../../components/preview/redux/dispatchActions';
import { setCurrentProject } from '../../components/projects/redux/actions';
import {
Expand Down Expand Up @@ -772,6 +772,9 @@ const handleUndoAction = (action, stages) => (dispatch, getState) => {

const type = action.type;
switch (type) {
case actionType.ALL_HIDE:
dispatch(handleAllHideAction(action, true, majorViewStage));
break;
case actionType.ALL_TURNED_ON:
dispatch(handleAllAction(action, false, majorViewStage, state));
break;
Expand Down Expand Up @@ -867,6 +870,9 @@ const handleRedoAction = (action, stages) => (dispatch, getState) => {

const type = action.type;
switch (type) {
case actionType.ALL_HIDE:
dispatch(handleAllHideAction(action, false, majorViewStage));
break;
case actionType.ALL_TURNED_ON:
dispatch(handleAllAction(action, true, majorViewStage, state));
break;
Expand Down Expand Up @@ -1028,6 +1034,77 @@ const handleAllActionByType = (action, isAdd, stage) => (dispatch, getState) =>
}
};

const handleAllHideAction = (action, isAdd, stage) => (dispatch, getState) => {
let data = action.data;
let ligandDataList = data.ligandList;
let proteinDataList = data.proteinList;
let complexDataList = data.complexList;
let surfaceDataList = data.surfaceList;
let vectorOnDataList = data.vectorOnList;

dispatch(setHideAll(data, !isAdd));

if (isAdd) {
ligandDataList.forEach(data => {
if (data) {
dispatch(addType['ligand'](stage, data, colourList[data.id % colourList.length], true, true));
}
});

proteinDataList.forEach(data => {
if (data) {
dispatch(addType['protein'](stage, data, colourList[data.id % colourList.length], true));
}
});

complexDataList.forEach(data => {
if (data) {
dispatch(addType['complex'](stage, data, colourList[data.id % colourList.length], true));
}
});

surfaceDataList.forEach(data => {
if (data) {
dispatch(addType['surface'](stage, data, colourList[data.id % colourList.length], true));
}
});
vectorOnDataList.forEach(data => {
if (data) {
dispatch(addType['vector'](stage, data, true));
}
});
} else {
ligandDataList.forEach(data => {
if (data) {
dispatch(removeType['ligand'](stage, data, true));
}
});

proteinDataList.forEach(data => {
if (data) {
dispatch(removeType['protein'](stage, data, colourList[data.id % colourList.length], true));
}
});

complexDataList.forEach(data => {
if (data) {
dispatch(removeType['complex'](stage, data, colourList[data.id % colourList.length], true));
}
});

surfaceDataList.forEach(data => {
if (data) {
dispatch(removeType['surface'](stage, data, colourList[data.id % colourList.length], true));
}
});
vectorOnDataList.forEach(data => {
if (data) {
dispatch(removeType['vector'](stage, data, true));
}
});
}
};

const handleAllAction = (action, isSelected, majorViewStage, state) => (dispatch, getState) => {
let isSelection =
action.object_type === actionObjectType.MOLECULE || action.object_type === actionObjectType.INSPIRATION;
Expand Down
14 changes: 14 additions & 0 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ export const findTrackAction = (action, state) => {
text: `${actionDescription.SITE} ${molGroupName} ${actionDescription.TURNED_OFF}`
};
}
} else if (action.type === selectionConstants.SET_HIDE_ALL) {
if (action.data) {
let objectType = actionObjectType.MOLECULE;
let description = action.isHide === true ? `` : `${actionDescription.CANCELED}`;

trackAction = {
type: actionType.ALL_HIDE,
timestamp: Date.now(),
username: username,
object_type: objectType,
data: action.data,
text: `${actionDescription.ALL} ${actionDescription.HIDDEN} ${description}`
};
}
} else if (action.type === selectionConstants.SET_SELECTED_ALL) {
if (action.item) {
let objectType = action.item.isInspiration === true ? actionObjectType.INSPIRATION : actionObjectType.MOLECULE;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragalysis-frontend",
"version": "0.9.30",
"version": "0.9.31",
"description": "Frontend for fragalysis",
"main": "webpack.config.js",
"scripts": {
Expand Down

0 comments on commit 9d6f428

Please sign in to comment.