fix(charting): remove duplicate range selector

This commit is contained in:
Developer
2026-07-15 19:15:06 +00:00
parent e0f66a51f7
commit 1bf8a34a97
7 changed files with 23 additions and 22 deletions
+7 -3
View File
@@ -76,6 +76,8 @@ interface LineSeriesChartProps {
scale?: MetricScale;
/** Available displayed time ranges. Defaults to the shared range choices. */
rangeOptions?: readonly ChartRangeOption[];
/** Whether to render the interactive range selector. */
showRangeSelector?: boolean;
/** Initial uncontrolled range. Defaults to the largest numeric option. */
defaultRangeSeconds?: ChartRangeValue;
/** Controlled range for consumers that refetch when the selection changes. */
@@ -90,6 +92,7 @@ export function LineSeriesChart({
unit = "none",
scale = "auto",
rangeOptions = DEFAULT_CHART_RANGES,
showRangeSelector = true,
defaultRangeSeconds,
rangeSeconds,
onRangeChange,
@@ -98,8 +101,9 @@ export function LineSeriesChart({
defaultRangeSeconds ??
[...rangeOptions].reverse().find((range) => typeof range.value === "number")
?.value;
const [localRangeSeconds, setLocalRangeSeconds] =
useState<ChartRangeValue | undefined>(initialRange);
const [localRangeSeconds, setLocalRangeSeconds] = useState<
ChartRangeValue | undefined
>(initialRange);
const selectedRangeSeconds = rangeSeconds ?? localRangeSeconds;
const latestTimestamp = series.reduce(
(max, seriesItem) =>
@@ -140,7 +144,7 @@ export function LineSeriesChart({
return (
<div className="space-y-2">
{rangeOptions.length > 0 && (
{showRangeSelector && rangeOptions.length > 0 && (
<div className="flex justify-end">
<Select
value={
@@ -38,6 +38,13 @@ describe("LineSeriesChart", () => {
).toHaveTextContent("2 hours");
});
it("can hide the interactive selector for configured widgets", () => {
render(<LineSeriesChart series={[]} showRangeSelector={false} />);
expect(
screen.queryByRole("combobox", { name: "Chart range" }),
).not.toBeInTheDocument();
});
it("offers all loaded values and reports that selection", () => {
const onRangeChange = vi.fn();
render(