/** * The Activity column: what nobody has read, then what the cards say happened. * * Two panes, because they answer two different questions. **Waiting** is a queue — mail that * has not been read, oldest first — and it is the only pane on this page whose fact lives * outside the board. **Recent** is history, derived from the cards' own records * (`lib/workflow/activity.ts`), and it is what says a board is moving when nobody is writing to * it. * * Three rules the panes keep: * * - **A waiting row carries its recipient's state.** A handoff to a session that is gone looks * exactly like one to a live peer otherwise, and picking the first up is the lead's work. * - **A broadcast is one row.** The bus writes one file per recipient sharing one message id; * the row names them once, `all (3)`, and keeps every name and state in its tooltip. * * Neither pane writes: the bus owns the inbox, and a page that marked mail read would eat the * queue it was describing. */ export function feedJs(rules: { labels: string }): string { return feedTemplate.replace("__ACTIVITY_LABEL__", rules.labels); } const feedTemplate = String.raw`(function () { "use strict"; var board = window.bfBoard || (window.bfBoard = {}); var el = board.el; var chipNode = board.chipNode; var ago = board.ago; var plural = board.plural; var paneHead = board.paneHead; var unreadableText = board.unreadableText; var ACTIVITY_LABEL = __ACTIVITY_LABEL__; /** The kind tables lived here: a glyph per kind was decoration, and the cards no longer draw one. */ /** The state a dot wears, worst first: the one a reader must act on leads a group. */ var STATE_RANK = { gone: 0, quiet: 1, absent: 2, unknown: 3, live: 4 }; /** A state dot, with the word it stands for on the hover: a colour alone says nothing. */ function dot(state) { var node = el("span", N.dot); node.setAttribute("data-state", state === undefined ? "unknown" : state); node.setAttribute("aria-hidden", "true"); node.title = state === undefined ? "the bus says nothing" : state; return node; } /** The worst state among a message's recipients, which is the one worth a dot. */ function worstOf(to) { var worst = undefined; for (var i = 0; i < to.length; i++) { var state = to[i].state === undefined ? "unknown" : to[i].state; if (worst === undefined || STATE_RANK[state] < STATE_RANK[worst]) worst = state; } return worst; } /** Who a message waits for: one name, or all (3) with every name on the hover. */ function recipients(to) { var node = el("span", N.mailTo); node.appendChild(dot(worstOf(to))); if (to.length === 1) { node.appendChild(document.createTextNode(to[0].label)); return node; } node.appendChild(document.createTextNode("all (" + to.length + ")")); var names = []; for (var i = 0; i < to.length; i++) { names.push(to[i].label + " (" + (to[i].state === undefined ? "no bus" : to[i].state) + ")"); } node.title = names.join(", "); return node; } /** One message nobody has read. */ function mailRow(message) { var row = el("li", "bf-row " + N.mail); // The paper is the accent and the kind is a word on the line: a glyph would be the third // time this card said what it is. var body = el("div", N.mailBody); row.appendChild(body); var line = el("div", "bf-row__meta"); line.appendChild(el("span", N.mailFrom, message.fromLabel)); var arrow = el("span", N.mailArrow, "\u2192"); arrow.setAttribute("aria-hidden", "true"); line.appendChild(arrow); line.appendChild(recipients(message.to)); // The kind, in words: the tag is the shape and the word is the fact. line.appendChild(chipNode({ label: message.kind, tone: "muted" })); line.appendChild(board.stamp(message.at, undefined, true)); body.appendChild(line); // The text is the reason to open it, and it never fits a row: on the hover, whole. row.title = message.fromLabel + " \u2192 " + message.to.map(function (each) { return each.label; }).join(", ") + ": " + message.text; return row; } /** What an event did, in the table's own words, with the lane the move went to. */ function eventWhat(event) { var label = ACTIVITY_LABEL[event.kind] || event.kind; if (event.lane === undefined) return label; var lane = board.laneOf(board.view, event.lane); return label.replace("{lane}", lane === undefined ? event.lane : lane.label.toLowerCase()); } /** One thing that happened: the lane it happened in, the card, and what it was. */ function eventRow(event) { var row = el("li", "bf-row " + N.event); var body = el("div", N.mailBody); row.appendChild(body); var line = el("div", "bf-row__meta"); if (event.lane !== undefined) { var laneDot = dot("live"); laneDot.setAttribute("data-lane", event.lane); laneDot.removeAttribute("data-state"); line.appendChild(laneDot); } line.appendChild(el("span", N.eventRef, "#" + event.card)); line.appendChild(el("span", N.eventWhat, eventWhat(event))); line.appendChild(board.stamp(event.at, undefined, true)); body.appendChild(line); row.title = "#" + event.card + " " + event.title; return row; } /** * The two panes, as separate signatures and builders. * * Separately, because they move on different clocks: a message landing must not rebuild the * history behind it, and a card's move must not repaint a queue somebody is reading. Neither * reads the filter: it narrows the cards, and a queue of mail is not one. */ board.feedPanes = function (view) { // The queue arrives with the count its cap left out, so a repository with twenty unread // messages does not read like a quiet one. var queue = view.waiting === undefined ? { messages: [], dropped: 0 } : view.waiting; var waiting = queue.messages; var recent = view.activity === undefined ? { events: [], dropped: 0 } : view.activity; var events = recent.events; var mailSig = []; for (var m = 0; m < waiting.length; m++) { var names = []; for (var t = 0; t < waiting[m].to.length; t++) names.push(waiting[m].to[t].label + ":" + waiting[m].to[t].state); mailSig.push(waiting[m].id + ":" + waiting[m].kind + ":" + waiting[m].at + ":" + names.join("+")); } var eventSig = [String(recent.dropped)]; for (var e = 0; e < events.length; e++) { eventSig.push(events[e].kind + ":" + events[e].card + ":" + events[e].at + ":" + (events[e].lane || "")); } return { waiting: { sig: mailSig.join("|"), count: waiting.length, total: waiting.length, build: function (slot) { // The pane says how deep the queue is, the way RECENT says how much history it left // out: a cap that dropped rows must not read like a quiet board. if (waiting.length > 0) slot.setAttribute("data-tone", "accent"); else slot.removeAttribute("data-tone"); // The head carries the rule as well as the number: a row is one send, so the count is not // the sum a reader takes across the cards. var tone = waiting.length > 0 ? "accent" : undefined; var head = paneHead("Waiting", waiting.length, waiting.length + queue.dropped, tone); head.title = "One row per send; a broadcast counts once here and once on each reader's card."; slot.appendChild(head); // A file this build cannot parse is not a row and not a number: it is a note under the // queue, drawn first so an inbox whose only file is that one does not read as quiet. var refused = queue.refused === undefined ? [] : queue.refused; if (refused.length > 0) slot.appendChild(el("p", N.teamEmpty, unreadableText(refused))); if (waiting.length === 0) { slot.appendChild(el("p", N.teamEmpty, "no mail is waiting")); return; } var list = el("ul", N.waiting); for (var i = 0; i < waiting.length; i++) list.appendChild(mailRow(waiting[i])); slot.appendChild(list); } }, recent: { sig: eventSig.join("|"), count: events.length, total: recent.events.length, build: function (slot) { // The count is what the rail has room for against what the board holds, so a busy // board does not read like a quiet one. slot.appendChild(paneHead("Recent", events.length, events.length + recent.dropped)); if (events.length === 0) { slot.appendChild(el("p", N.teamEmpty, "nothing has happened yet")); return; } var list = el("ul", N.recent); for (var i = 0; i < events.length; i++) list.appendChild(eventRow(events[i])); slot.appendChild(list); } } }; }; })();`;