diff --git a/src/areas/queue/QueuePage.tsx b/src/areas/queue/QueuePanel.tsx similarity index 55% rename from src/areas/queue/QueuePage.tsx rename to src/areas/queue/QueuePanel.tsx index 54fdc687..7726aeba 100644 --- a/src/areas/queue/QueuePage.tsx +++ b/src/areas/queue/QueuePanel.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react' import axios from 'axios' import { useAppStore } from '@shared/stores/appStore' import { useNavStore } from '@shared/stores/navStore' @@ -22,21 +22,29 @@ import { type QueueRow, } from './queueModel' -const POLL_MS = 2000 +/** Refresh rate while the panel is open. */ +const OPEN_POLL_MS = 2000 +/** Refresh rate while it is closed: only the button's count needs it. */ +const CLOSED_POLL_MS = 5000 +/** Newest runs fetched while closed: running and queued runs are always among them. */ +const CLOSED_LIMIT = 20 const PAGE_SIZE = 50 /** The list endpoint's largest page. */ const MAX_LIMIT = 200 const nowSeconds = () => Date.now() / 1000 +/** Closes the panel: opening a run's output leaves it. */ +const ClosePanelContext = createContext<() => void>(() => {}) + // ─── Data ───────────────────────────────────────────────────────────────────── /** - * Top-level run history, refreshed every 2 s while the page is mounted. The - * first MAX_LIMIT runs are polled; older pages ("Load more" past that) are - * fetched once and kept. + * Top-level run history. While the panel is open the first MAX_LIMIT runs are + * polled every 2 s and older pages ("Load more" past that) are fetched once and + * kept; while it is closed only the newest few are polled, for the count. */ -function useRunHistory(apiUrl: string) { +function useRunHistory(apiUrl: string, open: boolean) { const [polled, setPolled] = useState([]) const [older, setOlder] = useState([]) const [total, setTotal] = useState(0) @@ -45,13 +53,14 @@ function useRunHistory(apiUrl: string) { const [error, setError] = useState(null) const [loadingMore, setLoadingMore] = useState(false) const inFlight = useRef(false) + const fetchLimit = open ? limit : CLOSED_LIMIT const refresh = useCallback(async () => { - if (inFlight.current) return + if (!apiUrl || inFlight.current) return inFlight.current = true try { const { data } = await axios.get(`${apiUrl}/workflow-runs`, { - params: { top_level: true, limit, offset: 0 }, + params: { top_level: true, limit: fetchLimit, offset: 0 }, }) setPolled(data.runs) setTotal(data.total) @@ -62,13 +71,20 @@ function useRunHistory(apiUrl: string) { inFlight.current = false setLoaded(true) } - }, [apiUrl, limit]) + }, [apiUrl, fetchLimit]) useEffect(() => { void refresh() - const timer = setInterval(() => { void refresh() }, POLL_MS) + const timer = setInterval(() => { void refresh() }, open ? OPEN_POLL_MS : CLOSED_POLL_MS) return () => clearInterval(timer) - }, [refresh]) + }, [refresh, open]) + + // Closing drops the extra pages: the panel reopens on the newest runs. + useEffect(() => { + if (open) return + setLimit(PAGE_SIZE) + setOlder([]) + }, [open]) const loadMore = useCallback(async () => { if (limit < MAX_LIMIT) { @@ -113,7 +129,7 @@ function useChildRuns(apiUrl: string, runId: string, live: boolean) { } void fetchChildren() if (!live) return () => { alive = false } - const timer = setInterval(() => { void fetchChildren() }, POLL_MS) + const timer = setInterval(() => { void fetchChildren() }, OPEN_POLL_MS) return () => { alive = false; clearInterval(timer) } }, [apiUrl, runId, live]) return { children, error } @@ -145,7 +161,7 @@ const ICONS = { mesh: 'M12 2 3 7v10l9 5 9-5V7zM3 7l9 5 9-5M12 12v10', workflow: 'M4 5h5v5H4zM15 14h5v5h-5zM9 7.5h3.5a2 2 0 0 1 2 2V14', chevron: 'm9 6 6 6-6 6', - queue: 'M4 6h11M4 12h7M4 18h7M17 13v3l2 1.5', + queue: 'M4 6h11M4 12h6M4 18h6M17 11a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9zM17 13.5v2.2l1.4 1.1', } const STATUS_STYLES: Record = { @@ -161,7 +177,7 @@ const STATUS_STYLES: Record + {status === 'running' && !paused && @@ -170,21 +186,13 @@ function StatusPill({ status, paused = false }: { status: RunStatus, paused?: bo function SectionHeader({ title, count }: { title: string, count: number }): JSX.Element { return ( -
-

{title}

+
+

{title}

{count}
) } -function Empty({ text }: { text: string }): JSX.Element { - return ( -
-

{text}

-
- ) -} - /** The run's input image, else its output mesh's thumbnail, else a kind icon. */ function RunThumbnail({ row }: { row: QueueRow }): JSX.Element { const inputUrl = useInputPreview(row.inputImage) @@ -194,10 +202,10 @@ function RunThumbnail({ row }: { row: QueueRow }): JSX.Element { useEffect(() => { if (meshPath) ensureThumbnail(meshPath) }, [meshPath]) const src = inputUrl ?? (meshPath ? meshUrl : undefined) return ( -
+
{src ? - : } + : }
) } @@ -215,14 +223,15 @@ function ProgressBar({ progress }: { progress: number }): JSX.Element { ) } -function OutputActions({ row, compact = false }: { row: QueueRow, compact?: boolean }): JSX.Element | null { +function OutputActions({ row }: { row: QueueRow }): JSX.Element | null { const navigate = useNavStore((s) => s.navigate) + const closePanel = useContext(ClosePanelContext) if (!isFinishedStatus(row.status)) return null const target = runOpenTarget(row) const tooltip = target.openable ? undefined : target.reason - const button = 'rounded-lg px-2.5 py-1 text-[11.5px] font-medium transition-colors disabled:cursor-not-allowed' + const button = 'rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed' return ( -
+
) @@ -262,12 +274,12 @@ function stepSummary(row: QueueRow): string { } function StepList({ row, now }: { row: QueueRow, now: number }): JSX.Element { - if (row.steps.length === 0) return

No steps recorded.

+ if (row.steps.length === 0) return

No steps recorded.

return (
    {row.steps.map((step, index) => ( -
  1. - {index + 1} +
  2. + {index + 1} {step.name} {formatDuration(runElapsedSeconds({ startedAt: step.started_at, endedAt: step.ended_at ?? null }, now))} @@ -281,19 +293,19 @@ function StepList({ row, now }: { row: QueueRow, now: number }): JSX.Element { function ChildRuns({ row, apiUrl, resolveModel, now }: { row: QueueRow, apiUrl: string, resolveModel: ModelNameResolver, now: number }): JSX.Element { const { children, error } = useChildRuns(apiUrl, row.id, !isFinishedStatus(row.status)) - if (error && !children) return

    Could not load the generations: {error}

    - if (!children) return

    Loading generations…

    - if (children.length === 0) return

    No model generations in this run.

    + if (error && !children) return

    Could not load the generations: {error}

    + if (!children) return

    Loading generations…

    + if (children.length === 0) return

    No model generations in this run.

    return (
      {children.map((record) => { const child = rowFromRecord(record, resolveModel) return ( -
    1. +
    2. {child.name} {formatDuration(runElapsedSeconds(child, now))} - +
    3. ) })} @@ -306,35 +318,35 @@ function RunCard({ row, now, apiUrl, resolveModel }: { row: QueueRow, now: numbe const expandable = row.kind === 'workflow' const summary = stepSummary(row) const failed = row.status === 'error' && !row.current + const finished = isFinishedStatus(row.status) return ( -
    4. +
    5. setExpanded((v) => !v) : undefined} > - {expandable ? ( - - ) :