Commit f55c78c0 authored by Ridwan Amode's avatar Ridwan Amode
Browse files

filter panel open state now moved to gene

parent 72e6976f
Pipeline #197636 passed with stages
in 4 minutes and 25 seconds
......@@ -23,8 +23,6 @@ import { useParams, useLocation } from 'react-router-dom';
import { useRestoreScrollPosition } from 'src/shared/hooks/useRestoreScrollPosition';
import usePrevious from 'src/shared/hooks/usePrevious';
import { setFilterPanel } from 'src/content/app/entity-viewer/state/general/entityViewerGeneralSlice';
import { getFilterPanelOpen } from 'src/content/app/entity-viewer/state/general/entityViewerGeneralSelectors';
import {
getSelectedGeneViewTabs,
getCurrentView
......@@ -35,9 +33,11 @@ import {
GeneViewTabName
} from 'src/content/app/entity-viewer/state/gene-view/view/geneViewViewSlice';
import { updatePreviouslyViewedEntities } from 'src/content/app/entity-viewer/state/bookmarks/entityViewerBookmarksSlice';
import { setFilterPanel } from 'src/content/app/entity-viewer/state/gene-view/transcripts/geneViewTranscriptsSlice';
import {
getFilters,
getSortingRule
getSortingRule,
getFilterPanelOpen
} from 'src/content/app/entity-viewer/state/gene-view/transcripts/geneViewTranscriptsSelectors';
import * as urlFor from 'src/shared/helpers/urlHelper';
......@@ -315,7 +315,7 @@ const GeneViewWithData = (props: GeneViewWithDataProps) => {
<div className={styles.tabWrapper}>
<GeneViewTabs isFilterOpen={isFilterOpen} />
</div>
{props.gene.transcripts.length > 5 && isFilterOpen && (
{isFilterOpen && (
<div className={styles.filtersWrapper}>
<TranscriptsFilter
toggleFilter={toggleFilter}
......
......@@ -23,7 +23,8 @@ import { RootState } from 'src/store';
import {
TranscriptsStatePerGene,
Filters,
SortingRule
SortingRule,
filterPanelOpen
} from './geneViewTranscriptsSlice';
const getSliceForGene = (
......@@ -67,3 +68,8 @@ export const getSortingRule = (state: RootState): SortingRule => {
const transcriptsSlice = getSliceForGene(state);
return transcriptsSlice?.sortingRule ?? SortingRule.DEFAULT;
};
export const getFilterPanelOpen = (state: RootState): filterPanelOpen => {
const transcriptsSlice = getSliceForGene(state);
return transcriptsSlice?.filterPanelOpen ?? false;
};
......@@ -48,6 +48,7 @@ export type TranscriptsStatePerGene = {
expandedMoreInfoIds: string[];
filters: Filters;
sortingRule: SortingRule;
filterPanelOpen: filterPanelOpen;
};
export type GeneViewTranscriptsState = {
......@@ -64,14 +65,55 @@ export type Filter = {
export type Filters = Record<string, Filter>;
export type filterPanelOpen = boolean;
const defaultStatePerGene: TranscriptsStatePerGene = {
expandedIds: [],
expandedDownloadIds: [],
expandedMoreInfoIds: [],
filters: {},
sortingRule: SortingRule.DEFAULT
sortingRule: SortingRule.DEFAULT,
filterPanelOpen: false
};
export const resetFilterPanel =
(): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
const state = getState();
const activeGenomeId = getEntityViewerActiveGenomeId(state);
const activeEntityId = getEntityViewerActiveEntityId(state);
if (!activeGenomeId || !activeEntityId) {
return;
}
dispatch(
transcriptsSlice.actions.updateFilterPanel({
activeGenomeId,
activeEntityId,
filterPanelOpen: defaultStatePerGene.filterPanelOpen
})
);
};
export const setFilterPanel =
(
filterPanelOpen: filterPanelOpen
): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
const state = getState();
const activeGenomeId = getEntityViewerActiveGenomeId(state);
const activeEntityId = getEntityViewerActiveEntityId(state);
if (!activeGenomeId || !activeEntityId) {
return;
}
dispatch(
transcriptsSlice.actions.updateFilterPanel({
activeGenomeId,
activeEntityId,
filterPanelOpen
})
);
};
export const setFilters =
(filters: Filters): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
......@@ -231,6 +273,12 @@ type UpdateSortingRulePayload = {
sortingRule: SortingRule;
};
type UpdateFilterPanelOpenPayload = {
activeGenomeId: string;
activeEntityId: string;
filterPanelOpen: filterPanelOpen;
};
const transcriptsSlice = createSlice({
name: 'entity-viewer-gene-view-transcripts',
initialState: {} as GeneViewTranscriptsState,
......@@ -265,6 +313,19 @@ const transcriptsSlice = createSlice({
updatedState
);
},
updateFilterPanel(
state,
action: PayloadAction<UpdateFilterPanelOpenPayload>
) {
const { activeGenomeId, activeEntityId, filterPanelOpen } =
action.payload;
const updatedState = ensureGenePresence(state, action.payload);
return set(
`${activeGenomeId}.${activeEntityId}.filterPanelOpen`,
filterPanelOpen,
updatedState
);
},
updateFilters(state, action: PayloadAction<UpdateFiltersPayload>) {
const { activeGenomeId, activeEntityId, filters } = action.payload;
const updatedState = ensureGenePresence(state, action.payload);
......
......@@ -33,6 +33,3 @@ export const getEntityViewerActiveEntityId = (state: RootState) => {
export const getEntityViewerQueryParams = (
state: RootState
): { [key: string]: string } => getQueryParamsMap(state.router.location.search);
export const getFilterPanelOpen = (state: RootState) =>
state.entityViewer.general.filterPanelOpen || false;
......@@ -26,6 +26,7 @@ import entityViewerStorageService from 'src/content/app/entity-viewer/services/e
import { fetchGenomeData } from 'src/shared/state/genome/genomeActions';
import { ensureSpeciesIsEnabled } from 'src/content/app/species-selector/state/speciesSelectorActions';
import { resetFilterPanel } from 'src/content/app/entity-viewer/state/gene-view/transcripts/geneViewTranscriptsSlice';
import {
getEntityViewerActiveGenomeId,
......@@ -40,17 +41,13 @@ import { RootState } from 'src/store';
export type EntityViewerGeneralState = Readonly<{
activeGenomeId: string | null;
activeEntityIds: { [genomeId: string]: string };
filterPanelOpen: filterPanelOpen;
}>;
export const initialState: EntityViewerGeneralState = {
activeGenomeId: null, // FIXME add entity viewer storage service
activeEntityIds: {},
filterPanelOpen: false
activeEntityIds: {}
};
export type filterPanelOpen = boolean;
export const setDataFromUrl =
(params: EntityViewerParams): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
......@@ -95,6 +92,10 @@ export const setDataFromUrl =
);
}
if (activeGenomeId === genomeIdFromUrl && entityId !== activeEntityId) {
dispatch(resetFilterPanel());
}
entityViewerStorageService.updateGeneralState({
activeGenomeId: genomeIdFromUrl
});
......@@ -105,19 +106,6 @@ export const setDataFromUrl =
}
};
export const setFilterPanel =
(
filterPanelOpen: filterPanelOpen
): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
const activeGenomeId = getEntityViewerActiveGenomeId(getState());
if (!activeGenomeId) {
return;
}
dispatch(updateFilterPanel(filterPanelOpen));
};
export const setDefaultActiveGenomeId =
(): ThunkAction<void, any, null, Action<string>> =>
(dispatch, getState: () => RootState) => {
......@@ -140,9 +128,6 @@ const entityViewerGeneralSlice = createSlice({
setActiveGenomeId(state, action: PayloadAction<string>) {
state.activeGenomeId = action.payload;
},
updateFilterPanel(state, action: PayloadAction<boolean>) {
state.filterPanelOpen = action.payload;
},
updateActiveEntityForGenome(
state,
action: PayloadAction<{ genomeId: string; entityId: string }>
......@@ -165,7 +150,6 @@ export const {
loadInitialState,
setActiveGenomeId,
updateActiveEntityForGenome,
updateFilterPanel,
deleteGenome
} = entityViewerGeneralSlice.actions;
......
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