Commit 679ffbfd by Torkel Ödegaard

wip: progress on redux folder store

parent 9caa0301
import { updateLocation } from './location';
import { updateNavIndex } from './navModel';
import { updateNavIndex, UpdateNavIndexAction } from './navModel';
export { updateLocation, updateNavIndex };
export { updateLocation, updateNavIndex, UpdateNavIndexAction };
import { getBackendSrv } from 'app/core/services/backend_srv';
import { StoreState } from 'app/types';
import { ThunkAction } from 'redux-thunk';
import { FolderDTO } from 'app/types';
import { FolderDTO, NavModelItem } from 'app/types';
import { updateNavIndex, UpdateNavIndexAction } from 'app/core/actions';
export enum ActionTypes {
LoadFolder = 'LOAD_FOLDER',
......@@ -19,11 +20,45 @@ export const loadFolder = (folder: FolderDTO): LoadFolderAction => ({
export type Action = LoadFolderAction;
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action | UpdateNavIndexAction>;
function buildNavModel(folder: FolderDTO): NavModelItem {
return {
icon: 'fa fa-folder-open',
id: 'manage-folder',
subTitle: 'Manage folder dashboards & permissions',
url: '',
text: folder.title,
breadcrumbs: [{ title: 'Dashboards', url: 'dashboards' }],
children: [
{
active: false,
icon: 'fa fa-fw fa-th-large',
id: `folder-dashboards-${folder.uid}`,
text: 'Dashboards',
url: folder.url,
},
{
active: false,
icon: 'fa fa-fw fa-lock',
id: `folder-permissions-${folder.uid}`,
text: 'Permissions',
url: `${folder.url}/permissions`,
},
{
active: false,
icon: 'fa fa-fw fa-cog',
id: `folder-settings-${folder.uid}`,
text: 'Settings',
url: `${folder.url}/settings`,
},
],
};
}
export function getFolderByUid(uid: string): ThunkResult<void> {
return async dispatch => {
const folder = await getBackendSrv().getFolderByUid(uid);
dispatch(loadFolder(folder));
dispatch(updateNavIndex(buildNavModel(folder)));
};
}
import { FolderState } from 'app/types';
import { Action, ActionTypes } from './actions';
export const inititalState: FolderState = null;
export const folderReducer = (state = inititalState, action: Action): FolderState => {
switch (action.type) {
case ActionTypes.LoadFolder:
return {
...action.payload,
canSave: false,
hasChanged: false,
};
}
return state;
};
export default {
folder: folderReducer,
};
......@@ -4,11 +4,13 @@ import { createLogger } from 'redux-logger';
import sharedReducers from 'app/core/reducers';
import alertingReducers from 'app/features/alerting/state/reducers';
import teamsReducers from 'app/features/teams/state/reducers';
import manageDashboardsReducers from 'app/features/manage-dashboards/state/reducers';
const rootReducer = combineReducers({
...sharedReducers,
...alertingReducers,
...teamsReducers,
...manageDashboardsReducers,
});
export let store;
......
export interface FolderDTO {
id: number;
uid: string;
title: string;
url: string;
version: number;
hasAcl: boolean;
}
export interface FolderState {
id: number;
uid: string;
title: string;
url: string;
version: number;
canSave: boolean;
hasChanged: boolean;
}
import { FolderDTO } from './dashboard';
import { FolderDTO, FolderState } from './dashboard';
export { FolderDTO };
export { FolderDTO, FolderState };
//
// Location
......@@ -136,4 +136,5 @@ export interface StoreState {
alertRules: AlertRulesState;
teams: TeamsState;
team: TeamState;
folder: FolderState;
}
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