Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 51 additions & 44 deletions app/src/components/responsibilities/goal-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,43 +266,45 @@ export function GoalPage({
return (
<PageShell
backButton={{ label: "Routines", linkProps: back }}
description={summaryFor(goal, triggers.data, routines)}
action={
goal.status === "completed" ? undefined : (
<div className="flex shrink-0 items-center gap-2">
<Switch
aria-label="On"
checked={goal.status === "active"}
disabled={action.isPending}
onCheckedChange={(active) =>
action.mutate({
id: goal.id,
action: active ? "resume" : "pause",
})
}
/>
<span
aria-hidden="true"
className="-order-1 w-12 text-right text-muted-foreground text-sm"
>
{goal.status === "active" ? "On" : "Paused"}
</span>
</div>
)
}
description={
<>
<span className="block">
{summaryFor(goal, triggers.data, routines)}
</span>
{/* What starts it. A paused goal's summary already says nothing does. */}
{goal.status === "active" ? (
<span className="block">{`Its ${starters} start it.`}</span>
) : null}
</>
}
title={goal.title}
>
{/* What can be done to it now. The page title names it, so this first section has no heading. */}
{/* What else can be done to it. The page title names it, so this first section has no heading. */}
<PageSection>
<PageRows>
{goal.status !== "completed" ? (
<>
<Item size="sm">
<ItemMedia variant="icon">
<IconTarget />
</ItemMedia>
<ItemContent>
<ItemTitle>Active</ItemTitle>
<ItemDescription>
{goal.status === "active"
? `Its ${starters} start it.`
: `Paused. Its ${starters} won't start it.`}
</ItemDescription>
</ItemContent>
<ItemActions>
<Switch
aria-label="Active"
checked={goal.status === "active"}
disabled={action.isPending}
onCheckedChange={(active) =>
action.mutate({
id: goal.id,
action: active ? "resume" : "pause",
})
}
/>
</ItemActions>
</Item>
<Separator />
</>
) : null}
{goal.status === "active" ? (
<>
<Item
Expand Down Expand Up @@ -379,16 +381,6 @@ export function GoalPage({
<IconChevronRight className="size-4 text-muted-foreground" />
</ItemActions>
</Item>
<Separator />
<DeleteRow
description={deleteWords(routines)}
label={`Delete the goal ${goal.title}`}
onClick={() => {
remove.reset();
setConfirmingDelete(true);
}}
title="Delete goal"
/>
</PageRows>
{action.error ? (
<p className="mt-3 text-destructive text-sm" role="alert">
Expand Down Expand Up @@ -555,6 +547,21 @@ export function GoalPage({
<Triggers goal={goal} />
<Runs channelId={goal.conversationId} goalId={goal.id} />

{/* Away from the everyday controls, at the bottom. */}
<PageSection>
<PageRows>
<DeleteRow
description={deleteWords(routines)}
label={`Delete the goal ${goal.title}`}
onClick={() => {
remove.reset();
setConfirmingDelete(true);
}}
title="Delete goal"
/>
</PageRows>
</PageSection>

<Dialog onOpenChange={setConfirmingDelete} open={confirmingDelete}>
<DialogContent>
<DialogHeader>
Expand Down Expand Up @@ -603,7 +610,7 @@ export function GoalPage({

const RUN_LABEL: Record<string, string> = {
queued: "Queued",
running: "Running",
running: "Running now",
waiting: "Waiting for you",
succeeded: "Succeeded",
failed: "Failed",
Expand Down
186 changes: 42 additions & 144 deletions app/src/components/routines/bot-group.tsx
Original file line number Diff line number Diff line change
@@ -1,175 +1,73 @@
import { useQuery } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
import { AnimatePresence } from "motion/react";
import { BotOrb } from "@/components/agents/bot-orb";
import {
IconClock,
IconEye,
IconLoader2,
IconPlayerPause,
IconTarget,
} from "@/components/icons";
import { KIND_LABEL } from "@/components/responsibilities/triggers";
import { useGoalTriggers } from "@/components/responsibilities/use-goal-reads";
import { PageRows } from "@/components/layout/page-shell";
import { RoutineRow, routineCount } from "@/components/routines/routine-row";
import { Unfold } from "@/components/routines/unfold";
import {
type BotGroup,
isOff,
isRunning,
type RowTone,
rowFact,
rowName,
} from "@/lib/routines/by-bot";
import { describeEvent } from "@/lib/routines/events";
import { goalStarts, type MergedRoutine } from "@/lib/routines/merged";
import { cn } from "@/lib/utils";
import { Separator } from "@/components/ui/separator";
import { agentQueryOptions } from "@/lib/agents/queries";
import type { BotGroup } from "@/lib/routines/by-bot";
import type { MergedRoutine } from "@/lib/routines/merged";

const ROW_CLASS =
"flex flex-col gap-0.5 rounded-lg px-2 py-2 text-sm hover:bg-muted sm:flex-row sm:items-center sm:gap-3";

const FACT_CLASS: Record<RowTone, string> = {
running: "text-foreground",
warning: "text-warning",
muted: "text-muted-foreground",
normal: "text-muted-foreground",
};

function RowIcon({ row }: { row: MergedRoutine }) {
const className = "size-4 shrink-0 text-muted-foreground";
if (isRunning(row))
return (
<IconLoader2
className={cn(className, "animate-spin motion-reduce:animate-none")}
/>
);
if (isOff(row)) return <IconPlayerPause className={className} />;
switch (row.kind) {
case "routine":
return <IconClock className={className} />;
case "goal":
return <IconTarget className={className} />;
case "check-in":
return <IconEye className={className} />;
}
}

/** A row's one line: its icon, its name, and the one fact about it. */
function RowLine({
row,
starts,
}: {
row: MergedRoutine;
/** A goal's starts in words; the others have none. */
starts: string | null;
}) {
const fact = rowFact(row, starts);
return (
<>
<span className="flex min-w-0 flex-1 items-center gap-3">
<RowIcon row={row} />
<span className="truncate">{rowName(row)}</span>
</span>
<span
className={cn("shrink-0 pl-7 text-sm sm:pl-0", FACT_CLASS[fact.tone])}
>
{fact.text}
</span>
</>
);
}

/** Dimmed when its fact is the muted one: paused, or a goal that is completed. */
function rowClass(row: MergedRoutine, starts: string | null) {
return cn(ROW_CLASS, rowFact(row, starts).tone === "muted" && "opacity-60");
/**
* One row as the Routines page draws it. The shared row (`RoutineRow`), kept under this name for the
* Bot's page, which draws it too.
*/
export function GroupRow({ row }: { row: MergedRoutine }) {
return <RoutineRow row={row} />;
}

/**
* A goal's row. Its own component, so only an active goal reads its triggers (`useGoalTriggers`),
* which its starts are made of.
* The name a group heads with. A Bot no list has (one shared with you, or not listed for this
* person) is read on its own, so its group says its real name; "A Bot" only while that read is on
* its way or when it fails, as for a Bot that was deleted.
*/
function GoalRow({ row }: { row: Extract<MergedRoutine, { kind: "goal" }> }) {
const triggers = useGoalTriggers(row.goal.id, {
enabled: row.goal.status === "active",
function useGroupName(group: BotGroup): string {
const bot = useQuery({
...agentQueryOptions(group.botId),
enabled: !group.known,
retry: false,
});
const starts = goalStarts(
row.goal,
triggers.data
?.filter((trigger) => trigger.enabled)
.map((trigger) => `${KIND_LABEL[trigger.kind]} trigger`),
row.routines,
describeEvent,
);
return (
<Link
className={rowClass(row, starts)}
params={{ goalId: row.goal.id }}
to="/routines/goals/$goalId"
>
<RowLine row={row} starts={starts} />
</Link>
);
}

/** One row as the Routines page draws it, opening the routine, goal or check-in it is. */
export function GroupRow({ row }: { row: MergedRoutine }) {
switch (row.kind) {
case "routine":
return (
<Link
className={rowClass(row, null)}
params={{ routineId: row.routine.id }}
to="/routines/schedules/$routineId"
>
<RowLine row={row} starts={null} />
</Link>
);
case "goal":
return <GoalRow row={row} />;
case "check-in":
return (
<Link
className={rowClass(row, null)}
params={{ checkInId: row.checkIn.id }}
to="/routines/check-ins/$checkInId"
>
<RowLine row={row} starts={null} />
</Link>
);
}
return group.known ? group.name : (bot.data?.name ?? group.name);
}

/**
* One Bot's routines on the Routines page: the Bot's orb, name and how many it has, then one line
* per row. The name opens the Bot's own Routines page, except for "A Bot", a Bot no list knows,
* which has none.
* One Bot's routines on the Routines page: the Bot's orb, name and how many it has, then its rows in
* one card. The name opens the Bot's own Routines page, except for a Bot no list knows, which has none.
*/
export function BotGroupSection({ group }: { group: BotGroup }) {
const name = useGroupName(group);
return (
// Spaced with padding, not margin: the group's height opens and folds, and a margin outside it
// would jump.
<section aria-label={group.name} className="pb-6">
<div className="flex items-center gap-2 px-2 pb-1.5 text-muted-foreground text-sm">
<BotOrb name={group.name} seed={group.seed} size={18} />
<section aria-label={name} className="pb-8">
<div className="flex items-center gap-2 text-muted-foreground text-sm">
<BotOrb name={name} seed={group.seed} size={18} />
{group.known ? (
<Link
className="font-medium text-foreground hover:underline"
params={{ agentId: group.botId }}
to="/bots/$agentId/routines"
>
{group.name}
{name}
</Link>
) : (
<span className="font-medium text-foreground">{group.name}</span>
<span className="font-medium text-foreground">{name}</span>
)}
<span className="tabular-nums">{group.rows.length}</span>
<span className="tabular-nums">{routineCount(group.rows.length)}</span>
</div>
{/* A routine made or removed while the page is open opens or folds; the rest just appear. */}
<AnimatePresence initial={false}>
{group.rows.map((row) => (
<Unfold key={`${row.kind}:${row.id}`}>
<GroupRow row={row} />
</Unfold>
))}
</AnimatePresence>
<PageRows className="mt-3">
{/* A routine made or removed while the page is open opens or folds; the rest just appear. */}
<AnimatePresence initial={false}>
{group.rows.map((row, index) => (
<Unfold key={`${row.kind}:${row.id}`}>
{index > 0 ? <Separator /> : null}
<RoutineRow row={row} />
</Unfold>
))}
</AnimatePresence>
</PageRows>
</section>
);
}
6 changes: 3 additions & 3 deletions app/src/components/routines/delete-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from "@/components/ui/item";

/**
* The last row of a goal's, a schedule's or a check-in's actions card: delete it, after a
* confirmation the page opens. A row in the card with the page's other actions, never a button left
* on its own under the page, which reads as something that fell out of the layout.
* Delete a goal, a schedule or a check-in, after a confirmation the page opens. A row in a card of
* its own, in the last section of the page: away from the everyday controls, so it is never pressed
* on the way to Run now, and still a row, never a button left on its own under the page.
*/
export function DeleteRow({
title,
Expand Down
Loading
Loading