Commit 58e94fc0 by Peter Holmberg

moved state

parent 7a10bf01
import { ThunkAction } from 'redux-thunk';
import { getBackendSrv } from '../services/backend_srv';
import { DashboardAcl, DashboardSearchHit, StoreState } from '../../types';
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>;
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<void> {
return async dispatch => {
const starredDashboards = await getBackendSrv().search({ starred: true });
dispatch(starredDashboardsLoaded(starredDashboards));
};
}
import { navIndexReducer as navIndex } from './navModel'; import { navIndexReducer as navIndex } from './navModel';
import { locationReducer as location } from './location'; import { locationReducer as location } from './location';
import { appNotificationsReducer as appNotifications } from './appNotification'; import { appNotificationsReducer as appNotifications } from './appNotification';
import { userReducer as user } from './user';
export default { export default {
navIndex, navIndex,
location, location,
appNotifications, appNotifications,
user,
}; };
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;
};
...@@ -35,11 +35,6 @@ export const loadDashboardPermissions = (items: DashboardAclDTO[]): LoadDashboar ...@@ -35,11 +35,6 @@ export const loadDashboardPermissions = (items: DashboardAclDTO[]): LoadDashboar
payload: items, payload: items,
}); });
const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({
type: ActionTypes.LoadStarredDashboards,
payload: dashboards,
});
export function getDashboardPermissions(id: number): ThunkResult<void> { export function getDashboardPermissions(id: number): ThunkResult<void> {
return async dispatch => { return async dispatch => {
const permissions = await getBackendSrv().get(`/api/dashboards/id/${id}/permissions`); const permissions = await getBackendSrv().get(`/api/dashboards/id/${id}/permissions`);
...@@ -47,13 +42,6 @@ export function getDashboardPermissions(id: number): ThunkResult<void> { ...@@ -47,13 +42,6 @@ export function getDashboardPermissions(id: number): ThunkResult<void> {
}; };
} }
export function loadStarredDashboards(): ThunkResult<void> {
return async dispatch => {
const starredDashboards = await getBackendSrv().search({ starred: true });
dispatch(starredDashboardsLoaded(starredDashboards));
};
}
function toUpdateItem(item: DashboardAcl): DashboardAclUpdateDTO { function toUpdateItem(item: DashboardAcl): DashboardAclUpdateDTO {
return { return {
userId: item.userId, userId: item.userId,
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
setOrganizationName, setOrganizationName,
updateOrganization, updateOrganization,
} from './state/actions'; } from './state/actions';
import { loadStarredDashboards } from '../dashboard/state/actions'; import { loadStarredDashboards } from '../../core/actions/user';
import { NavModel, Organization, OrganizationPreferences, StoreState } from 'app/types'; import { NavModel, Organization, OrganizationPreferences, StoreState } from 'app/types';
import { getNavModel } from '../../core/selectors/navModel'; import { getNavModel } from '../../core/selectors/navModel';
......
...@@ -99,7 +99,7 @@ export class OrgPreferences extends PureComponent<Props> { ...@@ -99,7 +99,7 @@ export class OrgPreferences extends PureComponent<Props> {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
preferences: state.organization.preferences, preferences: state.organization.preferences,
starredDashboards: state.organization.starredDashboards, starredDashboards: state.user.starredDashboards,
}; };
} }
......
import { ThunkAction } from 'redux-thunk'; 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'; import { getBackendSrv } from '../../../core/services/backend_srv';
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>; type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>;
...@@ -7,7 +7,6 @@ type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>; ...@@ -7,7 +7,6 @@ type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>;
export enum ActionTypes { export enum ActionTypes {
LoadOrganization = 'LOAD_ORGANISATION', LoadOrganization = 'LOAD_ORGANISATION',
LoadPreferences = 'LOAD_PREFERENCES', LoadPreferences = 'LOAD_PREFERENCES',
LoadStarredDashboards = 'LOAD_STARRED_DASHBOARDS',
SetOrganizationName = 'SET_ORGANIZATION_NAME', SetOrganizationName = 'SET_ORGANIZATION_NAME',
SetOrganizationTheme = 'SET_ORGANIZATION_THEME', SetOrganizationTheme = 'SET_ORGANIZATION_THEME',
SetOrganizationHomeDashboard = 'SET_ORGANIZATION_HOME_DASHBOARD', SetOrganizationHomeDashboard = 'SET_ORGANIZATION_HOME_DASHBOARD',
...@@ -24,11 +23,6 @@ interface LoadPreferencesAction { ...@@ -24,11 +23,6 @@ interface LoadPreferencesAction {
payload: OrganizationPreferences; payload: OrganizationPreferences;
} }
interface LoadStarredDashboardsAction {
type: ActionTypes.LoadStarredDashboards;
payload: DashboardSearchHit[];
}
interface SetOrganizationNameAction { interface SetOrganizationNameAction {
type: ActionTypes.SetOrganizationName; type: ActionTypes.SetOrganizationName;
payload: string; payload: string;
...@@ -82,7 +76,6 @@ export const setOrganizationTimezone = (timezone: string) => ({ ...@@ -82,7 +76,6 @@ export const setOrganizationTimezone = (timezone: string) => ({
export type Action = export type Action =
| LoadOrganizationAction | LoadOrganizationAction
| LoadPreferencesAction | LoadPreferencesAction
| LoadStarredDashboardsAction
| SetOrganizationNameAction | SetOrganizationNameAction
| SetOrganizationThemeAction | SetOrganizationThemeAction
| SetOrganizationHomeDashboardAction | SetOrganizationHomeDashboardAction
......
import { DashboardSearchHit, Organization, OrganizationPreferences, OrganizationState } from 'app/types'; import { Organization, OrganizationPreferences, OrganizationState } from 'app/types';
import { Action, ActionTypes } from './actions'; import { Action, ActionTypes } from './actions';
const initialState: OrganizationState = { const initialState: OrganizationState = {
organization: {} as Organization, organization: {} as Organization,
preferences: {} as OrganizationPreferences, preferences: {} as OrganizationPreferences,
starredDashboards: [] as DashboardSearchHit[],
}; };
const organizationReducer = (state = initialState, action: Action): OrganizationState => { const organizationReducer = (state = initialState, action: Action): OrganizationState => {
...@@ -15,9 +14,6 @@ const organizationReducer = (state = initialState, action: Action): Organization ...@@ -15,9 +14,6 @@ const organizationReducer = (state = initialState, action: Action): Organization
case ActionTypes.LoadPreferences: case ActionTypes.LoadPreferences:
return { ...state, preferences: action.payload }; return { ...state, preferences: action.payload };
case ActionTypes.LoadStarredDashboards:
return { ...state, starredDashboards: action.payload };
case ActionTypes.SetOrganizationName: case ActionTypes.SetOrganizationName:
return { ...state, organization: { ...state.organization, name: action.payload } }; return { ...state, organization: { ...state.organization, name: action.payload } };
......
...@@ -6,7 +6,7 @@ import { FolderDTO, FolderState, FolderInfo } from './folders'; ...@@ -6,7 +6,7 @@ import { FolderDTO, FolderState, FolderInfo } from './folders';
import { DashboardState } from './dashboard'; import { DashboardState } from './dashboard';
import { DashboardAcl, OrgRole, PermissionLevel } from './acl'; import { DashboardAcl, OrgRole, PermissionLevel } from './acl';
import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys'; 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 { DataSource, DataSourcesState } from './datasources';
import { import {
TimeRange, TimeRange,
...@@ -86,6 +86,7 @@ export { ...@@ -86,6 +86,7 @@ export {
AppNotificationSeverity, AppNotificationSeverity,
AppNotificationTimeout, AppNotificationTimeout,
DashboardSearchHit, DashboardSearchHit,
UserState,
}; };
export interface StoreState { export interface StoreState {
...@@ -100,4 +101,5 @@ export interface StoreState { ...@@ -100,4 +101,5 @@ export interface StoreState {
users: UsersState; users: UsersState;
organization: OrganizationState; organization: OrganizationState;
appNotifications: AppNotificationsState; appNotifications: AppNotificationsState;
user: UserState;
} }
import { DashboardSearchHit } from './search';
export interface Organization { export interface Organization {
name: string; name: string;
id: number; id: number;
...@@ -14,5 +12,4 @@ export interface OrganizationPreferences { ...@@ -14,5 +12,4 @@ export interface OrganizationPreferences {
export interface OrganizationState { export interface OrganizationState {
organization: Organization; organization: Organization;
preferences: OrganizationPreferences; preferences: OrganizationPreferences;
starredDashboards: DashboardSearchHit[];
} }
export interface OrgUser { import { DashboardSearchHit } from './search';
export interface OrgUser {
avatarUrl: string; avatarUrl: string;
email: string; email: string;
lastSeenAt: string; lastSeenAt: string;
...@@ -43,3 +45,7 @@ export interface UsersState { ...@@ -43,3 +45,7 @@ export interface UsersState {
externalUserMngInfo: string; externalUserMngInfo: string;
hasFetched: boolean; hasFetched: boolean;
} }
export interface UserState {
starredDashboards: DashboardSearchHit[];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment