|
|
@@ -1,6 +1,5 @@
|
|
|
import React, { Component } from 'react';
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
-import { inject, observer } from 'mobx-react';
|
|
|
import { connect } from 'react-redux';
|
|
|
import PageHeader from 'app/core/components/PageHeader/PageHeader';
|
|
|
import Permissions from 'app/core/components/Permissions/Permissions';
|
|
|
@@ -9,50 +8,61 @@ import PermissionsInfo from 'app/core/components/Permissions/PermissionsInfo';
|
|
|
import AddPermissions from 'app/core/components/Permissions/AddPermissions';
|
|
|
import SlideDown from 'app/core/components/Animations/SlideDown';
|
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
|
|
-import { NavModel, StoreState, FolderState } from 'app/types';
|
|
|
-import { getFolderByUid } from './state/actions';
|
|
|
-import { PermissionsStore } from 'app/stores/PermissionsStore/PermissionsStore';
|
|
|
+import { NavModel, StoreState, FolderState, DashboardAcl, PermissionLevel } from 'app/types';
|
|
|
+import { getFolderByUid, getFolderPermissions, updateFolderPermission, removeFolderPermission } from './state/actions';
|
|
|
import { getLoadingNav } from './state/navModel';
|
|
|
+import PermissionList from 'app/core/components/PermissionList/PermissionList';
|
|
|
|
|
|
export interface Props {
|
|
|
navModel: NavModel;
|
|
|
- getFolderByUid: typeof getFolderByUid;
|
|
|
folderUid: string;
|
|
|
folder: FolderState;
|
|
|
- permissions: typeof PermissionsStore.Type;
|
|
|
- backendSrv: any;
|
|
|
+ getFolderByUid: typeof getFolderByUid;
|
|
|
+ getFolderPermissions: typeof getFolderPermissions;
|
|
|
+ updateFolderPermission: typeof updateFolderPermission;
|
|
|
+ removeFolderPermission: typeof removeFolderPermission;
|
|
|
+}
|
|
|
+
|
|
|
+export interface State {
|
|
|
+ isAdding: boolean;
|
|
|
}
|
|
|
|
|
|
-@inject('permissions')
|
|
|
-@observer
|
|
|
-export class FolderPermissions extends Component<Props> {
|
|
|
+export class FolderPermissions extends Component<Props, State> {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
- this.handleAddPermission = this.handleAddPermission.bind(this);
|
|
|
+
|
|
|
+ this.state = {
|
|
|
+ isAdding: false,
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
this.props.getFolderByUid(this.props.folderUid);
|
|
|
+ this.props.getFolderPermissions(this.props.folderUid);
|
|
|
}
|
|
|
|
|
|
- componentWillUnmount() {
|
|
|
- const { permissions } = this.props;
|
|
|
- permissions.hideAddPermissions();
|
|
|
- }
|
|
|
+ onOpenAddPermissions = () => {
|
|
|
+ this.setState({ isAdding: true });
|
|
|
+ };
|
|
|
|
|
|
- handleAddPermission() {
|
|
|
- const { permissions } = this.props;
|
|
|
- permissions.toggleAddPermissions();
|
|
|
- }
|
|
|
+ onRemoveItem = (item: DashboardAcl) => {
|
|
|
+ this.props.removeFolderPermission(item);
|
|
|
+ };
|
|
|
+
|
|
|
+ onPermissionChanged = (item: DashboardAcl, level: PermissionLevel) => {
|
|
|
+ this.props.updateFolderPermission(item, level);
|
|
|
+ };
|
|
|
|
|
|
render() {
|
|
|
- const { navModel, permissions, backendSrv, folder } = this.props;
|
|
|
+ const { navModel, folder } = this.props;
|
|
|
+ const { isAdding } = this.state;
|
|
|
|
|
|
if (folder.id === 0) {
|
|
|
return <PageHeader model={navModel} />;
|
|
|
}
|
|
|
|
|
|
const dashboardId = folder.id;
|
|
|
+ const folderInfo = { title: folder.tile, url: folder.url, id: folder.id };
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
@@ -64,18 +74,17 @@ export class FolderPermissions extends Component<Props> {
|
|
|
<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={permissions.isAddPermissionsVisible}
|
|
|
- >
|
|
|
+ <button className="btn btn-success pull-right" onClick={this.onOpenAddPermissions} disabled={isAdding}>
|
|
|
<i className="fa fa-plus" /> Add Permission
|
|
|
</button>
|
|
|
</div>
|
|
|
- <SlideDown in={permissions.isAddPermissionsVisible}>
|
|
|
- <AddPermissions permissions={permissions} />
|
|
|
- </SlideDown>
|
|
|
- <Permissions permissions={permissions} isFolder={true} dashboardId={dashboardId} backendSrv={backendSrv} />
|
|
|
+ <PermissionList
|
|
|
+ items={folder.permissions}
|
|
|
+ onRemoveItem={this.onRemoveItem}
|
|
|
+ onPermissionChanged={this.onPermissionChanged}
|
|
|
+ isFetching={false}
|
|
|
+ folderInfo={folderInfo}
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|
|
|
@@ -93,6 +102,9 @@ const mapStateToProps = (state: StoreState) => {
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
getFolderByUid,
|
|
|
+ getFolderPermissions,
|
|
|
+ updateFolderPermission,
|
|
|
+ removeFolderPermission,
|
|
|
};
|
|
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(FolderPermissions));
|