dashfolders: Clean up more variables and move newType, aclTypes and permissionOptions to the store #10275

This commit is contained in:
Johannes Schill
2018-01-18 21:24:55 +01:00
committed by Daniel Lee
parent 4ea9f3027a
commit 0722ea04a6
4 changed files with 35 additions and 45 deletions

View File

@@ -3,6 +3,17 @@ import { PermissionsStoreItem } from './PermissionsStoreItem';
const duplicateError = 'This permission exists already.';
export const permissionOptions = [{ value: 1, text: 'View' }, { value: 2, text: 'Edit' }, { value: 4, text: 'Admin' }];
export const aclTypes = [
{ value: 'Group', text: 'Team' },
{ value: 'User', text: 'User' },
{ value: 'Viewer', text: 'Everyone With Viewer Role' },
{ value: 'Editor', text: 'Everyone With Editor Role' },
];
const defaultNewType = aclTypes[0].value;
export const PermissionsStore = types
.model('PermissionsStore', {
fetching: types.boolean,
@@ -12,6 +23,7 @@ export const PermissionsStore = types
items: types.optional(types.array(PermissionsStoreItem), []),
error: types.maybe(types.string),
originalItems: types.optional(types.array(PermissionsStoreItem), []),
newType: types.optional(types.string, defaultNewType),
})
.views(self => ({
isValid: item => {
@@ -58,6 +70,12 @@ export const PermissionsStore = types
self.items[idx].updatePermission(permission, permissionName);
self.canUpdate = true;
},
setNewType(newType: string) {
self.newType = newType;
},
resetNewType() {
self.newType = defaultNewType;
},
update: flow(function* update(dashboardId: number) {
self.error = null;
const backendSrv = getEnv(self).backendSrv;