Skip to content

Commit 7fe4718

Browse files
committed
feat: when a catalog has one topology, show only topology card
Fixes #2174 fix: show loading animation, until card is shown or not chore: wip fix: fix incorrect import fix: change how merged pages work fix: fix issue from pr review
1 parent 5085c61 commit 7fe4718

19 files changed

+339
-73
lines changed

package-lock.json

Lines changed: 35 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@types/react-mentions": "^4.1.8",
4141
"@types/testing-library__jest-dom": "^5.14.5",
4242
"@types/testing-library__react": "^10.2.0",
43+
"allotment": "^1.20.2",
4344
"ansi-to-html": "^0.7.2",
4445
"autoprefixer": "^10.4.20",
4546
"axios": "^1.6.2",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { useRef } from "react";
3+
import { useSearchParams } from "react-router-dom";
4+
import { LoadingBarRef } from "react-top-loading-bar";
5+
import { getTopology } from "../services/topology";
6+
7+
export default function useTopologyByIDQuery(id?: string) {
8+
const [searchParams] = useSearchParams({
9+
sortBy: "status",
10+
sortOrder: "desc"
11+
});
12+
13+
const selectedLabel = searchParams.get("labels") ?? "All";
14+
const team = searchParams.get("team") ?? "All";
15+
const topologyType = searchParams.get("type") ?? "All";
16+
const healthStatus = searchParams.get("status") ?? "All";
17+
const sortBy = searchParams.get("sortBy") ?? "status";
18+
const sortOrder = searchParams.get("sortOrder") ?? "desc";
19+
const agentId = searchParams.get("agent_id") ?? undefined;
20+
const showHiddenComponents =
21+
searchParams.get("showHiddenComponents") ?? undefined;
22+
23+
const loadingBarRef = useRef<LoadingBarRef>(null);
24+
25+
return useQuery(
26+
[
27+
"topologies",
28+
id,
29+
healthStatus,
30+
team,
31+
selectedLabel,
32+
topologyType,
33+
showHiddenComponents,
34+
sortBy,
35+
sortOrder,
36+
agentId
37+
],
38+
() => {
39+
loadingBarRef.current?.continuousStart();
40+
const apiParams = {
41+
id,
42+
status: healthStatus,
43+
type: topologyType,
44+
team: team,
45+
labels: selectedLabel,
46+
sortBy,
47+
sortOrder,
48+
// only flatten, if topology type is set
49+
...(topologyType &&
50+
topologyType.toString().toLowerCase() !== "all" && {
51+
flatten: true
52+
}),
53+
hidden: showHiddenComponents === "no" ? false : undefined,
54+
agent_id: agentId
55+
};
56+
return getTopology(apiParams);
57+
},
58+
{
59+
enabled: !!id,
60+
onSettled: () => {
61+
loadingBarRef.current?.complete();
62+
}
63+
}
64+
);
65+
}

src/api/services/configs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ConfigChange,
1212
ConfigHealthCheckView,
1313
ConfigItem,
14+
ConfigItemDetails,
1415
ConfigSummary,
1516
ConfigTypeRelationships
1617
} from "../types/configs";
@@ -144,7 +145,7 @@ export const getAllChanges = (
144145
};
145146

146147
export const getConfig = (id: string) =>
147-
resolvePostGrestRequestWithPagination<ConfigItem[]>(
148+
resolvePostGrestRequestWithPagination<ConfigItemDetails[]>(
148149
ConfigDB.get(`/config_detail?id=eq.${id}&select=*,config_scrapers(id,name)`)
149150
);
150151

src/api/types/configs.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Agent, Avatar, CreatedAt, Timestamped } from "../traits";
22
import { HealthCheckSummary } from "./health";
3+
import { Topology } from "./topology";
34

45
export interface ConfigChange extends CreatedAt {
56
id: string;
@@ -69,13 +70,6 @@ export interface ConfigItem extends Timestamped, Avatar, Agent, Costs {
6970
id: string;
7071
name: string;
7172
};
72-
summary?: {
73-
relationships?: number;
74-
analysis?: number;
75-
changes?: number;
76-
playbook_runs?: number;
77-
checks?: number;
78-
};
7973
properties?: {
8074
icon: string;
8175
name: string;
@@ -87,6 +81,17 @@ export interface ConfigItem extends Timestamped, Avatar, Agent, Costs {
8781
last_scraped_time?: string;
8882
}
8983

84+
export interface ConfigItemDetails extends ConfigItem {
85+
summary?: {
86+
relationships?: number;
87+
analysis?: number;
88+
changes?: number;
89+
playbook_runs?: number;
90+
checks?: number;
91+
};
92+
components?: Topology[];
93+
}
94+
9095
export interface ConfigItemGraphData extends ConfigItem {
9196
expanded?: boolean;
9297
expandable?: boolean;

src/api/types/topology.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Agent, Namespaced, Timestamped } from "../traits";
22
import { CostsData, Severity, ValueType } from "./common";
3+
import { ConfigItem } from "./configs";
34
import { HealthCheckSummary } from "./health";
45
import { IncidentType } from "./incident";
56
import { User } from "./users";
@@ -68,6 +69,8 @@ export interface Topology extends Component, CostsData, Agent {
6869
children?: string[];
6970
is_leaf?: boolean;
7071
description?: string;
72+
config_id?: string;
73+
configs?: Pick<ConfigItem, "name" | "id" | "type">[];
7174
}
7275

7376
export type ComponentTeamItem = {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Topology } from "@flanksource-ui/api/types/topology";
2+
import { TopologyCard } from "../Topology/TopologyCard";
3+
import { useTopologyCardWidth } from "../Topology/TopologyPopover/topologyPreference";
4+
5+
type ConfigComponentsProps = {
6+
topology?: Topology;
7+
};
8+
9+
export default function ConfigComponents({ topology }: ConfigComponentsProps) {
10+
const [topologyCardSize] = useTopologyCardWidth();
11+
12+
return (
13+
<div className="flex w-full flex-1 overflow-y-auto">
14+
<div className="flex w-full flex-wrap p-4">
15+
{topology?.components?.map((component) => (
16+
<TopologyCard
17+
key={component.id}
18+
topology={component}
19+
size={topologyCardSize}
20+
menuPosition="absolute"
21+
/>
22+
))}
23+
</div>
24+
</div>
25+
);
26+
}

0 commit comments

Comments
 (0)