-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix issue with topoogy properties being empty
- Loading branch information
1 parent
55276c7
commit 7700f05
Showing
12 changed files
with
145 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/components/Topology/TopologyCard/TopologyCardPropertiesColumn.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Property } from "@flanksource-ui/api/types/topology"; | ||
import { CustomScroll } from "@flanksource-ui/ui/CustomScroll"; | ||
import { PropertyDisplay } from "./Property"; | ||
|
||
type TopologyCardPropertiesColumnProps = { | ||
properties: Property[]; | ||
}; | ||
|
||
export default function TopologyCardPropertiesColumn({ | ||
properties | ||
}: TopologyCardPropertiesColumnProps) { | ||
// Filter out properties that are hidden, have no text or value, and are not a | ||
// headline property. | ||
const noneHeadlineProperties = properties.filter( | ||
(i) => !i.headline && i.type !== "hidden" && (i.text || i.value) | ||
); | ||
|
||
if (noneHeadlineProperties.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<CustomScroll | ||
className="flex-1 py-2 pl-2" | ||
showMoreClass="text-xs linear-1.21rel mr-1 cursor-pointer" | ||
maxHeight="200px" | ||
minChildCount={6} | ||
> | ||
{noneHeadlineProperties.map((property, index) => ( | ||
<PropertyDisplay | ||
key={index} | ||
property={property} | ||
className={index === properties!.length - 1 ? "mb-0" : "mb-1.5"} | ||
/> | ||
))} | ||
</CustomScroll> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/components/Topology/TopologyCard/__tests__/TopologyCard.unit.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Topology } from "@flanksource-ui/api/types/topology"; | ||
import { render, screen } from "@flanksource-ui/test-utils"; | ||
import { rest } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
import { TopologyCard } from "../TopologyCard"; | ||
|
||
const data: Topology = { | ||
id: "01903a93-1d3f-ce22-2203-d558bccbd2d2", | ||
topology_id: "0d0f9eca-e1f9-45fa-b803-29d3237d70cc", | ||
agent_id: "00000000-0000-0000-0000-000000000000", | ||
external_id: "flux (aws)", | ||
name: "flux (aws)", | ||
namespace: "mission-control", | ||
labels: { | ||
"app.kubernetes.io/managed-by": "Helm", | ||
"helm.toolkit.fluxcd.io/name": "mission-control-flux", | ||
"helm.toolkit.fluxcd.io/namespace": "mission-control" | ||
}, | ||
hidden: true, | ||
status: "warning", | ||
health: "warning", | ||
description: "", | ||
status_reason: "", | ||
schedule: "@every 5m", | ||
icon: "flux", | ||
type: "Topology", | ||
summary: { | ||
healthy: 4, | ||
warning: 20, | ||
info: 8, | ||
insights: { | ||
// @ts-expect-error | ||
reliability: { | ||
low: 2 | ||
} | ||
}, | ||
// @ts-expect-error | ||
checks: { | ||
healthy: 34, | ||
unhealthy: 4 | ||
} | ||
}, | ||
is_leaf: false, | ||
created_at: "2024-06-21T11:33:58.207353Z", | ||
updated_at: "2024-08-23T17:00:21.522058Z", | ||
parents: ["01903a93-1d84-9dd8-7b27-dab78df75197"] | ||
}; | ||
|
||
const server = setupServer( | ||
rest.get("/api/canary/api/topology", (req, res, ctx) => { | ||
return res( | ||
ctx.status(204), | ||
ctx.json({ | ||
components: [data] | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
test("it should render card with data from props", () => { | ||
render(<TopologyCard topology={data} />); | ||
|
||
expect( | ||
screen.getAllByRole("link", { | ||
name: /flux \(aws\)/i | ||
})[0] | ||
).toHaveAttribute("href", "/topology/01903a93-1d3f-ce22-2203-d558bccbd2d2"); | ||
}); | ||
|
||
test("it should render card with data from api", async () => { | ||
render(<TopologyCard topologyId="01903a93-1d3f-ce22-2203-d558bccbd2d2" />); | ||
|
||
await screen.findAllByRole("link", { | ||
name: /flux \(aws\)/i | ||
}); | ||
|
||
expect( | ||
screen.getAllByRole("link", { | ||
name: /flux \(aws\)/i | ||
})[0] | ||
).toHaveAttribute("href", "/topology/01903a93-1d3f-ce22-2203-d558bccbd2d2"); | ||
}); |
14 changes: 6 additions & 8 deletions
14
src/components/Topology/TopologyPopover/topologyPreference.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters