Skip to content

Commit

Permalink
#462 Mass actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Nov 27, 2020
1 parent c67b599 commit e0c3756
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 33 deletions.
20 changes: 7 additions & 13 deletions js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ export const INITIAL_STATE = {
surfaceLists: {}, // map of $datasetID and its $list
inspirationLists: {}, // map of $datasetID and its $list

molecule_all_selection: null,
molecule_all_deselection: null,

molecule_all_type_selection: {},
molecule_all_type_deselection: {},
moleculeAllSelection: {},
moleculeAllTypeSelection: {},

// search
searchString: null,
Expand Down Expand Up @@ -123,6 +120,7 @@ const initializeContainerLists = (state, datasetID) => {
state.complexLists[datasetID] = state.complexLists[datasetID] || [];
state.surfaceLists[datasetID] = state.surfaceLists[datasetID] || [];
state.inspirationLists[datasetID] = state.inspirationLists[datasetID] || [];
state.moleculeAllSelection[datasetID] = state.moleculeAllSelection[datasetID] || [];
return state;
};

Expand Down Expand Up @@ -380,23 +378,19 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, { ...INITIAL_STATE, ...datasetsLists });

case constants.SET_SELECTED_ALL:
return Object.assign({}, state, {
molecule_all_selection: action.payload
});
return appendToList(state, 'moleculeAllSelection', action.payload.datasetID, action.payload.item.id);

case constants.SET_DESELECTED_ALL:
return Object.assign({}, state, {
molecule_all_deselection: action.payload
});
return removeFromList(state, 'moleculeAllSelection', action.payload.datasetID, action.payload.item.id);

case constants.SET_SELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_selection: action.payload
moleculeAllTypeSelection: action.payload.type
});

case constants.SET_DESELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_deselection: action.payload
moleculeAllTypeSelection: action.payload.type
});
default:
return state;
Expand Down
16 changes: 8 additions & 8 deletions js/reducers/selection/selectionReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ export const INITIAL_STATE = {
mol_group_selection: [],
object_selection: undefined,
filter: undefined,
molecule_all_selection: null,
molecule_all_deselection: null,
molecule_all_type_selection: [],
molecule_all_type_deselection: [],
moleculeAllSelection: [],
moleculeAllTypeSelection: [],

compoundsOfVectors: null, // list of all vector's compounds to pick
// compoundsOfVectors: {
Expand Down Expand Up @@ -282,22 +280,24 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {

case constants.SET_SELECTED_ALL:
return Object.assign({}, state, {
molecule_all_selection: action.item
moleculeAllSelection: [...new Set([...state.moleculeAllSelection, action.item.id])]
});

case constants.SET_DESELECTED_ALL:
let selectedMolecules = new Set(state.moleculeAllSelection);
selectedMolecules.delete(action.item.id);
return Object.assign({}, state, {
molecule_all_deselection: action.item
moleculeAllSelection: [...selectedMolecules]
});

case constants.SET_SELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_selection: action.payload.items
moleculeAllTypeSelection: action.payload.type
});

case constants.SET_DESELECTED_ALL_BY_TYPE:
return Object.assign({}, state, {
molecule_all_type_deselection: action.payload.items
moleculeAllTypeSelection: action.payload.type
});
// Cases like: @@redux/INIT
default:
Expand Down
76 changes: 65 additions & 11 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ export const saveActionsList = (snapshotID, actionList) => (dispatch, getState)
const currentVectors = state.selectionReducers.vectorOnList;
const currentBuyList = state.selectionReducers.to_buy_list;
const currentVector = state.selectionReducers.currentVector;
const currentSelectionAll = state.selectionReducers.moleculeAllSelection;

const currentDatasetLigands = state.datasetsReducers.ligandLists;
const currentDatasetProteins = state.datasetsReducers.proteinList;
const currentDatasetComplexes = state.datasetsReducers.complexLists;
const currentDatasetSurfaces = state.datasetsReducers.surfaceLists;
const currentDatasetSelectionAll = state.datasetsReducers.moleculeAllSelection;

const currentDatasetBuyList = state.datasetsReducers.compoundsToBuyDatasetMap;
const currentobjectsInView = state.nglReducers.objectsInView;
Expand All @@ -126,12 +128,22 @@ export const saveActionsList = (snapshotID, actionList) => (dispatch, getState)
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.ALL_TURNED_ON, getCollection(currentSelectionAll), currentActions);
getCurrentActionList(
orderedActionList,
actionType.ALL_TURNED_ON,
getCollectionOfDataset(currentDatasetSelectionAll),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.SIDECHAINS_TURNED_ON,
getCollection(currentProteins),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.INTERACTIONS_TURNED_ON,
Expand Down Expand Up @@ -160,19 +172,21 @@ export const saveActionsList = (snapshotID, actionList) => (dispatch, getState)
getCollectionOfDataset(currentDatasetLigands),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.SIDECHAINS_TURNED_ON,
getCollectionOfDataset(currentDatasetProteins),
currentActions
);

getCurrentActionList(
orderedActionList,
actionType.INTERACTIONS_TURNED_ON,
getCollectionOfDataset(currentDatasetComplexes),

currentActions
);

getCurrentActionList(
orderedActionList,
actionType.SURFACE_TURNED_ON,
Expand All @@ -187,6 +201,13 @@ export const saveActionsList = (snapshotID, actionList) => (dispatch, getState)
currentActions
);

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

getCurrentActionList(
orderedActionList,
actionType.REPRESENTATION_CHANGED,
Expand Down Expand Up @@ -233,15 +254,8 @@ const saveTrackingActions = (currentActions, snapshotID) => (dispatch, getState)
};

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
);
let actionList = orderedActionList.filter(action => action.type === type);

if (collection) {
collection.forEach(data => {
let action = actionList.find(action => action.object_id === data.id && action.dataset_id === data.datasetId);
Expand Down Expand Up @@ -409,6 +423,7 @@ const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getS
.finally(() => {
dispatch(restoreCompoundsActions(orderedActionList, stage));
dispatch(setMoleculeListIsLoading(false));
dispatch(restoreAllSelectionActions(orderedActionList, stage, false));
dispatch(setIsTrackingCompoundsRestoring(false));
});
};
Expand Down Expand Up @@ -477,6 +492,7 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
}

dispatch(restoreCartActions(moleculesAction));
dispatch(restoreAllSelectionActions(orderedActionList, stage, true));
};

const restoreCartActions = moleculesAction => (dispatch, getState) => {
Expand All @@ -493,6 +509,42 @@ const restoreCartActions = moleculesAction => (dispatch, getState) => {
}
};

const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dispatch, getState) => {
let state = getState();

let actions =
isSelection === true
? moleculesAction.filter(
action =>
action.type === actionType.ALL_TURNED_ON &&
(action.object_type === actionObjectType.INSPIRATION || action.object_type === actionObjectType.MOLECULE)
)
: moleculesAction.filter(
action =>
action.type === actionType.ALL_TURNED_ON &&
(action.object_type === actionObjectType.CROSS_REFERENCE ||
action.object_type === actionObjectType.COMPOUND)
);

if (actions) {
actions.forEach(action => {
if (action) {
if (action.isLigand) {
dispatch(handleMoleculeAction(action, 'ligand', true, stage, state, true));
}

if (action.isProtein) {
dispatch(handleMoleculeAction(action, 'protein', true, stage, state, true));
}

if (action.isComplex) {
dispatch(handleMoleculeAction(action, 'complex', true, stage, state, true));
}
}
});
}
};

const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, getState) => {
const nglView = stages.find(view => view.id === VIEWS.MAJOR_VIEW);

Expand All @@ -503,7 +555,9 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
});
}

let representationsChangesActions = moleculesAction.filter(action => action.type === actionType.REPRESENTATION_ADDED);
let representationsChangesActions = moleculesAction.filter(
action => action.type === actionType.REPRESENTATION_CHANGED
);
if (representationsChangesActions) {
representationsChangesActions.forEach(action => {
dispatch(changeRepresentation(true, action.change, action.object_id, action.representation, nglView));
Expand Down
1 change: 0 additions & 1 deletion js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { DJANGO_CONTEXT } from '../../utils/djangoContext';
export const findTrackAction = (action, state) => {
const username = DJANGO_CONTEXT['username'];
const target_on_name = state.apiReducers.target_on_name;
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;
const isActionRestoring = state.trackingReducers.isActionRestoring;

let trackAction = null;
Expand Down

0 comments on commit e0c3756

Please sign in to comment.