Commit 8692193e authored by Imran Salam's avatar Imran Salam
Browse files

slice browser reducer as it has overgrown

parent 29343278
......@@ -5,12 +5,21 @@ import * as browserActions from './browserActions';
import {
BrowserState,
defaultBrowserState,
trackPanelState,
drawerState,
ExampleObjects,
defaultExampleObjects,
ExampleObjectState,
defaultExampleObjectState,
ObjectState,
defaultObjectState
defaultObjectState,
BrowserOpenState,
TrackPanelState,
defaultTrackPanelState,
DrawerState,
defaultDrawerState,
BrowserLocationState,
defaultBrowserLocationState,
BrowserNavState,
defaultBrowserNavState,
TrackConfigState,
defaultTrackConfigState
} from './browserState';
function browserInfo(
......@@ -21,20 +30,63 @@ function browserInfo(
case getType(browserActions.updateBrowserActivated):
return { ...state, browserActivated: action.payload };
case getType(browserActions.toggleTrackPanel):
return trackPanelState(state, action.payload);
case getType(browserActions.changeDrawerView):
return {
...state,
drawerView: action.payload
browserOpenState: action.payload
? BrowserOpenState.SEMI_EXPANDED
: BrowserOpenState.EXPANDED
};
case getType(browserActions.toggleDrawer):
return drawerState(state, action.payload);
return {
...state,
browserOpenState: action.payload
? BrowserOpenState.COLLAPSED
: BrowserOpenState.SEMI_EXPANDED
};
default:
return state;
}
}
export function browserNav(
state: BrowserNavState = defaultBrowserNavState,
action: ActionType<typeof browserActions>
) {
switch (action.type) {
case getType(browserActions.toggleBrowserNav):
return { ...state, browserNavOpened: !state.browserNavOpened };
case getType(browserActions.updateBrowserNavStates):
return { ...state, browserNavStates: action.payload };
default:
return state;
}
}
export function browserLocation(
state: BrowserLocationState = defaultBrowserLocationState,
action: ActionType<typeof browserActions>
) {
switch (action.type) {
case getType(browserActions.updateChrLocation):
return { ...state, chrLocation: action.payload };
case getType(browserActions.updateDefaultChrLocation):
return {
...state,
chrLocation: action.payload,
defaultChrLocation: action.payload
};
case getType(browserActions.toggleGenomeSelector):
return { ...state, genomeSelectorActive: action.payload };
default:
return state;
}
}
export function trackConfig(
state: TrackConfigState = defaultTrackConfigState,
action: ActionType<typeof browserActions>
) {
switch (action.type) {
case getType(browserActions.updateCogList):
return { ...state, browserCogList: action.payload };
case getType(browserActions.updateCogTrackList):
......@@ -59,11 +111,20 @@ function browserInfo(
[action.payload[0]]: action.payload[1]
}
};
case getType(browserActions.updateDefaultChrLocation):
default:
return state;
}
}
export function trackPanel(
state: TrackPanelState = defaultTrackPanelState,
action: ActionType<typeof browserActions>
): TrackPanelState {
switch (action.type) {
case getType(browserActions.toggleTrackPanel):
return {
...state,
chrLocation: action.payload,
defaultChrLocation: action.payload
trackPanelOpened: action.payload
};
case getType(browserActions.openTrackPanelModal):
return {
......@@ -77,8 +138,6 @@ function browserInfo(
trackPanelModalOpened: false,
trackPanelModalView: ''
};
case getType(browserActions.toggleGenomeSelector):
return { ...state, genomeSelectorActive: action.payload };
case getType(browserActions.selectBrowserTab):
return {
...state,
......@@ -91,31 +150,21 @@ function browserInfo(
}
}
function exampleObjects(
state: ExampleObjects = defaultExampleObjects,
export function drawer(
state: DrawerState = defaultDrawerState,
action: ActionType<typeof browserActions>
): ExampleObjects {
): DrawerState {
switch (action.type) {
case getType(browserActions.fetchExampleObjects.failure):
return { ...state, exampleObjectsFetchFailed: true };
case getType(browserActions.fetchExampleObjects.request):
case getType(browserActions.changeDrawerView):
return {
...state,
exampleObjectsFetchFailed: false,
exampleObjectsFetching: true
};
case getType(browserActions.fetchExampleObjects.success):
type Payload = {
examples: {};
drawerView: action.payload
};
const json = action.payload as Payload;
case getType(browserActions.toggleDrawer):
return {
...state,
exampleObjectsFetchFailed: false,
exampleObjectsFetching: false,
examples: json.examples
drawerOpened: action.payload,
drawerView: action.payload ? state.drawerView : ''
};
default:
return state;
......@@ -155,8 +204,44 @@ function object(
}
}
function exampleObjects(
state: ExampleObjectState = defaultExampleObjectState,
action: ActionType<typeof browserActions>
): ExampleObjectState {
switch (action.type) {
case getType(browserActions.fetchExampleObjects.failure):
return { ...state, exampleObjectsFetchFailed: true };
case getType(browserActions.fetchExampleObjects.request):
return {
...state,
exampleObjectsFetchFailed: false,
exampleObjectsFetching: true
};
case getType(browserActions.fetchExampleObjects.success):
type Payload = {
examples: {};
};
const json = action.payload as Payload;
return {
...state,
exampleObjectsFetchFailed: false,
exampleObjectsFetching: false,
examples: json.examples
};
default:
return state;
}
}
export default combineReducers({
browserInfo,
browserLocation,
browserNav,
drawer,
exampleObjects,
object
object,
trackConfig,
trackPanel
});
......@@ -13,56 +13,56 @@ export const getBrowserActivated = (state: RootState): boolean =>
export const getBrowserOpenState = (state: RootState): BrowserOpenState =>
state.browser.browserInfo.browserOpenState;
export const getDrawerView = (state: RootState): string =>
state.browser.browserInfo.drawerView;
export const getDrawerOpened = (state: RootState): boolean =>
state.browser.browserInfo.drawerOpened;
export const getTrackPanelOpened = (state: RootState): boolean =>
state.browser.browserInfo.trackPanelOpened;
export const getBrowserNavOpened = (state: RootState): boolean =>
state.browser.browserInfo.browserNavOpened;
state.browser.browserNav.browserNavOpened;
export const getBrowserNavStates = (state: RootState): BrowserNavStates =>
state.browser.browserInfo.browserNavStates;
state.browser.browserNav.browserNavStates;
export const getChrLocation = (state: RootState): ChrLocation =>
state.browser.browserInfo.chrLocation;
state.browser.browserLocation.chrLocation;
export const getDefaultChrLocation = (state: RootState): ChrLocation =>
state.browser.browserInfo.defaultChrLocation;
state.browser.browserLocation.defaultChrLocation;
export const getTrackPanelModalOpened = (state: RootState): boolean =>
state.browser.browserInfo.trackPanelModalOpened;
export const getTrackPanelModalView = (state: RootState): string =>
state.browser.browserInfo.trackPanelModalView;
export const getGenomeSelectorActive = (state: RootState): boolean =>
state.browser.browserLocation.genomeSelectorActive;
export const getBrowserCogList = (state: RootState): number =>
state.browser.browserInfo.browserCogList;
state.browser.trackConfig.browserCogList;
export const getBrowserCogTrackList = (state: RootState): CogList =>
state.browser.browserInfo.browserCogTrackList;
state.browser.trackConfig.browserCogTrackList;
export const getBrowserSelectedCog = (state: RootState): string =>
state.browser.browserInfo.selectedCog;
state.browser.trackConfig.selectedCog;
export const getTrackConfigNames = (state: RootState): any =>
state.browser.browserInfo.trackConfigNames;
state.browser.trackConfig.trackConfigNames;
export const getTrackConfigLabel = (state: RootState): any =>
state.browser.browserInfo.trackConfigLabel;
state.browser.trackConfig.trackConfigLabel;
export const getApplyToAll = (state: RootState): boolean =>
state.browser.browserInfo.applyToAll;
state.browser.trackConfig.applyToAll;
export const getGenomeSelectorActive = (state: RootState): boolean =>
state.browser.browserInfo.genomeSelectorActive;
export const getTrackPanelModalOpened = (state: RootState): boolean =>
state.browser.trackPanel.trackPanelModalOpened;
export const getTrackPanelModalView = (state: RootState): string =>
state.browser.trackPanel.trackPanelModalView;
export const getSelectedBrowserTab = (state: RootState): TrackType =>
state.browser.browserInfo.selectedBrowserTab;
state.browser.trackPanel.selectedBrowserTab;
export const getTrackPanelOpened = (state: RootState): boolean =>
state.browser.trackPanel.trackPanelOpened;
export const getDrawerView = (state: RootState): string =>
state.browser.drawer.drawerView;
export const getDrawerOpened = (state: RootState): boolean =>
state.browser.drawer.drawerOpened;
export const getObjectFetchFailed = (state: RootState) =>
state.browser.object.objectFetchFailed;
......@@ -76,5 +76,11 @@ export const getObjectInfo = (state: RootState) =>
export const getTrackCategories = (state: RootState): [] =>
state.browser.object.trackCategories;
export const getExampleObjectsFetchFailed = (state: RootState) =>
state.browser.exampleObjects.exampleObjectsFetchFailed;
export const getExampleObjectsFetching = (state: RootState) =>
state.browser.exampleObjects.exampleObjectsFetching;
export const getExampleObjects = (state: RootState) =>
state.browser.exampleObjects.examples;
......@@ -23,61 +23,77 @@ export type CogList = {
};
export type BrowserState = Readonly<{
applyToAll: boolean;
browserActivated: boolean;
browserCogList: number;
browserCogTrackList: CogList;
browserOpenState: BrowserOpenState;
}>;
export const defaultBrowserState: BrowserState = {
browserActivated: false,
browserOpenState: BrowserOpenState.SEMI_EXPANDED
};
export type BrowserNavState = Readonly<{
browserNavOpened: boolean;
browserNavStates: BrowserNavStates;
browserOpenState: BrowserOpenState;
}>;
export const defaultBrowserNavState: BrowserNavState = {
browserNavOpened: false,
browserNavStates: [true, true, true, true, true, true]
};
export type BrowserLocationState = Readonly<{
chrLocation: ChrLocation;
defaultChrLocation: ChrLocation;
drawerOpened: boolean;
drawerView: string;
genomeSelectorActive: boolean;
selectedBrowserTab: TrackType;
}>;
export const defaultBrowserLocationState: BrowserLocationState = {
chrLocation: ['13', 0, 0],
defaultChrLocation: ['13', 0, 0],
genomeSelectorActive: false
};
export type TrackConfigState = Readonly<{
applyToAll: boolean;
browserCogList: number;
browserCogTrackList: CogList;
selectedCog: string;
trackConfigNames: any;
trackConfigLabel: any;
trackPanelModalOpened: boolean;
trackPanelModalView: string;
trackPanelOpened: boolean;
}>;
export const defaultBrowserState: BrowserState = {
export const defaultTrackConfigState: TrackConfigState = {
applyToAll: false,
browserActivated: false,
browserCogList: 0,
browserCogTrackList: {},
browserNavOpened: false,
browserNavStates: [true, true, true, true, true, true],
browserOpenState: BrowserOpenState.SEMI_EXPANDED,
chrLocation: ['13', 0, 0],
defaultChrLocation: ['13', 0, 0],
drawerOpened: false,
drawerView: '',
genomeSelectorActive: false,
selectedBrowserTab: TrackType.GENOMIC,
selectedCog: '',
trackConfigLabel: {},
trackConfigNames: {},
trackConfigNames: {}
};
export type TrackPanelState = Readonly<{
selectedBrowserTab: TrackType;
trackPanelModalOpened: boolean;
trackPanelModalView: string;
trackPanelOpened: boolean;
}>;
export const defaultTrackPanelState: TrackPanelState = {
selectedBrowserTab: TrackType.GENOMIC,
trackPanelModalOpened: false,
trackPanelModalView: '',
trackPanelOpened: true
};
export type ExampleObjects = Readonly<{
exampleObjectsFetchFailed: boolean;
exampleObjectsFetching: boolean;
examples: {
[key: string]: {};
};
export type DrawerState = Readonly<{
drawerOpened: boolean;
drawerView: string;
}>;
export const defaultExampleObjects: ExampleObjects = {
exampleObjectsFetchFailed: false,
exampleObjectsFetching: false,
examples: {}
export const defaultDrawerState = {
drawerOpened: false,
drawerView: ''
};
export type ObjectState = Readonly<{
......@@ -94,37 +110,16 @@ export const defaultObjectState: ObjectState = {
trackCategories: []
};
export const trackPanelState = (
state: BrowserState,
trackPanelOpened: boolean = !state.trackPanelOpened
) => {
const browserOpenState: BrowserOpenState = trackPanelOpened
? BrowserOpenState.SEMI_EXPANDED
: BrowserOpenState.EXPANDED;
return {
...state,
browserOpenState,
trackPanelOpened
export type ExampleObjectState = Readonly<{
exampleObjectsFetchFailed: boolean;
exampleObjectsFetching: boolean;
examples: {
[key: string]: {};
};
};
}>;
export const drawerState = (
state: BrowserState,
drawerOpened: boolean = !state.drawerOpened
) => {
if (drawerOpened === true) {
return {
...state,
browserOpenState: BrowserOpenState.COLLAPSED,
drawerOpened
};
} else {
return {
...state,
browserOpenState: BrowserOpenState.SEMI_EXPANDED,
drawerOpened,
drawerView: ''
};
}
export const defaultExampleObjectState: ExampleObjectState = {
exampleObjectsFetchFailed: false,
exampleObjectsFetching: false,
examples: {}
};
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