| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | import { css } from '@emotion/css'; | 
					
						
							| 
									
										
										
										
											2024-06-25 19:43:47 +08:00
										 |  |  | import { useState } from 'react'; | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | import Skeleton from 'react-loading-skeleton'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | import { GrafanaTheme2 } from '@grafana/data'; | 
					
						
							|  |  |  | import { Button, ConfirmModal, useStyles2 } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2023-12-12 19:05:36 +08:00
										 |  |  | import { SkeletonComponent, attachSkeleton } from '@grafana/ui/src/unstable'; | 
					
						
							| 
									
										
										
										
											2021-11-18 21:10:38 +08:00
										 |  |  | import { contextSrv } from 'app/core/core'; | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  | import { Trans } from 'app/core/internationalization'; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | const getTableHeader = () => ( | 
					
						
							|  |  |  |   <thead> | 
					
						
							|  |  |  |     <tr> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |       <th> | 
					
						
							|  |  |  |         <Trans i18nKey="admin.orgs.id-header">ID</Trans> | 
					
						
							|  |  |  |       </th> | 
					
						
							|  |  |  |       <th> | 
					
						
							|  |  |  |         <Trans i18nKey="admin.orgs.name-header">Name</Trans> | 
					
						
							|  |  |  |       </th> | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  |       <th style={{ width: '1%' }}></th> | 
					
						
							|  |  |  |     </tr> | 
					
						
							|  |  |  |   </thead> | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 19:05:36 +08:00
										 |  |  | function AdminOrgsTableComponent({ 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>(); | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |   const deleteOrgName = deleteOrg?.name; | 
					
						
							| 
									
										
										
										
											2020-04-27 16:00:17 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <table className="filter-table form-inline filter-table--hover"> | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  |       {getTableHeader()} | 
					
						
							| 
									
										
										
										
											2020-04-27 16:00:17 +08:00
										 |  |  |       <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> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |               <Trans i18nKey="admin.orgs.delete-body"> | 
					
						
							|  |  |  |                 Are you sure you want to delete '{{ deleteOrgName }}'? | 
					
						
							|  |  |  |                 <br /> <small>All dashboards for this organization will be removed!</small> | 
					
						
							|  |  |  |               </Trans> | 
					
						
							| 
									
										
										
										
											2020-04-27 16:00:17 +08:00
										 |  |  |             </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
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 19:05:36 +08:00
										 |  |  | const AdminOrgsTableSkeleton: SkeletonComponent = ({ rootProps }) => { | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  |   const styles = useStyles2(getSkeletonStyles); | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2023-12-12 19:05:36 +08:00
										 |  |  |     <table className="filter-table" {...rootProps}> | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  |       {getTableHeader()} | 
					
						
							|  |  |  |       <tbody> | 
					
						
							|  |  |  |         {new Array(3).fill(null).map((_, index) => ( | 
					
						
							|  |  |  |           <tr key={index}> | 
					
						
							|  |  |  |             <td> | 
					
						
							|  |  |  |               <Skeleton width={16} /> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |             <td> | 
					
						
							|  |  |  |               <Skeleton width={240} /> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |             <td> | 
					
						
							|  |  |  |               <Skeleton containerClassName={styles.deleteButton} width={22} height={24} /> | 
					
						
							|  |  |  |             </td> | 
					
						
							|  |  |  |           </tr> | 
					
						
							|  |  |  |         ))} | 
					
						
							|  |  |  |       </tbody> | 
					
						
							|  |  |  |     </table> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 19:05:36 +08:00
										 |  |  | export const AdminOrgsTable = attachSkeleton(AdminOrgsTableComponent, AdminOrgsTableSkeleton); | 
					
						
							| 
									
										
										
										
											2023-12-07 00:07:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const getSkeletonStyles = (theme: GrafanaTheme2) => ({ | 
					
						
							|  |  |  |   deleteButton: css({ | 
					
						
							|  |  |  |     alignItems: 'center', | 
					
						
							|  |  |  |     display: 'flex', | 
					
						
							|  |  |  |     height: 30, | 
					
						
							|  |  |  |     lineHeight: 1, | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  | }); |