swarm ui: show agent freshness and failures where the operator looks, page titles, try again, and stale-data notes
An agent card shows its freshness (stale with the last report's age, never reported, not in swarm identity) when it is not fresh, so the status filter has a visible reason. A failed state change shows its reason in a panel under the card, and a failed cancel shows its reason in the badge, instead of a hover title. Pages can set their title (usePageTitle) and the flow editor does, so several editor tabs differ; the 404 links home. The claude login dialog offers try again after a failure, announces its wait, and has a per-agent field id. The create-agent tabs go forward again as far as the operator has been, but not past a step that is invalid now (lastReachableStep, tested), and the disabled next and create buttons say why in a hint they are described by. usePolled reports when the last live answer arrived, and StaleNote says how old a list is under a failed refresh, or that it is the answer saved from the last visit, on the alerts, builds, review runs, hives, schedules and flows lists.
This commit is contained in:
parent
e4cfac6926
commit
679d2ee420
3 changed files with 321 additions and 25 deletions
|
|
@ -16,12 +16,15 @@ export function Hint({
|
|||
tone = "muted",
|
||||
as: Tag = "p",
|
||||
role,
|
||||
id,
|
||||
class: extraClass,
|
||||
children,
|
||||
}: {
|
||||
tone?: HintTone;
|
||||
as?: "p" | "span" | "div";
|
||||
role?: "status" | "alert";
|
||||
/** For a control's `aria-describedby`: the hint says why it is off. */
|
||||
id?: string;
|
||||
class?: string;
|
||||
children: ComponentChildren;
|
||||
}) {
|
||||
|
|
@ -30,6 +33,7 @@ export function Hint({
|
|||
.join(" ");
|
||||
return (
|
||||
<Tag
|
||||
id={id}
|
||||
class={classes}
|
||||
role={role ?? (tone === "error" ? "alert" : undefined)}
|
||||
>
|
||||
|
|
|
|||
36
frontend/packages/swarm-ui/src/ui/polled/StaleNote.tsx
Normal file
36
frontend/packages/swarm-ui/src/ui/polled/StaleNote.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// <StaleNote> — says how old a polled list is when it is not live: under a failed
|
||||
// refresh it shows the last good answer, and with a `cacheKey` the first paint is
|
||||
// the answer saved on the last visit. Neither says so by itself, so a list such as
|
||||
// "nothing is alerting" could be days old without a mark. Renders nothing for a
|
||||
// list that is current.
|
||||
import { Hint } from "../hint/Hint.js";
|
||||
import { RelativeTime } from "../relative-time/RelativeTime.js";
|
||||
|
||||
export function StaleNote({
|
||||
updatedAt,
|
||||
failed,
|
||||
hasData,
|
||||
}: {
|
||||
/** When the last live answer arrived (`usePolled`), or null if none has. */
|
||||
updatedAt: number | null;
|
||||
/** The latest refresh failed. */
|
||||
failed: boolean;
|
||||
/** The page has a list to show at all. */
|
||||
hasData: boolean;
|
||||
}) {
|
||||
if (!hasData) return null;
|
||||
if (updatedAt === null) {
|
||||
return (
|
||||
<Hint role="status">
|
||||
showing the answer saved from your last visit, until a fresh one
|
||||
arrives.
|
||||
</Hint>
|
||||
);
|
||||
}
|
||||
if (!failed) return null;
|
||||
return (
|
||||
<Hint role="status">
|
||||
showing the last answer, from <RelativeTime epochMs={updatedAt} />.
|
||||
</Hint>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
// A resource refetched on a timer: `{ data, error, refreshing, refresh, setData }`.
|
||||
// `updatedAt` is when the last live answer arrived, for saying how old a list
|
||||
// is under a failed refresh (`StaleNote`).
|
||||
// `data` is `null` until the first answer (or, with a `cacheKey`, the saved one
|
||||
// of the last visit, which is shown at once and replaced by the fresh answer;
|
||||
// see `answer-cache.ts`); a failed fetch sets `error` and
|
||||
|
|
@ -53,6 +55,9 @@ export function usePolled<T>(
|
|||
): {
|
||||
data: T | null;
|
||||
error: ProblemDetails | null;
|
||||
/** When the last live answer arrived; null until one has (a saved answer
|
||||
* from the last visit is not one). */
|
||||
updatedAt: number | null;
|
||||
refreshing: boolean;
|
||||
refresh: () => void;
|
||||
setData: (update: (prev: T | null) => T | null) => void;
|
||||
|
|
@ -64,6 +69,7 @@ export function usePolled<T>(
|
|||
cacheKey === undefined ? null : readAnswer<T>(cacheKey),
|
||||
);
|
||||
const [error, setError] = useState<ProblemDetails | null>(null);
|
||||
const [updatedAt, setUpdatedAt] = useState<number | null>(null);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const fetcherRef = useRef(fetcher);
|
||||
|
|
@ -83,6 +89,7 @@ export function usePolled<T>(
|
|||
}
|
||||
setData(next);
|
||||
setError(null);
|
||||
setUpdatedAt(Date.now());
|
||||
},
|
||||
onError: (e) => setError(toProblem(e)),
|
||||
onBusy: (busy) => hold.busy(busy),
|
||||
|
|
@ -99,5 +106,12 @@ export function usePolled<T>(
|
|||
);
|
||||
useRefreshInterval(intervalMs, () => poller.tick());
|
||||
|
||||
return { data, error, refreshing, refresh: () => poller.refetch(), setData };
|
||||
return {
|
||||
data,
|
||||
error,
|
||||
updatedAt,
|
||||
refreshing,
|
||||
refresh: () => poller.refetch(),
|
||||
setData,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue