Skip to content

Commit

Permalink
#428 Save current state as a sequence of actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Nov 2, 2020
1 parent ffb84ce commit a8d5908
Showing 1 changed file with 81 additions and 28 deletions.
109 changes: 81 additions & 28 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setCurrentActionsList } from './actions';
import { actionType } from './constants';
import { VIEWS } from '../../../js/constants/constants';

export const selectCurrentActionsList = () => (dispatch, getState) => {
const state = getState();
Expand All @@ -19,24 +20,39 @@ export const selectCurrentActionsList = () => (dispatch, getState) => {
const currentDatasetProteins = state.datasetsReducers.proteinList;
const currentDatasetComplexes = state.datasetsReducers.complexLists;
const currentDatasetSurfaces = state.datasetsReducers.surfaceLists;
const currentDatasets = state.datasetsReducers.datasets;

const currentDatasetBuyList = state.datasetsReducers.compoundsToBuyDatasetMap;
const currentobjectsInView = state.nglReducers.objectsInView;

const orderedActionList = actionList.reverse((a, b) => a.timestamp - b.timestamp);
const currentTargets = (currentTargetOn && [currentTargetOn]) || [];
const currentVectorSmiles = (currentVector && [currentVector]) || [];

let currentActions = [];

getCurrentActionList(orderedActionList, actionType.TARGET_LOADED, currentTargets, currentActions);
getCurrentActionList(orderedActionList, actionType.SITE_TURNED_ON, currentSites, currentActions);
getCurrentActionList(orderedActionList, actionType.LIGAND_TURNED_ON, currentLigands, currentActions);
getCurrentActionList(orderedActionList, actionType.SIDECHAINS_TURNED_ON, currentProteins, currentActions);
getCurrentActionList(orderedActionList, actionType.INTERACTIONS_TURNED_ON, currentComplexes, currentActions);
getCurrentActionList(orderedActionList, actionType.SURFACE_TURNED_ON, currentSurfaces, currentActions);
getCurrentActionList(orderedActionList, actionType.VECTORS_TURNED_ON, currentVectors, currentActions);
getCurrentActionList(orderedActionList, actionType.VECTOR_SELECTED, currentVectorSmiles, currentActions);
getCurrentActionList(orderedActionList, actionType.TARGET_LOADED, getCollection(currentTargets), currentActions);
getCurrentActionList(orderedActionList, actionType.SITE_TURNED_ON, getCollection(currentSites), currentActions);
getCurrentActionList(orderedActionList, actionType.LIGAND_TURNED_ON, getCollection(currentLigands), currentActions);
getCurrentActionList(
orderedActionList,
actionType.SIDECHAINS_TURNED_ON,
getCollection(currentProteins),
currentActions
);
getCurrentActionList(
orderedActionList,
actionType.INTERACTIONS_TURNED_ON,
getCollection(currentComplexes),
currentActions
);
getCurrentActionList(orderedActionList, actionType.SURFACE_TURNED_ON, getCollection(currentSurfaces), currentActions);
getCurrentActionList(orderedActionList, actionType.VECTORS_TURNED_ON, getCollection(currentVectors), currentActions);
getCurrentActionList(
orderedActionList,
actionType.VECTOR_SELECTED,
getCollection(currentVectorSmiles),
currentActions
);

getCurrentActionList(
orderedActionList,
Expand All @@ -48,44 +64,59 @@ export const selectCurrentActionsList = () => (dispatch, getState) => {
getCurrentActionList(
orderedActionList,
actionType.LIGAND_TURNED_ON,
getCollectionOfDataset(currentDatasets, currentDatasetLigands),
getCollectionOfDataset(currentDatasetLigands),
currentActions
);
getCurrentActionList(
orderedActionList,
actionType.SIDECHAINS_TURNED_ON,
getCollectionOfDataset(currentDatasets, currentDatasetProteins),
getCollectionOfDataset(currentDatasetProteins),
currentActions
);
getCurrentActionList(
orderedActionList,
actionType.INTERACTIONS_TURNED_ON,
getCollectionOfDataset(currentDatasets, currentDatasetComplexes),
getCollectionOfDataset(currentDatasetComplexes),

currentActions
);
getCurrentActionList(
orderedActionList,
actionType.SURFACE_TURNED_ON,
getCollectionOfDataset(currentDatasets, currentDatasetSurfaces),
getCollectionOfDataset(currentDatasetSurfaces),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.COMPOUND_SELECTED,
getCollectionOfDataset(currentDatasets, currentDatasetBuyList),
getCollectionOfDataset(currentDatasetBuyList),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.REPRESENTATION_CHANGED,
getCollectionOfDatasetOfRepresentation(currentobjectsInView),
currentActions
);

dispatch(setCurrentActionsList(currentActions));
};

const getCurrentActionList = (orderedActionList, actionType, collection, currentActions) => {
let actionList = orderedActionList.filter(action => action.type === actionType);
const getCurrentActionList = (orderedActionList, type, collection, currentActions) => {
let actionList =
type !== actionType.REPRESENTATION_CHANGED
? orderedActionList.filter(action => action.type === type)
: orderedActionList.filter(
action =>
action.type === actionType.REPRESENTATION_ADDED ||
action.type === actionType.REPRESENTATION_REMOVED ||
action.type === actionType.REPRESENTATION_CHANGED
);
if (collection) {
collection.forEach(data => {
let action = actionList.find(action => action.object_id === data);
let action = actionList.find(action => action.object_id === data.id && action.dataset_id === data.datasetId);

if (action) {
currentActions.push(Object.assign(mapCurrentAction(action)));
Expand All @@ -103,30 +134,52 @@ const mapCurrentAction = action => {
});
};

const getCollectionOfDataset = (currentDatasets, dataList) => {
const getCollection = dataList => {
let list = [];
if (currentDatasets && dataList) {
currentDatasets.forEach(data => {
let dataValues = dataList[data.id];
if (dataValues) {
list.push(...dataValues);
}
});
if (dataList) {
var result = dataList.map(value => ({ id: value }));
list.push(...result);
}
return list;
};

const getCollectionOfDataset = dataList => {
let list = [];
if (dataList) {
for (const datasetId in dataList) {
let values = dataList[datasetId];
if (values) {
var result = values.map(value => ({ id: value, datasetId: datasetId }));
list.push(...result);
}
}
}
return list;
};

const getCollectionOfShoppingCart = dataList => {
let list = [];
if (dataList) {
dataList.forEach(data => {
let dataValue = data.vector;
if (dataValue) {
list.push(dataValue);
let value = data.vector;
if (value) {
list.push({ id: value });
}
});
}
return list;
};

const getCollectionOfDatasetOfRepresentation = dataList => {
let list = [];
for (const view in dataList) {
let objectView = dataList[view];
if (objectView && objectView !== null && objectView.display_div === VIEWS.MAJOR_VIEW) {
let value = dataList[view].name;
if (value) {
list.push({ id: value });
}
}
}
return list;
};

0 comments on commit a8d5908

Please sign in to comment.