Commit cc55ab6b by Daniel Lee

dashfolders: adds permission modal to dashboard settings

parent 9cdc1428
...@@ -53,8 +53,7 @@ export class FolderPermissions extends Component<IContainerProps, any> { ...@@ -53,8 +53,7 @@ export class FolderPermissions extends Component<IContainerProps, any> {
onClick={this.handleAddPermission} onClick={this.handleAddPermission}
disabled={permissions.isAddPermissionsVisible} disabled={permissions.isAddPermissionsVisible}
> >
<i className="fa fa-plus" /> <i className="fa fa-plus" /> Add Permission
Add Permission
</button> </button>
</div> </div>
<SlideDown in={permissions.isAddPermissionsVisible}> <SlideDown in={permissions.isAddPermissionsVisible}>
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { store } from 'app/stores/store'; import { store } from 'app/stores/store';
import Permissions from 'app/core/components/Permissions/Permissions'; import Permissions from 'app/core/components/Permissions/Permissions';
import Tooltip from 'app/core/components/Tooltip/Tooltip'; 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 SlideDown from 'app/core/components/Animations/SlideDown';
export interface IProps { export interface IProps {
dashboardId: number; dashboardId: number;
...@@ -11,26 +14,44 @@ export interface IProps { ...@@ -11,26 +14,44 @@ export interface IProps {
folderSlug: string; folderSlug: string;
backendSrv: any; backendSrv: any;
} }
@observer
class DashboardPermissions extends Component<IProps, any> { class DashboardPermissions extends Component<IProps, any> {
permissions: any; permissions: any;
constructor(props) { constructor(props) {
super(props); super(props);
this.handleAddPermission = this.handleAddPermission.bind(this);
this.permissions = store.permissions; this.permissions = store.permissions;
} }
handleAddPermission() {
this.permissions.toggleAddPermissions();
}
render() { render() {
const { dashboardId, folderTitle, folderSlug, folderId, backendSrv } = this.props; const { dashboardId, folderTitle, folderSlug, folderId, backendSrv } = this.props;
return ( return (
<div> <div>
<div className="dashboard-settings__header"> <div className="dashboard-settings__header">
<h3 className="d-inline-block">Permissions</h3> <div className="page-action-bar">
<Tooltip className="page-sub-heading-icon" placement="auto" content={PermissionsInfo}> <h3 className="d-inline-block">Permissions</h3>
<i className="gicon gicon-question gicon--has-hover" /> <Tooltip className="page-sub-heading-icon" placement="auto" content={PermissionsInfo}>
</Tooltip> <i className="gicon gicon-question gicon--has-hover" />
</Tooltip>
<div className="page-action-bar__spacer" />
<button
className="btn btn-success pull-right"
onClick={this.handleAddPermission}
disabled={this.permissions.isAddPermissionsVisible}
>
<i className="fa fa-plus" /> Add Permission
</button>
</div>
</div> </div>
<SlideDown in={this.permissions.isAddPermissionsVisible}>
<AddPermissions permissions={this.permissions} backendSrv={backendSrv} dashboardId={dashboardId} />
</SlideDown>
<Permissions <Permissions
permissions={this.permissions} permissions={this.permissions}
isFolder={false} isFolder={false}
......
// import React from 'react';
// import Permissions from './Permissions';
// import { RootStore } from 'app/stores/RootStore/RootStore';
// import { backendSrv } from 'test/mocks/common';
// import { shallow } from 'enzyme';
// describe('Permissions', () => {
// let wrapper;
// beforeAll(() => {
// backendSrv.get.mockReturnValue(
// Promise.resolve([
// { id: 2, dashboardId: 1, role: 'Viewer', permission: 1, permissionName: 'View' },
// { id: 3, dashboardId: 1, role: 'Editor', permission: 1, permissionName: 'Edit' },
// {
// id: 4,
// dashboardId: 1,
// userId: 2,
// userLogin: 'danlimerick',
// userEmail: 'dan.limerick@gmail.com',
// permission: 4,
// permissionName: 'Admin',
// },
// ])
// );
// backendSrv.post = jest.fn();
// const store = RootStore.create(
// {},
// {
// backendSrv: backendSrv,
// }
// );
// wrapper = shallow(<Permissions backendSrv={backendSrv} isFolder={true} dashboardId={1} {...store} />);
// return wrapper.instance().loadStore(1, true);
// });
// describe('when permission for a user is added', () => {
// it('should save permission to db', () => {
// const userItem = {
// id: 2,
// login: 'user2',
// };
// wrapper
// .instance()
// .userPicked(userItem)
// .then(() => {
// expect(backendSrv.post.mock.calls.length).toBe(1);
// expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
// });
// });
// });
// describe('when permission for team is added', () => {
// it('should save permission to db', () => {
// const teamItem = {
// id: 2,
// name: 'ug1',
// };
// wrapper
// .instance()
// .teamPicked(teamItem)
// .then(() => {
// expect(backendSrv.post.mock.calls.length).toBe(1);
// expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
// });
// });
// });
// });
...@@ -400,7 +400,7 @@ select.gf-form-input ~ .gf-form-help-icon { ...@@ -400,7 +400,7 @@ select.gf-form-input ~ .gf-form-help-icon {
.cta-form { .cta-form {
position: relative; position: relative;
padding: 1rem; padding: 1rem;
background-color: $dark-4; background-color: $empty-list-cta-bg;
margin-bottom: 1rem; margin-bottom: 1rem;
border-top: 3px solid $green; border-top: 3px solid $green;
} }
......
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