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

fix: show loading animation, until card is shown or not
  • Loading branch information
mainawycliffe committed Aug 30, 2024
1 parent cc04eba commit a1b720e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
3 changes: 2 additions & 1 deletion 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,7 +139,7 @@ export const getAllChanges = (
};

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

Expand Down
19 changes: 12 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 @@ -69,13 +70,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 @@ -87,6 +81,17 @@ 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;
};
components?: Topology[];
}

export interface ConfigItemGraphData extends ConfigItem {
expanded?: boolean;
expandable?: boolean;
Expand Down
38 changes: 25 additions & 13 deletions src/components/Configs/ConfigDetailsTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SearchLayout } from "@flanksource-ui/ui/Layout/SearchLayout";
import IncidentDetailsPageSkeletonLoader from "@flanksource-ui/ui/SkeletonLoader/IncidentDetailsPageSkeletonLoader";
import clsx from "clsx";
import { useAtom } from "jotai";
import { ReactNode } from "react";
Expand All @@ -9,6 +10,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 @@ -69,21 +71,31 @@ export function ConfigDetailsTabs({
loading={isLoading}
contentClass="p-0 h-full overflow-y-hidden"
>
<div className={`flex h-full flex-row`}>
<div className="flex flex-1 flex-col">
<TabbedLinks
activeTabName={activeTabName}
tabLinks={configTabList}
contentClassName={clsx(
"bg-white border border-t-0 border-gray-300 flex-1 overflow-y-auto",
className
{isLoadingConfig ? (
<IncidentDetailsPageSkeletonLoader />
) : (
<div className={`flex h-full flex-row bg-gray-100`}>
<div className="flex flex-1 flex-col">
{configItem?.components && configItem.components.length === 1 && (
<div className="flex w-full flex-row items-center justify-between p-4">
<TopologyCard topology={configItem.components[0]} />
</div>
)}
>
<ErrorBoundary>{children}</ErrorBoundary>
</TabbedLinks>

<TabbedLinks
activeTabName={activeTabName}
tabLinks={configTabList}
contentClassName={clsx(
"bg-white border border-t-0 border-gray-300 flex-1 overflow-y-auto",
className
)}
>
<ErrorBoundary>{children}</ErrorBoundary>
</TabbedLinks>
</div>
<ConfigSidebar />
</div>
<ConfigSidebar />
</div>
)}
</SearchLayout>
</>
);
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
2 changes: 2 additions & 0 deletions src/pages/TopologyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export function TopologyPage() {

const { data, isLoading, refetch } = useTopologyPageQuery();

// We probably need to fetch related configs at this point

const currentTopology = useMemo(() => data?.components?.[0], [data]);

const topology = useMemo(() => {
Expand Down

0 comments on commit a1b720e

Please sign in to comment.