Skip to content

Commit ad5aa18

Browse files
author
Adriána Kohanová
committed
#532 Vector-selector view not properly restored
1 parent 926b442 commit ad5aa18

File tree

1 file changed

+141
-107
lines changed

1 file changed

+141
-107
lines changed

js/reducers/tracking/dispatchActions.js

+141-107
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ import {
125125
setInspirationMoleculeDataList
126126
} from '../../components/datasets/redux/actions';
127127
import { selectVectorAndResetCompounds } from '../../../js/reducers/selection/dispatchActions';
128-
import { ActionCreators as UndoActionCreators } from '../../undoredo/actions'
128+
import { ActionCreators as UndoActionCreators } from '../../undoredo/actions';
129129

130130
export const addCurrentActionsListToSnapshot = (snapshot, project, nglViewList) => async (dispatch, getState) => {
131131
let projectID = project && project.projectID;
@@ -148,103 +148,6 @@ export const saveCurrentActionsList = (snapshot, project, nglViewList, all = fal
148148

149149
const saveActionsList = (project, snapshot, actionList, nglViewList) => async (dispatch, getState) => {
150150
const state = getState();
151-
152-
const currentTargetOn = state.apiReducers.target_on;
153-
const currentSites = state.selectionReducers.mol_group_selection;
154-
const currentLigands = state.selectionReducers.fragmentDisplayList;
155-
const currentProteins = state.selectionReducers.proteinList;
156-
const currentComplexes = state.selectionReducers.complexList;
157-
const currentSelectionAll = state.selectionReducers.moleculeAllSelection;
158-
159-
const currentDatasetLigands = state.datasetsReducers.ligandLists;
160-
const currentDatasetProteins = state.datasetsReducers.proteinLists;
161-
const currentDatasetComplexes = state.datasetsReducers.complexLists;
162-
const currentDatasetSelectionAll = state.datasetsReducers.moleculeAllSelection;
163-
164-
const currentTargets = (currentTargetOn && [currentTargetOn]) || [];
165-
166-
let orderedActionList = actionList.reverse((a, b) => a.timestamp - b.timestamp);
167-
168-
let currentActions = [];
169-
170-
getCurrentActionList(orderedActionList, actionType.TARGET_LOADED, getCollection(currentTargets), currentActions);
171-
getCurrentActionList(orderedActionList, actionType.SITE_TURNED_ON, getCollection(currentSites), currentActions);
172-
getCurrentActionList(orderedActionList, actionType.LIGAND_TURNED_ON, getCollection(currentLigands), currentActions);
173-
174-
getCurrentActionListOfAllSelection(
175-
orderedActionList,
176-
actionType.ALL_TURNED_ON,
177-
getCollection(currentSelectionAll),
178-
currentActions,
179-
getCollection(currentLigands),
180-
getCollection(currentProteins),
181-
getCollection(currentComplexes)
182-
);
183-
184-
getCurrentActionListOfAllSelectionByType(
185-
orderedActionList,
186-
actionType.ALL_TURNED_ON_BY_TYPE,
187-
'ligand',
188-
getCollection(currentLigands),
189-
currentActions
190-
);
191-
192-
getCurrentActionListOfAllSelectionByType(
193-
orderedActionList,
194-
actionType.ALL_TURNED_ON_BY_TYPE,
195-
'protein',
196-
getCollection(currentProteins),
197-
currentActions
198-
);
199-
200-
getCurrentActionListOfAllSelectionByType(
201-
orderedActionList,
202-
actionType.ALL_TURNED_ON_BY_TYPE,
203-
'complex',
204-
getCollection(currentComplexes),
205-
currentActions
206-
);
207-
208-
getCurrentActionListOfAllSelectionByTypeOfDataset(
209-
orderedActionList,
210-
actionType.ALL_TURNED_ON_BY_TYPE,
211-
'ligand',
212-
getCollectionOfDataset(currentDatasetLigands),
213-
currentActions
214-
);
215-
216-
getCurrentActionListOfAllSelectionByTypeOfDataset(
217-
orderedActionList,
218-
actionType.ALL_TURNED_ON_BY_TYPE,
219-
'protein',
220-
getCollectionOfDataset(currentDatasetProteins),
221-
currentActions
222-
);
223-
224-
getCurrentActionListOfAllSelectionByTypeOfDataset(
225-
orderedActionList,
226-
actionType.ALL_TURNED_ON_BY_TYPE,
227-
'complex',
228-
getCollectionOfDataset(currentDatasetComplexes),
229-
currentActions
230-
);
231-
232-
getCurrentActionListOfAllSelection(
233-
orderedActionList,
234-
actionType.ALL_TURNED_ON,
235-
getCollectionOfDataset(currentDatasetSelectionAll),
236-
currentActions,
237-
getCollectionOfDataset(currentDatasetLigands),
238-
getCollectionOfDataset(currentDatasetProteins),
239-
getCollectionOfDataset(currentDatasetComplexes)
240-
);
241-
242-
getCurrentActionList(
243-
orderedActionList,
244-
actionType.SIDECHAINS_TURNED_ON,
245-
getCollection(currentProteins),
246-
currentActions
247-
);
248151
const snapshotID = snapshot && snapshot.id;
249152
if (snapshotID) {
250153
const currentTargetOn = state.apiReducers.target_on;
@@ -264,6 +167,7 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d
264167
const currentDatasetSurfaces = state.datasetsReducers.surfaceLists;
265168
const currentDatasetSelectionAll = state.datasetsReducers.moleculeAllSelection;
266169

170+
const showedCompoundList = state.previewReducers.compounds.showedCompoundList;
267171
const currentDatasetBuyList = state.datasetsReducers.compoundsToBuyDatasetMap;
268172
const currentobjectsInView = state.nglReducers.objectsInView;
269173

@@ -278,17 +182,72 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d
278182
getCurrentActionList(orderedActionList, actionType.SITE_TURNED_ON, getCollection(currentSites), currentActions);
279183
getCurrentActionList(orderedActionList, actionType.LIGAND_TURNED_ON, getCollection(currentLigands), currentActions);
280184

281-
getCurrentActionList(
185+
getCurrentActionListOfAllSelection(
282186
orderedActionList,
283187
actionType.ALL_TURNED_ON,
284188
getCollection(currentSelectionAll),
189+
currentActions,
190+
getCollection(currentLigands),
191+
getCollection(currentProteins),
192+
getCollection(currentComplexes)
193+
);
194+
195+
getCurrentActionListOfAllSelectionByType(
196+
orderedActionList,
197+
actionType.ALL_TURNED_ON_BY_TYPE,
198+
'ligand',
199+
getCollection(currentLigands),
285200
currentActions
286201
);
287-
getCurrentActionList(
202+
203+
getCurrentActionListOfAllSelectionByType(
204+
orderedActionList,
205+
actionType.ALL_TURNED_ON_BY_TYPE,
206+
'protein',
207+
getCollection(currentProteins),
208+
currentActions
209+
);
210+
211+
getCurrentActionListOfAllSelectionByType(
212+
orderedActionList,
213+
actionType.ALL_TURNED_ON_BY_TYPE,
214+
'complex',
215+
getCollection(currentComplexes),
216+
currentActions
217+
);
218+
219+
getCurrentActionListOfAllSelectionByTypeOfDataset(
220+
orderedActionList,
221+
actionType.ALL_TURNED_ON_BY_TYPE,
222+
'ligand',
223+
getCollectionOfDataset(currentDatasetLigands),
224+
currentActions
225+
);
226+
227+
getCurrentActionListOfAllSelectionByTypeOfDataset(
228+
orderedActionList,
229+
actionType.ALL_TURNED_ON_BY_TYPE,
230+
'protein',
231+
getCollectionOfDataset(currentDatasetProteins),
232+
currentActions
233+
);
234+
235+
getCurrentActionListOfAllSelectionByTypeOfDataset(
236+
orderedActionList,
237+
actionType.ALL_TURNED_ON_BY_TYPE,
238+
'complex',
239+
getCollectionOfDataset(currentDatasetComplexes),
240+
currentActions
241+
);
242+
243+
getCurrentActionListOfAllSelection(
288244
orderedActionList,
289245
actionType.ALL_TURNED_ON,
290246
getCollectionOfDataset(currentDatasetSelectionAll),
291-
currentActions
247+
currentActions,
248+
getCollectionOfDataset(currentDatasetLigands),
249+
getCollectionOfDataset(currentDatasetProteins),
250+
getCollectionOfDataset(currentDatasetComplexes)
292251
);
293252

294253
getCurrentActionList(
@@ -323,13 +282,27 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d
323282
currentActions
324283
);
325284

285+
getCurrentActionList(
286+
orderedActionList,
287+
actionType.VECTOR_COUMPOUND_ADDED,
288+
getCollection(showedCompoundList),
289+
currentActions
290+
);
291+
326292
getCurrentActionList(
327293
orderedActionList,
328294
actionType.MOLECULE_ADDED_TO_SHOPPING_CART,
329295
getCollectionOfShoppingCart(currentBuyList),
330296
currentActions
331297
);
332298

299+
getCurrentActionListOfAllShopingCart(
300+
orderedActionList,
301+
actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL,
302+
getCollectionOfShoppingCart(currentBuyList),
303+
currentActions
304+
);
305+
333306
getCurrentActionList(
334307
orderedActionList,
335308
actionType.LIGAND_TURNED_ON,
@@ -379,6 +352,9 @@ const saveActionsList = (project, snapshot, actionList, nglViewList) => async (d
379352
currentActions
380353
);
381354

355+
getCommonLastActionByType(orderedActionList, actionType.CLASS_SELECTED, currentActions);
356+
getCommonLastActionByType(orderedActionList, actionType.CLASS_UPDATED, currentActions);
357+
382358
if (nglViewList) {
383359
let nglStateList = nglViewList.map(nglView => {
384360
return { id: nglView.id, orientation: nglView.stage.viewerControls.getOrientation() };
@@ -488,6 +464,13 @@ const getCurrentActionList = (orderedActionList, type, collection, currentAction
488464
}
489465
};
490466

467+
const getCommonLastActionByType = (orderedActionList, type, currentActions) => {
468+
let action = orderedActionList.find(action => action.type === type);
469+
if (action) {
470+
currentActions.push(Object.assign({ ...action }));
471+
}
472+
};
473+
491474
const getCurrentActionListOfAllSelection = (
492475
orderedActionList,
493476
type,
@@ -573,6 +556,22 @@ const getCurrentActionListOfAllSelectionByTypeOfDataset = (
573556
}
574557
};
575558

559+
const getCurrentActionListOfAllShopingCart = (orderedActionList, type, collection, currentActions) => {
560+
let action = orderedActionList.find(action => action.type === type);
561+
if (action && collection) {
562+
let actionItems = action.items;
563+
let items = [];
564+
collection.forEach(data => {
565+
let item = actionItems.find(action => action.id === data.id && action.dataset_id === data.datasetId);
566+
if (item) {
567+
items.push(item);
568+
}
569+
});
570+
571+
currentActions.push(Object.assign({ ...action, items: items }));
572+
}
573+
};
574+
576575
const getCollection = dataList => {
577576
let list = [];
578577
if (dataList) {
@@ -887,27 +886,62 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
887886

888887
let vectorAction = orderedActionList.find(action => action.type === actionType.VECTOR_SELECTED);
889888
if (vectorAction) {
890-
dispatch(setCurrentVector(vectorAction.object_name));
889+
dispatch(selectVectorAndResetCompounds(vectorAction.object_name));
891890
}
892891

893-
dispatch(restoreCartActions(moleculesAction));
892+
dispatch(restoreCartActions(moleculesAction, stage));
894893
dispatch(restoreAllSelectionActions(orderedActionList, stage, true));
895894
dispatch(restoreAllSelectionByTypeActions(orderedActionList, stage, true));
896895
dispatch(setIsTrackingMoleculesRestoring(false));
897896
};
898897

899-
const restoreCartActions = moleculesAction => (dispatch, getState) => {
898+
const restoreCartActions = (moleculesAction, majorViewStage) => (dispatch, getState) => {
899+
let shoppingCartAllaction = moleculesAction.find(
900+
action => action.type === actionType.MOLECULE_ADDED_TO_SHOPPING_CART_ALL
901+
);
902+
if (shoppingCartAllaction) {
903+
dispatch(
904+
handleBuyListAll({ isSelected: true, items: shoppingCartAllaction.items, majorViewStage: majorViewStage })
905+
);
906+
}
907+
900908
let shoppingCartActions = moleculesAction.filter(
901909
action => action.type === actionType.MOLECULE_ADDED_TO_SHOPPING_CART
902910
);
903911
if (shoppingCartActions) {
904912
shoppingCartActions.forEach(action => {
905913
let data = action.item;
914+
let compoundId = action.compoundId;
915+
906916
if (data) {
907-
dispatch(appendToBuyList(data));
917+
dispatch(handleBuyList({ isSelected: true, data, compoundId }));
908918
}
909919
});
910920
}
921+
922+
let classSelectedAction = moleculesAction.find(action => action.type === actionType.CLASS_SELECTED);
923+
if (classSelectedAction) {
924+
dispatch(setCurrentCompoundClass(classSelectedAction.value, classSelectedAction.oldValue));
925+
}
926+
927+
let classUpdatedAction = moleculesAction.find(action => action.type === actionType.CLASS_UPDATED);
928+
if (classUpdatedAction) {
929+
let id = classUpdatedAction.object_id;
930+
let newValue = classUpdatedAction.newCompoundClasses;
931+
let oldValue = classUpdatedAction.oldCompoundClasses;
932+
let value = classUpdatedAction.object_name;
933+
value = value !== undefined ? value : '';
934+
dispatch(setCompoundClasses(newValue, oldValue, value, id));
935+
}
936+
937+
let vectorCompoundActions = moleculesAction.filter(action => action.type === actionType.VECTOR_COUMPOUND_ADDED);
938+
if (vectorCompoundActions) {
939+
vectorCompoundActions.forEach(action => {
940+
let data = action.item;
941+
let compoundId = action.compoundId;
942+
dispatch(handleShowVectorCompound({ isSelected: true, data, index: compoundId, majorViewStage: majorViewStage }));
943+
});
944+
}
911945
};
912946

913947
const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dispatch, getState) => {
@@ -2271,9 +2305,9 @@ export const mergeActions = (trackAction, list) => {
22712305
} else {
22722306
newList.push(trackAction);
22732307
}
2274-
return {merged: merged, list: newList};
2308+
return { merged: merged, list: newList };
22752309
} else {
2276-
return {merged: merged, list: [...list, trackAction]};
2310+
return { merged: merged, list: [...list, trackAction] };
22772311
}
22782312
// return {merged: merged, list: [...list, trackAction]};
22792313
};

0 commit comments

Comments
 (0)