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