"use client"; import { useState } from "react"; import { PRESET_GROUPS, type CategoryField, type ChartConfig, type ChartType, type MetricField, type SeriesGroupBy, type TimeBin, type TimeField, type XAxisField, type YMetric, } from "../../lib/chartConfig"; import type { ChartShape } from "../../lib/chartShare"; import { Checkbox } from "../ui/checkbox"; const sel = "rounded-md border border-border bg-card text-foreground px-2 py-1 text-sm"; const lbl = "flex flex-col gap-1 text-xs font-medium text-muted-foreground"; const METRIC_FIELDS: { value: MetricField; label: string }[] = [ { value: "duration", label: "Duration" }, { value: "viewCount", label: "Views" }, { value: "likeCount", label: "Likes" }, { value: "commentCount", label: "Comments" }, { value: "channelFollowerCount", label: "Followers" }, { value: "cueCount", label: "Cue count" }, { value: "coverage", label: "Transcript coverage" }, ]; // Map a gallery template's ChartConfig onto the search-page chart shape. The // query inside the template is ignored — the chart plots the live search. function shapeFromConfig(c: ChartConfig, prev: ChartShape): ChartShape { return { dataSource: c.search ? "search" : "metadata", type: c.type, x: c.x, y: c.y, groupBy: c.groupBy, cumulative: c.cumulative, metric: c.search?.metric ?? prev.metric, }; } // Controlled chart-configuration panel for the search page's single chart. // Mirrors ChartConfigEditor's controls (same labels/markup) but edits a // ChartShape live (no Save/Cancel) and carries no embedded query builder — // the query IS the current search. export function ChartShapeControls({ shape, onChange, }: { shape: ChartShape; onChange: (next: ChartShape) => void; }) { const [showExamples, setShowExamples] = useState(false); const patch = (p: Partial) => onChange({ ...shape, ...p }); const patchX = (x: XAxisField) => patch({ x }); const patchY = (y: YMetric) => patch({ y }); return (
Data source
{(["search", "metadata"] as const).map((m) => ( ))}
{showExamples && (
{PRESET_GROUPS.map((group) => (
{group.title}
{group.templates.map((t) => ( ))}
))}
)}
X axis {shape.x.kind === "time" && ( <> )} {shape.x.kind === "category" && ( )} {shape.x.kind === "numericBucket" && ( )}
{shape.dataSource === "metadata" && (
Y metric {shape.y.agg !== "count" && ( )}
)} {shape.dataSource === "search" && ( )}
); }