From 58e94fc0fa0a4ca00af4ce2ec3a081573c602035 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 30 Oct 2018 13:09:59 +0100 Subject: [PATCH] moved state --- public/app/core/actions/user.ts | 28 +++++++++++++++++++ public/app/core/reducers/index.ts | 2 ++ public/app/core/reducers/user.ts | 15 ++++++++++ .../app/features/dashboard/state/actions.ts | 12 -------- public/app/features/org/OrgDetailsPage.tsx | 2 +- public/app/features/org/OrgPreferences.tsx | 2 +- public/app/features/org/state/actions.ts | 9 +----- public/app/features/org/state/reducers.ts | 6 +--- public/app/types/index.ts | 4 ++- public/app/types/organization.ts | 3 -- public/app/types/user.ts | 8 +++++- 11 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 public/app/core/actions/user.ts create mode 100644 public/app/core/reducers/user.ts diff --git a/public/app/core/actions/user.ts b/public/app/core/actions/user.ts new file mode 100644 index 00000000000..dba0588c058 --- /dev/null +++ b/public/app/core/actions/user.ts @@ -0,0 +1,28 @@ +import { ThunkAction } from 'redux-thunk'; +import { getBackendSrv } from '../services/backend_srv'; +import { DashboardAcl, DashboardSearchHit, StoreState } from '../../types'; + +type ThunkResult = ThunkAction; + +export type Action = LoadStarredDashboardsAction; + +export enum ActionTypes { + LoadStarredDashboards = 'LOAD_STARRED_DASHBOARDS', +} + +interface LoadStarredDashboardsAction { + type: ActionTypes.LoadStarredDashboards; + payload: DashboardSearchHit[]; +} + +const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({ + type: ActionTypes.LoadStarredDashboards, + payload: dashboards, +}); + +export function loadStarredDashboards(): ThunkResult { + return async dispatch => { + const starredDashboards = await getBackendSrv().search({ starred: true }); + dispatch(starredDashboardsLoaded(starredDashboards)); + }; +} diff --git a/public/app/core/reducers/index.ts b/public/app/core/reducers/index.ts index 1c8670ed0d6..6455849ab46 100644 --- a/public/app/core/reducers/index.ts +++ b/public/app/core/reducers/index.ts @@ -1,9 +1,11 @@ import { navIndexReducer as navIndex } from './navModel'; import { locationReducer as location } from './location'; import { appNotificationsReducer as appNotifications } from './appNotification'; +import { userReducer as user } from './user'; export default { navIndex, location, appNotifications, + user, }; diff --git a/public/app/core/reducers/user.ts b/public/app/core/reducers/user.ts new file mode 100644 index 00000000000..d49395060ce --- /dev/null +++ b/public/app/core/reducers/user.ts @@ -0,0 +1,15 @@ +import { DashboardSearchHit, UserState } from '../../types'; +import { Action, ActionTypes } from '../actions/user'; + +const initialState: UserState = { + starredDashboards: [] as DashboardSearchHit[], +}; + +export const userReducer = (state: UserState = initialState, action: Action): UserState => { + switch (action.type) { + case ActionTypes.LoadStarredDashboards: + return { ...state, starredDashboards: action.payload }; + } + + return state; +}; diff --git a/public/app/features/dashboard/state/actions.ts b/public/app/features/dashboard/state/actions.ts index d5e3024e7b5..bc35ff31ff0 100644 --- a/public/app/features/dashboard/state/actions.ts +++ b/public/app/features/dashboard/state/actions.ts @@ -35,11 +35,6 @@ export const loadDashboardPermissions = (items: DashboardAclDTO[]): LoadDashboar payload: items, }); -const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({ - type: ActionTypes.LoadStarredDashboards, - payload: dashboards, -}); - export function getDashboardPermissions(id: number): ThunkResult { return async dispatch => { const permissions = await getBackendSrv().get(`/api/dashboards/id/${id}/permissions`); @@ -47,13 +42,6 @@ export function getDashboardPermissions(id: number): ThunkResult { }; } -export function loadStarredDashboards(): ThunkResult { - return async dispatch => { - const starredDashboards = await getBackendSrv().search({ starred: true }); - dispatch(starredDashboardsLoaded(starredDashboards)); - }; -} - function toUpdateItem(item: DashboardAcl): DashboardAclUpdateDTO { return { userId: item.userId, diff --git a/public/app/features/org/OrgDetailsPage.tsx b/public/app/features/org/OrgDetailsPage.tsx index fa065ba4f66..86a3fab3268 100644 --- a/public/app/features/org/OrgDetailsPage.tsx +++ b/public/app/features/org/OrgDetailsPage.tsx @@ -11,7 +11,7 @@ import { setOrganizationName, updateOrganization, } from './state/actions'; -import { loadStarredDashboards } from '../dashboard/state/actions'; +import { loadStarredDashboards } from '../../core/actions/user'; import { NavModel, Organization, OrganizationPreferences, StoreState } from 'app/types'; import { getNavModel } from '../../core/selectors/navModel'; diff --git a/public/app/features/org/OrgPreferences.tsx b/public/app/features/org/OrgPreferences.tsx index 4600aeb0a7b..a8133ba4a1c 100644 --- a/public/app/features/org/OrgPreferences.tsx +++ b/public/app/features/org/OrgPreferences.tsx @@ -99,7 +99,7 @@ export class OrgPreferences extends PureComponent { function mapStateToProps(state) { return { preferences: state.organization.preferences, - starredDashboards: state.organization.starredDashboards, + starredDashboards: state.user.starredDashboards, }; } diff --git a/public/app/features/org/state/actions.ts b/public/app/features/org/state/actions.ts index 18ac0cac7ac..719364d26de 100644 --- a/public/app/features/org/state/actions.ts +++ b/public/app/features/org/state/actions.ts @@ -1,5 +1,5 @@ import { ThunkAction } from 'redux-thunk'; -import { DashboardSearchHit, Organization, OrganizationPreferences, StoreState } from 'app/types'; +import { Organization, OrganizationPreferences, StoreState } from 'app/types'; import { getBackendSrv } from '../../../core/services/backend_srv'; type ThunkResult = ThunkAction; @@ -7,7 +7,6 @@ type ThunkResult = ThunkAction; export enum ActionTypes { LoadOrganization = 'LOAD_ORGANISATION', LoadPreferences = 'LOAD_PREFERENCES', - LoadStarredDashboards = 'LOAD_STARRED_DASHBOARDS', SetOrganizationName = 'SET_ORGANIZATION_NAME', SetOrganizationTheme = 'SET_ORGANIZATION_THEME', SetOrganizationHomeDashboard = 'SET_ORGANIZATION_HOME_DASHBOARD', @@ -24,11 +23,6 @@ interface LoadPreferencesAction { payload: OrganizationPreferences; } -interface LoadStarredDashboardsAction { - type: ActionTypes.LoadStarredDashboards; - payload: DashboardSearchHit[]; -} - interface SetOrganizationNameAction { type: ActionTypes.SetOrganizationName; payload: string; @@ -82,7 +76,6 @@ export const setOrganizationTimezone = (timezone: string) => ({ export type Action = | LoadOrganizationAction | LoadPreferencesAction - | LoadStarredDashboardsAction | SetOrganizationNameAction | SetOrganizationThemeAction | SetOrganizationHomeDashboardAction diff --git a/public/app/features/org/state/reducers.ts b/public/app/features/org/state/reducers.ts index 02ffa0d3423..b79f915a731 100644 --- a/public/app/features/org/state/reducers.ts +++ b/public/app/features/org/state/reducers.ts @@ -1,10 +1,9 @@ -import { DashboardSearchHit, Organization, OrganizationPreferences, OrganizationState } from 'app/types'; +import { Organization, OrganizationPreferences, OrganizationState } from 'app/types'; import { Action, ActionTypes } from './actions'; const initialState: OrganizationState = { organization: {} as Organization, preferences: {} as OrganizationPreferences, - starredDashboards: [] as DashboardSearchHit[], }; const organizationReducer = (state = initialState, action: Action): OrganizationState => { @@ -15,9 +14,6 @@ const organizationReducer = (state = initialState, action: Action): Organization case ActionTypes.LoadPreferences: return { ...state, preferences: action.payload }; - case ActionTypes.LoadStarredDashboards: - return { ...state, starredDashboards: action.payload }; - case ActionTypes.SetOrganizationName: return { ...state, organization: { ...state.organization, name: action.payload } }; diff --git a/public/app/types/index.ts b/public/app/types/index.ts index f99e8046289..c51622682d4 100644 --- a/public/app/types/index.ts +++ b/public/app/types/index.ts @@ -6,7 +6,7 @@ import { FolderDTO, FolderState, FolderInfo } from './folders'; import { DashboardState } from './dashboard'; import { DashboardAcl, OrgRole, PermissionLevel } from './acl'; import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys'; -import { Invitee, OrgUser, User, UsersState } from './user'; +import { Invitee, OrgUser, User, UsersState, UserState } from './user'; import { DataSource, DataSourcesState } from './datasources'; import { TimeRange, @@ -86,6 +86,7 @@ export { AppNotificationSeverity, AppNotificationTimeout, DashboardSearchHit, + UserState, }; export interface StoreState { @@ -100,4 +101,5 @@ export interface StoreState { users: UsersState; organization: OrganizationState; appNotifications: AppNotificationsState; + user: UserState; } diff --git a/public/app/types/organization.ts b/public/app/types/organization.ts index f525ecc6d83..52cb130e082 100644 --- a/public/app/types/organization.ts +++ b/public/app/types/organization.ts @@ -1,5 +1,3 @@ -import { DashboardSearchHit } from './search'; - export interface Organization { name: string; id: number; @@ -14,5 +12,4 @@ export interface OrganizationPreferences { export interface OrganizationState { organization: Organization; preferences: OrganizationPreferences; - starredDashboards: DashboardSearchHit[]; } diff --git a/public/app/types/user.ts b/public/app/types/user.ts index c0b7b135ff8..37c80074dca 100644 --- a/public/app/types/user.ts +++ b/public/app/types/user.ts @@ -1,4 +1,6 @@ -export interface OrgUser { +import { DashboardSearchHit } from './search'; + +export interface OrgUser { avatarUrl: string; email: string; lastSeenAt: string; @@ -43,3 +45,7 @@ export interface UsersState { externalUserMngInfo: string; hasFetched: boolean; } + +export interface UserState { + starredDashboards: DashboardSearchHit[]; +}