Commit e6b82b2f by Torkel Ödegaard

fix: fixed permission list caching issue, fixes #10750

parent 2d1bd270
import React, { Component } from 'react'; import React, { Component } from 'react';
import { inject, observer } from 'mobx-react'; import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx'; import { toJS } from 'mobx';
import IContainerProps from 'app/containers/IContainerProps'; import IContainerProps from 'app/containers/IContainerProps';
...@@ -8,6 +8,7 @@ import Tooltip from 'app/core/components/Tooltip/Tooltip'; ...@@ -8,6 +8,7 @@ import Tooltip from 'app/core/components/Tooltip/Tooltip';
import PermissionsInfo from 'app/core/components/Permissions/PermissionsInfo'; import PermissionsInfo from 'app/core/components/Permissions/PermissionsInfo';
import AddPermissions from 'app/core/components/Permissions/AddPermissions'; import AddPermissions from 'app/core/components/Permissions/AddPermissions';
import SlideDown from 'app/core/components/Animations/SlideDown'; import SlideDown from 'app/core/components/Animations/SlideDown';
@inject('nav', 'folder', 'view', 'permissions') @inject('nav', 'folder', 'view', 'permissions')
@observer @observer
export class FolderPermissions extends Component<IContainerProps, any> { export class FolderPermissions extends Component<IContainerProps, any> {
......
...@@ -14,6 +14,7 @@ describe('FolderSettings', () => { ...@@ -14,6 +14,7 @@ describe('FolderSettings', () => {
dashboard: { dashboard: {
id: 1, id: 1,
title: 'Folder Name', title: 'Folder Name',
uid: 'uid-str',
}, },
meta: { meta: {
url: '/dashboards/f/uid/folder-name', url: '/dashboards/f/uid/folder-name',
...@@ -23,19 +24,27 @@ describe('FolderSettings', () => { ...@@ -23,19 +24,27 @@ describe('FolderSettings', () => {
); );
const store = RootStore.create( const store = RootStore.create(
{}, {
view: {
path: 'asd',
query: {},
routeParams: {
uid: 'uid-str',
},
},
},
{ {
backendSrv: backendSrv, backendSrv: backendSrv,
} }
); );
wrapper = shallow(<FolderSettings backendSrv={backendSrv} {...store} />); wrapper = shallow(<FolderSettings backendSrv={backendSrv} {...store} />);
return wrapper page = wrapper.dive();
.dive() return page
.instance() .instance()
.loadStore() .loadStore()
.then(() => { .then(() => {
page = wrapper.dive(); page.update();
}); });
}); });
......
...@@ -5,6 +5,7 @@ export const Folder = types.model('Folder', { ...@@ -5,6 +5,7 @@ export const Folder = types.model('Folder', {
title: types.string, title: types.string,
url: types.string, url: types.string,
canSave: types.boolean, canSave: types.boolean,
uid: types.string,
hasChanged: types.boolean, hasChanged: types.boolean,
}); });
...@@ -14,15 +15,23 @@ export const FolderStore = types ...@@ -14,15 +15,23 @@ export const FolderStore = types
}) })
.actions(self => ({ .actions(self => ({
load: flow(function* load(uid: string) { load: flow(function* load(uid: string) {
// clear folder state
if (self.folder && self.folder.uid !== uid) {
self.folder = null;
}
const backendSrv = getEnv(self).backendSrv; const backendSrv = getEnv(self).backendSrv;
const res = yield backendSrv.getDashboardByUid(uid); const res = yield backendSrv.getDashboardByUid(uid);
self.folder = Folder.create({ self.folder = Folder.create({
id: res.dashboard.id, id: res.dashboard.id,
title: res.dashboard.title, title: res.dashboard.title,
url: res.meta.url, url: res.meta.url,
uid: res.dashboard.uid,
canSave: res.meta.canSave, canSave: res.meta.canSave,
hasChanged: false, hasChanged: false,
}); });
return res; return res;
}), }),
......
...@@ -115,6 +115,7 @@ export const PermissionsStore = types ...@@ -115,6 +115,7 @@ export const PermissionsStore = types
self.fetching = false; self.fetching = false;
self.error = null; self.error = null;
}), }),
addStoreItem: flow(function* addStoreItem() { addStoreItem: flow(function* addStoreItem() {
self.error = null; self.error = null;
let item = { let item = {
...@@ -152,11 +153,13 @@ export const PermissionsStore = types ...@@ -152,11 +153,13 @@ export const PermissionsStore = types
resetNewType(); resetNewType();
return updateItems(self); return updateItems(self);
}), }),
removeStoreItem: flow(function* removeStoreItem(idx: number) { removeStoreItem: flow(function* removeStoreItem(idx: number) {
self.error = null; self.error = null;
self.items.splice(idx, 1); self.items.splice(idx, 1);
return updateItems(self); return updateItems(self);
}), }),
updatePermissionOnIndex: flow(function* updatePermissionOnIndex( updatePermissionOnIndex: flow(function* updatePermissionOnIndex(
idx: number, idx: number,
permission: number, permission: number,
...@@ -166,18 +169,19 @@ export const PermissionsStore = types ...@@ -166,18 +169,19 @@ export const PermissionsStore = types
self.items[idx].updatePermission(permission, permissionName); self.items[idx].updatePermission(permission, permissionName);
return updateItems(self); return updateItems(self);
}), }),
setNewType(newType: string) { setNewType(newType: string) {
self.newItem = NewPermissionsItem.create({ type: newType }); self.newItem = NewPermissionsItem.create({ type: newType });
}, },
resetNewType() { resetNewType() {
resetNewType(); resetNewType();
}, },
toggleAddPermissions() { toggleAddPermissions() {
self.isAddPermissionsVisible = !self.isAddPermissionsVisible; self.isAddPermissionsVisible = !self.isAddPermissionsVisible;
}, },
showAddPermissions() {
self.isAddPermissionsVisible = true;
},
hideAddPermissions() { hideAddPermissions() {
self.isAddPermissionsVisible = false; self.isAddPermissionsVisible = false;
}, },
......
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