Skip to content

Commit

Permalink
#462 Mass actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Nov 20, 2020
1 parent 39da154 commit 0a6e5f7
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 53 deletions.
47 changes: 29 additions & 18 deletions js/components/preview/molecule/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
removeLigand,
searchMoleculeGroupByMoleculeID
} from './redux/dispatchActions';
import { setSelectedAll, setDeselectedAll } from '../../../reducers/selection/actions';
import { base_url } from '../../routes/constants';
import { moleculeProperty } from './helperConstants';
import { centerOnLigandByMoleculeID } from '../../../reducers/ngl/dispatchActions';
Expand Down Expand Up @@ -344,25 +345,25 @@ const MoleculeView = memo(
const current_style =
isLigandOn || isProteinOn || isComplexOn || isSurfaceOn || isVectorOn ? selected_style : not_selected_style;

const addNewLigand = () => {
const addNewLigand = (skipTracking = false) => {
if (selectMoleculeSite) {
selectMoleculeSite(data.site);
}
dispatch(addLigand(stage, data, colourToggle));
dispatch(addLigand(stage, data, colourToggle, false, skipTracking));
};

const removeSelectedLigand = () => {
dispatch(removeLigand(stage, data));
const removeSelectedLigand = (skipTracking = false) => {
dispatch(removeLigand(stage, data, skipTracking));
selectedAll.current = false;
};

const onLigand = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isLigandOn === false) {
addNewLigand();
addNewLigand(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedLigand();
removeSelectedLigand(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isLigandOn === false) {
addNewLigand();
Expand All @@ -372,25 +373,25 @@ const MoleculeView = memo(
}
};

const removeSelectedProtein = () => {
dispatch(removeHitProtein(stage, data, colourToggle));
const removeSelectedProtein = (skipTracking = false) => {
dispatch(removeHitProtein(stage, data, colourToggle, skipTracking));
selectedAll.current = false;
};

const addNewProtein = () => {
const addNewProtein = (skipTracking = false) => {
if (selectMoleculeSite) {
selectMoleculeSite(data.site);
}
dispatch(addHitProtein(stage, data, colourToggle));
dispatch(addHitProtein(stage, data, colourToggle, skipTracking));
};

const onProtein = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isProteinOn === false) {
addNewProtein();
addNewProtein(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedProtein();
removeSelectedProtein(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isProteinOn === false) {
addNewProtein();
Expand All @@ -400,25 +401,25 @@ const MoleculeView = memo(
}
};

const removeSelectedComplex = () => {
dispatch(removeComplex(stage, data, colourToggle));
const removeSelectedComplex = (skipTracking = false) => {
dispatch(removeComplex(stage, data, colourToggle, skipTracking));
selectedAll.current = false;
};

const addNewComplex = () => {
const addNewComplex = (skipTracking = false) => {
if (selectMoleculeSite) {
selectMoleculeSite(data.site);
}
dispatch(addComplex(stage, data, colourToggle));
dispatch(addComplex(stage, data, colourToggle, skipTracking));
};

const onComplex = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isComplexOn === false) {
addNewComplex();
addNewComplex(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedComplex();
removeSelectedComplex(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isComplexOn === false) {
addNewComplex();
Expand Down Expand Up @@ -487,6 +488,15 @@ const MoleculeView = memo(
}
};

const setCalledFromAll = () => {
let isSelected = selectedAll.current === true;
if (isSelected) {
dispatch(setSelectedAll(data));
} else {
dispatch(setDeselectedAll(data));
}
};

/**
* Check if given molecule is matching current filter
* @param Object item - item.name is attribute name, item.value is its value
Expand Down Expand Up @@ -610,6 +620,7 @@ const MoleculeView = memo(
// always deselect all if are selected only some of options
selectedAll.current = hasSomeValuesOn ? false : !selectedAll.current;

setCalledFromAll();
onLigand(true);
onProtein(true);
onComplex(true);
Expand Down
39 changes: 23 additions & 16 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const removeCurrentVector = currentMoleculeSmile => (dispatch, getState)
}
};

export const removeVector = (stage, data) => async (dispatch, getState) => {
export const removeVector = (stage, data, skipTracking = false) => async (dispatch, getState) => {
const state = getState();
const vector_list = state.selectionReducers.vector_list;
vector_list
Expand All @@ -173,12 +173,12 @@ export const removeVector = (stage, data) => async (dispatch, getState) => {

dispatch(updateVectorCompounds(data.smiles, undefined));
dispatch(updateBondColorMapOfCompounds(data.smiles, undefined));
dispatch(removeFromVectorOnList(generateMoleculeId(data)));
dispatch(removeFromVectorOnList(generateMoleculeId(data), skipTracking));

dispatch(setVectorList(vector_list.filter(item => item.moleculeId !== data.id)));
};

export const addHitProtein = (stage, data, colourToggle) => dispatch => {
export const addHitProtein = (stage, data, colourToggle, skipTracking = false) => dispatch => {
dispatch(
loadObject({
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateHitProteinObject(data, colourToggle, base_url)),
Expand All @@ -189,20 +189,20 @@ export const addHitProtein = (stage, data, colourToggle) => dispatch => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
});
dispatch(appendProteinList(generateMoleculeId(data)));
dispatch(appendProteinList(generateMoleculeId(data), skipTracking));
};

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

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

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

export const addSurface = (stage, data, colourToggle) => dispatch => {
Expand Down Expand Up @@ -278,9 +278,12 @@ export const removeDensity = (stage, data, colourToggle) => dispatch => {
dispatch(removeFromDensityList(generateMoleculeId(data)));
};

export const addLigand = (stage, data, colourToggle, centerOn = false) => (dispatch, getState) => {
export const addLigand = (stage, data, colourToggle, centerOn = false, skipTracking = false) => (
dispatch,
getState
) => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(appendFragmentDisplayList(generateMoleculeId(data)));
dispatch(appendFragmentDisplayList(generateMoleculeId(data), skipTracking));
return dispatch(
loadObject({
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateMoleculeObject(data, colourToggle)),
Expand All @@ -299,12 +302,12 @@ export const addLigand = (stage, data, colourToggle, centerOn = false) => (dispa
});
};

export const removeLigand = (stage, data) => dispatch => {
export const removeLigand = (stage, data, skipTracking = false) => dispatch => {
dispatch(deleteObject(Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateMoleculeObject(data)), stage));
dispatch(removeFromFragmentDisplayList(generateMoleculeId(data)));
dispatch(removeFromFragmentDisplayList(generateMoleculeId(data), skipTracking));

// remove vector
dispatch(removeVector(stage, data));
dispatch(removeVector(stage, data, skipTracking));
};

/**
Expand Down Expand Up @@ -412,7 +415,11 @@ export const applyDirectSelection = (stage, stageSummaryView) => (dispatch, getS
for (let molIndex = 0; molIndex < molCount; molIndex++) {
let mol = molList[molIndex];
let proteinCodeModded = mol.protein_code.toLowerCase();
if (m.exact ? proteinCodeModded === directProteinCodeModded : proteinCodeModded.includes(directProteinNameModded)) {
if (
m.exact
? proteinCodeModded === directProteinCodeModded
: proteinCodeModded.includes(directProteinNameModded)
) {
let molGroupId = groupId;
// Has to be declared here because otherwise we read stale value
const mol_group_selection = getState().selectionReducers.mol_group_selection;
Expand Down
45 changes: 31 additions & 14 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ export const setFragmentDisplayList = function(fragmentDisplayList) {
};
};

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

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

Expand All @@ -67,17 +69,19 @@ export const setProteinList = function(proteinList) {
};
};

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

export const removeFromProteinList = function(item) {
export const removeFromProteinList = function(item, skipTracking = false) {
return {
type: constants.REMOVE_FROM_PROTEIN_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};
export const setComplexList = function(complexList) {
Expand All @@ -87,17 +91,19 @@ export const setComplexList = function(complexList) {
};
};

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

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

Expand Down Expand Up @@ -157,10 +163,11 @@ export const appendVectorOnList = function(item) {
};
};

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

Expand Down Expand Up @@ -220,3 +227,13 @@ export const updateBondColorMapOfCompounds = (key, value) => ({
type: constants.UPDATE_BOND_COLOR_MAP_OF_COMPOUNDS,
payload: { key, value }
});

export const setSelectedAll = item => ({
type: constants.SET_SELECTED_ALL,
item: item
});

export const setDeselectedAll = item => ({
type: constants.SET_DESELECTED_ALL,
item: item
});
2 changes: 2 additions & 0 deletions js/reducers/selection/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const constants = {
RESET_SELECTION_STATE: prefix + 'RESET_SELECTION_STATE',
SET_MOL_GROUP_SELECTION: prefix + 'SET_MOL_GROUP_SELECTION',
SET_FILTER: prefix + 'SET_FILTER',
SET_SELECTED_ALL: prefix + 'SET_SELECTED_ALL',
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',

RESET_COMPOUNDS_OF_VECTORS: prefix + 'RESET_COMPOUNDS_OF_VECTORS',
UPDATE_VECTOR_COMPOUNDS: prefix + 'UPDATE_VECTOR_COMPOUNDS',
Expand Down
12 changes: 12 additions & 0 deletions js/reducers/selection/selectionReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const INITIAL_STATE = {
mol_group_selection: [],
object_selection: undefined,
filter: undefined,
molecule_all_selection: null,
molecule_all_deselection: null,

compoundsOfVectors: null, // list of all vector's compounds to pick
// compoundsOfVectors: {
Expand Down Expand Up @@ -275,6 +277,16 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
return Object.assign({}, state, {
bondColorMapOfVectors
});

case constants.SET_SELECTED_ALL:
return Object.assign({}, state, {
molecule_all_selection: action.item
});

case constants.SET_DESELECTED_ALL:
return Object.assign({}, state, {
molecule_all_deselection: action.item
});
// Cases like: @@redux/INIT
default:
return state;
Expand Down
7 changes: 5 additions & 2 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const actionType = {
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
UNDO: 'UNDO',
REDO: 'REDO'
REDO: 'REDO',
ALL_TURNED_ON: 'ALL_TURNED_ON',
ALL_TURNED_OFF: 'ALL_TURNED_OFF'
};

export const actionDescription = {
Expand All @@ -58,7 +60,8 @@ export const actionDescription = {
VECTOR: 'Vector',
SURFACE: 'Surface',
SITE: 'Site',
TARGET: 'Target'
TARGET: 'Target',
ALL: 'All'
};

export const actionObjectType = {
Expand Down
Loading

0 comments on commit 0a6e5f7

Please sign in to comment.