Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: a fire now button on each schedule

This commit is contained in:
iris 2026-11-16 11:29:23 +01:00
commit db924d9e77
3 changed files with 62 additions and 3 deletions

View file

@ -1,6 +1,6 @@
// <ScheduleCard> — one scheduled prompt as a card: its name as the title,
// "agents: foo, bar" beneath, then the message, the cadence and when it
// fires next. Edit, pause/resume and remove sit at the foot; edit swaps the
// fires next. Edit, fire now, pause/resume and remove sit at the foot; edit swaps the
// card for `ScheduleForm` (the page owns that swap).
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
import { ActionRow } from "../../ui/action-row/ActionRow.js";
@ -27,6 +27,7 @@ export function ScheduleCard({
schedule,
pending,
onEdit,
onFireNow,
onTogglePaused,
onRemove,
}: {
@ -34,6 +35,7 @@ export function ScheduleCard({
/** A pause/resume or remove for this schedule is in flight. */
pending: boolean;
onEdit: () => void;
onFireNow: () => void;
onTogglePaused: () => void;
onRemove: () => void;
}) {
@ -78,6 +80,19 @@ export function ScheduleCard({
<Button onClick={onEdit} disabled={pending}>
edit
</Button>
<span
title={
schedule.paused
? "resume it first: a paused schedule does not fire"
: schedule.interval_seconds === null
? "fires it now: its start moves to this moment"
: "fires it now: its start moves to this moment, so it repeats from now on"
}
>
<Button onClick={onFireNow} disabled={pending || schedule.paused}>
fire now
</Button>
</span>
<Button onClick={onTogglePaused} disabled={pending}>
{schedule.paused ? "resume" : "pause"}
</Button>
@ -115,6 +130,7 @@ function ScheduleCardSkeleton() {
</div>
<ActionRow align="end" class="ui-schedule-card-actions">
<Skeleton width="4em" height="2.75em" />
<Skeleton width="5.5em" height="2.75em" />
<Skeleton width="4.5em" height="2.75em" />
<Skeleton width="5em" height="2.75em" />
</ActionRow>

View file

@ -101,3 +101,13 @@ export function fmtLocal(unix: number): string {
timeStyle: "short",
});
}
/**
* The `PATCH /api/schedules/{id}` body that fires a schedule now: its start
* (the origin of its fire times) moves to `nowMs`, and a start that has passed
* fires its latest time right away. A repeating schedule goes on from there, so
* its later fires keep the interval but not their old clock times.
*/
export function fireNowBody(nowMs: number): { anchor_unix: number } {
return { anchor_unix: Math.floor(nowMs / 1000) };
}

View file

@ -27,7 +27,7 @@ import type { AgentRow } from "../../agent/AgentTypes.js";
import { ScheduleCard, ScheduleListSkeleton } from "./ScheduleCard.js";
import { agentNamesFrom, agentOptionsFor } from "./agent-options.js";
import { ScheduleForm } from "./ScheduleForm.js";
import { scheduleState, type Schedule } from "./ScheduleTypes.js";
import { fireNowBody, scheduleState, type Schedule } from "./ScheduleTypes.js";
// A refetch never touches an open form's own state (it lives in the form),
// so the usual 30s default is safe here too.
@ -118,6 +118,16 @@ function SchedulesBody() {
}
}
function fireNow(s: Schedule) {
return act(s.id, () =>
fetch(`/api/schedules/${encodeURIComponent(s.id)}`, {
method: "PATCH",
headers: { "content-type": "application/json" },
body: JSON.stringify(fireNowBody(Date.now())),
}),
);
}
function togglePaused(s: Schedule) {
return act(s.id, () =>
fetch(`/api/schedules/${encodeURIComponent(s.id)}`, {
@ -207,6 +217,7 @@ function SchedulesBody() {
schedule={s}
pending={pendingIds.has(s.id)}
onEdit={() => setEditingId(s.id)}
onFireNow={() => fireNow(s)}
onTogglePaused={() => togglePaused(s)}
onRemove={() => setRemoveTarget(s)}
/>