grafana/public/app/features/folders/state/reducers.ts

42 lines
937 B
TypeScript
Raw Normal View History

2018-09-13 06:56:09 -05:00
import { FolderState } from 'app/types';
2018-09-10 14:49:04 -05:00
import { Action, ActionTypes } from './actions';
2018-09-13 09:00:02 -05:00
import { processAclItems } from 'app/core/utils/acl';
2018-09-10 14:49:04 -05:00
2018-09-11 03:36:55 -05:00
export const inititalState: FolderState = {
id: 0,
2018-09-11 03:36:55 -05:00
uid: 'loading',
title: 'loading',
url: '',
2018-09-11 03:36:55 -05:00
canSave: false,
hasChanged: false,
version: 1,
permissions: [],
2018-09-11 03:36:55 -05:00
};
2018-09-10 14:49:04 -05:00
export const folderReducer = (state = inititalState, action: Action): FolderState => {
switch (action.type) {
case ActionTypes.LoadFolder:
return {
...state,
2018-09-10 14:49:04 -05:00
...action.payload,
hasChanged: false,
};
case ActionTypes.SetFolderTitle:
return {
...state,
title: action.payload,
hasChanged: action.payload.trim().length > 0,
};
case ActionTypes.LoadFolderPermissions:
return {
...state,
permissions: processAclItems(action.payload),
};
2018-09-10 14:49:04 -05:00
}
return state;
};
export default {
folder: folderReducer,
};