2018-10-03 02:43:10 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
|
import { connect } from 'react-redux';
|
2019-06-26 06:15:45 -05:00
|
|
|
import { renderMarkdown } from '@grafana/data';
|
2019-01-14 09:53:26 -06:00
|
|
|
import Page from 'app/core/components/Page/Page';
|
2018-10-03 02:43:10 -05:00
|
|
|
import UsersActionBar from './UsersActionBar';
|
2018-10-11 04:49:34 -05:00
|
|
|
import UsersTable from './UsersTable';
|
2018-10-03 02:43:10 -05:00
|
|
|
import InviteesTable from './InviteesTable';
|
2019-10-14 03:27:47 -05:00
|
|
|
import { Invitee, OrgUser, CoreEvents } from 'app/types';
|
2018-10-03 02:43:10 -05:00
|
|
|
import appEvents from 'app/core/app_events';
|
2018-12-14 06:49:14 -06:00
|
|
|
import { loadUsers, loadInvitees, setUsersSearchQuery, updateUser, removeUser } from './state/actions';
|
2019-01-17 02:01:17 -06:00
|
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
2018-10-03 02:43:10 -05:00
|
|
|
import { getInvitees, getUsers, getUsersSearchQuery } from './state/selectors';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
navModel: NavModel;
|
|
|
|
invitees: Invitee[];
|
|
|
|
users: OrgUser[];
|
|
|
|
searchQuery: string;
|
|
|
|
externalUserMngInfo: string;
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: boolean;
|
2018-10-03 02:43:10 -05:00
|
|
|
loadUsers: typeof loadUsers;
|
|
|
|
loadInvitees: typeof loadInvitees;
|
|
|
|
setUsersSearchQuery: typeof setUsersSearchQuery;
|
|
|
|
updateUser: typeof updateUser;
|
|
|
|
removeUser: typeof removeUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface State {
|
|
|
|
showInvites: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class UsersListPage extends PureComponent<Props, State> {
|
2018-10-05 01:43:56 -05:00
|
|
|
externalUserMngInfoHtml: string;
|
|
|
|
|
2019-07-11 10:05:45 -05:00
|
|
|
constructor(props: Props) {
|
2018-10-05 01:43:56 -05:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
if (this.props.externalUserMngInfo) {
|
2019-06-26 06:15:45 -05:00
|
|
|
this.externalUserMngInfoHtml = renderMarkdown(this.props.externalUserMngInfo);
|
2018-10-05 01:43:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
showInvites: false,
|
|
|
|
};
|
|
|
|
}
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchUsers();
|
|
|
|
this.fetchInvitees();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fetchUsers() {
|
|
|
|
return await this.props.loadUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fetchInvitees() {
|
|
|
|
return await this.props.loadInvitees();
|
|
|
|
}
|
|
|
|
|
2019-07-11 10:05:45 -05:00
|
|
|
onRoleChange = (role: string, user: OrgUser) => {
|
2018-10-03 02:43:10 -05:00
|
|
|
const updatedUser = { ...user, role: role };
|
|
|
|
|
|
|
|
this.props.updateUser(updatedUser);
|
|
|
|
};
|
|
|
|
|
2019-07-11 10:05:45 -05:00
|
|
|
onRemoveUser = (user: OrgUser) => {
|
2019-10-14 03:27:47 -05:00
|
|
|
appEvents.emit(CoreEvents.showConfirmModal, {
|
2018-10-03 02:43:10 -05:00
|
|
|
title: 'Delete',
|
|
|
|
text: 'Are you sure you want to delete user ' + user.login + '?',
|
|
|
|
yesText: 'Delete',
|
|
|
|
icon: 'fa-warning',
|
|
|
|
onConfirm: () => {
|
|
|
|
this.props.removeUser(user.userId);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-10-03 03:54:15 -05:00
|
|
|
onShowInvites = () => {
|
2018-10-03 02:43:10 -05:00
|
|
|
this.setState(prevState => ({
|
|
|
|
showInvites: !prevState.showInvites,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2018-10-11 04:49:34 -05:00
|
|
|
renderTable() {
|
|
|
|
const { invitees, users } = this.props;
|
|
|
|
|
|
|
|
if (this.state.showInvites) {
|
2018-12-14 06:49:14 -06:00
|
|
|
return <InviteesTable invitees={invitees} />;
|
2018-10-11 04:49:34 -05:00
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<UsersTable
|
|
|
|
users={users}
|
|
|
|
onRoleChange={(role, user) => this.onRoleChange(role, user)}
|
|
|
|
onRemoveUser={user => this.onRemoveUser(user)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:43:10 -05:00
|
|
|
render() {
|
2018-10-11 04:49:34 -05:00
|
|
|
const { navModel, hasFetched } = this.props;
|
2018-10-05 01:43:56 -05:00
|
|
|
const externalUserMngInfoHtml = this.externalUserMngInfoHtml;
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
return (
|
2019-01-17 02:01:17 -06:00
|
|
|
<Page navModel={navModel}>
|
2019-01-14 09:53:26 -06:00
|
|
|
<Page.Contents isLoading={!hasFetched}>
|
|
|
|
<>
|
2019-02-13 04:14:53 -06:00
|
|
|
<UsersActionBar onShowInvites={this.onShowInvites} showInvites={this.state.showInvites} />
|
|
|
|
{externalUserMngInfoHtml && (
|
|
|
|
<div className="grafana-info-box" dangerouslySetInnerHTML={{ __html: externalUserMngInfoHtml }} />
|
|
|
|
)}
|
|
|
|
{hasFetched && this.renderTable()}
|
2019-01-14 09:53:26 -06:00
|
|
|
</>
|
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
2018-10-03 02:43:10 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 10:05:45 -05:00
|
|
|
function mapStateToProps(state: any) {
|
2018-10-03 02:43:10 -05:00
|
|
|
return {
|
|
|
|
navModel: getNavModel(state.navIndex, 'users'),
|
|
|
|
users: getUsers(state.users),
|
|
|
|
searchQuery: getUsersSearchQuery(state.users),
|
|
|
|
invitees: getInvitees(state.users),
|
|
|
|
externalUserMngInfo: state.users.externalUserMngInfo,
|
2018-10-11 04:49:34 -05:00
|
|
|
hasFetched: state.users.hasFetched,
|
2018-10-03 02:43:10 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
loadUsers,
|
|
|
|
loadInvitees,
|
|
|
|
setUsersSearchQuery,
|
|
|
|
updateUser,
|
|
|
|
removeUser,
|
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(UsersListPage)
|
|
|
|
);
|