2019-09-05 05:47:20 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-02-16 03:20:41 -06:00
|
|
|
import { UserDTO, UserOrg } from 'app/types';
|
2019-09-05 05:47:20 -05:00
|
|
|
import { LoadingPlaceholder, Button } from '@grafana/ui';
|
|
|
|
|
|
|
|
export interface Props {
|
2021-02-16 03:20:41 -06:00
|
|
|
user: UserDTO;
|
2019-09-05 05:47:20 -05:00
|
|
|
orgs: UserOrg[];
|
|
|
|
isLoading: boolean;
|
|
|
|
loadOrgs: () => void;
|
|
|
|
setUserOrg: (org: UserOrg) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class UserOrganizations extends PureComponent<Props> {
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.loadOrgs();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { isLoading, orgs, user } = this.props;
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
return <LoadingPlaceholder text="Loading organizations..." />;
|
|
|
|
}
|
|
|
|
|
2021-04-30 03:04:01 -05:00
|
|
|
if (orgs.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-05 05:47:20 -05:00
|
|
|
return (
|
2021-04-30 03:04:01 -05:00
|
|
|
<div>
|
|
|
|
<h3 className="page-sub-heading">Organizations</h3>
|
|
|
|
<div className="gf-form-group">
|
|
|
|
<table className="filter-table form-inline">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Role</th>
|
|
|
|
<th />
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{orgs.map((org: UserOrg, index) => {
|
|
|
|
return (
|
|
|
|
<tr key={index}>
|
|
|
|
<td>{org.name}</td>
|
|
|
|
<td>{org.role}</td>
|
|
|
|
<td className="text-right">
|
|
|
|
{org.orgId === user.orgId ? (
|
|
|
|
<Button variant="secondary" size="sm" disabled>
|
|
|
|
Current
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
variant="secondary"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
|
|
|
this.props.setUserOrg(org);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Select
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</td>
|
2019-09-05 05:47:20 -05:00
|
|
|
</tr>
|
2021-04-30 03:04:01 -05:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-05 05:47:20 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserOrganizations;
|