diff --git a/client/actions/main.ts b/client/actions/main.ts index 95718be86..e016159b5 100644 --- a/client/actions/main.ts +++ b/client/actions/main.ts @@ -815,8 +815,7 @@ function filter(ftype?: PLANNING_VIEW) { LIST_VIEW_TYPE.SCHEDULE; const filterType = ftype || (urlParams.getString('filter') as PLANNING_VIEW) || - activeFilter(getState()) || - PLANNING_VIEW.COMBINED; + activeFilter(getState()); // Set the Redux/URL params for `filter` dispatch({ diff --git a/client/config.ts b/client/config.ts index 0b73a2353..5457be28d 100644 --- a/client/config.ts +++ b/client/config.ts @@ -1,6 +1,6 @@ import moment from 'moment-timezone'; -import {IPlanningConfig} from './interfaces'; +import {IPlanningConfig, PLANNING_VIEW} from './interfaces'; import {appConfig} from 'appConfig'; appConfig = appConfig as IPlanningConfig; @@ -82,6 +82,10 @@ if (appConfig.coverage == null) { appConfig.coverage = {}; } +if (appConfig.planning_default_view == null) { + appConfig.planning_default_view = PLANNING_VIEW.COMBINED; +} + export function updateConfigAfterLoad() { if (appConfig?.planning?.dateformat == null) { appConfig.planning.dateformat = appConfig.view.dateformat; diff --git a/client/interfaces.ts b/client/interfaces.ts index 76551680b..deda3fad9 100644 --- a/client/interfaces.ts +++ b/client/interfaces.ts @@ -288,6 +288,7 @@ export interface IPlanningConfig extends ISuperdeskGlobalConfig { street_map_url?: string; planning_auto_close_popup_editor?: boolean; start_of_week?: number; + planning_default_view: PLANNING_VIEW; planning?: { dateformat?: string; diff --git a/client/selectors/main.ts b/client/selectors/main.ts index 0e845d9ba..806533c64 100644 --- a/client/selectors/main.ts +++ b/client/selectors/main.ts @@ -17,6 +17,7 @@ import {currentEventFilterId, eventsInList, orderedEvents, storedEvents} from '. import {currentPlanningFilterId, orderedPlanningList, plansInList, storedPlannings} from './planning'; import {getEventsPlanningList, orderedEventsPlanning, selectedFilter} from './eventsplanning'; import {getSearchDateRange} from '../utils'; +import {planningConfig} from '../config'; export const getCurrentListViewType = (state?: IPlanningAppState) => ( @@ -24,15 +25,16 @@ export const getCurrentListViewType = (state?: IPlanningAppState) => ( ); export const activeFilter = (state: IPlanningAppState) => { const privileges = get(state, 'privileges', ''); + const defaultView = planningConfig.planning_default_view; if (privileges?.planning_event_management && privileges?.planning_planning_management) { - return state?.main?.filter ?? PLANNING_VIEW.COMBINED; + return state?.main?.filter ?? defaultView; } else if (privileges?.planning_event_management) { return state?.main?.filter ?? PLANNING_VIEW.EVENTS; } else if (privileges?.planning_planning_management) { return state?.main?.filter ?? PLANNING_VIEW.PLANNING; } else { - return null; + return defaultView; } }; export const isEventsPlanningView = (state) => diff --git a/client/selectors/tests/main_test.ts b/client/selectors/tests/main_test.ts index cd9b2e49f..a42030807 100644 --- a/client/selectors/tests/main_test.ts +++ b/client/selectors/tests/main_test.ts @@ -1,28 +1,29 @@ import * as selectors from '../index'; import moment from 'moment'; import {MAIN, SPIKED_STATE} from '../../constants'; +import {PLANNING_VIEW} from 'planning-extension/dist/interfaces'; +import {planningConfig} from 'config'; describe('main selectors', () => { - describe('is view filtered', () => { - let state; - - beforeEach(() => { - state = { - main: { - search: { - [MAIN.FILTERS.EVENTS]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, - [MAIN.FILTERS.COMBINED]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, - [MAIN.FILTERS.PLANNING]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, - }, - }, - privileges: { - planning_event_management: 1, - planning_planning_management: 1, + let state; + + beforeEach(() => { + state = { + main: { + search: { + [MAIN.FILTERS.EVENTS]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, + [MAIN.FILTERS.COMBINED]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, + [MAIN.FILTERS.PLANNING]: {currentSearch: {spikeState: SPIKED_STATE.NOT_SPIKED}, fulltext: ''}, }, - }; - }); - + }, + privileges: { + planning_event_management: 1, + planning_planning_management: 1, + }, + }; + }); + describe('is view filtered', () => { it('if default search then view is not filtered', () => { state.main.filter = MAIN.FILTERS.EVENTS; expect(selectors.main.isViewFiltered(state)).toBe(false); @@ -100,4 +101,18 @@ describe('main selectors', () => { expect(selectors.main.isViewFiltered(state)).toBe(true); }); }); + + describe('activeFilter', () => { + afterEach(() => { + planningConfig.planning_default_view = PLANNING_VIEW.COMBINED; + }); + + it('reads default from app config', () => { + planningConfig.planning_default_view = PLANNING_VIEW.PLANNING; + expect(selectors.main.activeFilter(state)).toBe(PLANNING_VIEW.PLANNING); + + planningConfig.planning_default_view = PLANNING_VIEW.EVENTS; + expect(selectors.main.activeFilter(state)).toBe(PLANNING_VIEW.EVENTS); + }); + }); });