Unverified Commit c19fa0da authored by Imran Salam's avatar Imran Salam Committed by GitHub
Browse files

Save the sidebar state for genomes in Genome browser and Entity viewer (#514)

parent f5416a16
Pipeline #169811 passed with stages
in 4 minutes and 34 seconds
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
"dotenv-webpack": "7.0.2", "dotenv-webpack": "7.0.2",
"eslint": "7.27.0", "eslint": "7.27.0",
"eslint-config-prettier": "8.3.0", "eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "^24.3.6", "eslint-plugin-jest": "24.3.6",
"eslint-plugin-prettier": "3.4.0", "eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.23.2", "eslint-plugin-react": "7.23.2",
"eslint-plugin-react-hooks": "4.2.0", "eslint-plugin-react-hooks": "4.2.0",
...@@ -18,7 +18,7 @@ import { ActionType, getType } from 'typesafe-actions'; ...@@ -18,7 +18,7 @@ import { ActionType, getType } from 'typesafe-actions';
import pickBy from 'lodash/pickBy'; import pickBy from 'lodash/pickBy';
import { import {
getInitialTrackPanelState, getTrackPanelState,
getTrackPanelStateForGenome, getTrackPanelStateForGenome,
TrackPanelState TrackPanelState
} from './trackPanelState'; } from './trackPanelState';
...@@ -26,7 +26,7 @@ import * as browserActions from 'src/content/app/browser/browserActions'; ...@@ -26,7 +26,7 @@ import * as browserActions from 'src/content/app/browser/browserActions';
import * as trackPanelActions from './trackPanelActions'; import * as trackPanelActions from './trackPanelActions';
export default function trackPanel( export default function trackPanel(
state: TrackPanelState = getInitialTrackPanelState(), state: TrackPanelState = getTrackPanelState(),
action: action:
| ActionType<typeof trackPanelActions> | ActionType<typeof trackPanelActions>
| ActionType<typeof browserActions> | ActionType<typeof browserActions>
...@@ -34,10 +34,15 @@ export default function trackPanel( ...@@ -34,10 +34,15 @@ export default function trackPanel(
switch (action.type) { switch (action.type) {
case getType(browserActions.setDataFromUrl): case getType(browserActions.setDataFromUrl):
const { activeGenomeId } = action.payload; const { activeGenomeId } = action.payload;
return {
...state, if (!state[activeGenomeId]) {
[activeGenomeId]: getTrackPanelStateForGenome(activeGenomeId) return {
}; ...state,
[activeGenomeId]: getTrackPanelStateForGenome(activeGenomeId)
};
} else {
return state;
}
case getType(trackPanelActions.updateTrackPanelForGenome): case getType(trackPanelActions.updateTrackPanelForGenome):
return { return {
...state, ...state,
......
...@@ -55,7 +55,7 @@ export const defaultTrackPanelStateForGenome: TrackPanelStateForGenome = { ...@@ -55,7 +55,7 @@ export const defaultTrackPanelStateForGenome: TrackPanelStateForGenome = {
collapsedTrackIds: [] collapsedTrackIds: []
}; };
export const getInitialTrackPanelState = (): TrackPanelState => { export const getTrackPanelState = (): TrackPanelState => {
const genomeId = browserStorageService.getActiveGenomeId(); const genomeId = browserStorageService.getActiveGenomeId();
return genomeId ? { [genomeId]: getTrackPanelStateForGenome(genomeId) } : {}; return genomeId ? { [genomeId]: getTrackPanelStateForGenome(genomeId) } : {};
}; };
...@@ -63,14 +63,19 @@ export const getInitialTrackPanelState = (): TrackPanelState => { ...@@ -63,14 +63,19 @@ export const getInitialTrackPanelState = (): TrackPanelState => {
export const getTrackPanelStateForGenome = ( export const getTrackPanelStateForGenome = (
genomeId: string genomeId: string
): TrackPanelStateForGenome => { ): TrackPanelStateForGenome => {
const storedTrackPanel = return genomeId
browserStorageService.getTrackPanels()[genomeId] || {}; ? {
return { ...defaultTrackPanelStateForGenome,
...defaultTrackPanelStateForGenome, ...getPersistentTrackPanelStateForGenome(genomeId)
...storedTrackPanel }
}; : defaultTrackPanelStateForGenome;
}; };
export const getPersistentTrackPanelStateForGenome = (
genomeId: string
): Partial<TrackPanelStateForGenome> =>
browserStorageService.getTrackPanels()[genomeId] || {};
export const pickPersistentTrackPanelProperties = ( export const pickPersistentTrackPanelProperties = (
trackPanel: Partial<TrackPanelStateForGenome> trackPanel: Partial<TrackPanelStateForGenome>
) => { ) => {
......
...@@ -33,8 +33,6 @@ import { ...@@ -33,8 +33,6 @@ import {
GeneViewTabName GeneViewTabName
} from 'src/content/app/entity-viewer/state/gene-view/view/geneViewViewSlice'; } from 'src/content/app/entity-viewer/state/gene-view/view/geneViewViewSlice';
import { updatePreviouslyViewedEntities } from 'src/content/app/entity-viewer/state/bookmarks/entityViewerBookmarksSlice'; import { updatePreviouslyViewedEntities } from 'src/content/app/entity-viewer/state/bookmarks/entityViewerBookmarksSlice';
import { closeSidebarModal } from 'src/content/app/entity-viewer/state/sidebar/entityViewerSidebarSlice';
import { isEntityViewerSidebarOpen } from 'src/content/app/entity-viewer/state/sidebar/entityViewerSidebarSelectors';
import { import {
getFilters, getFilters,
getSortingRule getSortingRule
...@@ -209,8 +207,6 @@ const GeneViewWithData = (props: GeneViewWithDataProps) => { ...@@ -209,8 +207,6 @@ const GeneViewWithData = (props: GeneViewWithDataProps) => {
const focusId = buildFocusIdForUrl({ type: 'gene', objectId: geneId }); const focusId = buildFocusIdForUrl({ type: 'gene', objectId: geneId });
const gbUrl = urlFor.browser({ genomeId, focus: focusId }); const gbUrl = urlFor.browser({ genomeId, focus: focusId });
const isSidebarOpen = useSelector(isEntityViewerSidebarOpen);
const shouldShowFilterIndicator = const shouldShowFilterIndicator =
sortingRule !== SortingRule.DEFAULT || Object.values(filters).some(Boolean); sortingRule !== SortingRule.DEFAULT || Object.values(filters).some(Boolean);
...@@ -233,10 +229,6 @@ const GeneViewWithData = (props: GeneViewWithDataProps) => { ...@@ -233,10 +229,6 @@ const GeneViewWithData = (props: GeneViewWithDataProps) => {
return; return;
} }
if (isSidebarOpen) {
dispatch(closeSidebarModal());
}
dispatch( dispatch(
updatePreviouslyViewedEntities({ updatePreviouslyViewedEntities({
genomeId, genomeId,
......
...@@ -35,7 +35,7 @@ export const getEntityViewerGenomeState = (state: RootState) => { ...@@ -35,7 +35,7 @@ export const getEntityViewerGenomeState = (state: RootState) => {
export const getEntityViewerSidebarUIState = (state: RootState) => { export const getEntityViewerSidebarUIState = (state: RootState) => {
const activeEntityId = getEntityViewerActiveEntityId(state); const activeEntityId = getEntityViewerActiveEntityId(state);
return activeEntityId return activeEntityId
? getEntityViewerGenomeState(state)?.entities[activeEntityId]?.uIState || ? getEntityViewerGenomeState(state)?.entities[activeEntityId]?.uiState ||
null null
: null; : null;
}; };
......
...@@ -56,7 +56,7 @@ export type EntityViewerSidebarGenomeState = Readonly<{ ...@@ -56,7 +56,7 @@ export type EntityViewerSidebarGenomeState = Readonly<{
selectedTabName: SidebarTabName; selectedTabName: SidebarTabName;
entities: { entities: {
[entityId: string]: { [entityId: string]: {
uIState: EntityViewerSidebarUIState; uiState: EntityViewerSidebarUIState;
}; };
}; };
sidebarModalView: SidebarModalView | null; sidebarModalView: SidebarModalView | null;
...@@ -222,7 +222,7 @@ const entityViewerSidebarSlice = createSlice({ ...@@ -222,7 +222,7 @@ const entityViewerSidebarSlice = createSlice({
}; };
mergeWith( mergeWith(
state[genomeId].entities[entityId].uIState, state[genomeId].entities[entityId].uiState,
newFragment, newFragment,
overwriteArray overwriteArray
); );
......
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