From ea7ce7d71f474e105ca59ec6a02af367fd640b34 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 22:30:38 +0000 Subject: [PATCH 1/2] feat(timeline): a Timeline page to review what came in, and Latest on Home The Timeline page under Explore: newest first with Older, a "3 new" pill from a light 15-second look while the tab is visible, runs of the same actor and kind within 30 minutes as one line, filters in the address (remembered per browser) for words, unreviewed, important, kinds by family, source or person, namespace, entity, dates and automation, and review with toggles, j/k/r/i keys, Hide and "Mark all shown as reviewed" with undo. Filters open in a sheet on a phone. Home's overview gets a Latest card with the five newest unreviewed items. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01TuKmkGM2u3919KZMZLfDCK --- docs/automations.md | 3 +- docs/frontend.md | 6 +- docs/timeline.md | 40 +- nextjs-frontend/__tests__/nav-groups.test.tsx | 12 +- .../__tests__/timeline-model.test.ts | 149 ++++++++ .../__tests__/timeline-ui.test.tsx | 224 ++++++++++++ nextjs-frontend/app/(app)/timeline/page.tsx | 15 + .../components/app-shell/nav-config.ts | 2 + .../components/home/home-screen.tsx | 3 + .../components/timeline/filters.tsx | 219 +++++++++++ nextjs-frontend/components/timeline/item.tsx | 346 ++++++++++++++++++ .../components/timeline/latest-card.tsx | 62 ++++ nextjs-frontend/components/timeline/model.ts | 319 ++++++++++++++++ .../components/timeline/timeline-page.tsx | 326 +++++++++++++++++ .../components/timeline/use-timeline.ts | 124 +++++++ 15 files changed, 1843 insertions(+), 7 deletions(-) create mode 100644 nextjs-frontend/__tests__/timeline-model.test.ts create mode 100644 nextjs-frontend/__tests__/timeline-ui.test.tsx create mode 100644 nextjs-frontend/app/(app)/timeline/page.tsx create mode 100644 nextjs-frontend/components/timeline/filters.tsx create mode 100644 nextjs-frontend/components/timeline/item.tsx create mode 100644 nextjs-frontend/components/timeline/latest-card.tsx create mode 100644 nextjs-frontend/components/timeline/model.ts create mode 100644 nextjs-frontend/components/timeline/timeline-page.tsx create mode 100644 nextjs-frontend/components/timeline/use-timeline.ts diff --git a/docs/automations.md b/docs/automations.md index 5b46c1ed7..16f42f9da 100644 --- a/docs/automations.md +++ b/docs/automations.md @@ -18,7 +18,8 @@ merged is called built. | The shapes of triggers, joins, an If, policy and intents, checked (`app/domain/automation_spec.py`) | built | | The action registry with risk from each action's effect, and one action, `log_line` (`app/domain/actions.py`) | built | | Settings → Automations: how often followers look and how long the event log is kept | built | -| Storing and running automations, schedules and timers, joins, the real actions, approvals, variables, the timeline page, the studio | planned | +| The Timeline page with filters, grouping, review keys and new items, and Home's Latest card ([Timeline](timeline.md)) | built | +| Storing and running automations, schedules and timers, joins, the real actions, approvals, variables, the studio | planned | ## Contract diff --git a/docs/frontend.md b/docs/frontend.md index 50249a135..248bcca2f 100644 --- a/docs/frontend.md +++ b/docs/frontend.md @@ -38,9 +38,9 @@ nextjs-frontend/ The nav rail (`components/app-shell/nav-config.ts`) is in four groups, each named above its first item (a line when the rail is collapsed to icons): what people use every day (Home, Library, Search, Chat, Notes), **Explore** what Lens -found (Entities, Topics, Graph, Podcasts, Reports), **Automate** what runs by itself (Pipelines, Routines, Extensions, -Sensors, or Sources for people who aren't admins), and **Manage** Lens (Costs, Analytics, Settings, Admin). Every page -stays one click from Home; ⌘K reaches every page, recording and setting by name. +found (Timeline, Entities, Topics, Graph, Podcasts, Reports), **Automate** what runs by itself (Pipelines, Routines, +Extensions, Sensors, or Sources for people who aren't admins), and **Manage** Lens (Costs, Analytics, Settings, +Admin). Every page stays one click from Home; ⌘K reaches every page, recording and setting by name. ## Design system diff --git a/docs/timeline.md b/docs/timeline.md index f6062f0a2..c1dca1d76 100644 --- a/docs/timeline.md +++ b/docs/timeline.md @@ -10,8 +10,8 @@ Status: in progress. The studio's timeline is built in steps; only what is merge | --- | --- | | The timeline API (`GET /api/v1/activities`), the MCP tool `timeline` and the assistant's `timeline` | built | | Review marks: reviewed, important and hidden, per person; the filters on them; `mark_activities` for agents | built | -| The Timeline page under Explore: filters, grouping, review with keys, new items as they come | planned | -| A Latest card on Home with the newest unreviewed items | planned | +| The Timeline page under Explore: filters, grouping, review with keys, new items as they come | built | +| A Latest card on Home with the newest unreviewed items | built | | What each item caused (automation runs, approvals), and Approve and Decline on waiting approvals | planned | ## What shows @@ -21,6 +21,42 @@ more kinds as the [automations](automations.md#kinds) modules add them). Activit web-app chat) show to them alone, and those for admins to admins. Noisy kinds, like sensor readings, are left out unless you ask for them by kind. +## The page + +**Timeline** under Explore in the navigation, for everyone (members see their namespaces). + +- Newest first. **Older** reads the next page. While the tab is visible the page looks for new items every 15 + seconds; when there are some, a **3 new** pill at the top brings them in, so the list never jumps under you. +- A run of the same source or person and the same kind, each within 30 minutes of the one before, is one line + ("Work Gmail received 37 emails"), so a first mailbox sync reads as one line. A click opens it to its items. +- Each line has an icon by kind, the summary (a link to what it is about), who did it, the namespace, the kind and + how long ago. Opened, an item shows its object's fields, the automation run that caused it if one did, **Open** and + **Hide**. +- Filters: words in the summary (Enter applies), **Unreviewed only**, **Important**, kinds by family (Email, + Calendar, Files, Notes, Sensors, Chat, Automations, System; noisy kinds like sensor readings only when picked), + source or person (from those on the timeline), namespace, entity (as activities tag it), a date range, and an + automation (what it did or caused). Filters live in the address, so a view can be linked, and the last set you used + comes back the next time you open the page in this browser. **Clear** drops them all. +- On a phone the list is one column and the filters open in a sheet from **Filters**. + +### Reviewing + +| Key | Does | +| --- | --- | +| `j` / `k` | move to the next or previous line | +| `Enter` | open or close the line | +| `r` | mark it reviewed, or not | +| `i` | mark it important, or not | + +Hovering or focusing a line shows its **Important** (star) and **Reviewed** (circle) toggles; once set they stay in +sight. On a line of several items they mark every item. **Mark all shown as reviewed** marks everything on the page +you haven't reviewed, with **Undo** in the message rather than a confirm; **Hide** works the same way. + +### Home + +The overview on Home has a **Latest** card with the five newest activities you haven't reviewed and a link to the +timeline with **Unreviewed only** on. + ## Review marks Each person marks activities for themselves alone; nobody else sees or sets them, admins included. diff --git a/nextjs-frontend/__tests__/nav-groups.test.tsx b/nextjs-frontend/__tests__/nav-groups.test.tsx index 03dd5397d..2adf86445 100644 --- a/nextjs-frontend/__tests__/nav-groups.test.tsx +++ b/nextjs-frontend/__tests__/nav-groups.test.tsx @@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import { Nav } from "@/components/app-shell/nav"; +import { isActive, navFor } from "@/components/app-shell/nav-config"; import { TooltipProvider } from "@/components/ui/tooltip"; jest.mock("next/navigation", () => ({ usePathname: () => "/settings/llm" })); @@ -17,7 +18,8 @@ const nav = (collapsed: boolean) => test("names each group above its first item", () => { nav(false); const text = screen.getByRole("navigation", { name: "Primary" }).textContent ?? ""; - expect(text.indexOf("Explore")).toBeLessThan(text.indexOf("Entities")); + expect(text.indexOf("Explore")).toBeLessThan(text.indexOf("Timeline")); + expect(text.indexOf("Timeline")).toBeLessThan(text.indexOf("Entities")); expect(text.indexOf("Notes")).toBeLessThan(text.indexOf("Explore")); expect(text.indexOf("Automate")).toBeLessThan(text.indexOf("Pipelines")); expect(text.indexOf("Manage")).toBeLessThan(text.indexOf("Costs")); @@ -29,3 +31,11 @@ test("collapsed to icons, the groups are lines rather than names", () => { expect(screen.queryByText("Explore")).not.toBeInTheDocument(); expect(screen.getByRole("link", { name: "Entities" })).toBeInTheDocument(); }); + +test("the timeline is under Explore for everyone", () => { + for (const admin of [true, false]) { + const t = navFor(admin).find((i) => i.href === "/timeline"); + expect(t?.group).toBe("Explore"); + } + expect(isActive("/timeline", "/timeline")).toBe(true); +}); diff --git a/nextjs-frontend/__tests__/timeline-model.test.ts b/nextjs-frontend/__tests__/timeline-model.test.ts new file mode 100644 index 000000000..c385032fe --- /dev/null +++ b/nextjs-frontend/__tests__/timeline-model.test.ts @@ -0,0 +1,149 @@ +import { + automationWhere, + familyOf, + filterCount, + fromParams, + group, + groupSummary, + isFiltered, + kindsByFamily, + mergeNew, + newest, + NO_FILTERS, + objectFields, + objectHref, + toParams, + toQuery, + unseen, + type Activity, +} from "@/components/timeline/model"; + +const MIN = 60_000; +const T0 = Date.parse("2026-10-15T12:00:00.000Z"); + +function act(id: string, minutesAgo: number, kind = "asset.added", actor = "lens:source/1", name = "Work Gmail"): Activity { + return { + id, + type: "Create", + kind, + published: new Date(T0 - minutesAgo * MIN).toISOString(), + actor: { type: "Service", id: actor, name }, + object: { type: "Note", id: `lens:recording/${id}`, name: id, url: `/resources/${id}` }, + summary: `${name} added “${id}”`, + space: 3, + tag: [], + lens: { source: "recordings", pos: [] }, + }; +} + +describe("filters in the address", () => { + it("go to and from the query, so a view can be linked", () => { + const f = { + ...NO_FILTERS, + kinds: ["email.received", "file.added"], + actor: ["lens:source/12"], + namespace: ["family"], + tag: "St Mary's School", + from: "2026-10-01", + to: "2026-10-15", + automation: "4", + q: "school trip", + unreviewed: true, + important: true, + }; + const p = toParams(f); + expect(p.toString()).toBe( + "kinds=email.received%2Cfile.added&actor=lens%3Asource%2F12&ns=family&tag=St+Mary%27s+School&from=2026-10-01&to=2026-10-15&automation=4&q=school+trip&unreviewed=1&important=1", + ); + expect(fromParams(p)).toEqual(f); + expect(filterCount(f)).toBe(10); + }); + + it("leave out what isn't set, and drop what is malformed", () => { + expect(toParams(NO_FILTERS).toString()).toBe(""); + expect(isFiltered(NO_FILTERS)).toBe(false); + const f = fromParams(new URLSearchParams("from=yesterday&to=2026-13&automation=x&unreviewed=yes&kinds=,a.b,")); + expect(f).toEqual({ ...NO_FILTERS, kinds: ["a.b"] }); + }); + + it("make the API's query, always leaving out what you hid", () => { + expect(toQuery(NO_FILTERS)).toEqual({ hidden: false }); + const q = toQuery({ ...NO_FILTERS, unreviewed: true, important: true, automation: "4", from: "2026-10-01", to: "2026-10-02" }); + expect(q.reviewed).toBe(false); + expect(q.important).toBe(true); + expect(q.where).toBe(automationWhere("4")); + expect(JSON.parse(q.where as string).any).toHaveLength(2); + // the whole of both days, in the viewer's own time + expect(Date.parse(q.since as string)).toBe(new Date(2026, 9, 1).getTime() - 1); + expect(Date.parse(q.until as string)).toBe(new Date(2026, 9, 2, 23, 59, 59, 999).getTime()); + }); +}); + +describe("grouping", () => { + it("collapses a run of the same actor and kind within 30 minutes into one line", () => { + const items = [act("a", 0), act("b", 5), act("c", 30), act("d", 61), act("e", 62, "email.received"), act("f", 63)]; + const gs = group(items); + expect(gs.map((g) => g.items.map((a) => a.id))).toEqual([["a", "b", "c"], ["d"], ["e"], ["f"]]); + expect(groupSummary(gs[0])).toBe("Work Gmail added 3 assets"); + expect(groupSummary(gs[1])).toBe("Work Gmail added “d”"); + }); + + it("reads a first mailbox sync as one line, and keeps other actors apart", () => { + const sync = Array.from({ length: 37 }, (_, i) => act(`m${i}`, i, "email.received")); + const other = act("x", 40, "email.received", "lens:source/2", "Home Gmail"); + const gs = group([...sync, other]); + expect(gs).toHaveLength(2); + expect(groupSummary(gs[0])).toBe("Work Gmail received 37 emails"); + expect(groupSummary({ key: "k", items: [act("1", 0, "thing.done"), act("2", 1, "thing.done")] }, "Thing done")).toBe( + "Work Gmail: 2 × thing done", + ); + }); +}); + +describe("new items", () => { + it("are those not shown yet, merged on top newest first without doubles", () => { + const shown = [act("b", 10), act("a", 20)]; + const incoming = [act("c", 5), act("b", 10), act("d", 1)]; + expect(unseen(shown, incoming).map((a) => a.id)).toEqual(["c", "d"]); + expect(mergeNew(shown, incoming).map((a) => a.id)).toEqual(["d", "c", "b", "a"]); + expect(newest(mergeNew(shown, incoming))).toBe(act("d", 1).published); + expect(newest([])).toBeUndefined(); + }); +}); + +describe("kinds and objects", () => { + it("puts each kind under its family", () => { + expect(familyOf("email.received")).toBe("Email"); + expect(familyOf("calendar_event.added")).toBe("Calendar"); + expect(familyOf("asset.added")).toBe("Files"); + expect(familyOf("sensor.reading")).toBe("Sensors"); + expect(familyOf("chat.message")).toBe("Chat"); + expect(familyOf("automation.ran")).toBe("Automations"); + expect(familyOf("note.saved")).toBe("Notes"); + expect(familyOf("backup.finished")).toBe("System"); + const fam = kindsByFamily([ + { name: "file.added", label: "File added" }, + { name: "email.received", label: "Email received" }, + { name: "asset.added", label: "Asset added" }, + ]); + expect(fam.map(([f, ks]) => [f, ks.map((k) => k.name)])).toEqual([ + ["Email", ["email.received"]], + ["Files", ["asset.added", "file.added"]], + ]); + }); + + it("links an activity to its object and lists the object's own fields", () => { + const a = act("7", 0); + expect(objectHref(a)).toBe("/resources/7"); + expect(objectHref({ ...a, object: { type: "Note", id: "lens:entity/9" } })).toBe("/entities/9"); + expect(objectHref({ ...a, object: { type: "Note", id: "lens:nothing/9" } })).toBeNull(); + const fields = objectFields({ + ...a, + object: { ...a.object, media: "document", from: ["office@stmarys.org"], deep: { x: 1 }, empty: "" }, + }); + expect(fields).toEqual([ + ["media", "document"], + ["from", "office@stmarys.org"], + ]); + }); +}); diff --git a/nextjs-frontend/__tests__/timeline-ui.test.tsx b/nextjs-frontend/__tests__/timeline-ui.test.tsx new file mode 100644 index 000000000..715a3c4a0 --- /dev/null +++ b/nextjs-frontend/__tests__/timeline-ui.test.tsx @@ -0,0 +1,224 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; +import "@testing-library/jest-dom"; +import type { ReactNode } from "react"; + +import { Activities } from "@/app/openapi-client"; +import type { ActivityPage, StreamActivity } from "@/app/openapi-client/types.gen"; +import { LatestCard } from "@/components/timeline/latest-card"; +import { TimelinePage } from "@/components/timeline/timeline-page"; +import { ToastProvider } from "@/components/ui/toast"; +import { TooltipProvider } from "@/components/ui/tooltip"; + +jest.mock("@/app/openapi-client", () => ({ + Activities: { + listActivities: jest.fn(), + listActivityKinds: jest.fn(), + markActivities: jest.fn(), + }, +})); +const replace = jest.fn(); +let search = ""; +jest.mock("next/navigation", () => ({ + useRouter: () => ({ push: jest.fn(), replace }), + usePathname: () => "/timeline", + useSearchParams: () => new URLSearchParams(search), +})); +jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) })); +jest.mock("@/lib/hooks/session", () => ({ + useArchive: () => ({ admin: false, namespaces: [{ id: 3, name: "family" }, { id: 4, name: "work" }] }), +})); + +const ok = (data: unknown) => Promise.resolve({ data, response: { ok: true, status: 200 } }); +const m = (f: unknown) => f as jest.Mock; +const NOW = Date.now(); + +function act_(id: string, minutesAgo: number, kind = "email.received", actor = ["lens:source/1", "Work Gmail"]): StreamActivity { + return { + id, + type: "Create", + kind, + published: new Date(NOW - minutesAgo * 60_000).toISOString(), + actor: { type: "Service", id: actor[0], name: actor[1] }, + object: { type: "Note", id: `lens:recording/${id}`, name: `Mail ${id}`, url: `/resources/${id}`, subject: `Mail ${id}` }, + summary: `${actor[1]} received “Mail ${id}”`, + space: 3, + tag: [], + lens: { source: "recordings", pos: [] }, + }; +} + +// three emails from one mailbox within minutes (one line), then an upload by a person an hour earlier +const ITEMS = [ + act_("e3", 1), + act_("e2", 2), + act_("e1", 3), + act_("u1", 90, "asset.added", ["lens:account/1", "Adeel"]), +]; +const PAGE: ActivityPage = { items: ITEMS, next: null, namespaces: { "3": "family" }, marks: { u1: { reviewed: true } } }; + +function wrap(ui: ReactNode) { + const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }); + return render( + + + {ui} + + , + ); +} + +beforeEach(() => { + search = ""; + localStorage.clear(); + m(Activities.listActivityKinds).mockReturnValue( + ok([ + { name: "email.received", label: "Email received", source: "x", type: "Create", object_type: "Note", schema: {} }, + { name: "asset.added", label: "Asset added", source: "recordings", type: "Create", object_type: "Note", schema: {} }, + ]), + ); + m(Activities.markActivities).mockImplementation(({ body }) => + ok({ marks: Object.fromEntries(body.ids.map((id: string) => [id, { reviewed: !!body.reviewed }])), unknown: [] }), + ); + // the first page, then nothing new when it looks again + m(Activities.listActivities).mockImplementation(({ query }) => + ok(query.since ? { items: [], next: null, namespaces: {}, marks: {} } : PAGE), + ); +}); + +test("the list groups a run of emails into one line that opens to its items, and shows what you reviewed", async () => { + wrap(); + const list = await screen.findByRole("list", { name: "Timeline" }); + const rows = within(list).getAllByTestId("timeline-row"); + expect(rows).toHaveLength(2); + expect(rows[0]).toHaveTextContent("Work Gmail received 3 emails"); + expect(rows[0]).toHaveTextContent("family"); + expect(rows[1]).toHaveTextContent("Adeel received “Mail u1”"); + expect(within(rows[1]).getByRole("button", { name: "Reviewed (r)" })).toHaveAttribute("aria-pressed", "true"); + // the page asks for what isn't hidden + expect(m(Activities.listActivities).mock.calls[0][0].query).toMatchObject({ hidden: false, limit: 50 }); + fireEvent.click(within(rows[0]).getByRole("button", { name: "Show the 3" })); + expect(within(rows[0]).getByRole("link", { name: "Work Gmail received “Mail e1”" })).toHaveAttribute("href", "/resources/e1"); + // one item opens to its details + fireEvent.click(within(rows[1]).getByRole("button", { name: "Show details" })); + expect(within(rows[1]).getByText("Subject")).toBeInTheDocument(); + expect(within(rows[1]).getByRole("link", { name: "Open" })).toHaveAttribute("href", "/resources/u1"); +}); + +test("marks: a toggle marks every item of a line, and Mark all shown as reviewed can be undone", async () => { + wrap(); + const rows = within(await screen.findByRole("list", { name: "Timeline" })).getAllByTestId("timeline-row"); + fireEvent.click(within(rows[0]).getByRole("button", { name: "Mark important (i)" })); + await waitFor(() => + expect(m(Activities.markActivities)).toHaveBeenCalledWith( + expect.objectContaining({ body: { ids: ["e3", "e2", "e1"], important: true } }), + ), + ); + expect(within(rows[0]).getByRole("button", { name: "Important (i)" })).toHaveAttribute("aria-pressed", "true"); + m(Activities.markActivities).mockClear(); + fireEvent.click(screen.getByRole("button", { name: "Mark all shown as reviewed" })); + await waitFor(() => + expect(m(Activities.markActivities)).toHaveBeenCalledWith( + expect.objectContaining({ body: { ids: ["e3", "e2", "e1"], reviewed: true } }), + ), + ); + expect(await screen.findByText("Marked 3 reviewed")).toBeInTheDocument(); + expect(screen.getByRole("button", { name: "Mark all shown as reviewed" })).toBeDisabled(); + fireEvent.click(screen.getByRole("button", { name: "Undo" })); + await waitFor(() => + expect(m(Activities.markActivities)).toHaveBeenLastCalledWith( + expect.objectContaining({ body: { ids: ["e3", "e2", "e1"], reviewed: false } }), + ), + ); + expect(within(rows[0]).getByRole("button", { name: "Mark reviewed (r)" })).toHaveAttribute("aria-pressed", "false"); +}); + +test("keys: j and k move, r marks reviewed, i marks important", async () => { + wrap(); + const rows = within(await screen.findByRole("list", { name: "Timeline" })).getAllByTestId("timeline-row"); + fireEvent.keyDown(window, { key: "j" }); + expect(rows[0]).toHaveFocus(); + fireEvent.keyDown(window, { key: "j" }); + expect(rows[1]).toHaveFocus(); + fireEvent.keyDown(window, { key: "r" }); // u1 was reviewed: r clears it + await waitFor(() => + expect(m(Activities.markActivities)).toHaveBeenCalledWith(expect.objectContaining({ body: { ids: ["u1"], reviewed: false } })), + ); + fireEvent.keyDown(window, { key: "k" }); + expect(rows[0]).toHaveFocus(); + fireEvent.keyDown(window, { key: "i" }); + await waitFor(() => + expect(m(Activities.markActivities)).toHaveBeenCalledWith( + expect.objectContaining({ body: { ids: ["e3", "e2", "e1"], important: true } }), + ), + ); + // typing in a field isn't a key for the page + m(Activities.markActivities).mockClear(); + const box = screen.getByRole("searchbox", { name: "Words in the summary" }); + fireEvent.keyDown(box, { key: "r" }); + expect(m(Activities.markActivities)).not.toHaveBeenCalled(); +}); + +test("hiding takes an item out of sight, with an undo", async () => { + wrap(); + const rows = within(await screen.findByRole("list", { name: "Timeline" })).getAllByTestId("timeline-row"); + fireEvent.click(within(rows[1]).getByRole("button", { name: "Show details" })); + fireEvent.click(within(rows[1]).getByRole("button", { name: "Hide" })); + await waitFor(() => expect(screen.getAllByTestId("timeline-row")).toHaveLength(1)); + expect(m(Activities.markActivities)).toHaveBeenCalledWith(expect.objectContaining({ body: { ids: ["u1"], hidden: true } })); + fireEvent.click(await screen.findByRole("button", { name: "Undo" })); + await waitFor(() => expect(screen.getAllByTestId("timeline-row")).toHaveLength(2)); +}); + +test("filters go in the address, and new items wait behind a pill", async () => { + m(Activities.listActivities).mockImplementation(({ query }) => + ok( + query.since + ? { items: [act_("e4", 0)], next: null, namespaces: { "3": "family" }, marks: {} } + : { ...PAGE, items: ITEMS.slice(3) }, + ), + ); + wrap(); + await screen.findByRole("list", { name: "Timeline" }); + expect(screen.getAllByTestId("timeline-row")).toHaveLength(1); + const pill = await screen.findByRole("button", { name: "1 new" }); + await act(async () => fireEvent.click(pill)); + const rows = screen.getAllByTestId("timeline-row"); + expect(rows).toHaveLength(2); + expect(rows[0]).toHaveTextContent("Work Gmail received “Mail e4”"); + // a filter changes the address, and is remembered for next time + fireEvent.click(screen.getByRole("checkbox", { name: "Unreviewed only" })); + expect(replace).toHaveBeenLastCalledWith("/timeline?unreviewed=1"); + expect(localStorage.getItem("lens.timeline.filters")).toBe("unreviewed=1"); + const words = screen.getByRole("searchbox", { name: "Words in the summary" }); + fireEvent.change(words, { target: { value: "trip" } }); + fireEvent.keyDown(words, { key: "Enter" }); + expect(replace).toHaveBeenLastCalledWith("/timeline?q=trip"); +}); + +test("filters in the address make the query, and an empty address brings back the last ones", async () => { + localStorage.setItem("lens.timeline.filters", "important=1"); + wrap(); + await waitFor(() => expect(replace).toHaveBeenCalledWith("/timeline?important=1")); + replace.mockClear(); + search = "unreviewed=1&ns=family"; + m(Activities.listActivities).mockClear(); + wrap(); + await waitFor(() => + expect(m(Activities.listActivities).mock.calls[0][0].query).toMatchObject({ + reviewed: false, + namespace: ["family"], + hidden: false, + }), + ); + expect(replace).not.toHaveBeenCalled(); +}); + +test("Home's Latest card lists what you haven't reviewed", async () => { + m(Activities.listActivities).mockReturnValue(ok({ items: ITEMS.slice(0, 2), next: null, namespaces: { "3": "family" } })); + wrap(); + expect(await screen.findByRole("link", { name: "Work Gmail received “Mail e3”" })).toHaveAttribute("href", "/resources/e3"); + expect(m(Activities.listActivities).mock.calls[0][0].query).toEqual({ reviewed: false, hidden: false, limit: 5 }); + expect(screen.getByRole("link", { name: "Timeline" })).toHaveAttribute("href", "/timeline?unreviewed=1"); + expect(screen.queryByRole("button", { name: /Mark/ })).not.toBeInTheDocument(); +}); diff --git a/nextjs-frontend/app/(app)/timeline/page.tsx b/nextjs-frontend/app/(app)/timeline/page.tsx new file mode 100644 index 000000000..ad3e15a0b --- /dev/null +++ b/nextjs-frontend/app/(app)/timeline/page.tsx @@ -0,0 +1,15 @@ +import type { Metadata } from "next"; +import { Suspense } from "react"; + +import { TimelinePage } from "@/components/timeline/timeline-page"; + +export const metadata: Metadata = { title: "Timeline" }; + +/** What came in from every source, newest first, to review (backend: GET /api/v1/activities, docs/timeline.md). */ +export default function Page() { + return ( + + + + ); +} diff --git a/nextjs-frontend/components/app-shell/nav-config.ts b/nextjs-frontend/components/app-shell/nav-config.ts index 48d253bc4..ff49b052d 100644 --- a/nextjs-frontend/components/app-shell/nav-config.ts +++ b/nextjs-frontend/components/app-shell/nav-config.ts @@ -4,6 +4,7 @@ import { ChartLine, ChartNoAxesColumn, HardDriveDownload, + History, House, LibraryBig, MessagesSquare, @@ -51,6 +52,7 @@ export const NAV: NavItem[] = [ { label: "Search", href: "/search", icon: Search, group: "" }, { label: "Chat", href: "/chat", icon: MessagesSquare, group: "" }, { label: "Notes", href: "/notes", icon: NotebookPen, group: "" }, + { label: "Timeline", href: "/timeline", icon: History, group: "Explore" }, { label: "Entities", href: "/entities", icon: Shapes, group: "Explore" }, { label: "Topics", href: "/topics", icon: Tags, group: "Explore" }, { label: "Graph", href: "/graph", icon: Waypoints, group: "Explore" }, diff --git a/nextjs-frontend/components/home/home-screen.tsx b/nextjs-frontend/components/home/home-screen.tsx index eb76b7118..5696d43d0 100644 --- a/nextjs-frontend/components/home/home-screen.tsx +++ b/nextjs-frontend/components/home/home-screen.tsx @@ -9,6 +9,7 @@ import { AccessRequests, Resources, Sources, Speakers, Tokens } from "@/app/open import { buildAttention, greeting, type AttentionItem } from "@/components/home/attention"; import { QuickImport } from "@/components/home/quick-import"; import { rememberView, useRecentViews, type ViewedKind } from "@/components/home/recently-viewed"; +import { LatestCard } from "@/components/timeline/latest-card"; import { useRecordingActions } from "@/components/library/actions"; import { elapsed, isActiveJob, latestJobs, statusView, stepLabel, totalDuration } from "@/components/library/model"; import { Badge } from "@/components/ui/badge"; @@ -388,6 +389,8 @@ export function HomeScreen({ switcher }: { switcher?: React.ReactNode } = {}) {
+ +
Processing now{running.length ? ` · ${running.length}` : ""} {jobs.isLoading ? ( diff --git a/nextjs-frontend/components/timeline/filters.tsx b/nextjs-frontend/components/timeline/filters.tsx new file mode 100644 index 000000000..1aabf07b9 --- /dev/null +++ b/nextjs-frontend/components/timeline/filters.tsx @@ -0,0 +1,219 @@ +"use client"; + +import { X } from "lucide-react"; +import { useEffect, useState } from "react"; + +import type { ActivityKind } from "@/app/openapi-client/types.gen"; +import { kindsByFamily, NO_FILTERS, isFiltered, type Filters } from "@/components/timeline/model"; +import { Button } from "@/components/ui/button"; +import { Checkbox, Input, Select } from "@/components/ui/field"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/menu"; +import { cn } from "@/lib/utils"; + +export type Actor = { id: string; name: string }; + +/** A text filter applied on Enter or when it loses focus, so each keystroke doesn't reload the timeline. */ +function TextFilter({ + label, + value, + onApply, + placeholder, + list, + className, +}: { + label: string; + value: string; + onApply: (v: string) => void; + placeholder?: string; + list?: string; + className?: string; +}) { + const [draft, setDraft] = useState(value); + useEffect(() => setDraft(value), [value]); + const apply = () => draft.trim() !== value && onApply(draft.trim()); + return ( + setDraft(e.target.value)} + onBlur={apply} + onKeyDown={(e) => { + if (e.key === "Enter") { + e.preventDefault(); + apply(); + } + }} + className={cn("h-8 text-[13px]", className)} + /> + ); +} + +/** Kind chips by family (Email, Calendar, Files, …) in a popover; noisy kinds are named as such. */ +function KindPicker({ + kinds, + value, + onChange, +}: { + kinds: ActivityKind[]; + value: string[]; + onChange: (v: string[]) => void; +}) { + const toggle = (k: string) => onChange(value.includes(k) ? value.filter((x) => x !== k) : [...value, k]); + const label = kinds.find((k) => k.name === value[0])?.label ?? value[0]; + return ( + + + + + + {kindsByFamily(kinds).map(([family, ks]) => ( +
+ {family} +
+ {ks.map((k) => { + const on = value.includes(k.name); + return ( + + ); + })} +
+
+ ))} + {value.length > 0 && ( + + )} +
+
+ ); +} + +/** The timeline's filters: words, unreviewed and important, kinds, source or person, namespace, entity, dates and + * automation. Inline on a computer; stacked in a sheet on a phone (`stacked`). */ +export function FiltersBar({ + value, + onChange, + kinds, + actors, + namespaces, + tags, + stacked, +}: { + value: Filters; + onChange: (f: Filters) => void; + kinds: ActivityKind[]; + /** People and sources seen on the timeline, for "Source or person". */ + actors: Actor[]; + namespaces: string[]; + /** Entities seen in tags, offered as you type. */ + tags: string[]; + stacked?: boolean; +}) { + const set = (patch: Partial) => onChange({ ...value, ...patch }); + const people = actors.filter((a) => !a.id.startsWith("lens:automation/")); + const automations = actors.filter((a) => a.id.startsWith("lens:automation/")); + const listId = stacked ? "timeline-tags-sheet" : "timeline-tags"; + return ( +
+
+ set({ unreviewed: v })} /> + set({ important: v })} /> +
+ set({ kinds: v })} /> + set({ namespace: e.target.value ? [e.target.value] : [] })} + options={[{ value: "", label: "Every namespace" }, ...namespaces.map((n) => ({ value: n, label: n }))]} + /> + )} + set({ tag: v })} + list={listId} + className={stacked ? undefined : "w-36"} + /> + + {tags.map((t) => ( + + + set({ from: e.target.value })} + className="h-8 w-[140px] text-[13px]" + /> + to + set({ to: e.target.value })} + className="h-8 w-[140px] text-[13px]" + /> + + {(automations.length > 0 || value.automation) && ( +