Skip to content

Commit 56aabcb

Browse files
Merge remote-tracking branch 'remotes/origin/#455' into allfunctionality
2 parents ff48631 + 653e165 commit 56aabcb

File tree

2 files changed

+258
-24
lines changed

2 files changed

+258
-24
lines changed

js/components/helpers/useEnableUserInteracion.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export const useDisableUserInteraction = () => {
1212
const countOfPendingNglObjects = useSelector(state => state.nglReducers.countOfPendingNglObjects);
1313
const isLoadingTree = useSelector(state => state.projectReducers.isLoadingTree);
1414
const isLoadingCurrentSnapshot = useSelector(state => state.projectReducers.isLoadingCurrentSnapshot);
15+
const isRestoring = useSelector(state => state.trackingReducers.isActionRestoring);
1516

1617
useEffect(() => {
1718
if (
19+
isRestoring === false &&
1820
isLoadingTree === false &&
1921
isLoadingCurrentSnapshot === false &&
2022
countOfPendingVectorLoadRequests === 0 &&
@@ -39,6 +41,7 @@ export const useDisableUserInteraction = () => {
3941
disableInteraction,
4042
isLoadingCurrentSnapshot,
4143
isLoadingTree,
44+
isRestoring,
4245
proteinsHasLoaded
4346
]);
4447

js/reducers/tracking/dispatchActions.js

+255-24
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,74 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
127127
getCurrentActionList(orderedActionList, actionType.SITE_TURNED_ON, getCollection(currentSites), currentActions);
128128
getCurrentActionList(orderedActionList, actionType.LIGAND_TURNED_ON, getCollection(currentLigands), currentActions);
129129

130-
getCurrentActionList(orderedActionList, actionType.ALL_TURNED_ON, getCollection(currentSelectionAll), currentActions);
131-
getCurrentActionList(
130+
getCurrentActionListOfAllSelection(
132131
orderedActionList,
133132
actionType.ALL_TURNED_ON,
134-
getCollectionOfDataset(currentDatasetSelectionAll),
133+
getCollection(currentSelectionAll),
134+
currentActions,
135+
getCollection(currentLigands),
136+
getCollection(currentProteins),
137+
getCollection(currentComplexes)
138+
);
139+
140+
getCurrentActionListOfAllSelectionByType(
141+
orderedActionList,
142+
actionType.ALL_TURNED_ON_BY_TYPE,
143+
'ligand',
144+
getCollection(currentLigands),
145+
currentActions
146+
);
147+
148+
getCurrentActionListOfAllSelectionByType(
149+
orderedActionList,
150+
actionType.ALL_TURNED_ON_BY_TYPE,
151+
'protein',
152+
getCollection(currentProteins),
153+
currentActions
154+
);
155+
156+
getCurrentActionListOfAllSelectionByType(
157+
orderedActionList,
158+
actionType.ALL_TURNED_ON_BY_TYPE,
159+
'complex',
160+
getCollection(currentComplexes),
161+
currentActions
162+
);
163+
164+
getCurrentActionListOfAllSelectionByTypeOfDataset(
165+
orderedActionList,
166+
actionType.ALL_TURNED_ON_BY_TYPE,
167+
'ligand',
168+
getCollectionOfDataset(currentDatasetLigands),
169+
currentActions
170+
);
171+
172+
getCurrentActionListOfAllSelectionByTypeOfDataset(
173+
orderedActionList,
174+
actionType.ALL_TURNED_ON_BY_TYPE,
175+
'protein',
176+
getCollectionOfDataset(currentDatasetProteins),
177+
currentActions
178+
);
179+
180+
getCurrentActionListOfAllSelectionByTypeOfDataset(
181+
orderedActionList,
182+
actionType.ALL_TURNED_ON_BY_TYPE,
183+
'complex',
184+
getCollectionOfDataset(currentDatasetComplexes),
135185
currentActions
136186
);
137187

188+
getCurrentActionListOfAllSelection(
189+
orderedActionList,
190+
actionType.ALL_TURNED_ON,
191+
getCollectionOfDataset(currentDatasetSelectionAll),
192+
currentActions,
193+
getCollectionOfDataset(currentDatasetLigands),
194+
getCollectionOfDataset(currentDatasetProteins),
195+
getCollectionOfDataset(currentDatasetComplexes)
196+
);
197+
138198
getCurrentActionList(
139199
orderedActionList,
140200
actionType.SIDECHAINS_TURNED_ON,
@@ -279,6 +339,91 @@ const getCurrentActionList = (orderedActionList, type, collection, currentAction
279339
}
280340
};
281341

342+
const getCurrentActionListOfAllSelection = (
343+
orderedActionList,
344+
type,
345+
collection,
346+
currentActions,
347+
ligandList,
348+
proteinList,
349+
complexList
350+
) => {
351+
let actionList = orderedActionList.filter(action => action.type === type);
352+
353+
if (collection) {
354+
collection.forEach(data => {
355+
let action = actionList.find(action => action.object_id === data.id && action.dataset_id === data.datasetId);
356+
357+
if (action) {
358+
let ligandAction = ligandList.find(
359+
data => data.id === action.object_id && action.dataset_id === data.datasetId
360+
);
361+
let proteinAction = proteinList.find(
362+
data => data.id === action.object_id && action.dataset_id === data.datasetId
363+
);
364+
let complexAction = complexList.find(
365+
data => data.id === action.object_id && action.dataset_id === data.datasetId
366+
);
367+
368+
let isLigand = ligandAction && ligandAction != null ? true : false;
369+
let isProtein = proteinAction && proteinAction != null ? true : false;
370+
let isComplex = complexAction && complexAction != null ? true : false;
371+
currentActions.push(
372+
Object.assign({ ...action, isLigand: isLigand, isProtein: isProtein, isComplex: isComplex })
373+
);
374+
}
375+
});
376+
}
377+
};
378+
379+
const getCurrentActionListOfAllSelectionByType = (orderedActionList, type, controlType, collection, currentActions) => {
380+
let action = orderedActionList.find(
381+
action =>
382+
action.type === type &&
383+
action.control_type === controlType &&
384+
(action.object_type === actionObjectType.MOLECULE || action.object_type === actionObjectType.INSPIRATION)
385+
);
386+
if (action && collection) {
387+
let actionItems = action.items;
388+
let items = [];
389+
collection.forEach(data => {
390+
let item = actionItems.find(action => action.id === data.id && action.dataset_id === data.datasetId);
391+
if (item) {
392+
items.push(item);
393+
}
394+
});
395+
396+
currentActions.push(Object.assign({ ...action, items: items }));
397+
}
398+
};
399+
400+
const getCurrentActionListOfAllSelectionByTypeOfDataset = (
401+
orderedActionList,
402+
type,
403+
controlType,
404+
collection,
405+
currentActions
406+
) => {
407+
let action = orderedActionList.find(
408+
action =>
409+
action.type === type &&
410+
action.control_type === controlType &&
411+
(action.object_type === actionObjectType.COMPOUND || action.object_type === actionObjectType.CROSS_REFERENCE)
412+
);
413+
if (action && collection) {
414+
let actionItems = action.items;
415+
let items = [];
416+
collection.forEach(data => {
417+
let item = actionItems.find(item => item.molecule.id === data.id && item.datasetID === data.datasetId);
418+
if (item) {
419+
items.push(item);
420+
}
421+
});
422+
423+
currentActions.push(Object.assign({ ...action, items: items }));
424+
}
425+
};
426+
282427
const getCollection = dataList => {
283428
let list = [];
284429
if (dataList) {
@@ -429,11 +574,11 @@ export const restoreAfterTargetActions = (stages, projectId) => async (dispatch,
429574
.finally(() => {});
430575

431576
await dispatch(restoreSitesActions(orderedActionList, summaryView));
432-
await dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage));
433-
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
577+
await dispatch(loadData(orderedActionList, targetId, majorView));
578+
await dispatch(restoreActions(orderedActionList, majorView.stage));
434579
await dispatch(restoreRepresentationActions(orderedActionList, stages));
435580
await dispatch(restoreProject(projectId));
436-
dispatch(restoreNglStateAction(orderedActionList, stages));
581+
await dispatch(restoreNglStateAction(orderedActionList, stages));
437582
dispatch(setIsActionsRestoring(false, true));
438583
}
439584
};
@@ -451,21 +596,23 @@ const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState
451596
}
452597
};
453598

599+
const restoreActions = (orderedActionList, stage) => (dispatch, getState) => {
600+
dispatch(restoreMoleculesActions(orderedActionList, stage));
601+
};
602+
603+
const loadData = (orderedActionList, targetId, majorView) => async (dispatch, getState) => {
604+
await dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage));
605+
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
606+
};
607+
454608
const loadAllDatasets = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
455609
dispatch(setMoleculeListIsLoading(true));
456-
await dispatch(loadDataSets(target_on))
457-
.then(results => {
458-
return dispatch(loadDatasetCompoundsWithScores());
459-
})
460-
.catch(error => {
461-
throw new Error(error);
462-
})
463-
.finally(() => {
464-
dispatch(restoreCompoundsActions(orderedActionList, stage));
465-
dispatch(setMoleculeListIsLoading(false));
466-
dispatch(restoreAllSelectionActions(orderedActionList, stage, false));
467-
dispatch(setIsTrackingCompoundsRestoring(false));
468-
});
610+
611+
await dispatch(loadDataSets(target_on));
612+
await dispatch(loadDatasetCompoundsWithScores());
613+
dispatch(setMoleculeListIsLoading(false));
614+
615+
dispatch(restoreCompoundsActions(orderedActionList, stage));
469616
};
470617

471618
const loadAllMolecules = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
@@ -492,8 +639,6 @@ const loadAllMolecules = (orderedActionList, target_on, stage) => async (dispatc
492639
listToSet[molResult.mol_group] = molResult.molecules;
493640
});
494641
dispatch(setAllMolLists(listToSet));
495-
dispatch(restoreMoleculesActions(orderedActionList, stage));
496-
dispatch(setIsTrackingMoleculesRestoring(false));
497642
} catch (error) {
498643
throw new Error(error);
499644
}
@@ -534,6 +679,8 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
534679

535680
dispatch(restoreCartActions(moleculesAction));
536681
dispatch(restoreAllSelectionActions(orderedActionList, stage, true));
682+
dispatch(restoreAllSelectionByTypeActions(orderedActionList, stage, true));
683+
dispatch(setIsTrackingMoleculesRestoring(false));
537684
};
538685

539686
const restoreCartActions = moleculesAction => (dispatch, getState) => {
@@ -570,6 +717,14 @@ const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dis
570717
if (actions) {
571718
actions.forEach(action => {
572719
if (action) {
720+
if (isSelection) {
721+
dispatch(setSelectedAll(action.item, action.isLigand, action.isProtein, action.isComplex));
722+
} else {
723+
dispatch(
724+
setSelectedAllOfDataset(action.dataset_id, action.item, action.isLigand, action.isProtein, action.isComplex)
725+
);
726+
}
727+
573728
if (action.isLigand) {
574729
dispatch(handleMoleculeAction(action, 'ligand', true, stage, state, true));
575730
}
@@ -586,6 +741,70 @@ const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dis
586741
}
587742
};
588743

744+
const restoreAllSelectionByTypeActions = (moleculesAction, stage, isSelection) => (dispatch, getState) => {
745+
let state = getState();
746+
747+
let actions =
748+
isSelection === true
749+
? moleculesAction.filter(
750+
action =>
751+
action.type === actionType.ALL_TURNED_ON_BY_TYPE &&
752+
(action.object_type === actionObjectType.INSPIRATION || action.object_type === actionObjectType.MOLECULE)
753+
)
754+
: moleculesAction.filter(
755+
action =>
756+
action.type === actionType.ALL_TURNED_ON_BY_TYPE &&
757+
(action.object_type === actionObjectType.CROSS_REFERENCE ||
758+
action.object_type === actionObjectType.COMPOUND)
759+
);
760+
761+
if (actions) {
762+
actions.forEach(action => {
763+
if (action) {
764+
let actionItems = action.items;
765+
let type = action.control_type;
766+
767+
if (isSelection) {
768+
dispatch(setSelectedAllByType(type, actionItems, action.object_type === actionObjectType.INSPIRATION));
769+
770+
actionItems.forEach(data => {
771+
if (data) {
772+
if (type === 'ligand') {
773+
dispatch(addType[type](stage, data, colourList[data.id % colourList.length], true, true));
774+
} else {
775+
dispatch(addType[type](stage, data, colourList[data.id % colourList.length], true));
776+
}
777+
}
778+
});
779+
} else {
780+
dispatch(
781+
setSelectedAllByTypeOfDataset(
782+
type,
783+
action.dataset_id,
784+
actionItems,
785+
action.object_type === actionObjectType.CROSS_REFERENCE
786+
)
787+
);
788+
789+
actionItems.forEach(data => {
790+
if (data && data.molecule) {
791+
dispatch(
792+
addTypeCompound[type](
793+
stage,
794+
data.molecule,
795+
colourList[data.molecule.id % colourList.length],
796+
data.datasetID,
797+
true
798+
)
799+
);
800+
}
801+
});
802+
}
803+
}
804+
});
805+
}
806+
};
807+
589808
const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, getState) => {
590809
const nglView = stages.find(view => view.id === VIEWS.MAJOR_VIEW);
591810

@@ -650,6 +869,10 @@ const restoreCompoundsActions = (orderedActionList, stage) => (dispatch, getStat
650869
dispatch(appendMoleculeToCompoundsOfDatasetToBuy(action.dataset_id, data.id, data.name));
651870
}
652871
});
872+
873+
dispatch(restoreAllSelectionActions(orderedActionList, stage, false));
874+
dispatch(restoreAllSelectionByTypeActions(orderedActionList, stage, false));
875+
dispatch(setIsTrackingCompoundsRestoring(false));
653876
};
654877

655878
const addType = {
@@ -758,7 +981,9 @@ const getCompound = (action, state) => {
758981

759982
if (moleculeList) {
760983
let moleculeListOfDataset = moleculeList[datasetID];
761-
molecule = moleculeListOfDataset.find(m => m.name === name);
984+
if (moleculeListOfDataset) {
985+
molecule = moleculeListOfDataset.find(m => m.name === name);
986+
}
762987
}
763988
return molecule;
764989
};
@@ -1042,7 +1267,13 @@ const handleAllActionByType = (action, isAdd, stage) => (dispatch, getState) =>
10421267
actionItems.forEach(data => {
10431268
if (data && data.molecule) {
10441269
dispatch(
1045-
addTypeCompound[type](stage, data.molecule, colourList[data.id % colourList.length], data.datasetID, true)
1270+
addTypeCompound[type](
1271+
stage,
1272+
data.molecule,
1273+
colourList[data.molecule.id % colourList.length],
1274+
data.datasetID,
1275+
true
1276+
)
10461277
);
10471278
}
10481279
});
@@ -1062,7 +1293,7 @@ const handleAllActionByType = (action, isAdd, stage) => (dispatch, getState) =>
10621293
removeTypeCompound[type](
10631294
stage,
10641295
data.molecule,
1065-
colourList[data.id % colourList.length],
1296+
colourList[data.molecule.id % colourList.length],
10661297
data.datasetID,
10671298
true
10681299
)

0 commit comments

Comments
 (0)