mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { isString, isEmpty, set } from 'lodash';
|
|
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
|
|
import { UserState, ThunkResult } from 'app/types';
|
|
import config from 'app/core/config';
|
|
import { TimeZone } from '@grafana/data';
|
|
import { contextSrv } from 'app/core/core';
|
|
|
|
export const initialState: UserState = {
|
|
orgId: config.bootData.user.orgId,
|
|
timeZone: config.bootData.user.timezone,
|
|
};
|
|
|
|
export const slice = createSlice({
|
|
name: 'user/profile',
|
|
initialState,
|
|
reducers: {
|
|
updateTimeZone: (state, action: PayloadAction<TimeZone>): UserState => {
|
|
return {
|
|
...state,
|
|
timeZone: action.payload,
|
|
};
|
|
},
|
|
},
|
|
});
|
|
|
|
export const updateTimeZoneForSession = (timeZone: TimeZone): ThunkResult<void> => {
|
|
return async (dispatch) => {
|
|
const { updateTimeZone } = slice.actions;
|
|
|
|
if (!isString(timeZone) || isEmpty(timeZone)) {
|
|
timeZone = config?.bootData?.user?.timezone;
|
|
}
|
|
|
|
set(contextSrv, 'user.timezone', timeZone);
|
|
dispatch(updateTimeZone(timeZone));
|
|
};
|
|
};
|
|
|
|
export const userReducer = slice.reducer;
|
|
export default { user: slice.reducer };
|