Dashboard: Add week start option to global and dashboard preferences (#40010)

* Add global week start option to shared preferences

* Add default_week_start to configuration docs

* Add week start option to dashboards

* Add week start argument to tsdb time range parser

* Fix strict check issues

* Add tests for week start

* Change wording on default_week_start documentation

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Update week_start column to be a nullable field

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>

* Update configuration to include browser option

* Update WeekStartPicker container selector

Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>

* Add menuShouldPortal to WeekStartPicker to remove deprecation warning

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Add inputId to WeekStartPicker

* Use e2e selector on WeekStartPicker aria-label

* Simplify WeekStartPicker onChange condition

* Specify value type on WeekStartPicker weekStarts

* Remove setWeekStart side effect from reducer

* Fix updateLocale failing to reset week start

* Store week start as string to handle empty values

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
This commit is contained in:
Guilherme Caulada
2021-10-18 10:27:14 -03:00
committed by GitHub
co-authored by achatterjee-grafana Emil Tullstedt Hugo Häggmark Alex Khomenko
parent db62ce477d
commit a9faab6b09
27 changed files with 362 additions and 21 deletions
@@ -7,6 +7,7 @@ import {
setUpdating,
teamsLoaded,
updateTimeZone,
updateWeekStart,
userLoaded,
userReducer,
userSessionRevoked,
@@ -33,6 +34,15 @@ describe('userReducer', () => {
});
});
describe('when updateWeekStart is dispatched', () => {
it('then state should be correct', () => {
reducerTester<UserState>()
.givenReducer(userReducer, { ...initialUserState })
.whenActionIsDispatched(updateWeekStart({ weekStart: 'xyz' }))
.thenStateShouldEqual({ ...initialUserState, weekStart: 'xyz' });
});
});
describe('when setUpdating is dispatched', () => {
it('then state should be correct', () => {
reducerTester<UserState>()
+19 -1
View File
@@ -1,6 +1,6 @@
import { isEmpty, isString, set } from 'lodash';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { dateTimeFormat, dateTimeFormatTimeAgo, TimeZone } from '@grafana/data';
import { dateTimeFormat, dateTimeFormatTimeAgo, setWeekStart, TimeZone } from '@grafana/data';
import { Team, ThunkResult, UserDTO, UserOrg, UserSession } from 'app/types';
import config from 'app/core/config';
@@ -9,6 +9,7 @@ import { contextSrv } from 'app/core/core';
export interface UserState {
orgId: number;
timeZone: TimeZone;
weekStart: string;
fiscalYearStartMonth: number;
user: UserDTO | null;
teams: Team[];
@@ -23,6 +24,7 @@ export interface UserState {
export const initialUserState: UserState = {
orgId: config.bootData.user.orgId,
timeZone: config.bootData.user.timezone,
weekStart: config.bootData.user.weekStart,
fiscalYearStartMonth: 0,
orgsAreLoading: false,
sessionsAreLoading: false,
@@ -41,6 +43,9 @@ export const slice = createSlice({
updateTimeZone: (state, action: PayloadAction<{ timeZone: TimeZone }>) => {
state.timeZone = action.payload.timeZone;
},
updateWeekStart: (state, action: PayloadAction<{ weekStart: string }>) => {
state.weekStart = action.payload.weekStart;
},
updateFiscalYearStartMonth: (state, action: PayloadAction<{ fiscalYearStartMonth: number }>) => {
state.fiscalYearStartMonth = action.payload.fiscalYearStartMonth;
},
@@ -110,6 +115,18 @@ export const updateTimeZoneForSession = (timeZone: TimeZone): ThunkResult<void>
};
};
export const updateWeekStartForSession = (weekStart: string): ThunkResult<void> => {
return async (dispatch) => {
if (!isString(weekStart) || isEmpty(weekStart)) {
weekStart = config?.bootData?.user?.weekStart;
}
set(contextSrv, 'user.weekStart', weekStart);
dispatch(updateWeekStart({ weekStart }));
setWeekStart(weekStart);
};
};
export const {
setUpdating,
initLoadOrgs,
@@ -121,6 +138,7 @@ export const {
initLoadSessions,
sessionsLoaded,
updateTimeZone,
updateWeekStart,
updateFiscalYearStartMonth,
} = slice.actions;