-
Notifications
You must be signed in to change notification settings - Fork 868
Add dashboard charts frontend #43878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c58c71b
Add dashboard charts frontend
sgress454 889ee4a
fixes from review
sgress454 51ec11f
right-align legend
sgress454 d465d90
fix icon alignment
sgress454 2498c42
chart descriptions
sgress454 e642328
style updates
sgress454 f72a3ed
fixes from review comments
sgress454 7f725ca
filter charts by fleet_id
sgress454 dc7c731
downsample -> resolution
sgress454 a6ba032
fix clear all style
sgress454 27a97ae
comments
sgress454 6e95593
remove sun/moon
sgress454 041a203
comments
sgress454 b6f2576
delete sun and moon icons
sgress454 23951c8
changelog
sgress454 692c1f3
fixes from code review
sgress454 c55713d
more review fixes
sgress454 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| - Added "Hosts active" and "Hosts enrolled" charts to dashboard. |
This file contains hidden or 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 hidden or 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
144 changes: 144 additions & 0 deletions
144
frontend/pages/DashboardPage/cards/ChartCard/ChartCard.tests.tsx
This file contains hidden or 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,144 @@ | ||
| /* eslint-disable @typescript-eslint/no-empty-function, class-methods-use-this */ | ||
| import React from "react"; | ||
| import { screen, waitFor } from "@testing-library/react"; | ||
| import { http, HttpResponse } from "msw"; | ||
|
|
||
| import { createCustomRenderer, baseUrl } from "test/test-utils"; | ||
| import mockServer from "test/mock-server"; | ||
|
|
||
| import ChartCard from "./ChartCard"; | ||
|
|
||
| // Mock ResizeObserver for CheckerboardViz | ||
| const MOCK_WIDTH = 600; | ||
|
|
||
| class MockResizeObserver { | ||
| callback: ResizeObserverCallback; | ||
|
|
||
| constructor(callback: ResizeObserverCallback) { | ||
| this.callback = callback; | ||
| } | ||
|
|
||
| observe(target: Element) { | ||
| this.callback( | ||
| [ | ||
| { | ||
| target, | ||
| contentRect: { width: MOCK_WIDTH, height: 400 } as DOMRectReadOnly, | ||
| borderBoxSize: [], | ||
| contentBoxSize: [], | ||
| devicePixelContentBoxSize: [], | ||
| }, | ||
| ], | ||
| this | ||
| ); | ||
| } | ||
|
|
||
| // eslint-disable-next-line class-methods-use-this | ||
| unobserve() {} | ||
|
|
||
| // eslint-disable-next-line class-methods-use-this | ||
| disconnect() {} | ||
| } | ||
|
|
||
| const generateMockChartResponse = (metric: string, days: number) => { | ||
| const data = []; | ||
| for (let d = 0; d < days; d += 1) { | ||
| const dateStr = `2026-03-${String(d + 1).padStart(2, "0")}`; | ||
| for (let h = 0; h < 24; h += 2) { | ||
| data.push({ | ||
| timestamp: `${dateStr}T${String(h).padStart(2, "0")}:00:00`, | ||
| value: Math.floor(Math.random() * 100), | ||
| }); | ||
| } | ||
| } | ||
| return { | ||
| metric, | ||
| visualization: metric === "uptime" ? "checkerboard" : "line", | ||
| total_hosts: 100, | ||
| resolution: "2h", | ||
| days, | ||
| filters: {}, | ||
| data, | ||
| }; | ||
| }; | ||
|
|
||
| const chartHandler = http.get(baseUrl("/charts/:metric"), ({ params }) => { | ||
| const metric = params.metric as string; | ||
| return HttpResponse.json(generateMockChartResponse(metric, 30)); | ||
| }); | ||
|
|
||
| const emptyChartHandler = http.get(baseUrl("/charts/:metric"), () => { | ||
| return HttpResponse.json({ | ||
| metric: "uptime", | ||
| visualization: "checkerboard", | ||
| total_hosts: 0, | ||
| resolution: "2h", | ||
| days: 30, | ||
| filters: {}, | ||
| data: [], | ||
| }); | ||
| }); | ||
|
|
||
| describe("ChartCard", () => { | ||
| const origGetBCR = Element.prototype.getBoundingClientRect; | ||
| const origResizeObserver = global.ResizeObserver; | ||
|
|
||
| beforeAll(() => { | ||
| global.ResizeObserver = (MockResizeObserver as unknown) as typeof ResizeObserver; | ||
| Element.prototype.getBoundingClientRect = function mockBCR() { | ||
| return { | ||
| width: MOCK_WIDTH, | ||
| height: 400, | ||
|
sgress454 marked this conversation as resolved.
|
||
| top: 0, | ||
| left: 0, | ||
| bottom: 400, | ||
| right: MOCK_WIDTH, | ||
| x: 0, | ||
| y: 0, | ||
| toJSON: () => {}, | ||
| }; | ||
| }; | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| Element.prototype.getBoundingClientRect = origGetBCR; | ||
| global.ResizeObserver = origResizeObserver; | ||
| }); | ||
|
|
||
| it("renders the checkerboard visualization for uptime (default)", async () => { | ||
| mockServer.use(chartHandler); | ||
| const render = createCustomRenderer({ withBackendMock: true }); | ||
| const { container } = render(<ChartCard />); | ||
|
|
||
| // Wait for data to load — checkerboard cells should appear | ||
| await waitFor(() => { | ||
| const rects = container.querySelectorAll("rect"); | ||
| expect(rects.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| // Legend should be visible | ||
| expect(screen.getByText("No data")).toBeInTheDocument(); | ||
| expect(screen.getByText("Less")).toBeInTheDocument(); | ||
| expect(screen.getByText("More")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows the no-data message when API returns empty data", async () => { | ||
| mockServer.use(emptyChartHandler); | ||
| const render = createCustomRenderer({ withBackendMock: true }); | ||
| render(<ChartCard />); | ||
|
|
||
| await screen.findByText("No chart data available yet."); | ||
| }); | ||
|
|
||
| it("renders the current dataset heading", async () => { | ||
| mockServer.use(chartHandler); | ||
| const render = createCustomRenderer({ withBackendMock: true }); | ||
| render(<ChartCard />); | ||
|
|
||
| // Only one dataset is wired up today, so it renders as a heading rather | ||
| // than a dropdown. Days selection is fixed at 30 and has no UI yet. | ||
| await waitFor(() => { | ||
| expect(screen.getByText("Hosts active")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.