Skip to content

Commit 0a6e5f7

Browse files
author
Adriána Kohanová
committed
#462 Mass actions
1 parent 39da154 commit 0a6e5f7

File tree

8 files changed

+165
-53
lines changed

8 files changed

+165
-53
lines changed

js/components/preview/molecule/moleculeView.js

+29-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
removeLigand,
2828
searchMoleculeGroupByMoleculeID
2929
} from './redux/dispatchActions';
30+
import { setSelectedAll, setDeselectedAll } from '../../../reducers/selection/actions';
3031
import { base_url } from '../../routes/constants';
3132
import { moleculeProperty } from './helperConstants';
3233
import { centerOnLigandByMoleculeID } from '../../../reducers/ngl/dispatchActions';
@@ -344,25 +345,25 @@ const MoleculeView = memo(
344345
const current_style =
345346
isLigandOn || isProteinOn || isComplexOn || isSurfaceOn || isVectorOn ? selected_style : not_selected_style;
346347

347-
const addNewLigand = () => {
348+
const addNewLigand = (skipTracking = false) => {
348349
if (selectMoleculeSite) {
349350
selectMoleculeSite(data.site);
350351
}
351-
dispatch(addLigand(stage, data, colourToggle));
352+
dispatch(addLigand(stage, data, colourToggle, false, skipTracking));
352353
};
353354

354-
const removeSelectedLigand = () => {
355-
dispatch(removeLigand(stage, data));
355+
const removeSelectedLigand = (skipTracking = false) => {
356+
dispatch(removeLigand(stage, data, skipTracking));
356357
selectedAll.current = false;
357358
};
358359

359360
const onLigand = calledFromSelectAll => {
360361
if (calledFromSelectAll === true && selectedAll.current === true) {
361362
if (isLigandOn === false) {
362-
addNewLigand();
363+
addNewLigand(calledFromSelectAll);
363364
}
364365
} else if (calledFromSelectAll && selectedAll.current === false) {
365-
removeSelectedLigand();
366+
removeSelectedLigand(calledFromSelectAll);
366367
} else if (!calledFromSelectAll) {
367368
if (isLigandOn === false) {
368369
addNewLigand();
@@ -372,25 +373,25 @@ const MoleculeView = memo(
372373
}
373374
};
374375

375-
const removeSelectedProtein = () => {
376-
dispatch(removeHitProtein(stage, data, colourToggle));
376+
const removeSelectedProtein = (skipTracking = false) => {
377+
dispatch(removeHitProtein(stage, data, colourToggle, skipTracking));
377378
selectedAll.current = false;
378379
};
379380

380-
const addNewProtein = () => {
381+
const addNewProtein = (skipTracking = false) => {
381382
if (selectMoleculeSite) {
382383
selectMoleculeSite(data.site);
383384
}
384-
dispatch(addHitProtein(stage, data, colourToggle));
385+
dispatch(addHitProtein(stage, data, colourToggle, skipTracking));
385386
};
386387

387388
const onProtein = calledFromSelectAll => {
388389
if (calledFromSelectAll === true && selectedAll.current === true) {
389390
if (isProteinOn === false) {
390-
addNewProtein();
391+
addNewProtein(calledFromSelectAll);
391392
}
392393
} else if (calledFromSelectAll && selectedAll.current === false) {
393-
removeSelectedProtein();
394+
removeSelectedProtein(calledFromSelectAll);
394395
} else if (!calledFromSelectAll) {
395396
if (isProteinOn === false) {
396397
addNewProtein();
@@ -400,25 +401,25 @@ const MoleculeView = memo(
400401
}
401402
};
402403

403-
const removeSelectedComplex = () => {
404-
dispatch(removeComplex(stage, data, colourToggle));
404+
const removeSelectedComplex = (skipTracking = false) => {
405+
dispatch(removeComplex(stage, data, colourToggle, skipTracking));
405406
selectedAll.current = false;
406407
};
407408

408-
const addNewComplex = () => {
409+
const addNewComplex = (skipTracking = false) => {
409410
if (selectMoleculeSite) {
410411
selectMoleculeSite(data.site);
411412
}
412-
dispatch(addComplex(stage, data, colourToggle));
413+
dispatch(addComplex(stage, data, colourToggle, skipTracking));
413414
};
414415

415416
const onComplex = calledFromSelectAll => {
416417
if (calledFromSelectAll === true && selectedAll.current === true) {
417418
if (isComplexOn === false) {
418-
addNewComplex();
419+
addNewComplex(calledFromSelectAll);
419420
}
420421
} else if (calledFromSelectAll && selectedAll.current === false) {
421-
removeSelectedComplex();
422+
removeSelectedComplex(calledFromSelectAll);
422423
} else if (!calledFromSelectAll) {
423424
if (isComplexOn === false) {
424425
addNewComplex();
@@ -487,6 +488,15 @@ const MoleculeView = memo(
487488
}
488489
};
489490

491+
const setCalledFromAll = () => {
492+
let isSelected = selectedAll.current === true;
493+
if (isSelected) {
494+
dispatch(setSelectedAll(data));
495+
} else {
496+
dispatch(setDeselectedAll(data));
497+
}
498+
};
499+
490500
/**
491501
* Check if given molecule is matching current filter
492502
* @param Object item - item.name is attribute name, item.value is its value
@@ -610,6 +620,7 @@ const MoleculeView = memo(
610620
// always deselect all if are selected only some of options
611621
selectedAll.current = hasSomeValuesOn ? false : !selectedAll.current;
612622

623+
setCalledFromAll();
613624
onLigand(true);
614625
onProtein(true);
615626
onComplex(true);

js/components/preview/molecule/redux/dispatchActions.js

+23-16
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const removeCurrentVector = currentMoleculeSmile => (dispatch, getState)
162162
}
163163
};
164164

165-
export const removeVector = (stage, data) => async (dispatch, getState) => {
165+
export const removeVector = (stage, data, skipTracking = false) => async (dispatch, getState) => {
166166
const state = getState();
167167
const vector_list = state.selectionReducers.vector_list;
168168
vector_list
@@ -173,12 +173,12 @@ export const removeVector = (stage, data) => async (dispatch, getState) => {
173173

174174
dispatch(updateVectorCompounds(data.smiles, undefined));
175175
dispatch(updateBondColorMapOfCompounds(data.smiles, undefined));
176-
dispatch(removeFromVectorOnList(generateMoleculeId(data)));
176+
dispatch(removeFromVectorOnList(generateMoleculeId(data), skipTracking));
177177

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

181-
export const addHitProtein = (stage, data, colourToggle) => dispatch => {
181+
export const addHitProtein = (stage, data, colourToggle, skipTracking = false) => dispatch => {
182182
dispatch(
183183
loadObject({
184184
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateHitProteinObject(data, colourToggle, base_url)),
@@ -189,20 +189,20 @@ export const addHitProtein = (stage, data, colourToggle) => dispatch => {
189189
const currentOrientation = stage.viewerControls.getOrientation();
190190
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
191191
});
192-
dispatch(appendProteinList(generateMoleculeId(data)));
192+
dispatch(appendProteinList(generateMoleculeId(data), skipTracking));
193193
};
194194

195-
export const removeHitProtein = (stage, data, colourToggle) => dispatch => {
195+
export const removeHitProtein = (stage, data, colourToggle, skipTracking = false) => dispatch => {
196196
dispatch(
197197
deleteObject(
198198
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateHitProteinObject(data, colourToggle, base_url)),
199199
stage
200200
)
201201
);
202-
dispatch(removeFromProteinList(generateMoleculeId(data)));
202+
dispatch(removeFromProteinList(generateMoleculeId(data), skipTracking));
203203
};
204204

205-
export const addComplex = (stage, data, colourToggle) => dispatch => {
205+
export const addComplex = (stage, data, colourToggle, skipTracking = false) => dispatch => {
206206
dispatch(
207207
loadObject({
208208
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateComplexObject(data, colourToggle, base_url)),
@@ -213,17 +213,17 @@ export const addComplex = (stage, data, colourToggle) => dispatch => {
213213
const currentOrientation = stage.viewerControls.getOrientation();
214214
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
215215
});
216-
dispatch(appendComplexList(generateMoleculeId(data)));
216+
dispatch(appendComplexList(generateMoleculeId(data), skipTracking));
217217
};
218218

219-
export const removeComplex = (stage, data, colourToggle) => dispatch => {
219+
export const removeComplex = (stage, data, colourToggle, skipTracking = false) => dispatch => {
220220
dispatch(
221221
deleteObject(
222222
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateComplexObject(data, colourToggle, base_url)),
223223
stage
224224
)
225225
);
226-
dispatch(removeFromComplexList(generateMoleculeId(data)));
226+
dispatch(removeFromComplexList(generateMoleculeId(data), skipTracking));
227227
};
228228

229229
export const addSurface = (stage, data, colourToggle) => dispatch => {
@@ -278,9 +278,12 @@ export const removeDensity = (stage, data, colourToggle) => dispatch => {
278278
dispatch(removeFromDensityList(generateMoleculeId(data)));
279279
};
280280

281-
export const addLigand = (stage, data, colourToggle, centerOn = false) => (dispatch, getState) => {
281+
export const addLigand = (stage, data, colourToggle, centerOn = false, skipTracking = false) => (
282+
dispatch,
283+
getState
284+
) => {
282285
const currentOrientation = stage.viewerControls.getOrientation();
283-
dispatch(appendFragmentDisplayList(generateMoleculeId(data)));
286+
dispatch(appendFragmentDisplayList(generateMoleculeId(data), skipTracking));
284287
return dispatch(
285288
loadObject({
286289
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateMoleculeObject(data, colourToggle)),
@@ -299,12 +302,12 @@ export const addLigand = (stage, data, colourToggle, centerOn = false) => (dispa
299302
});
300303
};
301304

302-
export const removeLigand = (stage, data) => dispatch => {
305+
export const removeLigand = (stage, data, skipTracking = false) => dispatch => {
303306
dispatch(deleteObject(Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateMoleculeObject(data)), stage));
304-
dispatch(removeFromFragmentDisplayList(generateMoleculeId(data)));
307+
dispatch(removeFromFragmentDisplayList(generateMoleculeId(data), skipTracking));
305308

306309
// remove vector
307-
dispatch(removeVector(stage, data));
310+
dispatch(removeVector(stage, data, skipTracking));
308311
};
309312

310313
/**
@@ -412,7 +415,11 @@ export const applyDirectSelection = (stage, stageSummaryView) => (dispatch, getS
412415
for (let molIndex = 0; molIndex < molCount; molIndex++) {
413416
let mol = molList[molIndex];
414417
let proteinCodeModded = mol.protein_code.toLowerCase();
415-
if (m.exact ? proteinCodeModded === directProteinCodeModded : proteinCodeModded.includes(directProteinNameModded)) {
418+
if (
419+
m.exact
420+
? proteinCodeModded === directProteinCodeModded
421+
: proteinCodeModded.includes(directProteinNameModded)
422+
) {
416423
let molGroupId = groupId;
417424
// Has to be declared here because otherwise we read stale value
418425
const mol_group_selection = getState().selectionReducers.mol_group_selection;

js/reducers/selection/actions.js

+31-14
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ export const setFragmentDisplayList = function(fragmentDisplayList) {
4646
};
4747
};
4848

49-
export const appendFragmentDisplayList = function(item) {
49+
export const appendFragmentDisplayList = function(item, skipTracking = false) {
5050
return {
5151
type: constants.APPEND_FRAGMENT_DISPLAY_LIST,
52-
item: item
52+
item: item,
53+
skipTracking: skipTracking
5354
};
5455
};
5556

56-
export const removeFromFragmentDisplayList = function(item) {
57+
export const removeFromFragmentDisplayList = function(item, skipTracking = false) {
5758
return {
5859
type: constants.REMOVE_FROM_FRAGMENT_DISPLAY_LIST,
59-
item: item
60+
item: item,
61+
skipTracking: skipTracking
6062
};
6163
};
6264

@@ -67,17 +69,19 @@ export const setProteinList = function(proteinList) {
6769
};
6870
};
6971

70-
export const appendProteinList = function(item) {
72+
export const appendProteinList = function(item, skipTracking = false) {
7173
return {
7274
type: constants.APPEND_PROTEIN_LIST,
73-
item: item
75+
item: item,
76+
skipTracking: skipTracking
7477
};
7578
};
7679

77-
export const removeFromProteinList = function(item) {
80+
export const removeFromProteinList = function(item, skipTracking = false) {
7881
return {
7982
type: constants.REMOVE_FROM_PROTEIN_LIST,
80-
item: item
83+
item: item,
84+
skipTracking: skipTracking
8185
};
8286
};
8387
export const setComplexList = function(complexList) {
@@ -87,17 +91,19 @@ export const setComplexList = function(complexList) {
8791
};
8892
};
8993

90-
export const appendComplexList = function(item) {
94+
export const appendComplexList = function(item, skipTracking = false) {
9195
return {
9296
type: constants.APPEND_COMPLEX_LIST,
93-
item: item
97+
item: item,
98+
skipTracking: skipTracking
9499
};
95100
};
96101

97-
export const removeFromComplexList = function(item) {
102+
export const removeFromComplexList = function(item, skipTracking = false) {
98103
return {
99104
type: constants.REMOVE_FROM_COMPLEX_LIST,
100-
item: item
105+
item: item,
106+
skipTracking: skipTracking
101107
};
102108
};
103109

@@ -157,10 +163,11 @@ export const appendVectorOnList = function(item) {
157163
};
158164
};
159165

160-
export const removeFromVectorOnList = function(item) {
166+
export const removeFromVectorOnList = function(item, skipTracking = false) {
161167
return {
162168
type: constants.REMOVE_FROM_VECTOR_ON_LIST,
163-
item: item
169+
item: item,
170+
skipTracking: skipTracking
164171
};
165172
};
166173

@@ -220,3 +227,13 @@ export const updateBondColorMapOfCompounds = (key, value) => ({
220227
type: constants.UPDATE_BOND_COLOR_MAP_OF_COMPOUNDS,
221228
payload: { key, value }
222229
});
230+
231+
export const setSelectedAll = item => ({
232+
type: constants.SET_SELECTED_ALL,
233+
item: item
234+
});
235+
236+
export const setDeselectedAll = item => ({
237+
type: constants.SET_DESELECTED_ALL,
238+
item: item
239+
});

js/reducers/selection/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const constants = {
3232
RESET_SELECTION_STATE: prefix + 'RESET_SELECTION_STATE',
3333
SET_MOL_GROUP_SELECTION: prefix + 'SET_MOL_GROUP_SELECTION',
3434
SET_FILTER: prefix + 'SET_FILTER',
35+
SET_SELECTED_ALL: prefix + 'SET_SELECTED_ALL',
36+
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',
3537

3638
RESET_COMPOUNDS_OF_VECTORS: prefix + 'RESET_COMPOUNDS_OF_VECTORS',
3739
UPDATE_VECTOR_COMPOUNDS: prefix + 'UPDATE_VECTOR_COMPOUNDS',

js/reducers/selection/selectionReducers.js

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const INITIAL_STATE = {
1616
mol_group_selection: [],
1717
object_selection: undefined,
1818
filter: undefined,
19+
molecule_all_selection: null,
20+
molecule_all_deselection: null,
1921

2022
compoundsOfVectors: null, // list of all vector's compounds to pick
2123
// compoundsOfVectors: {
@@ -275,6 +277,16 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
275277
return Object.assign({}, state, {
276278
bondColorMapOfVectors
277279
});
280+
281+
case constants.SET_SELECTED_ALL:
282+
return Object.assign({}, state, {
283+
molecule_all_selection: action.item
284+
});
285+
286+
case constants.SET_DESELECTED_ALL:
287+
return Object.assign({}, state, {
288+
molecule_all_deselection: action.item
289+
});
278290
// Cases like: @@redux/INIT
279291
default:
280292
return state;

js/reducers/tracking/constants.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export const actionType = {
3838
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
3939
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
4040
UNDO: 'UNDO',
41-
REDO: 'REDO'
41+
REDO: 'REDO',
42+
ALL_TURNED_ON: 'ALL_TURNED_ON',
43+
ALL_TURNED_OFF: 'ALL_TURNED_OFF'
4244
};
4345

4446
export const actionDescription = {
@@ -58,7 +60,8 @@ export const actionDescription = {
5860
VECTOR: 'Vector',
5961
SURFACE: 'Surface',
6062
SITE: 'Site',
61-
TARGET: 'Target'
63+
TARGET: 'Target',
64+
ALL: 'All'
6265
};
6366

6467
export const actionObjectType = {

0 commit comments

Comments
 (0)