Skip to content

Commit

Permalink
add config for default view
Browse files Browse the repository at this point in the history
STT-26
  • Loading branch information
petrjasek committed Jul 24, 2024
1 parent f022b48 commit 8931057
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
3 changes: 1 addition & 2 deletions client/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 5 additions & 1 deletion client/config.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions client/selectors/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ 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) => (
state?.main?.listViewType ?? LIST_VIEW_TYPE.SCHEDULE
);
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) =>
Expand Down
51 changes: 33 additions & 18 deletions client/selectors/tests/main_test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 8931057

Please sign in to comment.