Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

feat(goals): groups live inside the Goals rail — collapse, move menu, drag-and-drop

Yuting Zhong97beddf3c341
diff --git a/notfair/src/components/app-sidebar.tsx b/notfair/src/components/app-sidebar.tsx
index 2941e86f..540ed75b 100644
--- a/notfair/src/components/app-sidebar.tsx
+++ b/notfair/src/components/app-sidebar.tsx
@@ -1,10 +1,10 @@
import Link from "next/link";
-import { Fragment } from "react";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
+ SidebarGroupAction,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
@@ -14,7 +14,7 @@ import {
SidebarTrigger,
} from "@/components/ui/sidebar";
import { SidebarBrand } from "@/components/sidebar-brand";
-import { BookOpen, FolderKanban, LayoutGrid, Plug, Plus, Settings, type LucideIcon } from "lucide-react";
+import { BookOpen, FolderPlus, LayoutGrid, Plug, Plus, Settings, type LucideIcon } from "lucide-react";
import { listProjects } from "@/server/db/projects";
import { getActiveProject } from "@/server/active-project";
import { listProjectAgents } from "@/server/agent-meta";
@@ -26,6 +26,8 @@ import {
} from "@/server/db/goals";
import { colorForAgentSlug } from "@/lib/agent-colors";
import { SidebarGoalItem } from "@/components/sidebar-goal-item";
+import { SidebarGoalGroup } from "@/components/sidebar-goal-group";
+import { GoalGroupEditor, type GoalGroupEditorGoal } from "@/components/goal-group-editor";
import { readHarnessUsage } from "@/server/harness-usage";
import { projectHref } from "@/lib/project-href";
import { goalLabel } from "@/lib/goal-label";
@@ -69,12 +71,27 @@ export async function AppSidebar() {
...liveGoals.filter((g) => pinnedIds.has(g.id)),
...liveGoals.filter((g) => !pinnedIds.has(g.id)),
];
- const totalGoals = active ? listGoals(active.slug).length : 0;
+ const allGoals = active ? listGoals(active.slug) : [];
+ const totalGoals = allGoals.length;
const goalGroups = active ? listGoalGroups(active.slug) : [];
const memberships = active ? listGoalGroupMemberships(active.slug) : [];
const groupIdByGoal = new Map(memberships.map((membership) => [membership.goal_id, membership.group_id]));
const ungroupedRailGoals = railGoals.filter((goal) => !groupIdByGoal.has(goal.id));
const agentBySlug = new Map(agentEntries.map((a) => [a.agent_id, a]));
+ // Move-to-group menu targets on every goal row.
+ const groupTargets = goalGroups.map((group) => ({ id: group.id, name: group.name }));
+ // Full goal list for the create-group dialog behind the + header action.
+ const groupNameById = new Map(goalGroups.map((group) => [group.id, group.name]));
+ const editorGoals: GoalGroupEditorGoal[] = allGoals.map((goal) => {
+ const memberOf = groupIdByGoal.get(goal.id) ?? null;
+ return {
+ id: goal.id,
+ label: goalLabel(goal),
+ status: goal.status,
+ current_group_id: memberOf,
+ current_group_name: memberOf ? groupNameById.get(memberOf) ?? null : null,
+ };
+ });
// Best-effort fetch of harness usage. For Codex this hits the
// chatgpt.com wham/usage endpoint (cached 60s in-process); for
// Claude Code it just reads the local stats-cache. Either failure
@@ -110,6 +127,16 @@ export async function AppSidebar() {
{active && (
<SidebarGroup>
<SidebarGroupLabel>Goals</SidebarGroupLabel>
+ <GoalGroupEditor
+ projectSlug={active.slug}
+ goals={editorGoals}
+ trigger={
+ <SidebarGroupAction title="New group">
+ <FolderPlus />
+ <span className="sr-only">New group</span>
+ </SidebarGroupAction>
+ }
+ />
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
@@ -135,48 +162,22 @@ export async function AppSidebar() {
pinned={pinnedIds.has(goal.id)}
dotClass={GOAL_DOT[goal.status] ?? "ns-dot-mute"}
labelClass={color.label}
+ projectSlug={active.slug}
+ groups={groupTargets}
+ groupId={null}
/>
);
})}
- {totalGoals > 0 && (
- <SidebarMenuItem>
- <SidebarMenuButton asChild>
- <Link href={projectHref(active.slug, "/goals")}>
- <LayoutGrid />
- <span>All goals</span>
- <span className="ml-auto text-[11px] tabular-nums text-[hsl(var(--notfair-ink-4))]">
- {totalGoals}
- </span>
- </Link>
- </SidebarMenuButton>
- </SidebarMenuItem>
- )}
- </SidebarMenu>
- </SidebarGroupContent>
- </SidebarGroup>
- )}
-
- {active && goalGroups.length > 0 && (
- <SidebarGroup>
- <SidebarGroupLabel>Groups</SidebarGroupLabel>
- <SidebarGroupContent>
- <SidebarMenu>
{goalGroups.map((group) => {
const groupGoals = railGoals.filter((goal) => groupIdByGoal.get(goal.id) === group.id);
- const totalMembers = memberships.filter((membership) => membership.group_id === group.id).length;
return (
- <Fragment key={group.id}>
- <SidebarMenuItem>
- <SidebarMenuButton asChild>
- <Link href={projectHref(active.slug, `/groups/${group.id}`)}>
- <FolderKanban />
- <span className="truncate">{group.name}</span>
- <span className="ml-auto text-[11px] tabular-nums text-[hsl(var(--notfair-ink-4))]">
- {totalMembers}
- </span>
- </Link>
- </SidebarMenuButton>
- </SidebarMenuItem>
+ <SidebarGoalGroup
+ key={group.id}
+ groupId={group.id}
+ name={group.name}
+ href={projectHref(active.slug, `/groups/${group.id}`)}
+ liveCount={groupGoals.length}
+ >
{groupGoals.map((goal) => {
const agent = agentBySlug.get(goal.agent_id);
if (!agent) return null;
@@ -192,13 +193,28 @@ export async function AppSidebar() {
pinned={pinnedIds.has(goal.id)}
dotClass={GOAL_DOT[goal.status] ?? "ns-dot-mute"}
labelClass={color.label}
- nested
+ projectSlug={active.slug}
+ groups={groupTargets}
+ groupId={group.id}
/>
);
})}
- </Fragment>
+ </SidebarGoalGroup>
);
})}
+ {totalGoals > 0 && (
+ <SidebarMenuItem>
+ <SidebarMenuButton asChild>
+ <Link href={projectHref(active.slug, "/goals")}>
+ <LayoutGrid />
+ <span>All goals</span>
+ <span className="ml-auto text-[11px] tabular-nums text-[hsl(var(--notfair-ink-4))]">
+ {totalGoals}
+ </span>
+ </Link>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ )}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
diff --git a/notfair/src/components/goal-group-editor.tsx b/notfair/src/components/goal-group-editor.tsx
index 07ee2701..9ed4b69e 100644
--- a/notfair/src/components/goal-group-editor.tsx
+++ b/notfair/src/components/goal-group-editor.tsx
@@ -34,10 +34,13 @@ export function GoalGroupEditor({
projectSlug,
goals,
group,
+ trigger,
}: {
projectSlug: string;
goals: GoalGroupEditorGoal[];
group?: { id: string; name: string; description: string };
+ /** Custom dialog trigger — defaults to the page-header button. */
+ trigger?: React.ReactNode;
}) {
const router = useRouter();
const editing = Boolean(group);
@@ -117,10 +120,12 @@ export function GoalGroupEditor({
}}
>
<DialogTrigger asChild>
- <button type="button" className={editing ? "ns-btn ns-btn-ghost" : "ns-btn ns-btn-primary"}>
- {editing ? <Settings2 className="size-3.5" /> : <FolderPlus className="size-3.5" />}
- {editing ? "Manage group" : "New group"}
- </button>
+ {trigger ?? (
+ <button type="button" className={editing ? "ns-btn ns-btn-ghost" : "ns-btn ns-btn-primary"}>
+ {editing ? <Settings2 className="size-3.5" /> : <FolderPlus className="size-3.5" />}
+ {editing ? "Manage group" : "New group"}
+ </button>
+ )}
</DialogTrigger>
<DialogContent className="max-h-[85vh] overflow-y-auto sm:max-w-xl">
<DialogHeader>
diff --git a/notfair/src/components/sidebar-goal-group.test.tsx b/notfair/src/components/sidebar-goal-group.test.tsx
new file mode 100644
index 00000000..a9b75759
--- /dev/null
+++ b/notfair/src/components/sidebar-goal-group.test.tsx
@@ -0,0 +1,92 @@
+// @vitest-environment jsdom
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
+
+import { GOAL_DRAG_TYPE, SidebarGoalGroup } from "@/components/sidebar-goal-group";
+import { SidebarMenu, SidebarProvider } from "@/components/ui/sidebar";
+
+// Mock at the server-action boundary, per repo test conventions.
+const moveGoal = vi.hoisted(() => vi.fn());
+vi.mock("@/server/actions/goal-groups", () => ({
+ moveGoalToGroupAction: moveGoal,
+ renameGoalGroupAction: vi.fn(),
+ deleteGoalGroupAction: vi.fn(),
+}));
+
+const refresh = vi.hoisted(() => vi.fn());
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({ refresh, push: vi.fn() }),
+}));
+
+beforeAll(() => {
+ // SidebarProvider's useIsMobile needs matchMedia, which jsdom lacks.
+ window.matchMedia = vi.fn().mockImplementation((query: string) => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ dispatchEvent: vi.fn(),
+ }));
+});
+
+beforeEach(() => {
+ moveGoal.mockReset();
+ refresh.mockReset();
+ window.localStorage.clear();
+});
+
+function renderGroup() {
+ return render(
+ <SidebarProvider>
+ <SidebarMenu>
+ <SidebarGoalGroup
+ groupId="g1"
+ name="Ads MCP reliability"
+ href="/p/groups/g1"
+ liveCount={2}
+ >
+ <li>member goal row</li>
+ </SidebarGoalGroup>
+ </SidebarMenu>
+ </SidebarProvider>,
+ );
+}
+
+describe("SidebarGoalGroup", () => {
+ it("shows the header with live count and its member goals expanded", () => {
+ renderGroup();
+ const header = screen.getByRole("button", { name: /^ads mcp reliability/i });
+ expect(header).toHaveAttribute("aria-expanded", "true");
+ expect(screen.getByText("2")).toBeInTheDocument();
+ expect(screen.getByText("member goal row")).toBeVisible();
+ });
+
+ it("collapses on header click without unmounting members, and persists", () => {
+ renderGroup();
+ const header = screen.getByRole("button", { name: /^ads mcp reliability/i });
+ fireEvent.click(header);
+ expect(header).toHaveAttribute("aria-expanded", "false");
+ // Hidden, not removed — member dialog state must survive collapse.
+ expect(screen.getByText("member goal row")).not.toBeVisible();
+ expect(window.localStorage.getItem("notfair.rail.group.g1.collapsed")).toBe("1");
+ fireEvent.click(header);
+ expect(screen.getByText("member goal row")).toBeVisible();
+ expect(window.localStorage.getItem("notfair.rail.group.g1.collapsed")).toBeNull();
+ });
+
+ it("moves a dropped goal into the group", async () => {
+ moveGoal.mockResolvedValue({ ok: true });
+ renderGroup();
+ const item = screen.getByRole("button", { name: /^ads mcp reliability/i })
+ .closest("li")!;
+ fireEvent.drop(item, {
+ dataTransfer: {
+ types: [GOAL_DRAG_TYPE],
+ getData: (type: string) => (type === GOAL_DRAG_TYPE ? "goal-9" : ""),
+ },
+ });
+ await waitFor(() => expect(moveGoal).toHaveBeenCalledWith("goal-9", "g1"));
+ await waitFor(() => expect(refresh).toHaveBeenCalled());
+ });
+});
diff --git a/notfair/src/components/sidebar-goal-group.tsx b/notfair/src/components/sidebar-goal-group.tsx
new file mode 100644
index 00000000..f841f6b9
--- /dev/null
+++ b/notfair/src/components/sidebar-goal-group.tsx
@@ -0,0 +1,266 @@
+"use client";
+
+import Link from "next/link";
+import { useRouter } from "next/navigation";
+import { useEffect, useState, useTransition, type DragEvent } from "react";
+import { toast } from "sonner";
+import {
+ ChevronRight,
+ LayoutDashboard,
+ MoreVertical,
+ Pencil,
+ Trash2,
+} from "lucide-react";
+import {
+ SidebarMenuAction,
+ SidebarMenuButton,
+ SidebarMenuItem,
+ SidebarMenuSub,
+} from "@/components/ui/sidebar";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import {
+ deleteGoalGroupAction,
+ moveGoalToGroupAction,
+ renameGoalGroupAction,
+} from "@/server/actions/goal-groups";
+import { cn } from "@/lib/utils";
+
+/** DataTransfer MIME type carrying a goal id during a rail drag. */
+export const GOAL_DRAG_TYPE = "application/x-notfair-goal";
+
+/**
+ * One goal group in the sidebar rail: a collapsible header (chevron + name +
+ * live-goal count) with its member goals nested beneath, a ⋮ menu (dashboard,
+ * rename, delete), and a drop target for goal rows dragged from the rail.
+ */
+export function SidebarGoalGroup({
+ groupId,
+ name,
+ href,
+ liveCount,
+ children,
+}: {
+ groupId: string;
+ name: string;
+ /** Group dashboard route. */
+ href: string;
+ liveCount: number;
+ children?: React.ReactNode;
+}) {
+ const router = useRouter();
+ const [pending, startTransition] = useTransition();
+ const [collapsed, setCollapsed] = useState(false);
+ const [dragOver, setDragOver] = useState(false);
+ const [renameOpen, setRenameOpen] = useState(false);
+ const [deleteOpen, setDeleteOpen] = useState(false);
+ const [draft, setDraft] = useState(name);
+
+ // Collapse state survives navigation via localStorage; read after mount so
+ // the server-rendered (expanded) markup hydrates cleanly.
+ const storageKey = `notfair.rail.group.${groupId}.collapsed`;
+ useEffect(() => {
+ setCollapsed(window.localStorage.getItem(storageKey) === "1");
+ }, [storageKey]);
+
+ function persistCollapsed(next: boolean) {
+ setCollapsed(next);
+ if (next) window.localStorage.setItem(storageKey, "1");
+ else window.localStorage.removeItem(storageKey);
+ }
+
+ function run(
+ fn: () => Promise<{ ok: boolean; error?: string }>,
+ successMsg: string,
+ after?: () => void,
+ ) {
+ startTransition(async () => {
+ const r = await fn();
+ if (!r.ok) {
+ toast.error(r.error ?? "Action failed.");
+ return;
+ }
+ toast.success(successMsg);
+ after?.();
+ router.refresh();
+ });
+ }
+
+ function onDragOver(e: DragEvent) {
+ if (!e.dataTransfer.types.includes(GOAL_DRAG_TYPE)) return;
+ e.preventDefault();
+ e.dataTransfer.dropEffect = "move";
+ setDragOver(true);
+ }
+
+ function onDrop(e: DragEvent) {
+ setDragOver(false);
+ const goalId = e.dataTransfer.getData(GOAL_DRAG_TYPE);
+ if (!goalId) return;
+ e.preventDefault();
+ run(
+ () => moveGoalToGroupAction(goalId, groupId),
+ `Moved to ${name}.`,
+ // Expand so the user sees the goal land.
+ () => persistCollapsed(false),
+ );
+ }
+
+ return (
+ <SidebarMenuItem
+ onDragOver={onDragOver}
+ onDragLeave={() => setDragOver(false)}
+ onDrop={onDrop}
+ >
+ <SidebarMenuButton
+ onClick={() => persistCollapsed(!collapsed)}
+ aria-expanded={!collapsed}
+ className={cn(
+ dragOver && "bg-sidebar-accent ring-2 ring-sidebar-ring",
+ )}
+ >
+ <ChevronRight
+ aria-hidden
+ className={cn(
+ "!size-3.5 shrink-0 text-[hsl(var(--notfair-ink-4))] transition-transform",
+ !collapsed && "rotate-90",
+ )}
+ />
+ <span className="truncate font-medium">{name}</span>
+ <span className="ml-auto text-[11px] tabular-nums text-[hsl(var(--notfair-ink-4))]">
+ {liveCount}
+ </span>
+ </SidebarMenuButton>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <SidebarMenuAction showOnHover aria-label={`Group actions: ${name}`}>
+ <MoreVertical />
+ </SidebarMenuAction>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="right" align="start" className="min-w-44">
+ <DropdownMenuItem asChild>
+ <Link href={href}>
+ <LayoutDashboard />
+ Open dashboard
+ </Link>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ disabled={pending}
+ onSelect={() => {
+ setDraft(name);
+ setRenameOpen(true);
+ }}
+ >
+ <Pencil />
+ Rename…
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ variant="destructive"
+ disabled={pending}
+ onSelect={() => setDeleteOpen(true)}
+ >
+ <Trash2 />
+ Delete…
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+
+ {/* Members stay mounted while collapsed so their dialog state survives. */}
+ <SidebarMenuSub hidden={collapsed}>{children}</SidebarMenuSub>
+
+ <Dialog open={renameOpen} onOpenChange={setRenameOpen}>
+ <DialogContent className="max-w-sm">
+ <DialogHeader>
+ <DialogTitle>Rename group</DialogTitle>
+ <DialogDescription>
+ Changes the display name everywhere — the goals inside are
+ untouched.
+ </DialogDescription>
+ </DialogHeader>
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ run(
+ () => renameGoalGroupAction(groupId, draft),
+ "Group renamed.",
+ () => setRenameOpen(false),
+ );
+ }}
+ >
+ <Input
+ value={draft}
+ onChange={(e) => setDraft(e.target.value)}
+ autoFocus
+ aria-label="Group name"
+ />
+ <DialogFooter className="mt-4">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => setRenameOpen(false)}
+ disabled={pending}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" disabled={pending || !draft.trim()}>
+ Rename
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+
+ <Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
+ <DialogContent className="max-w-sm">
+ <DialogHeader>
+ <DialogTitle>Delete “{name}”?</DialogTitle>
+ <DialogDescription>
+ Removes the group and its dashboard. Its goals become ungrouped —
+ their heartbeats and history are untouched.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter>
+ <Button
+ variant="outline"
+ onClick={() => setDeleteOpen(false)}
+ disabled={pending}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ disabled={pending}
+ onClick={() =>
+ run(
+ () => deleteGoalGroupAction(groupId),
+ "Group deleted. Its goals are now ungrouped.",
+ () => setDeleteOpen(false),
+ )
+ }
+ >
+ <Trash2 className="size-3.5" />
+ Delete group
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </SidebarMenuItem>
+ );
+}
diff --git a/notfair/src/components/sidebar-goal-item.tsx b/notfair/src/components/sidebar-goal-item.tsx
index 198c752d..a2bba43e 100644
--- a/notfair/src/components/sidebar-goal-item.tsx
+++ b/notfair/src/components/sidebar-goal-item.tsx
@@ -5,6 +5,10 @@ import { usePathname, useRouter } from "next/navigation";
import { useState, useTransition } from "react";
import { toast } from "sonner";
import {
+ Check,
+ FolderKanban,
+ FolderMinus,
+ FolderPlus,
MoreVertical,
Pause,
Pencil,
@@ -22,7 +26,11 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuPortal,
DropdownMenuSeparator,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
@@ -42,14 +50,20 @@ import {
resumeGoalAction,
setGoalPinnedAction,
} from "@/server/actions/goals";
+import {
+ createGoalGroupAction,
+ moveGoalToGroupAction,
+} from "@/server/actions/goal-groups";
+import { GOAL_DRAG_TYPE } from "@/components/sidebar-goal-group";
import { cn } from "@/lib/utils";
type LiveStatus = "intake" | "proposed" | "active" | "paused";
/**
* One goal row in the sidebar rail: link to the goal screen plus a ⋮ menu
- * (pin, rename, pause/resume, delete). Server sidebar computes the display
- * bits (dot/label classes); this component owns the interactions.
+ * (pin, rename, move to group, pause/resume, delete). Rows are draggable onto
+ * group headers. Server sidebar computes the display bits (dot/label classes);
+ * this component owns the interactions.
*/
export function SidebarGoalItem({
href,
@@ -60,7 +74,9 @@ export function SidebarGoalItem({
pinned,
dotClass,
labelClass,
- nested = false,
+ projectSlug,
+ groups,
+ groupId,
}: {
href: string;
/** Project home — where the user lands after deleting the open goal. */
@@ -71,14 +87,20 @@ export function SidebarGoalItem({
pinned: boolean;
dotClass: string;
labelClass: string;
- nested?: boolean;
+ projectSlug: string;
+ /** Every group in the project — targets for "Move to group". */
+ groups: { id: string; name: string }[];
+ /** The group this goal currently belongs to, if any. */
+ groupId: string | null;
}) {
const router = useRouter();
const pathname = usePathname();
const [pending, startTransition] = useTransition();
const [renameOpen, setRenameOpen] = useState(false);
const [deleteOpen, setDeleteOpen] = useState(false);
+ const [newGroupOpen, setNewGroupOpen] = useState(false);
const [draft, setDraft] = useState(label);
+ const [groupDraft, setGroupDraft] = useState("");
function run(
fn: () => Promise<{ ok: boolean; error?: string }>,
@@ -114,8 +136,15 @@ export function SidebarGoalItem({
return (
<SidebarMenuItem>
- <SidebarMenuButton asChild className={nested ? "pl-7" : undefined}>
- <Link href={href}>
+ <SidebarMenuButton asChild>
+ <Link
+ href={href}
+ draggable
+ onDragStart={(e) => {
+ e.dataTransfer.setData(GOAL_DRAG_TYPE, goalId);
+ e.dataTransfer.effectAllowed = "move";
+ }}
+ >
<span className={cn("ns-dot", dotClass)} aria-hidden />
<span className={cn("truncate", labelClass)}>{label}</span>
{pinned && (
@@ -156,6 +185,56 @@ export function SidebarGoalItem({
<Pencil />
Rename…
</DropdownMenuItem>
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger disabled={pending}>
+ <FolderKanban />
+ Move to group
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent className="min-w-44">
+ {groups.map((group) => (
+ <DropdownMenuItem
+ key={group.id}
+ disabled={pending || group.id === groupId}
+ onSelect={() =>
+ run(
+ () => moveGoalToGroupAction(goalId, group.id),
+ `Moved to ${group.name}.`,
+ )
+ }
+ >
+ <span className="truncate">{group.name}</span>
+ {group.id === groupId && <Check className="ml-auto" />}
+ </DropdownMenuItem>
+ ))}
+ {groups.length > 0 && <DropdownMenuSeparator />}
+ <DropdownMenuItem
+ disabled={pending}
+ onSelect={() => {
+ setGroupDraft("");
+ setNewGroupOpen(true);
+ }}
+ >
+ <FolderPlus />
+ New group…
+ </DropdownMenuItem>
+ {groupId && (
+ <DropdownMenuItem
+ disabled={pending}
+ onSelect={() =>
+ run(
+ () => moveGoalToGroupAction(goalId, null),
+ "Removed from group.",
+ )
+ }
+ >
+ <FolderMinus />
+ Remove from group
+ </DropdownMenuItem>
+ )}
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
{status === "active" && (
<DropdownMenuItem
disabled={pending}
@@ -255,6 +334,55 @@ export function SidebarGoalItem({
</DialogFooter>
</DialogContent>
</Dialog>
+
+ <Dialog open={newGroupOpen} onOpenChange={setNewGroupOpen}>
+ <DialogContent className="max-w-sm">
+ <DialogHeader>
+ <DialogTitle>New group with “{label}”</DialogTitle>
+ <DialogDescription>
+ A group is one dashboard for related goals. This goal becomes its
+ first member — add more from any goal’s menu or by dragging.
+ </DialogDescription>
+ </DialogHeader>
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+ run(
+ () =>
+ createGoalGroupAction({
+ project_slug: projectSlug,
+ name: groupDraft,
+ goal_ids: [goalId],
+ }),
+ "Group created.",
+ () => setNewGroupOpen(false),
+ );
+ }}
+ >
+ <Input
+ value={groupDraft}
+ onChange={(e) => setGroupDraft(e.target.value)}
+ placeholder="Ads MCP reliability"
+ maxLength={80}
+ autoFocus
+ aria-label="Group name"
+ />
+ <DialogFooter className="mt-4">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => setNewGroupOpen(false)}
+ disabled={pending}
+ >
+ Cancel
+ </Button>
+ <Button type="submit" disabled={pending || !groupDraft.trim()}>
+ Create group
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
</SidebarMenuItem>
);
}
diff --git a/notfair/src/server/actions/goal-groups.ts b/notfair/src/server/actions/goal-groups.ts
index 40511732..1e49bdc6 100644
--- a/notfair/src/server/actions/goal-groups.ts
+++ b/notfair/src/server/actions/goal-groups.ts
@@ -5,8 +5,11 @@ import {
createGoalGroup,
deleteGoalGroup,
getGoalGroup,
+ renameGoalGroup,
saveGoalGroup,
+ setGoalGroupMembership,
} from "@/server/db/goal-groups";
+import { getGoal } from "@/server/db/goals";
import { getProject } from "@/server/db/projects";
export type GoalGroupActionResult = {
@@ -80,6 +83,36 @@ export async function saveGoalGroupAction(input: {
}
}
+export async function renameGoalGroupAction(
+ groupId: string,
+ name: string,
+): Promise<GoalGroupActionResult> {
+ const fields = cleanFields(name);
+ if ("error" in fields) return { ok: false, error: fields.error };
+ try {
+ const group = renameGoalGroup(groupId, fields.name);
+ if (!group) return { ok: false, error: "Goal group not found." };
+ revalidatePath("/", "layout");
+ return { ok: true, group_id: group.id };
+ } catch (error) {
+ return { ok: false, error: messageForError(error) };
+ }
+}
+
+export async function moveGoalToGroupAction(
+ goalId: string,
+ groupId: string | null,
+): Promise<GoalGroupActionResult> {
+ if (!getGoal(goalId)) return { ok: false, error: "Goal not found." };
+ try {
+ setGoalGroupMembership(goalId, groupId);
+ revalidatePath("/", "layout");
+ return { ok: true, group_id: groupId ?? undefined };
+ } catch (error) {
+ return { ok: false, error: messageForError(error) };
+ }
+}
+
export async function deleteGoalGroupAction(groupId: string): Promise<GoalGroupActionResult> {
if (!deleteGoalGroup(groupId)) return { ok: false, error: "Goal group not found." };
revalidatePath("/", "layout");
diff --git a/notfair/src/server/db/goal-groups.test.ts b/notfair/src/server/db/goal-groups.test.ts
index 694e7dec..0534c2b7 100644
--- a/notfair/src/server/db/goal-groups.test.ts
+++ b/notfair/src/server/db/goal-groups.test.ts
@@ -15,6 +15,7 @@ import {
getGoalGroup,
listGoalGroupMemberships,
listGoalsInGroup,
+ renameGoalGroup,
saveGoalGroup,
setGoalGroupMembership,
} from "./goal-groups";
@@ -88,6 +89,16 @@ describe("goal groups", () => {
.toEqual({ n: 0 });
});
+ it("renames a group in place without touching members", () => {
+ const goal = createGoal({ project_slug: PROJECT, agent_id: "renamed", statement: "Rename me" });
+ const group = createGoalGroup({ project_slug: PROJECT, name: "Rail before", goal_ids: [goal.id] });
+
+ const renamed = renameGoalGroup(group.id, "Rail after");
+ expect(renamed?.name).toBe("Rail after");
+ expect(listGoalsInGroup(group.id).map((g) => g.id)).toEqual([goal.id]);
+ expect(renameGoalGroup("missing-group", "Nope")).toBeNull();
+ });
+
it("deleting a group ungroups goals without deleting them", () => {
const goal = createGoal({ project_slug: PROJECT, agent_id: "survivor", statement: "Stay" });
const group = createGoalGroup({ project_slug: PROJECT, name: "Temporary", goal_ids: [goal.id] });
diff --git a/notfair/src/server/db/goal-groups.ts b/notfair/src/server/db/goal-groups.ts
index cfaa59cc..b600d94c 100644
--- a/notfair/src/server/db/goal-groups.ts
+++ b/notfair/src/server/db/goal-groups.ts
@@ -126,6 +126,13 @@ export function listGoalsInGroup(groupId: string): Goal[] {
.all(groupId) as Goal[];
}
+export function renameGoalGroup(id: string, name: string): GoalGroup | null {
+ const changed = getDb()
+ .prepare("UPDATE goal_groups SET name = ?, updated_at = ? WHERE id = ?")
+ .run(name, now(), id).changes;
+ return changed > 0 ? getGoalGroup(id) : null;
+}
+
export function saveGoalGroup(input: {
id: string;
name: string;