Skip to content

Commit

Permalink
feat: add Topology details to component details panel
Browse files Browse the repository at this point in the history
Closes #1414
  • Loading branch information
mainawycliffe committed Oct 30, 2023
1 parent 4d9cb5d commit bfe8ed9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/api/services/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ export const getTopology = async (
);
};

type ComponentsTopology = {
id: string;
topologies: {
id: string;
name: string;
};
};

export const getComponentsTopology = async (id: string) => {
const res = await IncidentCommander.get<ComponentsTopology[] | null>(
`/components?id=eq.${id}&select=id,topologies(id,name)`
);
return res.data?.[0] ?? null;
};

export const getTopologyWithoutUnroll = async (params: IParam) => {
params = arrangeTopologyParams(params);
const query = stringify(params);
Expand Down
28 changes: 27 additions & 1 deletion src/components/TopologyDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Title from "../Title/title";
import { FormatProperty } from "../TopologyCard/Property";
import { TopologyLink } from "../TopologyLink";
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { getComponentsTopology } from "../../api/services/topology";
import { Link } from "react-router-dom";

type Props = {
topology?: Topology;
Expand All @@ -23,6 +26,13 @@ export default function TopologyDetails({
isCollapsed = true,
onCollapsedStateChange = () => {}
}: Props) {
const { data } = useQuery({
queryFn: () => getComponentsTopology(topology!.id),
enabled: topology != null,
queryKey: ["components", "topology", topology?.id],
select: (data) => data?.topologies
});

const items = useMemo(() => {
if (topology == null) {
return [];
Expand Down Expand Up @@ -77,8 +87,24 @@ export default function TopologyDetails({
)
});
}

if (data != null) {
items.push({
label: "Topology",
value: (
<Link
to={{
pathname: `/settings/topologies/${data.id}`
}}
className="flex flex-nowrap hover:text-gray-500 my-auto"
>
{data.name}
</Link>
)
});
}
return items;
}, [refererId, topology]);
}, [data, refererId, topology]);

if (topology == null) {
return null;
Expand Down

0 comments on commit bfe8ed9

Please sign in to comment.