Skip to content

Commit

Permalink
feat: when a catalog has one topology, show only topology card
Browse files Browse the repository at this point in the history
Fixes #2174
  • Loading branch information
mainawycliffe committed Aug 23, 2024
1 parent 5f45fba commit bd84b45
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/api/services/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ConfigChange,
ConfigHealthCheckView,
ConfigItem,
ConfigItemDetails,
ConfigSummary,
ConfigTypeRelationships
} from "../types/configs";
Expand Down Expand Up @@ -138,8 +139,10 @@ export const getAllChanges = (
};

export const getConfig = (id: string) =>
resolvePostGrestRequestWithPagination<ConfigItem[]>(
ConfigDB.get(`/config_detail?id=eq.${id}&select=*,config_scrapers(id,name)`)
resolvePostGrestRequestWithPagination<ConfigItemDetails[]>(
ConfigDB.get(
`/config_detail?id=eq.${id}&select=*,config_scrapers(id,name),config_component_relationships(component_id,component:components(*))`
)
);

export type ConfigsTagList = {
Expand Down
22 changes: 15 additions & 7 deletions src/api/types/configs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Agent, Avatar, CreatedAt, Timestamped } from "../traits";
import { HealthCheckSummary } from "./health";
import { Topology } from "./topology";

export interface ConfigChange extends CreatedAt {
id: string;
Expand Down Expand Up @@ -67,13 +68,6 @@ export interface ConfigItem extends Timestamped, Avatar, Agent, Costs {
id: string;
name: string;
};
summary?: {
relationships?: number;
analysis?: number;
changes?: number;
playbook_runs?: number;
checks?: number;
};
properties?: {
icon: string;
name: string;
Expand All @@ -85,6 +79,20 @@ export interface ConfigItem extends Timestamped, Avatar, Agent, Costs {
last_scraped_time?: string;
}

export interface ConfigItemDetails extends ConfigItem {
summary?: {
relationships?: number;
analysis?: number;
changes?: number;
playbook_runs?: number;
checks?: number;
};
config_component_relationships: {
component_id: string;
component: Topology;
}[];
}

export interface ConfigItemGraphData extends ConfigItem {
expanded?: boolean;
expandable?: boolean;
Expand Down
20 changes: 19 additions & 1 deletion src/components/Configs/ConfigDetailsTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Head } from "../../ui/Head";
import { refreshButtonClickedTrigger } from "../../ui/SlidingSideBar/SlidingSideBar";
import TabbedLinks from "../../ui/Tabs/TabbedLinks";
import { ErrorBoundary } from "../ErrorBoundary";
import { TopologyCard } from "../Topology/TopologyCard";
import { useConfigDetailsTabs } from "./ConfigTabsLinks";
import ConfigSidebar from "./Sidebar/ConfigSidebar";

Expand Down Expand Up @@ -46,6 +47,10 @@ export function ConfigDetailsTabs({

const configTabList = useConfigDetailsTabs(configItem?.summary);

// Show topology section if there is only one relationship
const showTopologySection =
configItem?.config_component_relationships.length === 1;

return (
<>
<Head
Expand All @@ -69,8 +74,21 @@ export function ConfigDetailsTabs({
loading={isLoading}
contentClass="p-0 h-full overflow-y-hidden"
>
<div className={`flex h-full flex-row`}>
<div className={`flex h-full flex-row bg-gray-100`}>
<div className="flex flex-1 flex-col">
{showTopologySection && (
<div className="flex w-full flex-row items-center justify-between p-4">
<TopologyCard
topologyId={
configItem?.config_component_relationships[0].component_id
}
// topology={
// configItem?.config_component_relationships[0].component
// }
/>
</div>
)}

<TabbedLinks
activeTabName={activeTabName}
tabLinks={configTabList}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Configs/ConfigTabsLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Badge } from "@flanksource-ui/ui/Badge/Badge";
import { useParams } from "react-router-dom";
import { ConfigItem } from "../../api/types/configs";
import { ConfigItemDetails } from "../../api/types/configs";

export function useConfigDetailsTabs(countSummary?: ConfigItem["summary"]) {
export function useConfigDetailsTabs(
countSummary?: ConfigItemDetails["summary"]
) {
const { id } = useParams<{ id: string }>();

return [
Expand Down
15 changes: 14 additions & 1 deletion src/components/Topology/TopologyCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ export const StatusStyles: Record<keyof typeof ComponentStatus, string> = {
interface IProps {
size?: Size | string;
topologyId?: string;
topology?: Topology;
topology?: Pick<
Topology,
| "summary"
| "is_leaf"
| "id"
| "properties"
| "components"
| "agent_id"
| "status"
| "status_reason"
| "text"
| "name"
| "icon"
>;
selectionMode?: boolean;
hideMenu?: boolean;
// where to open new links
Expand Down

0 comments on commit bd84b45

Please sign in to comment.