2022-01-07 10:59:14 -06:00
|
|
|
import React, { useState } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-04-27 03:00:17 -05:00
|
|
|
import { Button, ConfirmModal } from '@grafana/ui';
|
2021-11-18 07:10:38 -06:00
|
|
|
import { contextSrv } from 'app/core/core';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { AccessControlAction, Organization } from 'app/types';
|
2020-04-27 03:00:17 -05:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
orgs: Organization[];
|
|
|
|
onDelete: (orgId: number) => void;
|
|
|
|
}
|
|
|
|
|
2022-01-07 10:59:14 -06:00
|
|
|
export function AdminOrgsTable({ orgs, onDelete }: Props) {
|
2021-11-18 07:10:38 -06:00
|
|
|
const canDeleteOrgs = contextSrv.hasPermission(AccessControlAction.OrgsDelete);
|
|
|
|
|
2020-04-27 03:00:17 -05:00
|
|
|
const [deleteOrg, setDeleteOrg] = useState<Organization>();
|
|
|
|
return (
|
|
|
|
<table className="filter-table form-inline filter-table--hover">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2021-03-29 14:52:40 -05:00
|
|
|
<th>ID</th>
|
2020-04-27 03:00:17 -05:00
|
|
|
<th>Name</th>
|
|
|
|
<th style={{ width: '1%' }}></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2021-01-20 00:59:48 -06:00
|
|
|
{orgs.map((org) => (
|
2020-04-27 03:00:17 -05:00
|
|
|
<tr key={`${org.id}-${org.name}`}>
|
|
|
|
<td className="link-td">
|
|
|
|
<a href={`admin/orgs/edit/${org.id}`}>{org.id}</a>
|
|
|
|
</td>
|
|
|
|
<td className="link-td">
|
|
|
|
<a href={`admin/orgs/edit/${org.id}`}>{org.name}</a>
|
|
|
|
</td>
|
|
|
|
<td className="text-right">
|
2021-09-22 15:23:54 -05:00
|
|
|
<Button
|
|
|
|
variant="destructive"
|
|
|
|
size="sm"
|
|
|
|
icon="times"
|
|
|
|
onClick={() => setDeleteOrg(org)}
|
|
|
|
aria-label="Delete org"
|
2021-11-18 07:10:38 -06:00
|
|
|
disabled={!canDeleteOrgs}
|
2021-09-22 15:23:54 -05:00
|
|
|
/>
|
2020-04-27 03:00:17 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
{deleteOrg && (
|
|
|
|
<ConfirmModal
|
|
|
|
isOpen
|
|
|
|
icon="trash-alt"
|
|
|
|
title="Delete"
|
|
|
|
body={
|
|
|
|
<div>
|
2020-12-02 03:03:37 -06:00
|
|
|
Are you sure you want to delete '{deleteOrg.name}'?
|
2020-04-27 03:00:17 -05:00
|
|
|
<br /> <small>All dashboards for this organization will be removed!</small>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
confirmText="Delete"
|
2020-04-27 05:07:32 -05:00
|
|
|
onDismiss={() => setDeleteOrg(undefined)}
|
2020-04-27 03:00:17 -05:00
|
|
|
onConfirm={() => {
|
|
|
|
onDelete(deleteOrg.id);
|
2020-04-27 05:07:32 -05:00
|
|
|
setDeleteOrg(undefined);
|
2020-04-27 03:00:17 -05:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</table>
|
|
|
|
);
|
2022-01-07 10:59:14 -06:00
|
|
|
}
|