8000 feat(timeline): snooze a source or kind until a time you pick by adeelahmad · Pull Request #668 · adeelahmad/lense · GitHub
[go: up one dir, main page]

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
2 changes: 2 additions & 0 deletions changelog.d/timeline-snooze-until.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The mute menu on a timeline item can now snooze its source or kind until a time you pick (**Mute Work Gmail
until…**), starting at nine tomorrow morning; Enter mutes.
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ request, to another check that proves the same thing; loosening a requirement or
| The graph as it was at any version | [test_graph_history.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_graph_history.py) `test_the_explorer_and_cypher_as_of_a_version`, `test_the_canvas_as_of_a_version`; [test_graph_history.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_graph_history.py) `test_every_curation_is_an_event_and_every_version_replays` |
| Sources, sensors, people and agents as actors in the graph, with ADDED links to what they brought in, on the canvas, in the explorer and in Cypher | [test_graph.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_graph.py) `test_sources_are_actors_in_the_graph`; jest [graph-explorer.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/graph-explorer.test.ts) `shows a source only while something it brought in is visible` |
| A For you order of the timeline, learned from each person's own reactions, comments, marks and opens, each item saying why, with Latest the default; through the API, MCP, the assistant and the page | [test_timeline_for_you.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_for_you.py) `test_for_you_learns_from_reactions_comments_and_marks_and_says_why`, `test_opening_an_item_counts_for_you_a_little_each_time_up_to_a_few`, `test_agents_read_for_you_too`; jest [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `keep the For you order as a view, not a filter`, [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `For you: the toggle goes in the address, each placed line says why, and Latest stays the default` |
| Muting a source, a person or a kind on the timeline, for good or until a time, for the person alone, with nothing deleted; through the API, MCP, the assistant (asking first after outside text) and the page | [test_timeline_mutes.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_mutes.py) `test_a_mute_hides_an_actor_or_a_kind_for_the_person_alone`, `test_agents_mute_too_and_the_assistant_asks_first_after_outside_text`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `muting a source takes everything from it out, lists it as muted, and Undo or the chip brings it back`, `the menu beside Mute snoozes a source for an hour, a day or a week, or mutes the item's kind`, [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `a snooze ends an hour, a day or a week from now` |
| Muting a source, a person or a kind on the timeline, for good or until a time, for the person alone, with nothing deleted; through the API, MCP, the assistant (asking first after outside text) and the page | [test_timeline_mutes.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_mutes.py) `test_a_mute_hides_an_actor_or_a_kind_for_the_person_alone`, `test_agents_mute_too_and_the_assistant_asks_first_after_outside_text`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `muting a source takes everything from it out, lists it as muted, and Undo or the chip brings it back`, `the menu beside Mute snoozes a source for an hour, a day or a week, or mutes the item's kind`, `a snooze can end at a time you pick, nine tomorrow to start with, and Enter mutes`, [timeline-model.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-model.test.ts) `a snooze ends an hour, a day or a week from now`, `a snooze to a time you pick starts at nine tomorrow, in the browser's own time` |
| An asset moved to another namespace is `asset.moved`, a Move seen where it is now, and a sensor a person pauses, ignores, resumes or sets back to new is `sensor.changed`, an Update with the status it had before, seen in its namespace or by admins; a change that changes nothing logs nothing | [test_timeline_verbs.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_verbs.py) `test_moving_an_asset_is_a_move_seen_where_it_is_now`, `test_switching_a_sensor_is_an_update_with_what_it_was` |
| A file a watched folder finds changed in its source and reads again is `file.changed`, an Update linking the asset it was before, not a second `file.added`; it is still a child of `asset.added`, so triggers on new assets fire on it as before | [test_events_content.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/domain/test_events_content.py) `test_a_file_changed_in_its_source_is_file_changed_linked_to_the_asset_it_was_before` |
| An opened timeline item shows what it caused, the runs it started of the automations the person manages and the approvals those asked for, with Approve and Decline on waiting ones; `GET /activities/{id}/caused`, `approvals?activity=`, MCP `activity_caused` and the assistant | [test_timeline_caused.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_timeline_caused.py) `test_an_item_lists_what_it_caused_and_the_waiting_approval_is_decided_there`, `test_agents_read_what_an_item_caused_too`; jest [timeline-ui.test.tsx](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/timeline-ui.test.tsx) `an opened item shows what it caused, and a waiting approval is approved there` |
Expand Down
7 changes: 4 additions & 3 deletions docs/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,16 @@ block.
## Muting

Each person mutes a source or person (an actor) or a kind of activity ("hide syslog"), for good or until a time
(snoozed for an hour, a day or a week), for themselves alone. Muting hides; it never deletes: a muted actor's activities stay stored,
(snoozed for an hour, a day, a week or until a time they pick), for themselves alone. Muting hides; it never deletes: a muted actor's activities stay stored,
still trigger automations and still show to everyone else, and come back the moment the mute is lifted or runs out.
The timeline leaves them out as it leaves out what you hid, so `hidden=true` shows them and `hidden=false` (the
page) does not; a For you page scores only what is left.

- On the page, **Mute Work Gmail** on an opened item mutes its actor with one click; the small menu beside it has
**Mute Work Gmail for an hour**, **for a day** and **for a week** (a snooze: the mute runs out by itself), **Mute
Work Gmail until…** (a time you pick, nine tomorrow morning to start with; Enter mutes), **Mute
Email received items** (the kind) and the kind for each of those. The **Muted** row above the list shows each, with when a snooze ends, and lifts one with its ×.
Any other time is through the API, MCP and the assistant.
The API, MCP and the assistant take any time too.
- `POST /api/v1/activities/mute` with `{"actor": "lens:source/12", "name": "Work Gmail"}` or `{"kind":
"sensor.reading"}` (the kinds under it count too), and `"until"` as an ISO 8601 time to snooze it, mutes for
yourself; `"on": false` lifts it. The answer, and `GET /api/v1/activities/mutes`, is your mutes now: `{actor, kind,
Expand Down Expand Up @@ -282,7 +283,7 @@ has any more. Comments on them stay, since they are what people wrote, and an as

- Server-sent updates instead of the page polling for new items.
- For you could cache each person's affinity for a minute rather than summing it on every read.
- A muted actor's own line in the Filters, and a snooze to a time you pick from the page (the API takes any `until`).
- A muted actor's own line in the Filters.
- A file changed in its source is read again as a new asset beside the earlier one (`file.changed` links them);
reading the change into the same asset is to come. A file in a namespace's own folders changed in place is read
again into the same asset with no activity yet.
Expand Down
8 changes: 8 additions & 0 deletions nextjs-frontend/__tests__/timeline-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
objectFields,
objectHref,
snoozeUntil,
localInput,
tomorrowMorning,
toParams,
toQuery,
unseen,
Expand Down Expand Up @@ -194,3 +196,9 @@ test("a snooze ends an hour, a day or a week from now", () => {
expect(snoozeUntil("a day", now)).toBe("2026-10-20T09:00:00.000Z");
expect(snoozeUntil("a week", now)).toBe("2026-10-26T09:00:00.000Z");
});

test("a snooze to a time you pick starts at nine tomorrow, in the browser's own time", () => {
const d = tomorrowMorning(new Date(2026, 9, 31, 22, 15));
expect(localInput(d)).toBe("2026-11-01T09:00");
expect(localInput(new Date(2026, 0, 5, 7, 3))).toBe("2026-01-05T07:03");
});
31 changes: 31 additions & 0 deletions nextjs-frontend/__tests__/timeline-ui.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Activities, Chats } from "@/app/openapi-client";
import type { ActivityPage, StreamActivity } from "@/app/openapi-client/types.gen";
import { ASK_ABOUT_EVENT } from "@/components/page-chat/page-chat-model";
import { LatestCard } from "@/components/timeline/latest-card";
import { localInput, tomorrowMorning } from "@/components/timeline/model";
import { TimelinePage } from "@/components/timeline/timeline-page";
import { ToastProvider } from "@/components/ui/toast";
import { TooltipProvider } from "@/components/ui/tooltip";
Expand Down Expand Up @@ -633,6 +634,36 @@ test("the menu beside Mute snoozes a source for an hour, a day or a week, or mut
expect(await screen.findByText("Muted Work Gmail for a day")).toBeInTheDocument();
});

test("a snooze can end at a time you pick, nine tomorrow to start with, and Enter mutes", async () => {
wrap(<TimelinePage />);
const rows = within(await screen.findByRole("list", { name: "Timeline" })).getAllByTestId("timeline-row");
fireEvent.click(within(rows[1]).getByRole("button", { name: "Show details" }));
fireEvent.keyDown(within(rows[1]).getByRole("button", { name: "More ways to mute Adeel" }), { key: "Enter" });
fireEvent.click(await screen.findByRole("menuitem", { name: "Mute Adeel until…" }));
const dialog = await screen.findByRole("dialog", { name: "Mute Adeel until" });
const input = within(dialog).getByLabelText("Until") as HTMLInputElement;
expect(input).toHaveFocus();
expect(input.value).toBe(localInput(tomorrowMorning()));
// a time gone by says so and mutes nothing
fireEvent.change(input, { target: { value: "2020-01-01T09:00" } });
fireEvent.submit(input.form!);
expect(await within(dialog).findByRole("alert")).toHaveTextContent("Pick a time still to come.");
expect(m(Activities.muteActivities)).not.toHaveBeenCalled();
const later = new Date(Date.now() + 3 * 86_400_000);
later.setHours(18, 30, 0, 0);
fireEvent.change(input, { target: { value: localInput(later) } });
fireEvent.submit(input.form!);
await waitFor(() =>
expect(m(Activities.muteActivities)).toHaveBeenCalledWith(
expect.objectContaining({
body: { actor: "lens:account/1", name: "Adeel", until: later.toISOString(), on: true },
}),
),
);
expect(await screen.findByText(`Muted Adeel until ${later.toLocaleString()}`)).toBeInTheDocument();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});

test("the address can name one item, opened above the timeline, with a way back", async () => {
search = "item=u1";
wrap(<TimelinePage />);
Expand Down
80 changes: 77 additions & 3 deletions nextjs-frontend/components/timeline/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
Bell,
CalendarClock,
CalendarDays,
ChevronDown,
ChevronRight,
Expand All @@ -22,7 +23,7 @@ import {
type LucideIcon,
} from "lucide-react";
import Link from "next/link";
import { forwardRef, useState, type KeyboardEvent, type ReactNode } from "react";
import { forwardRef, useState, type FormEvent, type KeyboardEvent, type ReactNode } from "react";

import type { Reaction } from "@/app/openapi-client/types.gen";
import { askAbout } from "@/components/page-chat/page-chat-model";
Expand All @@ -33,9 +34,11 @@ import {
familyOf,
fieldLabel,
groupSummary,
localInput,
objectFields,
objectHref,
SNOOZES,
tomorrowMorning,
type Activity,
type Family,
type Group,
Expand All @@ -47,6 +50,7 @@ import { useOpened } from "@/components/timeline/use-timeline";
import { sumReactions } from "@/components/timeline/social-model";
import { Badge } from "@/components/ui/badge";
import { Button, IconButton } from "@/components/ui/button";
import { Dialog } from "@/components/ui/dialog";
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@/components/ui/menu";
import { DateTime } from "@/components/ui/states";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -209,11 +213,13 @@ export function ActivityDetail({
}

/** How to mute from an item: its actor (the default) or its kind, for good or for a snooze (an hour, a day, a week). */
export type MuteOpts = { kind?: boolean; span?: Snooze };
export type MuteOpts = { kind?: boolean; span?: Snooze; until?: Date };
const SNOOZE_SPANS = Object.keys(SNOOZES) as Snooze[];

/** Mute the item's actor with one click, and the other ways (a snooze, its kind) behind a small menu beside it. */
/** Mute the item's actor with one click, and the other ways (a snooze, one to a time you pick, its kind) behind a
* small menu beside it. */
function MuteButton({ name, kind, onMute }: { name: string; kind?: string; onMute: (opts?: MuteOpts) => void }) {
const [picking, setPicking] = useState<{ kind: boolean } | null>(null);
return (
<span className="inline-flex items-center">
<Button
Expand All @@ -237,6 +243,9 @@ function MuteButton({ name, kind, onMute }: { name: string; kind?: string; onMut
Mute {name} for {span}
</MenuItem>
))}
<MenuItem icon={<CalendarClock />} => setPicking({ kind: false })}>
Mute {name} until…
</MenuItem>
{kind && (
<>
<MenuItem icon={<VolumeX />} => onMute({ kind: true })}>
Expand All @@ -247,14 +256,79 @@ function MuteButton({ name, kind, onMute }: { name: string; kind?: string; onMut
Mute {kind} items for {span}
</MenuItem>
))}
<MenuItem icon={<CalendarClock />} => setPicking({ kind: true })}>
Mute {kind} items until…
</MenuItem>
</>
)}
</MenuContent>
</Menu>
{picking && (
<SnoozeUntil
what={picking.kind ? `${kind} items` : name}
=> setPicking(null)}
=> {
onMute({ kind: picking.kind || undefined, until });
setPicking(null);
}}
/>
)}
</span>
);
}

/** Pick when a snooze ends: tomorrow at nine to start with, Enter mutes. */
function SnoozeUntil({ what, onPick, onClose }: { what: string; onPick: (until: Date) => void; onClose: () => void }) {
const [value, setValue] = useState(() => localInput(tomorrowMorning()));
const [error, setError] = useState("");
const submit = (e: FormEvent) => {
e.preventDefault();
const until = new Date(value);
if (Number.isNaN(until.getTime()) || until.getTime() <= Date.now()) {
setError("Pick a time still to come.");
return;
}
onPick(until);
};
return (
<Dialog
open
=> !o && onClose()}
title={`Mute ${what} until`}
description="It comes back by itself then; the Muted list ends it sooner."
actions={
<>
<Button variant="ghost" >
Cancel
</Button>
<Button type="submit" form="snooze-until" variant="primary">
Mute
</Button>
</>
}
>
<form id="snooze-until" className="flex flex-col gap-1.5">
<input
type="datetime-local"
aria-label="Until"
value={value}
min={localInput(new Date())}
=> {
setValue(e.target.value);
setError("");
}}
className="h-9 rounded-md border border-border bg-surface px-2 text-[14px] text-fg"
/>
{error && (
<p role="alert" className="text-[12.5px] text-red-dark">
{error}
</p>
)}
</form>
</Dialog>
);
}

type RowProps = {
group: Group;
/** The namespace names by id. */
Expand Down
11 changes: 11 additions & 0 deletions nextjs-frontend/components/timeline/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ export function viewName(f: Filters, labels: Record<string, string> = {}): strin
export const SNOOZES = { "an hour": 3_600_000, "a day": 86_400_000, "a week": 7 * 86_400_000 } as const;
export type Snooze = keyof typeof SNOOZES;

/** A `datetime-local` input's value for a moment, in the browser's own time zone (YYYY-MM-DDTHH:mm). */
export function localInput(d: Date): string {
const p = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}`;
}

/** Where a snooze to a time you pick starts: tomorrow at nine in the morning, local time. */
export function tomorrowMorning(now = new Date()): Date {
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 9, 0);
}

/** A snooze's end from now, as the `until` of a mute. */
export function snoozeUntil(span: Snooze, now = Date.now()): string {
return new Date(now + SNOOZES[span]).toISOString();
Expand Down
2 changes: 1 addition & 1 deletion nextjs-frontend/components/timeline/timeline-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function TimelinePage() {
(a: Activity, opts?: MuteOpts) =>
mutes.mute(
opts?.kind ? { kind: a.kind, name: labels[a.kind] ?? a.kind } : { actor: a.actor.id, name: a.actor.name },
opts?.span,
opts?.until ?? opts?.span,
),
[mutes, labels],
);
Expand Down
13 changes: 10 additions & 3 deletions nextjs-frontend/components/timeline/use-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,21 @@ export function useMutes() {
onError: (e) => toast({ tone: "red", title: "Couldn’t save the mute", body: (e as Error).message }),
});
const mute = useCallback(
(target: { actor: string; name: string } | { kind: string; name: string }, span?: Snooze) => {
(target: { actor: string; name: string } | { kind: string; name: string }, when?: Snooze | Date) => {
const until = when instanceof Date ? when.toISOString() : when ? snoozeUntil(when) : undefined;
const title =
when instanceof Date
? `Muted ${target.name} until ${when.toLocaleString()}`
: when
? `Muted ${target.name} for ${when}`
: `Muted ${target.name}`;
mutate(
{ ...target, until: span ? snoozeUntil(span) : undefined, on: true },
{ ...target, until, on: true },
{
onSuccess: () =>
toast({
tone: "green",
title: span ? `Muted ${target.name} for ${span}` : `Muted ${target.name}`,
title,
body: "Its activities stay, for everyone else and for your automations; hidden=true shows them to you.",
action: { label: "Undo", onClick: () => mutate({ ...target, on: false }) },
}),
Expand Down
Loading
0