From fd8d409e84f34a2cda5c8865d3252d3734b4b96e Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Mon, 23 Nov 2026 16:09:11 +0000 Subject: [PATCH 1/2] Move metrics display settings into query box --- app/components/DocsPopover.tsx | 3 +- app/components/Heatmap.tsx | 30 ---- app/pages/system/MetricsExplorer.tsx | 205 +++++++++++++++------------ test/e2e/oxql.e2e.ts | 41 ++++-- 4 files changed, 143 insertions(+), 136 deletions(-) diff --git a/app/components/DocsPopover.tsx b/app/components/DocsPopover.tsx index a5ddf326b..7f282cf72 100644 --- a/app/components/DocsPopover.tsx +++ b/app/components/DocsPopover.tsx @@ -7,7 +7,6 @@ */ import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react' -import cn from 'classnames' import type { JSX } from 'react' import { Info16Icon, OpenLink12Icon } from '@oxide/design-system/icons/react' @@ -48,7 +47,7 @@ export const DocsPopover = ({ heading, icon, summary, links }: DocsPopoverProps) return ( -
+
diff --git a/app/components/Heatmap.tsx b/app/components/Heatmap.tsx index c90498316..99fe4310e 100644 --- a/app/components/Heatmap.tsx +++ b/app/components/Heatmap.tsx @@ -399,33 +399,3 @@ function HeatmapLegend({
) } - -const SAMPLE_VALUES = [1, 5, 10, 50, 95, 100] -const SAMPLE_VALUES_METADATA = getSampleCountMetadata(SAMPLE_VALUES) -const LONGEST_SAMPLE_ITEM = SAMPLE_VALUES.map((n) => n.toLocaleString().length).reduce( - (acc, length) => Math.max(acc, length), - 0 -) - -export function SampleColorStrip({ colorScale }: { colorScale: ColorScale }) { - const scaleCount = getScalingFunction(SAMPLE_VALUES_METADATA, colorScale) - - return ( -
- {SAMPLE_VALUES.map((n) => ( -
-
- {n.toLocaleString()} -
-
-
- ))} -
- ) -} diff --git a/app/pages/system/MetricsExplorer.tsx b/app/pages/system/MetricsExplorer.tsx index 99a5eccc4..302d4726d 100644 --- a/app/pages/system/MetricsExplorer.tsx +++ b/app/pages/system/MetricsExplorer.tsx @@ -5,7 +5,6 @@ * * Copyright Oxide Computer Company */ -import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react' import { useQuery } from '@tanstack/react-query' import { useWindowVirtualizer } from '@tanstack/react-virtual' import cn from 'classnames' @@ -36,12 +35,14 @@ import { Info12Icon, Monitoring16Icon, Monitoring24Icon, + NextArrow12Icon, Settings16Icon, + Success12Icon, } from '@oxide/design-system/icons/react' import { timeseries as timeseriesMetadata } from '~/api/__generated__/timeseries-metadata' import { DocsPopover } from '~/components/DocsPopover' -import { Heatmap, SampleColorStrip } from '~/components/Heatmap' +import { Heatmap } from '~/components/Heatmap' import { type ColorScale } from '~/components/heatmap-color-scale' import { MoreActionsMenu } from '~/components/MoreActionsMenu' import { @@ -63,7 +64,6 @@ import { useElementSize } from '~/hooks/use-element-size' import { addToast } from '~/stores/toast' import { Button, buttonStyle } from '~/ui/lib/Button' import { CardBlock } from '~/ui/lib/CardBlock' -import { Checkbox } from '~/ui/lib/Checkbox' import { CopyToClipboard } from '~/ui/lib/CopyToClipboard' import { Divider } from '~/ui/lib/Divider' import * as Dropdown from '~/ui/lib/DropdownMenu' @@ -71,9 +71,7 @@ import { EmptyMessage } from '~/ui/lib/EmptyMessage' import { ErrorInlineCode } from '~/ui/lib/InlineCode' import { Message } from '~/ui/lib/Message' import { PageHeader, PageTitle } from '~/ui/lib/PageHeader' -import { Radio } from '~/ui/lib/Radio' import { TextInputError } from '~/ui/lib/TextInput' -import { TipIcon } from '~/ui/lib/TipIcon' import { Tooltip } from '~/ui/lib/Tooltip' import { truncate } from '~/ui/lib/Truncate' import { docLinks } from '~/util/links' @@ -770,82 +768,107 @@ type ChartSettingsProps = { colorScale: Setting } -const colorScaleInfo = { - linear: { - label: 'Linear', - description: - 'Shades each cell by its count as a fraction of the highest measured count.', - }, - logarithmic: { - label: 'Logarithmic', - description: - "Shades each cell by its count's order of magnitude, so 1, 10, and 100 are evenly spaced.", - }, - ranked: { - label: 'Ranked', - description: - 'Shades a cell by where its count ranks among all measured counts. Not a direct representation of magnitude, but helps emphasize patterns and outliers.', - }, -} satisfies Record +const colorScaleLabels = { + linear: 'Linear', + logarithmic: 'Logarithmic', + ranked: 'Ranked', +} satisfies Record + +const onOffLabels = { on: 'On', off: 'Off' } + +type SettingSubmenuProps = { + label: string + options: Record + value: T + onChange: (value: T) => void +} + +function SettingSubmenu({ + label, + options, + value, + onChange, +}: SettingSubmenuProps) { + const entries = R.entries(options) + return ( + + {/* override the default right padding so the arrow sits at the trailing edge */} + + {label} + + {/* stack every label in one cell so the trigger is always as wide as + the longest one, and the menu doesn't resize on selection */} + + {entries.map(([optionValue, optionLabel]) => ( + + {optionLabel} + + ))} + + + + + + { + // RadioGroup values are untyped, so look the key back up + const option = entries.find(([key]) => key === newValue) + if (option) onChange(option[0]) + }} + > + {entries.map(([optionValue, optionLabel]) => ( + + {optionLabel} + {optionValue === value && } + + ))} + + + + ) +} function ChartSettings({ dropFirstPoint, colorScale }: ChartSettingsProps) { return ( - - -
+ + +
- - -

Chart settings

- -
- {dropFirstPoint && ( -
- dropFirstPoint.onChange(e.target.checked)} - > - Drop first data point - - - With deltas and cumulative counters, the initial point is a delta from the - earliest observed value. It's therefore typically much larger, and not worth - comparing to the rest of your data. - -
- )} - {colorScale && ( -
- - Heatmap color scale - -
- {R.entries(colorScaleInfo).map(([value, { label, description }]) => ( - - colorScale.onChange(value)} - > - {label} - - -

{description}

- -
-
- ))} -
-
- )} -
-
- +
+ + {dropFirstPoint && ( + dropFirstPoint.onChange(value === 'on')} + /> + )} + {colorScale && ( + + )} + +
) } @@ -1019,7 +1042,7 @@ export default function MetricsExplorer() { if (chartsRef.current) { setScrollMargin(chartsRef.current.getBoundingClientRect().top + window.scrollY) } - }, [preChartsSize?.height, charts.length, hasSettings]) + }, [preChartsSize?.height, charts.length]) const virtualizer = useWindowVirtualizer({ count: charts.length, @@ -1054,6 +1077,20 @@ export default function MetricsExplorer() { {query.status === 'success' && ( )} + {query.status === 'success' && hasSettings && ( + + )} @@ -1120,20 +1157,6 @@ export default function MetricsExplorer() { )) .with({ status: 'success' }, () => ( - {hasSettings && ( -
- -
- )}
{ const settings = page.getByRole('button', { name: 'Chart settings' }) - const dropFirst = page.getByLabel('Drop first data point') + const dropFirst = page.getByRole('menuitem', { name: /^Drop first data point/ }) + const on = page.getByRole('menuitemradio', { name: 'On', exact: true }) + const off = page.getByRole('menuitemradio', { name: 'Off', exact: true }) // a plain gauge is never cumulative, so there's no giant first point to drop. // and since the only other option is about heatmaps, there should be no @@ -125,12 +127,18 @@ test('"Drop first point" appears for cumulative-derived charts and updates them' await expect(canvas).toBeVisible() const firstDroppedImage = await chartImage(canvas) await settings.click() - await expect(dropFirst).toBeChecked() - - await dropFirst.uncheck() + await expect(dropFirst).toHaveAccessibleName('Drop first data point On') + await dropFirst.click() + await expect(on).toBeChecked() + + // selecting keeps the menu open + await off.click() + await expect(off).toBeChecked() + await expect(dropFirst).toHaveAccessibleName('Drop first data point Off') expect(await chartImage(canvas)).not.toEqual(firstDroppedImage) - await dropFirst.check() + await on.click() + await expect(on).toBeChecked() expect(await chartImage(canvas)).toEqual(firstDroppedImage) }) @@ -138,19 +146,22 @@ test('heatmap color scale appears for distributions and updates the chart', asyn page, }) => { const settings = page.getByRole('button', { name: 'Chart settings' }) - const colorScale = page.getByRole('group', { name: 'Heatmap color scale' }) + const colorScale = page.getByRole('menuitem', { name: /^Color scale/ }) await runQuery(page, oxqlQueries.multiJoinedTables) await settings.click() - await expect(page.getByLabel('Drop first data point')).toBeVisible() + await expect(page.getByRole('menuitem', { name: /^Drop first data point/ })).toBeVisible() await expect(colorScale).toBeHidden() await page.keyboard.press('Escape') await runQuery(page, oxqlQueries.diskLatency) await settings.click() - const ranked = colorScale.getByRole('radio', { name: 'Ranked', exact: true }) - const linear = colorScale.getByRole('radio', { name: 'Linear', exact: true }) - const logarithmic = colorScale.getByRole('radio', { name: 'Logarithmic', exact: true }) + // trigger shows the current value + await expect(colorScale).toHaveAccessibleName('Color scale Ranked') + await colorScale.click() + const ranked = page.getByRole('menuitemradio', { name: 'Ranked', exact: true }) + const linear = page.getByRole('menuitemradio', { name: 'Linear', exact: true }) + const logarithmic = page.getByRole('menuitemradio', { name: 'Logarithmic', exact: true }) await expect(ranked).toBeChecked() const chart = page.getByRole('figure', { name: 'virtual_disk:io_latency' }).first() @@ -160,18 +171,22 @@ test('heatmap color scale appears for distributions and updates the chart', asyn const rankedImage = await chartImage(canvas) await expect(chart.getByText('1', { exact: true })).toBeVisible() - await linear.check() + await linear.click() + await expect(linear).toBeChecked() + await expect(colorScale).toHaveAccessibleName('Color scale Linear') const linearImage = await chartImage(canvas) expect(linearImage).not.toEqual(rankedImage) await expect(chart.getByText('0', { exact: true })).toBeVisible() - await logarithmic.check() + await logarithmic.click() + await expect(logarithmic).toBeChecked() const logarithmicImage = await chartImage(canvas) expect(logarithmicImage).not.toEqual(rankedImage) expect(logarithmicImage).not.toEqual(linearImage) await expect(chart.getByText('1', { exact: true })).toBeVisible() - await ranked.check() + await ranked.click() + await expect(ranked).toBeChecked() expect(await chartImage(canvas)).toEqual(rankedImage) }) From c1c8e278cdef4cc927b79e1ac7a91d6f5a651b9b Mon Sep 17 00:00:00 2001 From: benjaminleonard Date: Tue, 24 Nov 2026 10:20:12 +0000 Subject: [PATCH 2/2] Responsive improvements --- app/pages/system/MetricsExplorer.tsx | 56 ++++++++++++++++------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/app/pages/system/MetricsExplorer.tsx b/app/pages/system/MetricsExplorer.tsx index 302d4726d..b52c04d02 100644 --- a/app/pages/system/MetricsExplorer.tsx +++ b/app/pages/system/MetricsExplorer.tsx @@ -898,8 +898,9 @@ function ResultsSummary({ tables }: { tables: OxqlTable[] }) { const timeseries = tables.flatMap((t) => t.timeseries) const nPoints = R.sumBy(timeseries, (t) => t.points.timestamps.length) return ( -
- {timeseries.length} timeseries /{' '} +
+ {timeseries.length} timeseries + / {nPoints.toLocaleString()} {pluralize('point', nPoints)} @@ -1073,28 +1074,35 @@ export default function MetricsExplorer() {
-
- {query.status === 'success' && ( - - )} - {query.status === 'success' && hasSettings && ( - - )} - - +
+
+ {query.status === 'success' && ( + + )} +
+
+ {query.status === 'success' && hasSettings && ( + + )} + + +