Skip to content

Commit 560b23d

Browse files
author
Adriána Kohanová
committed
Merge remote-tracking branch 'remotes/origin/#433' into #455
# Conflicts: # js/components/snapshot/redux/dispatchActions.js # js/reducers/tracking/dispatchActions.js
2 parents d3792b8 + d319bf6 commit 560b23d

File tree

11 files changed

+212
-41
lines changed

11 files changed

+212
-41
lines changed

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

+34-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
updateVectorCompounds,
2020
updateBondColorMapOfCompounds,
2121
resetBondColorMapOfVectors,
22-
setCurrentVector
22+
setCurrentVector,
23+
setHideAll
2324
} from '../../../../reducers/selection/actions';
2425
import { base_url } from '../../../routes/constants';
2526
import {
@@ -115,11 +116,11 @@ const handleVector = (json, stage, data) => (dispatch, getState) => {
115116
dispatch(updateBondColorMapOfCompounds(data.smiles, vectorBondColorMap));
116117
};
117118

118-
export const addVector = (stage, data) => async (dispatch, getState) => {
119+
export const addVector = (stage, data, skipTracking = false) => async (dispatch, getState) => {
119120
const currentVector = getState().selectionReducers.currentVector;
120121

121122
dispatch(incrementCountOfPendingVectorLoadRequests());
122-
dispatch(appendVectorOnList(generateMoleculeId(data)));
123+
dispatch(appendVectorOnList(generateMoleculeId(data), skipTracking));
123124
dispatch(selectVectorAndResetCompounds(currentVector));
124125

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

229-
export const addSurface = (stage, data, colourToggle) => dispatch => {
230+
export const addSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
230231
dispatch(
231232
loadObject({
232233
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
@@ -237,17 +238,17 @@ export const addSurface = (stage, data, colourToggle) => dispatch => {
237238
const currentOrientation = stage.viewerControls.getOrientation();
238239
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
239240
});
240-
dispatch(appendSurfaceList(generateMoleculeId(data)));
241+
dispatch(appendSurfaceList(generateMoleculeId(data), skipTracking));
241242
};
242243

243-
export const removeSurface = (stage, data, colourToggle) => dispatch => {
244+
export const removeSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
244245
dispatch(
245246
deleteObject(
246247
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
247248
stage
248249
)
249250
);
250-
dispatch(removeFromSurfaceList(generateMoleculeId(data)));
251+
dispatch(removeFromSurfaceList(generateMoleculeId(data), skipTracking));
251252
};
252253

253254
export const addDensity = (stage, data, colourToggle) => dispatch => {
@@ -330,39 +331,51 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
330331
const vectorOnList = state.selectionReducers.vectorOnList;
331332
const surfaceList = state.selectionReducers.surfaceList;
332333
const proteinList = state.selectionReducers.proteinList;
334+
const vectorList = state.selectionReducers.vector_list;
335+
336+
let ligandDataList = [];
337+
let complexDataList = [];
338+
let vectorOnDataList = [];
339+
let surfaceDataList = [];
340+
let proteinDataList = [];
333341

334342
fragmentDisplayList.forEach(moleculeId => {
335343
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
336344
if (data) {
337-
dispatch(removeLigand(stage, data));
345+
ligandDataList.push(data);
346+
dispatch(removeLigand(stage, data, true));
338347
}
339348
});
340349
complexList.forEach(moleculeId => {
341350
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
342351
if (data) {
343-
dispatch(removeComplex(stage, data, colourList[0]));
352+
complexDataList.push(data);
353+
dispatch(removeComplex(stage, data, colourList[0], true));
344354
}
345355
});
346356
vectorOnList.forEach(moleculeId => {
347357
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
348358
if (data) {
349-
dispatch(removeVector(stage, data));
359+
vectorOnDataList.push(data);
360+
dispatch(removeVector(stage, data, true));
350361
}
351362
});
352363

353364
// remove Surface
354365
surfaceList.forEach(moleculeId => {
355366
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
356367
if (data) {
357-
dispatch(removeSurface(stage, data));
368+
surfaceDataList.push(data);
369+
dispatch(removeSurface(stage, data, colourList[0], true));
358370
}
359371
});
360372

361373
// remove Protein
362374
proteinList.forEach(moleculeId => {
363375
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
364376
if (data) {
365-
dispatch(removeHitProtein(stage, data));
377+
proteinDataList.push(data);
378+
dispatch(removeHitProtein(stage, data, colourList[0], true));
366379
}
367380
});
368381

@@ -371,6 +384,15 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
371384
dispatch(resetCompoundsOfVectors());
372385
dispatch(resetBondColorMapOfVectors());
373386
dispatch(setCompoundImage(noCompoundImage));
387+
388+
let data = {
389+
ligandList: ligandDataList,
390+
proteinList: proteinDataList,
391+
complexList: complexDataList,
392+
surfaceList: surfaceDataList,
393+
vectorOnList: vectorOnDataList
394+
};
395+
dispatch(setHideAll(data));
374396
};
375397

376398
export const searchMoleculeGroupByMoleculeID = moleculeID => (dispatch, getState) =>

js/components/preview/redux/dispatchActions.js

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export const shouldLoadProtein = ({
4646
const state = getState();
4747
const targetIdList = state.apiReducers.target_id_list;
4848
const targetOnName = state.apiReducers.target_on_name;
49-
const currentSnapshotData = state.projectReducers.currentSnapshot.data;
50-
// const isLoadingCurrentSnapshot = state.projectReducers.isLoadingCurrentSnapshot;
5149
if (
5250
targetIdList &&
5351
targetIdList.length > 0 &&

js/components/snapshot/modals/newSnapshotForm.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo, useState } from 'react';
1+
import React, { memo, useState, useContext } from 'react';
22
import { Grid, makeStyles, Typography } from '@material-ui/core';
33
import { useDispatch, useSelector } from 'react-redux';
44
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
@@ -9,6 +9,8 @@ import { TextField } from 'formik-material-ui';
99
import { Button } from '../../common/Inputs/Button';
1010
import { SnapshotType } from '../../projects/redux/constants';
1111
import { createNewSnapshot } from '../redux/dispatchActions';
12+
import { NglContext } from '../../nglView/nglProvider';
13+
1214
import moment from 'moment';
1315

1416
const useStyles = makeStyles(theme => ({
@@ -33,6 +35,7 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
3335
const classes = useStyles();
3436
const [state, setState] = useState();
3537
const dispatch = useDispatch();
38+
const { nglViewList } = useContext(NglContext);
3639

3740
const currentSnapshot = useSelector(state => state.projectReducers.currentSnapshot);
3841
const currentProject = useSelector(state => state.projectReducers.currentProject);
@@ -70,11 +73,13 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
7073
const parent = isForceProjectCreated === false ? currentSnapshot.id : null;
7174
const session_project = currentProject.projectID;
7275

73-
dispatch(createNewSnapshot({ title, description, type, author, parent, session_project })).catch(error => {
74-
setState(() => {
75-
throw error;
76-
});
77-
});
76+
dispatch(createNewSnapshot({ title, description, type, author, parent, session_project, nglViewList })).catch(
77+
error => {
78+
setState(() => {
79+
throw error;
80+
});
81+
}
82+
);
7883
}}
7984
>
8085
{({ submitForm, isSubmitting }) => (

js/components/snapshot/redux/dispatchActions.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const createInitSnapshotFromCopy = ({
178178
return Promise.reject('ProjectID is missing');
179179
};
180180

181-
export const createNewSnapshot = ({ title, description, type, author, parent, session_project }) => (
181+
export const createNewSnapshot = ({ title, description, type, author, parent, session_project, nglViewList }) => (
182182
dispatch,
183183
getState
184184
) => {
@@ -215,7 +215,7 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
215215
}).then(res => {
216216
// redirect to project with newest created snapshot /:projectID/:snapshotID
217217
if (res.data.id && session_project) {
218-
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project))).then(() => {
218+
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList))).then(() => {
219219
if (disableRedirect === false) {
220220
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
221221
// use react-router !
@@ -284,7 +284,8 @@ export const createNewSnapshotWithoutStateModification = ({
284284
type,
285285
author,
286286
parent,
287-
session_project
287+
session_project,
288+
nglViewList
288289
}) => (dispatch, getState) => {
289290
if (!session_project) {
290291
return Promise.reject('Project ID is missing!');
@@ -320,13 +321,13 @@ export const createNewSnapshotWithoutStateModification = ({
320321
disableRedirect: true
321322
})
322323
);
323-
dispatch(saveCurrentActionsList(res.data.id, session_project));
324+
dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList));
324325
}
325326
});
326327
});
327328
};
328329

329-
export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState) => {
330+
export const saveAndShareSnapshot = nglViewList => (dispatch, getState) => {
330331
const state = getState();
331332
const targetId = state.apiReducers.target_on;
332333
const loggedInUserID = DJANGO_CONTEXT['pk'];
@@ -357,7 +358,15 @@ export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState)
357358
dispatch(sendTrackingActionsByProjectId(projectID, author));
358359

359360
return dispatch(
360-
createNewSnapshotWithoutStateModification({ title, description, type, author, parent, session_project })
361+
createNewSnapshotWithoutStateModification({
362+
title,
363+
description,
364+
type,
365+
author,
366+
parent,
367+
session_project,
368+
nglViewList
369+
})
361370
);
362371
})
363372
.catch(error => {

js/components/snapshot/withSnapshotManagement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const withSnapshotManagement = WrappedComponent => {
7878
startIcon={<Share />}
7979
disabled={disableShareButton || disableUserInteraction}
8080
onClick={() => {
81-
dispatch(saveAndShareSnapshot(target));
81+
dispatch(saveAndShareSnapshot(nglViewList));
8282
}}
8383
>
8484
Share

js/reducers/selection/actions.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,19 @@ export const setSurfaceList = function(surfaceList) {
114114
};
115115
};
116116

117-
export const appendSurfaceList = function(item) {
117+
export const appendSurfaceList = function(item, skipTracking = false) {
118118
return {
119119
type: constants.APPEND_SURFACE_LIST,
120-
item: item
120+
item: item,
121+
skipTracking: skipTracking
121122
};
122123
};
123124

124-
export const removeFromSurfaceList = function(item) {
125+
export const removeFromSurfaceList = function(item, skipTracking = false) {
125126
return {
126127
type: constants.REMOVE_FROM_SURFACE_LIST,
127-
item: item
128+
item: item,
129+
skipTracking: skipTracking
128130
};
129131
};
130132

@@ -156,10 +158,11 @@ export const setVectorOnList = function(vectorOnList) {
156158
};
157159
};
158160

159-
export const appendVectorOnList = function(item) {
161+
export const appendVectorOnList = function(item, skipTracking = false) {
160162
return {
161163
type: constants.APPEND_VECTOR_ON_LIST,
162-
item: item
164+
item: item,
165+
skipTracking: skipTracking
163166
};
164167
};
165168

@@ -253,3 +256,9 @@ export const setDeselectedAllByType = (type, items, isInspiration) => ({
253256
type: constants.SET_DESELECTED_ALL_BY_TYPE,
254257
payload: { type, items, isInspiration }
255258
});
259+
260+
export const setHideAll = (data, isHide = true) => ({
261+
type: constants.SET_HIDE_ALL,
262+
isHide: isHide,
263+
data: data
264+
});

js/reducers/selection/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const constants = {
3636
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',
3737
SET_SELECTED_ALL_BY_TYPE: prefix + 'SET_SELECTED_ALL_BY_TYPE',
3838
SET_DESELECTED_ALL_BY_TYPE: prefix + 'SET_DESELECTED_ALL_BY_TYPE',
39+
SET_HIDE_ALL: prefix + 'SET_HIDE_ALL',
3940

4041
RESET_COMPOUNDS_OF_VECTORS: prefix + 'RESET_COMPOUNDS_OF_VECTORS',
4142
UPDATE_VECTOR_COMPOUNDS: prefix + 'UPDATE_VECTOR_COMPOUNDS',

js/reducers/selection/selectionReducers.js

+4
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
299299
return Object.assign({}, state, {
300300
moleculeAllTypeSelection: action.payload.type
301301
});
302+
303+
case constants.SET_HIDE_ALL:
304+
return state;
305+
302306
// Cases like: @@redux/INIT
303307
default:
304308
return state;

js/reducers/tracking/constants.js

+4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export const actionType = {
4040
REPRESENTATION_CHANGED: 'REPRESENTATION_CHANGED',
4141
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
4242
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
43+
NGL_STATE: 'NGL_STATE',
4344
UNDO: 'UNDO',
4445
REDO: 'REDO',
46+
ALL_HIDE: 'ALL_HIDE',
4547
ALL_TURNED_ON: 'ALL_TURNED_ON',
4648
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
4749
ALL_TURNED_ON_BY_TYPE: 'ALL_TURNED_ON_BY_TYPE',
@@ -54,6 +56,8 @@ export const actionDescription = {
5456
TURNED_OFF: 'was turned off',
5557
SELECTED: 'was selected',
5658
DESELECTED: 'was deselected',
59+
HIDDEN: 'hidden',
60+
CANCELED: 'canceled',
5761
ADDED: 'was added',
5862
REMOVED: 'was removed',
5963
CHANGED: 'was changed',

0 commit comments

Comments
 (0)