Public: anyone can read this; the crew can change it.
Filter the desk to what needs the agent now #12
Check · Review · Land · Live done — Landed and live in production.
mason/speed-to-lead:mason/7-filter-the-desk-to-what-needs-the-agent → main 2 commits fork 3 threads · 3 unresolved
12 files
changed +291
−22
README.md +8 −1
| @@ -12,7 +12,11 @@ goes.** | ||
| 12 | 12 | |
| 13 | 13 | ## How it works |
| 14 | 14 | |
| 15 | **The desk** (the first screen) lists your leads, newest first. Each row | |
| 15 | **The desk** (the first screen) lists your leads, newest first. Links above | |
| 16 | the list narrow it: **Needs you** (a first reply or follow-up waiting), | |
| 17 | **In follow-up** (open, nothing waiting), **Closed** and **All**, each with | |
| 18 | its count (`/?show=needs|open|closed|all`; `GET /leads?show=…` and the MCP | |
| 19 | `list_leads` tool take the same filter). Each row | |
| 16 | 20 | shows the person's name, where they came from (Zillow, your website form, |
| 17 | 21 | an open house, a referral), what they asked, and a **response clock** |
| 18 | 22 | counting since they asked: |
| @@ -111,6 +115,7 @@ curl -X POST https://<app>/leads -H 'content-type: application/json' \ | ||
| 111 | 115 | "source":"zillow","message":"Can we see 418 Juniper Ln?","consent":true}' |
| 112 | 116 | |
| 113 | 117 | curl https://<app>/leads # the desk |
| 118 | curl "https://<app>/leads?show=needs" # only who is waiting on you | |
| 114 | 119 | curl https://<app>/leads/1 -H 'accept: application/json' # one lead, every message |
| 115 | 120 | curl -X POST https://<app>/leads/1/reply -H 'content-type: application/json' -d '{}' |
| 116 | 121 | curl -X POST https://<app>/leads/1/reply -H 'content-type: application/json' -d '{"body":"edited words"}' |
| @@ -138,6 +143,8 @@ On the desk: | ||
| 138 | 143 | - `j` / `k` (or the arrow keys) move between leads; **enter opens one**. |
| 139 | 144 | - `n` logs a lead by hand: type each answer and press enter (name, email, |
| 140 | 145 | phone, source as a number, what they asked, consent `y` or `n`). |
| 146 | - `f` cycles the views (needs you, in follow-up, closed, all); the desk | |
| 147 | shows the current one with its count. | |
| 141 | 148 | - `R` restarts the sample leads from now (admins only; asks first). |
| 142 | 149 | - `esc` leaves. |
| 143 | 150 |
contract/openapi.json +48
| @@ -20,6 +20,19 @@ | ||
| 20 | 20 | "maximum": 500, |
| 21 | 21 | "default": 100 |
| 22 | 22 | } |
| 23 | }, | |
| 24 | { | |
| 25 | "name": "show", | |
| 26 | "in": "query", | |
| 27 | "schema": { | |
| 28 | "enum": [ | |
| 29 | "needs", | |
| 30 | "open", | |
| 31 | "closed", | |
| 32 | "all" | |
| 33 | ], | |
| 34 | "description": "needs: a reply or follow-up waits on you; open: in follow-up, nothing waiting; closed: qualified or lost; all (default, also for any other value)." | |
| 35 | } | |
| 23 | 36 | } |
| 24 | 37 | ], |
| 25 | 38 | "responses": { |
| @@ -935,6 +948,39 @@ | ||
| 935 | 948 | "within_5_min_pct" |
| 936 | 949 | ] |
| 937 | 950 | }, |
| 951 | "show": { | |
| 952 | "enum": [ | |
| 953 | "needs", | |
| 954 | "open", | |
| 955 | "closed", | |
| 956 | "all" | |
| 957 | ], | |
| 958 | "description": "The view listed." | |
| 959 | }, | |
| 960 | "counts": { | |
| 961 | "type": "object", | |
| 962 | "description": "How many leads each view holds.", | |
| 963 | "properties": { | |
| 964 | "needs": { | |
| 965 | "type": "integer" | |
| 966 | }, | |
| 967 | "open": { | |
| 968 | "type": "integer" | |
| 969 | }, | |
| 970 | "closed": { | |
| 971 | "type": "integer" | |
| 972 | }, | |
| 973 | "all": { | |
| 974 | "type": "integer" | |
| 975 | } | |
| 976 | }, | |
| 977 | "required": [ | |
| 978 | "needs", | |
| 979 | "open", | |
| 980 | "closed", | |
| 981 | "all" | |
| 982 | ] | |
| 983 | }, | |
| 938 | 984 | "leads": { |
| 939 | 985 | "type": "array", |
| 940 | 986 | "items": { |
| @@ -944,6 +990,8 @@ | ||
| 944 | 990 | }, |
| 945 | 991 | "required": [ |
| 946 | 992 | "record", |
| 993 | "show", | |
| 994 | "counts", | |
| 947 | 995 | "leads" |
| 948 | 996 | ] |
| 949 | 997 | }, |
src/actions.test.ts +28
| @@ -242,3 +242,31 @@ test("the sample desk: twelve leads, some red, some mid-cadence; only an admin r | ||
| 242 | 242 | for (const m of must(getLead(sampleDb, alice, { id: lead.id })).messages) |
| 243 | 243 | if (m.channel === "text") expect(lead.consent).toBe(true); |
| 244 | 244 | }); |
| 245 | ||
| 246 | test("the desk's views: each lists exactly its leads, counts add up, a bad value is all", () => { | |
| 247 | const sampleDb = openDb(mkdtempSync(join(tmpdir(), "app-views-"))); | |
| 248 | must(resetSample(sampleDb, root, T0)); | |
| 249 | const at = { now: T0.getTime() }; | |
| 250 | const everyone = must(listLeads(sampleDb, alice, at)).leads; | |
| 251 | const show = (v: unknown) => must(listLeads(sampleDb, alice, { ...at, show: v })); | |
| 252 | const needs = show("needs"), open = show("open"), closed = show("closed"); | |
| 253 | const ids = (d: { leads: { id: number }[] }) => d.leads.map((l) => l.id); | |
| 254 | expect(needs.leads.every((l) => l.ready !== null && !["qualified", "lost"].includes(l.state))).toBe(true); | |
| 255 | expect(open.leads.every((l) => l.ready === null && !["qualified", "lost"].includes(l.state))).toBe(true); | |
| 256 | expect(closed.leads.every((l) => ["qualified", "lost"].includes(l.state))).toBe(true); | |
| 257 | expect(needs.leads.length).toBeGreaterThan(0); | |
| 258 | expect(open.leads.length).toBeGreaterThan(0); | |
| 259 | expect(closed.leads.length).toBeGreaterThan(0); | |
| 260 | expect([...ids(needs), ...ids(open), ...ids(closed)].sort()).toEqual(ids({ leads: everyone }).sort()); | |
| 261 | expect(needs.counts).toEqual({ | |
| 262 | needs: needs.leads.length, | |
| 263 | open: open.leads.length, | |
| 264 | closed: closed.leads.length, | |
| 265 | all: everyone.length, | |
| 266 | }); | |
| 267 | const newestFirst = (d: { leads: { created_at: string }[] }) => | |
| 268 | d.leads.every((l, i) => i === 0 || d.leads[i - 1]!.created_at >= l.created_at); | |
| 269 | expect(newestFirst(needs) && newestFirst(open) && newestFirst(closed)).toBe(true); | |
| 270 | for (const bad of ["nope", "", undefined, null, 7]) expect(ids(show(bad))).toEqual(ids({ leads: everyone })); | |
| 271 | expect(show("nope").show).toBe("all"); | |
| 272 | }); |
src/actions.ts +11 −4
| @@ -15,15 +15,18 @@ import { | ||
| 15 | 15 | advance, |
| 16 | 16 | clearLeads, |
| 17 | 17 | close, |
| 18 | countViews, | |
| 18 | 19 | desk, |
| 19 | 20 | detail, |
| 21 | inView, | |
| 20 | 22 | insertLead, |
| 21 | 23 | readyFor, |
| 22 | 24 | redraftUnsent, |
| 23 | 25 | removeLead, |
| 24 | send, | |
| 25 | type Desk, | |
| 26 | 26 | responseRecord, |
| 27 | send, | |
| 28 | viewOf, | |
| 29 | type Desk, | |
| 27 | 30 | type LeadDetail, |
| 28 | 31 | type NewLead, |
| 29 | 32 | } from "./leads.ts"; |
| @@ -76,7 +79,7 @@ const stamp = (at?: Date): string => (at ?? new Date()).toISOString(); | ||
| 76 | 79 | export function listLeads( |
| 77 | 80 | db: Database, |
| 78 | 81 | who: Who, |
| 79 | input: { limit?: number; now?: number } = {}, | |
| 82 | input: { limit?: number; now?: number; show?: unknown } = {}, | |
| 80 | 83 | ): Result<Desk> { |
| 81 | 84 | // Leads are a team's desk, not anyone's own: anything but "yes" is a no. |
| 82 | 85 | if (permit(who, "lead", "list") !== "yes") |
| @@ -85,9 +88,13 @@ export function listLeads( | ||
| 85 | 88 | Math.max(Math.trunc(input.limit ?? 200) || 200, 1), |
| 86 | 89 | 500, |
| 87 | 90 | ); |
| 91 | const show = viewOf(input.show); | |
| 92 | const all = desk(db, 500); | |
| 88 | 93 | return ok({ |
| 89 | 94 | record: responseRecord(db, input.now ?? Date.now()), |
The terminal (src/terminal.ts) calls listLeads without show and has no way to filter; add the view key there with a test. |
||
| 90 | leads: desk(db, limit), | |
| 95 | show, | |
| 96 | counts: countViews(all), | |
| 97 | leads: all.filter((l) => inView(l, show)).slice(0, limit), | |
| 91 | 98 | }); |
| 92 | 99 | } |
| 93 | 100 |
src/leads.ts +41 −1
| @@ -68,9 +68,49 @@ export interface DeskLead extends Lead { | ||
| 68 | 68 | readonly next_at: string | null; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | /** The desk as the doors see it: the leads, and the record above them. */ | |
| 71 | /** | |
| 72 | * Ways to look at the desk. `needs`: a first reply or a follow-up is waiting | |
| 73 | * on the agent. `open`: still in the cadence, nothing waiting. `closed`: | |
| 74 | * qualified or lost. `all`: everyone. The first three never overlap. | |
| 75 | */ | |
| 76 | export const VIEWS = ["needs", "open", "closed", "all"] as const; | |
| 77 | export type View = (typeof VIEWS)[number]; | |
| 78 | ||
| 79 | /** What a door says about the views, in one place. */ | |
| 80 | export const VIEW_HELP = | |
| 81 | "needs: a reply or follow-up waits on you; open: in follow-up, nothing waiting; closed: qualified or lost; all (default, also for any other value)."; | |
| 82 | ||
| 83 | /** A view from user text; anything unknown is `all`. */ | |
| 84 | export const viewOf = (text: unknown): View => | |
| 85 | VIEWS.find((v) => v === text) ?? "all"; | |
| 86 | ||
| 87 | export const inView = (lead: DeskLead, view: View): boolean => { | |
| 88 | const closed = CLOSED.includes(lead.state); | |
| 89 | switch (view) { | |
| 90 | case "needs": | |
| 91 | return !closed && lead.ready !== null; | |
| 92 | case "open": | |
| 93 | return !closed && lead.ready === null; | |
| 94 | case "closed": | |
| 95 | return closed; | |
| 96 | case "all": | |
| 97 | return true; | |
| 98 | } | |
| 99 | }; | |
| 100 | ||
| 101 | /** How many leads each view holds. */ | |
| 102 | export const countViews = (leads: readonly DeskLead[]): Record<View, number> => ({ | |
| 103 | needs: leads.filter((l) => inView(l, "needs")).length, | |
| 104 | open: leads.filter((l) => inView(l, "open")).length, | |
| 105 | closed: leads.filter((l) => inView(l, "closed")).length, | |
| 106 | all: leads.length, | |
| 107 | }); | |
| 108 | ||
| 109 | /** The desk as the doors see it: the leads in a view, and the record above them. */ | |
| 72 | 110 | export interface Desk { |
| 73 | 111 | readonly record: ResponseRecord; |
| 112 | readonly show: View; | |
| 113 | readonly counts: Record<View, number>; | |
| 74 | 114 | readonly leads: DeskLead[]; |
| 75 | 115 | } |
| 76 | 116 |
src/mcp.ts +10 −3
| @@ -19,6 +19,7 @@ import { | ||
| 19 | 19 | } from "./actions.ts"; |
| 20 | 20 | import { SOURCES } from "./drafts.ts"; |
| 21 | 21 | import { title } from "./env.ts"; |
| 22 | import { VIEW_HELP, VIEWS } from "./leads.ts"; | |
| 22 | 23 | import { fields } from "./http.ts"; |
| 23 | 24 | import type { Who } from "./who.ts"; |
| 24 | 25 | |
| @@ -43,13 +44,19 @@ export const tools: readonly Tool[] = [ | ||
| 43 | 44 | { |
| 44 | 45 | name: "list_leads", |
| 45 | 46 | description: |
| 46 | "The desk: your response record (median first reply, share answered within 5 minutes, last 30 days) and every lead, newest first, with what is ready to approve.", | |
| 47 | "The desk: your response record (median first reply, share answered within 5 minutes, last 30 days) and the leads (optionally only those that need you, are in follow-up, or are closed), newest first, with what is ready to approve.", | |
| 47 | 48 | inputSchema: { |
| 48 | 49 | type: "object", |
| 49 | properties: { limit: { type: "integer", minimum: 1, maximum: 500 } }, | |
| 50 | properties: { | |
| 51 | limit: { type: "integer", minimum: 1, maximum: 500 }, | |
| 52 | show: { | |
| 53 | enum: [...VIEWS], | |
| 54 | description: VIEW_HELP, | |
| 55 | }, | |
| 56 | }, | |
| 50 | 57 | }, |
| 51 | 58 | run: (db, who, args) => |
| 52 | listLeads(db, who, { limit: Number(args.limit ?? 200) }), | |
| 59 | listLeads(db, who, { limit: Number(args.limit ?? 200), show: args.show }), | |
| 53 | 60 | }, |
| 54 | 61 | { |
| 55 | 62 | name: "get_lead", |
src/pages/desk.ts +28 −2
| @@ -7,7 +7,7 @@ import { day, clock, consent, source, STATE_LABEL } from "./parts.ts"; | ||
| 7 | 7 | import { layout } from "./layout.ts"; |
| 8 | 8 | import { escape } from "../http.ts"; |
| 9 | 9 | import { recordLine } from "../clock.ts"; |
| 10 | import type { DeskLead, ResponseRecord } from "../leads.ts"; | |
| 10 | import type { DeskLead, ResponseRecord, View } from "../leads.ts"; | |
| 11 | 11 | import type { Agent } from "../env.ts"; |
| 12 | 12 | import type { Who } from "../who.ts"; |
| 13 | 13 | |
| @@ -16,6 +16,8 @@ export function deskPage(input: { | ||
| 16 | 16 | agent: Agent; |
| 17 | 17 | leads: readonly DeskLead[] | undefined; |
| 18 | 18 | record?: ResponseRecord | undefined; |
| 19 | show?: View | undefined; | |
| 20 | counts?: Record<View, number> | undefined; | |
| 19 | 21 | mayAdd: boolean; |
| 20 | 22 | mayReset: boolean; |
| 21 | 23 | notice?: string | undefined; |
| @@ -34,13 +36,22 @@ export function deskPage(input: { | ||
| 34 | 36 | </section>`, |
| 35 | 37 | }); |
| 36 | 38 | const now = Date.now(); |
| 39 | const show = input.show ?? "all"; | |
| 40 | const counts = input.counts; | |
| 37 | 41 | const waiting = leads.filter((l) => l.ready?.day === 0).length; |
| 38 | 42 | const due = leads.filter((l) => l.ready !== null && l.ready.day > 0).length; |
| 39 | 43 | const summary = `<p class="summary" aria-live="polite"><b>${waiting}</b> waiting for a first reply <span aria-hidden="true">·</span> <b>${due}</b> follow-up${due === 1 ? "" : "s"} due today</p>`; |
| 40 | 44 | const record = input.record === undefined ? "" : `<p class="record">${escape(recordLine(input.record))}</p>`; |
| 45 | const views = | |
| 46 | counts === undefined | |
| 47 | ? "" | |
| 48 | : `<nav class="views" aria-label="Show">${VIEW_LABEL.map( | |
| 49 | ([view, label]) => | |
| 50 | `<a href="${view === "all" ? "/" : `/?show=${view}`}"${view === show ? ' aria-current="page"' : ""}>${label} <b>${counts[view]}</b></a>`, | |
| 51 | ).join("")}</nav>`; | |
| 41 | 52 | const list = |
| 42 | 53 | leads.length === 0 |
| 43 | ? `<p class="empty">No leads yet. New inquiries appear here the moment they arrive.</p>` | |
| 54 | ? `<p class="empty">${EMPTY[show]}</p>` | |
| 44 | 55 | : `<ul class="desk">${leads.map((lead) => row(lead, now)).join("")}</ul>`; |
| 45 | 56 | return layout({ |
| 46 | 57 | who, |
| @@ -51,6 +62,7 @@ export function deskPage(input: { | ||
| 51 | 62 | body: `<div id="desk" data-live="lead.added lead.changed"> |
| 52 | 63 | <div class="desk-head"><h1>Leads</h1>${summary}</div> |
| 53 | 64 | ${record} |
| 65 | ${views} | |
| 54 | 66 | ${list} |
| 55 | 67 | </div> |
| 56 | 68 | ${input.mayAdd ? addForm : ""} |
| @@ -62,6 +74,20 @@ export function deskPage(input: { | ||
| 62 | 74 | }); |
| 63 | 75 | } |
| 64 | 76 | |
| 77 | const VIEW_LABEL: readonly (readonly [View, string])[] = [ | |
| 78 | ["needs", "Needs you"], | |
| 79 | ["open", "In follow-up"], | |
| 80 | ["closed", "Closed"], | |
| 81 | ["all", "All"], | |
| 82 | ]; | |
| 83 | ||
| 84 | const EMPTY: Record<View, string> = { | |
| 85 | needs: "Nobody is waiting on you.", | |
| 86 | open: "Nobody is in follow-up.", | |
| 87 | closed: "No closed leads yet.", | |
| 88 | all: "No leads yet. New inquiries appear here the moment they arrive.", | |
| 89 | }; | |
| 90 | ||
| 65 | 91 | function status(lead: DeskLead): string { |
| 66 | 92 | if (lead.state === "qualified" || lead.state === "lost") |
| 67 | 93 | return `<span class="status" data-state="${lead.state}">${STATE_LABEL[lead.state]}</span>`; |
src/routes.ts +25 −3
| @@ -45,6 +45,7 @@ import { | ||
| 45 | 45 | staticFile, |
| 46 | 46 | text, |
| 47 | 47 | } from "./http.ts"; |
| 48 | import { VIEW_HELP, VIEWS } from "./leads.ts"; | |
| 48 | 49 | import { events } from "./live.ts"; |
| 49 | 50 | import { rpc } from "./mcp.ts"; |
| 50 | 51 | import { deskPage } from "./pages/desk.ts"; |
| @@ -138,6 +139,10 @@ export const DESK_LEAD: Schema = { | ||
| 138 | 139 | }, |
| 139 | 140 | required: [...LEAD_REQUIRED, "ready", "next_at"], |
| 140 | 141 | }; |
| 142 | const SHOW: Schema = { | |
| 143 | enum: [...VIEWS], | |
| 144 | description: VIEW_HELP, | |
| 145 | }; | |
| 141 | 146 | export const DESK: Schema = { |
| 142 | 147 | type: "object", |
| 143 | 148 | properties: { |
| @@ -160,9 +165,21 @@ export const DESK: Schema = { | ||
| 160 | 165 | }, |
| 161 | 166 | required: ["days", "leads", "replied", "median_ms", "within_5_min_pct"], |
| 162 | 167 | }, |
| 168 | show: { enum: [...VIEWS], description: "The view listed." }, | |
| 169 | counts: { | |
| 170 | type: "object", | |
| 171 | description: "How many leads each view holds.", | |
| 172 | properties: { | |
| 173 | needs: { type: "integer" }, | |
| 174 | open: { type: "integer" }, | |
| 175 | closed: { type: "integer" }, | |
| 176 | all: { type: "integer" }, | |
| 177 | }, | |
| 178 | required: ["needs", "open", "closed", "all"], | |
| 179 | }, | |
| 163 | 180 | leads: { type: "array", items: DESK_LEAD }, |
| 164 | 181 | }, |
| 165 | required: ["record", "leads"], | |
| 182 | required: ["record", "show", "counts", "leads"], | |
| 166 | 183 | }; |
| 167 | 184 | const NEW_LEAD: Schema = { |
| 168 | 185 | type: "object", |
| @@ -302,13 +319,17 @@ export const routes: readonly Route[] = [ | ||
| 302 | 319 | path: "/", |
| 303 | 320 | handle: (c) => { |
| 304 | 321 | const { notice, clear } = readNotice(c.request); |
| 305 | const leads = listLeads(c.db, c.who); | |
| 322 | const leads = listLeads(c.db, c.who, { | |
| 323 | show: c.url.searchParams.get("show"), | |
| 324 | }); | |
| 306 | 325 | return html( |
| 307 | 326 | deskPage({ |
| 308 | 327 | who: c.who, |
| 309 | 328 | agent: currentAgent(c.db), |
| 310 | 329 | leads: leads.ok ? leads.value.leads : undefined, |
| 311 | 330 | record: leads.ok ? leads.value.record : undefined, |
| 331 | show: leads.ok ? leads.value.show : undefined, | |
| 332 | counts: leads.ok ? leads.value.counts : undefined, | |
| 312 | 333 | mayAdd: permit(c.who, "lead", "create") === "yes", |
| 313 | 334 | mayReset: permit(c.who, "lead", "delete") === "yes", |
| 314 | 335 | notice, |
| @@ -327,11 +348,12 @@ export const routes: readonly Route[] = [ | ||
| 327 | 348 | answer( |
| 328 | 349 | listLeads(c.db, c.who, { |
| 329 | 350 | limit: whole(c.url.searchParams.get("limit")) ?? 200, |
| 351 | show: c.url.searchParams.get("show"), | |
| 330 | 352 | }), |
| 331 | 353 | ), |
| 332 | 354 | api: { |
| 333 | 355 | summary: "The desk: your response record, and every lead, newest inquiry first.", |
| 334 | query: { limit: LIMIT }, | |
| 356 | query: { limit: LIMIT, show: SHOW }, | |
| 335 | 357 | answer: DESK, |
| 336 | 358 | }, |
| 337 | 359 | }, |
src/server.test.ts +21
| @@ -543,3 +543,24 @@ test("the desk carries the response record: in the page, in JSON, and in the API | ||
| 543 | 543 | }; |
| 544 | 544 | expect(Object.keys(spec.components.schemas.Desk.properties)).toContain("record"); |
| 545 | 545 | }); |
| 546 | ||
| 547 | test("the desk views: links with counts, aria-current, bad value is all, JSON matches HTML", async () => { | |
| 548 | const all = await (await api("/", {}, alice)).text(); | |
| 549 | expect(all).toContain('href="/?show=needs"'); | |
| 550 | for (const label of ["Needs you", "In follow-up", "Closed", "All"]) expect(all).toContain(label); | |
| 551 | expect(all).toMatch(/<a href="\/"[^>]*aria-current="page">All/); | |
| 552 | for (const show of ["needs", "open", "closed"]) { | |
| 553 | const page = await (await api(`/?show=${show}`, {}, alice)).text(); | |
| 554 | expect(page).toMatch(new RegExp(`href="/\\?show=${show}" aria-current="page"`)); | |
| 555 | const json = (await (await api(`/leads?show=${show}`, {}, alice)).json()) as { | |
| 556 | show: string; | |
| 557 | leads: { id: number }[]; | |
| 558 | }; | |
| 559 | expect(json.show).toBe(show); | |
| 560 | const inHtml = [...page.matchAll(/href="\/leads\/(\d+)"/g)].map((m) => Number(m[1])); | |
| 561 | expect(inHtml).toEqual(json.leads.map((l) => l.id)); | |
| 562 | } | |
| 563 | const bad = await (await api("/?show=zzz", {}, alice)).text(); | |
| 564 | expect(bad).toMatch(/<a href="\/"[^>]*aria-current="page">All/); | |
| 565 | expect(((await (await api("/leads?show=zzz", {}, alice)).json()) as { show: string }).show).toBe("all"); | |
| 566 | }); |
src/terminal.test.ts +20
| @@ -274,3 +274,23 @@ test("the desk header carries the response record", () => { | ||
| 274 | 274 | expect(read(t)).toContain("Median first reply:"); |
| 275 | 275 | expect(read(t)).toContain("answered within 5 minutes"); |
| 276 | 276 | }); |
| 277 | ||
| 278 | test("f cycles the desk's views; each shows its count and only its leads", () => { | |
| 279 | const db = fresh(); | |
| 280 | const t = terminal(db, alice); | |
| 281 | const all = read(t); | |
| 282 | expect(all).toContain("[All "); | |
| 283 | expect(all).toContain("Needs you"); | |
| 284 | t.key("f"); | |
| 285 | const needs = read(t); | |
| 286 | expect(needs).toContain("[Needs you "); | |
| 287 | const wanted = (listLeads(db, alice, { show: "needs" }) as { ok: true; value: { leads: { name: string }[]; counts: { needs: number } } }).value; | |
| 288 | expect(needs).toContain(`[Needs you ${wanted.counts.needs}]`); | |
| 289 | for (const l of wanted.leads) expect(needs).toContain(l.name.slice(0, 18)); | |
| 290 | t.key("f"); | |
| 291 | expect(read(t)).toContain("[In follow-up "); | |
| 292 | t.key("f"); | |
| 293 | expect(read(t)).toContain("[Closed "); | |
| 294 | t.key("f"); | |
| 295 | expect(read(t)).toContain("[All "); | |
| 296 | }); |
src/terminal.ts +33 −8
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * may — the hints only leave out keys the table would refuse. |
| 6 | 6 | * |
| 7 | 7 | * Screens: |
| 8 | * desk j/k move · enter open · n log a lead · p profile · R restart samples (admin) · esc quit | |
| 8 | * desk j/k move · enter open · f view (needs/open/closed/all) · n log a lead · p profile · R restart samples (admin) · esc quit | |
| 9 | 9 | * lead s approve and send · e edit, then send · q qualified · x lost · |
| 10 | 10 | * D remove (admin) · esc back |
| 11 | 11 | * edit type; enter is a new line · ctrl-d approve and send · esc cancel |
| @@ -34,7 +34,7 @@ import { between, elapsed, recordLine, tone } from "./clock.ts"; | ||
| 34 | 34 | import { permit } from "./contract.ts"; |
| 35 | 35 | import { SOURCE_LABEL, SOURCES, channelFor } from "./drafts.ts"; |
| 36 | 36 | import { ssh, title, where } from "./env.ts"; |
| 37 | import type { DeskLead, LeadDetail, Message } from "./leads.ts"; | |
| 37 | import { VIEWS, type DeskLead, type LeadDetail, type Message, type View as DeskView } from "./leads.ts"; | |
| 38 | 38 | import { currentAgent } from "./profile.ts"; |
| 39 | 39 | import type { Who } from "./who.ts"; |
| 40 | 40 | |
| @@ -118,6 +118,19 @@ export interface Terminal { | ||
| 118 | 118 | readonly done: boolean; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | const VIEW_LABEL: Record<DeskView, string> = { | |
| 122 | needs: "Needs you", | |
| 123 | open: "In follow-up", | |
| 124 | closed: "Closed", | |
| 125 | all: "All", | |
| 126 | }; | |
| 127 | const EMPTY: Record<DeskView, string> = { | |
| 128 | needs: "Nobody is waiting on you.", | |
| 129 | open: "Nobody is in follow-up.", | |
| 130 | closed: "No closed leads yet.", | |
| 131 | all: "No leads yet. Press n to log one.", | |
| 132 | }; | |
| 133 | ||
| 121 | 134 | export function terminal( |
| 122 | 135 | db: Database, |
| 123 | 136 | me: Who, |
| @@ -125,12 +138,13 @@ export function terminal( | ||
| 125 | 138 | ): Terminal { |
| 126 | 139 | let view: View = { name: "desk" }; |
| 127 | 140 | let cursor = 0; |
| 141 | let show: DeskView = "all"; | |
| 128 | 142 | let said = ""; |
| 129 | 143 | let done = false; |
| 130 | 144 | const admin = (): boolean => permit(me, "lead", "delete") === "yes"; |
| 131 | 145 | |
| 132 | 146 | const leads = (): DeskLead[] => { |
| 133 | const listed = listLeads(db, me); | |
| 147 | const listed = listLeads(db, me, { show }); | |
| 134 | 148 | return listed.ok ? listed.value.leads : []; |
| 135 | 149 | }; |
| 136 | 150 | const lead = (id: number): LeadDetail | undefined => { |
| @@ -158,13 +172,21 @@ export function terminal( | ||
| 158 | 172 | } |
| 159 | 173 | |
| 160 | 174 | function deskScreen(): string[] { |
| 161 | const listed = listLeads(db, me); | |
| 175 | const listed = listLeads(db, me, { show }); | |
| 162 | 176 | if (!listed.ok) |
| 163 | 177 | return [listed.message, "", dim("esc quit")]; |
| 164 | 178 | const rows = listed.value.leads; |
| 165 | 179 | cursor = Math.min(cursor, Math.max(0, rows.length - 1)); |
| 166 | const lines: string[] = [dim(recordLine(listed.value.record)), ""]; | |
| 167 | if (rows.length === 0) lines.push(dim("No leads yet. Press n to log one.")); | |
| 180 | const counts = listed.value.counts; | |
| 181 | const lines: string[] = [ | |
| 182 | dim(recordLine(listed.value.record)), | |
| 183 | VIEWS.map((v) => { | |
| 184 | const tab = `${VIEW_LABEL[v]} ${counts[v]}`; | |
| 185 | return v === show ? bold(`[${tab}]`) : dim(tab); | |
| 186 | }).join(" "), | |
| 187 | "", | |
| 188 | ]; | |
| 189 | if (rows.length === 0) lines.push(dim(EMPTY[show])); | |
| 168 | 190 | rows.forEach((l, i) => { |
| 169 | 191 | const next = |
| 170 | 192 | l.ready === null |
| @@ -180,7 +202,7 @@ export function terminal( | ||
| 180 | 202 | lines.push( |
| 181 | 203 | "", |
| 182 | 204 | dim( |
| 183 | `j/k move · enter open · n log a lead · p profile${admin() ? " · R restart the samples" : ""} · esc quit`, | |
| 205 | `j/k move · enter open · f view · n log a lead · p profile${admin() ? " · R restart the samples" : ""} · esc quit`, | |
| 184 | 206 | ), |
| 185 | 207 | ); |
| 186 | 208 | return lines; |
| @@ -368,7 +390,10 @@ export function terminal( | ||
| 368 | 390 | cursor = Math.max(cursor - 1, 0); |
| 369 | 391 | else if (input === "\r" && rows[cursor] !== undefined) |
| 370 | 392 | view = { name: "lead", id: rows[cursor]!.id }; |
| 371 | else if (input === "n") | |
| 393 | else if (input === "f") { | |
| 394 | show = VIEWS[(VIEWS.indexOf(show) + 1) % VIEWS.length]!; | |
| 395 | cursor = 0; | |
| 396 | } else if (input === "n") | |
| 372 | 397 | view = { name: "add", step: 0, typed: "", fields: {} }; |
| 373 | 398 | else if (input === "p") view = { name: "profile" }; |
| 374 | 399 | else if (input === "R") |
static/app.css +18
| @@ -143,6 +143,24 @@ footer { | ||
| 143 | 143 | .summary b { |
| 144 | 144 | color: var(); |
| 145 | 145 | } |
| 146 | .views { | |
| 147 | display: flex; | |
| 148 | flex-wrap: wrap; | |
| 149 | gap: var(); | |
| 150 | margin: 0 0 var(); | |
| 151 | } | |
| 152 | .views a { | |
| 153 | padding: var() var(); | |
| 154 | border: 1px solid var(); | |
| 155 | border-radius: 999px; | |
| 156 | color: var(); | |
| 157 | text-decoration: none; | |
| 158 | } | |
| 159 | .views a[aria-current] { | |
| 160 | color: var(); | |
| 161 | font-weight: 600; | |
| 162 | border-color: var(); | |
| 163 | } | |
| 146 | 164 | .record { |
| 147 | 165 | margin: 0 0 var(); |
| 148 | 166 | color: var(); |
new above
offline
Duplicate words: "Each row Each row".