Skip to content

Commit

Permalink
Merge pull request #1468 from flanksource/1414-add-link-scraper-topol…
Browse files Browse the repository at this point in the history
…ogy-details-panel

feat: add Topology details to component details panel
  • Loading branch information
moshloop authored Oct 31, 2023
2 parents 883d2a5 + a90c21c commit 06b8f4f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/api/services/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
36 changes: 31 additions & 5 deletions src/components/TopologyDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { useQuery } from "@tanstack/react-query";
import { isEmpty, map } from "lodash";
import { useMemo } from "react";
import { BsCardList } from "react-icons/bs";
import { Link } from "react-router-dom";
import { getComponentsTopology } from "../../api/services/topology";
import { isCostsEmpty } from "../../api/types/configs";
import { Topology } from "../../api/types/topology";
import CollapsiblePanel from "../CollapsiblePanel";
import ConfigCostValue from "../ConfigCosts/ConfigCostValue";
import { DescriptionCard } from "../DescriptionCard";
import EmptyState from "../EmptyState";
import { Icon } from "../Icon";
import Title from "../Title/title";
import { FormatProperty } from "../TopologyCard/Property";
import { TopologyLink } from "../TopologyLink";
import { useMemo } from "react";
import { Topology } from "../../api/types/topology";
import ConfigCostValue from "../ConfigCosts/ConfigCostValue";
import { isCostsEmpty } from "../../api/types/configs";

type Props = {
topology?: Topology;
Expand All @@ -25,6 +28,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 @@ -86,8 +96,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 06b8f4f

Please sign in to comment.