-
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.
feat: show linked catalogs and components for check
Closes #1505 tests: add tests for relationships refactor: rename to CheckLinkedTo
- Loading branch information
1 parent
7cf7125
commit 38b4188
Showing
5 changed files
with
157 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { useMemo } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { HealthCheck } from "../../../api/types/health"; | ||
import { DataTable } from "../../DataTable"; | ||
import { Icon } from "../../Icon"; | ||
|
||
type CheckRelationshipsComponent = { | ||
relationship: "component"; | ||
name: string; | ||
id: string; | ||
icon?: string; | ||
}; | ||
|
||
type CheckRelationshipsConfig = { | ||
relationship: "config"; | ||
name: string; | ||
id: string; | ||
type?: string; | ||
}; | ||
|
||
type CheckRelationshipsRow = | ||
| CheckRelationshipsComponent | ||
| CheckRelationshipsConfig; | ||
|
||
const columns: ColumnDef<CheckRelationshipsRow>[] = [ | ||
{ | ||
id: "Name", | ||
header: "Name", | ||
cell: ({ row }) => { | ||
const { name } = row.original; | ||
const icon = | ||
row.original.relationship === "component" | ||
? row.original.icon | ||
: row.original.type; | ||
|
||
return ( | ||
<div className="flex items-center"> | ||
{icon && ( | ||
<Icon name={icon} className="mr-2 h-5 w-5 " secondary={name} /> | ||
)} | ||
{name} | ||
</div> | ||
); | ||
} | ||
}, | ||
{ | ||
id: "Type", | ||
header: "Type", | ||
cell: ({ row }) => { | ||
const { relationship } = row.original; | ||
return relationship === "config" ? "Config" : "Component"; | ||
} | ||
} | ||
]; | ||
|
||
type CheckRelationshipsProps = { | ||
check: Partial<HealthCheck>; | ||
}; | ||
|
||
export default function CheckLinkedTo({ check }: CheckRelationshipsProps) { | ||
const navigate = useNavigate(); | ||
|
||
const items = useMemo(() => { | ||
const combined: CheckRelationshipsRow[] = [ | ||
...(check.components | ||
? check.components?.map((component) => ({ | ||
relationship: "component" as const, | ||
name: component.components.name, | ||
id: component.components.id, | ||
icon: component.components.icon | ||
})) | ||
: []), | ||
...(check.configs | ||
? check.configs?.map((config) => ({ | ||
relationship: "config" as const, | ||
name: config.configs.name, | ||
id: config.configs.id, | ||
type: config.configs.type | ||
})) | ||
: []) | ||
]; | ||
return combined; | ||
}, [check.components, check.configs]); | ||
|
||
const handleRowClick = (row: CheckRelationshipsRow) => { | ||
if (row.relationship === "component") { | ||
navigate(`/topology/${row.id}`); | ||
} else { | ||
navigate(`/configs/${row.id}`); | ||
} | ||
}; | ||
|
||
if (!check || items.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<DataTable | ||
handleRowClick={(row) => handleRowClick(row.original)} | ||
columns={columns} | ||
data={items} | ||
/> | ||
</div> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/components/Canary/CanaryPopup/__tests__/CheckLinkedTo.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,35 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import CheckLinkedTo from "../CheckLinkedTo"; | ||
|
||
describe("CheckLinkedTo", () => { | ||
const mockCheck = { | ||
components: [ | ||
{ components: { name: "Component 1", id: "1", icon: "icon1" } }, | ||
{ components: { name: "Component 2", id: "2", icon: "icon2" } } | ||
], | ||
configs: [ | ||
{ configs: { name: "Config 1", id: "3", type: "type1" } }, | ||
{ configs: { name: "Config 2", id: "4", type: "type2" } } | ||
] | ||
}; | ||
|
||
it("renders correctly", () => { | ||
render( | ||
<MemoryRouter> | ||
<CheckLinkedTo check={mockCheck} /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect( | ||
screen.getByRole("cell", { | ||
name: "Component 1" | ||
}) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole("cell", { name: /Component 2/i }) | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole("cell", { name: /Config 1/i })).toBeInTheDocument(); | ||
expect(screen.getByRole("cell", { name: /Config 2/i })).toBeInTheDocument(); | ||
}); | ||
}); |