Unverified Commit 25f12055 authored by Manoj Pandian Sakthivel's avatar Manoj Pandian Sakthivel Committed by GitHub
Browse files

Species do not get removed from Entity Viewer (#470)

parent 52bee27d
Pipeline #135067 passed with stages
in 6 minutes and 44 seconds
......@@ -49,6 +49,20 @@ export class EntityViewerStorageService {
localStorageOptions
);
}
public deleteGenome(genomeIdToDelete: string): void {
const activeGenomeId = this.getGeneralState().activeGenomeId;
if (activeGenomeId === genomeIdToDelete) {
this.updateGeneralState({
activeGenomeId: undefined
});
}
this.storageService.removeAt(
StorageKeys.GENERAL_STATE,
['activeEntityIds', genomeIdToDelete],
localStorageOptions
);
}
}
export default new EntityViewerStorageService(storageService);
......@@ -15,7 +15,7 @@
*/
import { createAction } from 'typesafe-actions';
import { ActionCreator, Action } from 'redux';
import { Action } from 'redux';
import { batch } from 'react-redux';
import { push, replace } from 'connected-react-router';
import { ThunkAction } from 'redux-thunk';
......@@ -45,12 +45,12 @@ export const setActiveGenomeId = createAction(
'entity-viewer/set-active-genome-id'
)<string>();
export const setDataFromUrl: ActionCreator<ThunkAction<
void,
any,
null,
Action<string>
>> = (params: EntityViewerParams) => (dispatch, getState: () => RootState) => {
export const setDataFromUrl = (
params: EntityViewerParams
): ThunkAction<void, any, null, Action<string>> => (
dispatch,
getState: () => RootState
) => {
const state = getState();
const { genomeId: genomeIdFromUrl } = params;
......@@ -100,18 +100,19 @@ export const setDataFromUrl: ActionCreator<ThunkAction<
entityViewerStorageService.updateGeneralState({
activeGenomeId: genomeIdFromUrl
});
entityViewerStorageService.updateGeneralState({
activeEntityIds: { [genomeIdFromUrl]: entityId }
});
}
};
export const setDefaultActiveGenomeId: ActionCreator<ThunkAction<
export const setDefaultActiveGenomeId = (): ThunkAction<
void,
any,
null,
Action<string>
>> = () => (dispatch, getState: () => RootState) => {
> => (dispatch, getState: () => RootState) => {
const state = getState();
const [firstCommittedSpecies] = getCommittedSpecies(state);
const activeGenomeId = firstCommittedSpecies.genome_id;
......@@ -122,12 +123,9 @@ export const setDefaultActiveGenomeId: ActionCreator<ThunkAction<
});
};
export const changeActiveGenomeId: ActionCreator<ThunkAction<
void,
any,
null,
Action<string>
>> = (genomeId: string) => (dispatch) => {
export const changeActiveGenomeId = (
genomeId: string
): ThunkAction<void, any, null, Action<string>> => (dispatch) => {
const newUrl = urlHelper.entityViewer({ genomeId });
batch(() => {
dispatch(setActiveGenomeId(genomeId));
......@@ -139,12 +137,9 @@ export const updateActiveEntityForGenome = createAction(
'entity-viewer/update-active-entity-ids'
)<{ [objectId: string]: string }>();
export const updateEntityId: ActionCreator<ThunkAction<
void,
any,
null,
Action<string>
>> = (activeEntityId: string) => {
export const updateEntityId = (
activeEntityId: string
): ThunkAction<void, any, null, Action<string>> => {
return (dispatch, getState: () => RootState) => {
const state = getState();
const activeGenomeId = getEntityViewerActiveGenomeId(state);
......@@ -160,3 +155,16 @@ export const updateEntityId: ActionCreator<ThunkAction<
dispatch(updateActiveEntityForGenome(updatedActiveEntityIds));
};
};
export const deleteGenome = createAction('entity-viewer/delete-genome')<
string
>();
export const deleteSpeciesInEntityViewer = (
genomeIdToRemove: string
): ThunkAction<void, any, null, Action<string>> => {
return (dispatch) => {
dispatch(deleteGenome(genomeIdToRemove));
entityViewerStorageService.deleteGenome(genomeIdToRemove);
};
};
......@@ -15,6 +15,7 @@
*/
import { ActionType, getType } from 'typesafe-actions';
import pickBy from 'lodash/pickBy';
import {
buildInitialState,
......@@ -35,6 +36,23 @@ export default function entityViewerReducer(
}
case getType(actions.updateActiveEntityForGenome):
return { ...state, activeEntityIds: action.payload };
case getType(actions.deleteGenome): {
const genomeIdToRemove = action.payload;
const activeGenomeId = state.activeGenomeId;
const newState = {
...state,
activeGenomeId:
activeGenomeId === genomeIdToRemove ? null : activeGenomeId,
activeEntityIds: pickBy(
state.activeEntityIds,
(value, key) => key !== genomeIdToRemove
)
};
return newState;
}
default:
return state;
}
......
......@@ -26,6 +26,7 @@ import speciesSelectorStorageService from 'src/content/app/species-selector/serv
import analyticsTracking from 'src/services/analytics-service';
import buildAnalyticsObject from 'src/analyticsHelper';
import { deleteSpeciesInGenomeBrowser } from 'src/content/app/browser/browserActions';
import { deleteSpeciesInEntityViewer } from 'src/content/app/entity-viewer/state/general/entityViewerGeneralActions';
import {
getCommittedSpecies,
......@@ -352,6 +353,7 @@ export const deleteSpeciesAndSave = (
dispatch(updateCommittedSpecies(updatedCommittedSpecies));
dispatch(deleteSpeciesInGenomeBrowser(genomeId));
dispatch(deleteSpeciesInEntityViewer(genomeId));
speciesSelectorStorageService.saveSelectedSpecies(updatedCommittedSpecies);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment