|
| 1 | +import { type FC } from "react"; |
| 2 | +import { Spinner } from "@canonical/react-components"; |
| 3 | +import { type TooltipRow } from "components/RichTooltipRow"; |
| 4 | +import { RichTooltipTable } from "components/RichTooltipTable"; |
| 5 | +import { Link } from "react-router-dom"; |
| 6 | +import ItemName from "components/ItemName"; |
| 7 | +import { useClusterLink } from "context/useClusterLinks"; |
| 8 | +import ClusterLinkStatus from "./ClusterLinkStatus"; |
| 9 | +import ResourceLabel from "components/ResourceLabel"; |
| 10 | +import { ROOT_PATH } from "util/rootPath"; |
| 11 | +import ClusterLinkAddresses from "./ClusterLinkAddresses"; |
| 12 | +import { getLinkIdentity } from "util/clusterLink"; |
| 13 | +import { useIdentities } from "context/useIdentities"; |
| 14 | + |
| 15 | +interface Props { |
| 16 | + clusterLink: string; |
| 17 | +} |
| 18 | + |
| 19 | +const ClusterLinkRichTooltip: FC<Props> = ({ clusterLink }) => { |
| 20 | + const { data: link, isLoading: isLinkLoading } = useClusterLink(clusterLink); |
| 21 | + const { data: identities = [] } = useIdentities(); |
| 22 | + |
| 23 | + if (!link && !isLinkLoading) { |
| 24 | + return ( |
| 25 | + <> |
| 26 | + Cluster link <ResourceLabel type="cluster-link" value={clusterLink} />{" "} |
| 27 | + not found |
| 28 | + </> |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + const identity = getLinkIdentity(identities, clusterLink); |
| 33 | + const authGroupCount = identity?.groups?.length ?? 0; |
| 34 | + |
| 35 | + const rows: TooltipRow[] = [ |
| 36 | + { |
| 37 | + title: "Cluster link", |
| 38 | + value: link ? ( |
| 39 | + <Link |
| 40 | + to={`${ROOT_PATH}/ui/cluster/links`} |
| 41 | + onClick={(e) => { |
| 42 | + e.stopPropagation(); |
| 43 | + }} |
| 44 | + > |
| 45 | + <ItemName item={{ name: clusterLink }} /> |
| 46 | + </Link> |
| 47 | + ) : ( |
| 48 | + <Spinner /> |
| 49 | + ), |
| 50 | + valueTitle: clusterLink, |
| 51 | + }, |
| 52 | + { |
| 53 | + title: "Status", |
| 54 | + value: link ? <ClusterLinkStatus link={link} /> : "-", |
| 55 | + className: "status-row", |
| 56 | + }, |
| 57 | + { |
| 58 | + title: "Description", |
| 59 | + value: link?.description || "-", |
| 60 | + valueTitle: link?.description || "", |
| 61 | + }, |
| 62 | + { |
| 63 | + title: "Type", |
| 64 | + value: link?.type || "-", |
| 65 | + }, |
| 66 | + { |
| 67 | + title: "Addresses", |
| 68 | + value: link ? <ClusterLinkAddresses clusterLink={link} /> : "-", |
| 69 | + }, |
| 70 | + { |
| 71 | + title: "Auth groups", |
| 72 | + value: authGroupCount, |
| 73 | + }, |
| 74 | + ]; |
| 75 | + |
| 76 | + return ( |
| 77 | + <RichTooltipTable rows={rows} className="cluster-link-rich-tooltip-table" /> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +export default ClusterLinkRichTooltip; |
0 commit comments