fix: memory.list tag filter (#1) + Web UI shared-project visibility (#2) #3

Merged
jknapp merged 3 commits from fix/list-tag-filter-and-shared-project-visibility into main 2026-06-12 19:01:33 +00:00
Showing only changes of commit 86433afe1f - Show all commits
+35 -18
View File
@@ -1,8 +1,9 @@
import Link from "next/link"; import Link from "next/link";
import { and, desc, eq, isNull, sql } from "drizzle-orm"; import { and, desc, eq, inArray, isNull, sql } from "drizzle-orm";
import { auth } from "@/auth"; import { auth } from "@/auth";
import { db } from "@/lib/db/client"; import { db } from "@/lib/db/client";
import { memories, projects } from "@/lib/db/schema"; import { memories, projects } from "@/lib/db/schema";
import { getAccessibleProjects, getUserGroupNames } from "@/lib/access";
import { Container, PageHeader } from "@/app/_components/ui/container"; import { Container, PageHeader } from "@/app/_components/ui/container";
import { Card } from "@/app/_components/ui/card"; import { Card } from "@/app/_components/ui/card";
import { Badge } from "@/app/_components/ui/badge"; import { Badge } from "@/app/_components/ui/badge";
@@ -13,24 +14,37 @@ export const dynamic = "force-dynamic";
export default async function ProjectsPage() { export default async function ProjectsPage() {
const session = await auth(); const session = await auth();
const userId = session!.user.id; const userId = session!.user.id;
const groupNames = await getUserGroupNames(userId);
const rows = await db // The project list is owned shared: projects the user owns PLUS
.select({ // projects shared with one of their groups (any access). Visibility was
id: projects.id, // previously owner-only (`eq(projects.userId, userId)`), which hid
key: projects.key, // projects another user shared in via project_shares even though
displayName: projects.displayName, // project.identify already reported them as {shared, access}.
createdAt: projects.createdAt, const accessible = await getAccessibleProjects(userId, groupNames);
memoryCount: sql<number>`count(${memories.id})::int`, const accessById = new Map(accessible.map((p) => [p.projectId, p.access]));
lastActivity: sql<Date | null>`max(${memories.createdAt})`, const accessibleIds = accessible.map((p) => p.projectId);
})
.from(projects) const rows =
.leftJoin( accessibleIds.length === 0
memories, ? []
and(eq(memories.projectId, projects.id), isNull(memories.deletedAt)), : await db
) .select({
.where(eq(projects.userId, userId)) id: projects.id,
.groupBy(projects.id) key: projects.key,
.orderBy(desc(sql`max(${memories.createdAt})`)); displayName: projects.displayName,
createdAt: projects.createdAt,
memoryCount: sql<number>`count(${memories.id})::int`,
lastActivity: sql<Date | null>`max(${memories.createdAt})`,
})
.from(projects)
.leftJoin(
memories,
and(eq(memories.projectId, projects.id), isNull(memories.deletedAt)),
)
.where(inArray(projects.id, accessibleIds))
.groupBy(projects.id)
.orderBy(desc(sql`max(${memories.createdAt})`));
return ( return (
<Container className="pt-6"> <Container className="pt-6">
@@ -57,6 +71,9 @@ export default async function ProjectsPage() {
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<span className="font-mono text-sm text-fg truncate">{p.key}</span> <span className="font-mono text-sm text-fg truncate">{p.key}</span>
<Badge>{p.memoryCount}</Badge> <Badge>{p.memoryCount}</Badge>
{accessById.get(p.id) !== "owner" ? (
<Badge tone="accent">shared · {accessById.get(p.id)}</Badge>
) : null}
</div> </div>
{p.displayName && p.displayName !== p.key ? ( {p.displayName && p.displayName !== p.key ? (
<div className="text-xs text-fg-muted truncate mt-0.5">{p.displayName}</div> <div className="text-xs text-fg-muted truncate mt-0.5">{p.displayName}</div>