@lysyi3m/sidecar 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -132,6 +132,10 @@ const BRAND_MARK = raw('<svg viewBox="0 0 18 18" class="brand-mark" aria-hidden=
|
|
|
132
132
|
const SIDEBAR_ICON = raw('<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 3.5h11v9h-11zM6 3.5v9"/></svg>');
|
|
133
133
|
/** A tray with an arrow into it: save. */
|
|
134
134
|
const EXPORT_ICON = raw('<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2.5v7.5M5 7l3 3 3-3M2.5 10.5v2.5h11v-2.5"/></svg>');
|
|
135
|
+
/** The sidebar's sections, in the order they appear. */
|
|
136
|
+
export const SECTIONS = ["active", "closed"];
|
|
137
|
+
/** The sections a browser that has never toggled one sees collapsed. */
|
|
138
|
+
export const DEFAULT_COLLAPSED = new Set(["closed"]);
|
|
135
139
|
/** The page around its content: the sidebar with the case list, and the main column. */
|
|
136
140
|
function shell(opts) {
|
|
137
141
|
return html `<!doctype html>
|
|
@@ -148,7 +152,7 @@ function shell(opts) {
|
|
|
148
152
|
<div class="shell${opts.chrome.collapsed ? " is-collapsed" : ""}">
|
|
149
153
|
<aside class="sidebar">
|
|
150
154
|
<div class="sidebar-head"><a class="brand" href="/">${BRAND_MARK}sidecar</a><span class="brand-version">v${SIDECAR_VERSION}</span></div>
|
|
151
|
-
${sideList(opts.cases, opts.activeCase)}
|
|
155
|
+
${sideList(opts.cases, opts.activeCase, opts.chrome.sections)}
|
|
152
156
|
</aside>
|
|
153
157
|
<main class="main"><div class="page">
|
|
154
158
|
<div class="topbar"><button class="icon-button sidebar-toggle" type="button" aria-label="Toggle the case list" data-toggle-sidebar>${SIDEBAR_ICON}</button><div class="crumbs">${opts.crumbs}</div>${opts.actions ? html `<div class="topbar-actions">${opts.actions}</div>` : ""}</div>
|
|
@@ -159,8 +163,11 @@ ${opts.content}
|
|
|
159
163
|
</html>`;
|
|
160
164
|
}
|
|
161
165
|
const isUnreadable = (c) => c.state === "unreadable";
|
|
162
|
-
/**
|
|
163
|
-
|
|
166
|
+
/**
|
|
167
|
+
* The sidebar's case list. The page refreshes it from /fragments/sidebar. A section in `collapsed`
|
|
168
|
+
* renders closed, unless it holds the open case.
|
|
169
|
+
*/
|
|
170
|
+
export function sideList(cases, activeCase, collapsed = DEFAULT_COLLAPSED) {
|
|
164
171
|
const open = cases.filter((c) => c.state === "open");
|
|
165
172
|
// An unreadable case is listed with the closed ones, never hidden.
|
|
166
173
|
const closed = cases.filter((c) => c.state === "closed" || isUnreadable(c));
|
|
@@ -168,27 +175,38 @@ export function sideList(cases, activeCase) {
|
|
|
168
175
|
const item = (c) => isUnreadable(c)
|
|
169
176
|
? html `<a class="side-case" href="/cases/${c.case_id}"${current(c)}>
|
|
170
177
|
<div class="side-title">${c.case_id}</div>
|
|
171
|
-
<div class="side-meta"><span class="
|
|
178
|
+
<div class="side-meta"><span class="side-tag">unreadable</span></div>
|
|
172
179
|
</a>`
|
|
173
180
|
: html `<a class="side-case" href="/cases/${c.case_id}"${current(c)}>
|
|
174
181
|
<div class="side-title">${c.title || c.case_id}</div>
|
|
175
|
-
<div class="side-meta"><span
|
|
182
|
+
<div class="side-meta"><span>${ago(c.updated)}</span>${
|
|
176
183
|
// The section heading already says active or closed; only a state worth noticing gets a tag.
|
|
177
184
|
c.in_flight ? html `<span class="side-tag is-accent">asking</span>` : ""}</div>
|
|
178
185
|
</a>`;
|
|
186
|
+
const section = (name, label, members) => {
|
|
187
|
+
if (!members.length)
|
|
188
|
+
return "";
|
|
189
|
+
const expanded = !collapsed.has(name) || members.some((c) => c.case_id === activeCase) ? "true" : "false";
|
|
190
|
+
return html `<section class="side-group" data-section="${name}">
|
|
191
|
+
<button class="side-section label" type="button" data-section="${name}" aria-expanded="${expanded}" aria-label="${label}, ${String(members.length)} ${members.length === 1 ? "case" : "cases"}"><span class="chevron" aria-hidden="true"></span>${label}<span class="side-count" aria-hidden="true">${String(members.length)}</span></button>
|
|
192
|
+
<div class="side-group-body">${members.map(item)}</div>
|
|
193
|
+
</section>`;
|
|
194
|
+
};
|
|
179
195
|
const query = activeCase ? `?active=${activeCase}` : "";
|
|
180
|
-
return html `<nav class="side-list" id="side-list" aria-label="Cases" data-refresh="/fragments/sidebar${query}">${cases.length === 0 ? html `<div class="side-empty">No cases yet.</div>` : ""}${
|
|
196
|
+
return html `<nav class="side-list" id="side-list" aria-label="Cases" data-refresh="/fragments/sidebar${query}">${cases.length === 0 ? html `<div class="side-empty">No cases yet.</div>` : ""}${section("active", "Active", open)}${section("closed", "Closed", closed)}</nav>`;
|
|
181
197
|
}
|
|
182
198
|
/* ---------------------------------------------------------------- index */
|
|
183
|
-
|
|
199
|
+
/** The index's state filters, by the case state each shows, with the label the sidebar uses. */
|
|
200
|
+
const FILTERS = ["open", "closed"];
|
|
201
|
+
const FILTER_LABELS = { open: "active", closed: "closed" };
|
|
184
202
|
export function indexPage(cases, query, chrome = { collapsed: false }) {
|
|
185
|
-
const filter = FILTERS.find((f) => f === query.state) ?? "
|
|
203
|
+
const filter = FILTERS.find((f) => f === query.state) ?? "open";
|
|
186
204
|
const content = html `<div class="toolbar">
|
|
187
|
-
<div class="segmented" role="group" aria-label="Case state">${FILTERS.map((name) => html `<button type="button" class="label" data-filter="${name}" aria-pressed="${String(filter === name)}">${name} <span data-count></span></button>`)}</div>
|
|
205
|
+
<div class="segmented" role="group" aria-label="Case state">${FILTERS.map((name) => html `<button type="button" class="label" data-filter="${name}" aria-pressed="${String(filter === name)}">${FILTER_LABELS[name]} <span data-count></span></button>`)}</div>
|
|
188
206
|
<div class="search-group"><input type="search" data-search placeholder="Filter by title, id or directory…" aria-label="Filter cases" value="${query.search ?? ""}"><span class="result-count" data-result-count></span></div>
|
|
189
207
|
</div>
|
|
190
208
|
<div class="table-scroll"><table data-cases data-filter-state="${filter}">
|
|
191
|
-
<thead><tr><th>Case</th><th
|
|
209
|
+
<thead><tr><th>Case</th><th>Driver</th><th>Navigator</th><th>Last activity</th></tr></thead>
|
|
192
210
|
${caseRows(cases)}
|
|
193
211
|
</table></div>
|
|
194
212
|
<p class="message" data-message hidden></p>`;
|
|
@@ -206,15 +224,15 @@ ${caseRows(cases)}
|
|
|
206
224
|
export function caseRows(cases) {
|
|
207
225
|
return html `<tbody id="case-rows" data-refresh="/fragments/cases">${cases.map((c) => {
|
|
208
226
|
if (isUnreadable(c)) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<td class="
|
|
227
|
+
// Listed under the closed filter, as the sidebar lists it with the closed cases.
|
|
228
|
+
return html `<tr data-href="/cases/${c.case_id}" data-state="closed" data-haystack="${c.case_id}">
|
|
229
|
+
<td><span class="case-title">${c.case_id}</span> ${stateChip("unreadable")}<div class="case-sub mono">${c.error}</div></td>
|
|
230
|
+
<td></td><td></td><td></td>
|
|
212
231
|
</tr>`;
|
|
213
232
|
}
|
|
214
233
|
const haystack = [c.title, c.case_id, c.workspace].join(" ").toLowerCase();
|
|
215
234
|
return html `<tr data-href="/cases/${c.case_id}" data-state="${c.state}" data-haystack="${haystack}">
|
|
216
235
|
<td><a class="case-title" href="/cases/${c.case_id}">${c.title || c.case_id}</a><div class="case-sub case-where mono"><span>${c.case_id}</span><span>·</span>${pathLine(c.workspace)}</div></td>
|
|
217
|
-
<td class="col-state">${stateChip(c.state)}</td>
|
|
218
236
|
<td>${driverLine(c.driver, c.driver_model, c.driver_effort)}</td>
|
|
219
237
|
<td>${agentLine(c.navigator, c.model, c.effort)}</td>
|
|
220
238
|
<td><div>${ago(c.updated)}</div><div class="case-sub mono">${time(c.updated, "stamp")}</div></td>
|
|
@@ -253,8 +271,8 @@ function caseHead(model) {
|
|
|
253
271
|
const opinions = [...state.asks.values()].filter((a) => a.terminal?.kind === "opinion").length;
|
|
254
272
|
const fact = (name, value) => html `<div class="fact"><dt class="label">${name}</dt><dd>${value}</dd></div>`;
|
|
255
273
|
return html `<header class="case-head" id="case-head">
|
|
256
|
-
<
|
|
257
|
-
<div class="case-path mono">${pathLine(opened.workspace)}</div>
|
|
274
|
+
<h1 class="title">${opened.title}</h1>
|
|
275
|
+
<div class="case-meta">${stateChip(status)}<div class="case-path case-where mono"><span>${caseId}</span><span>·</span>${pathLine(opened.workspace)}</div></div>
|
|
258
276
|
<dl class="facts">${[
|
|
259
277
|
fact("Driver", driverLine(opened.driver, state.driverModel, state.driverEffort)),
|
|
260
278
|
fact("Navigator", agentLine(opened.navigator, opened.model, opened.effort)),
|
|
@@ -11,7 +11,7 @@ import { loadConfig } from "../config.js";
|
|
|
11
11
|
import { CaseIndex, stampOf, unchanged } from "./cases.js";
|
|
12
12
|
import { dashboardBase, isLoopbackHost } from "./links.js";
|
|
13
13
|
import { MARKS } from "./marks.js";
|
|
14
|
-
import { caseRows, casePage, caseUnits, indexPage, sideList } from "./pages.js";
|
|
14
|
+
import { caseRows, casePage, caseUnits, DEFAULT_COLLAPSED, indexPage, SECTIONS, sideList, } from "./pages.js";
|
|
15
15
|
import { caseModel } from "./view.js";
|
|
16
16
|
// The dashboard: a read-only web UI over the case store. Two pages — the case index at / and one
|
|
17
17
|
// case at /cases/<id> — rendered on the server (pages.ts) from the view model (view.ts), styled by
|
|
@@ -50,6 +50,7 @@ const ASSETS = new Map(readdirSync(STATIC)
|
|
|
50
50
|
const COOKIE = "sidecar_token";
|
|
51
51
|
/** A cookie that keeps UI state is named `sidecar_ui_<name>`. */
|
|
52
52
|
const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
|
|
53
|
+
const SECTIONS_COOKIE = "sidecar_ui_sections";
|
|
53
54
|
/** A client's address; a dual-stack listener reports an IPv4 client in its IPv4-mapped form. */
|
|
54
55
|
const isLoopbackAddress = (address) => isLoopbackHost(address.replace(/^::ffff:(?=[\d.]+$)/i, ""));
|
|
55
56
|
export async function startDashboard(store, opts = {}) {
|
|
@@ -136,6 +137,21 @@ const cookieValue = (header, name) => {
|
|
|
136
137
|
* only a script can read: the server renders it, so a page never paints the sidebar open first.
|
|
137
138
|
*/
|
|
138
139
|
const sidebarCollapsed = (header) => cookieValue(header, SIDEBAR_COOKIE) === "collapsed";
|
|
140
|
+
/**
|
|
141
|
+
* The sidebar sections this browser keeps collapsed: their names joined with `|`. An unknown name
|
|
142
|
+
* is skipped. Without the cookie, the default applies; an empty value collapses none.
|
|
143
|
+
*/
|
|
144
|
+
const collapsedSections = (header) => {
|
|
145
|
+
const value = cookieValue(header, SECTIONS_COOKIE);
|
|
146
|
+
if (value === undefined)
|
|
147
|
+
return DEFAULT_COLLAPSED;
|
|
148
|
+
const names = new Set(value.split("|"));
|
|
149
|
+
return new Set(SECTIONS.filter((s) => names.has(s)));
|
|
150
|
+
};
|
|
151
|
+
const chromeOf = (header) => ({
|
|
152
|
+
collapsed: sidebarCollapsed(header),
|
|
153
|
+
sections: collapsedSections(header),
|
|
154
|
+
});
|
|
139
155
|
/** Constant-time comparison, so response timing does not leak the token. */
|
|
140
156
|
function same(a, b) {
|
|
141
157
|
const x = Buffer.from(a);
|
|
@@ -192,16 +208,16 @@ function app(store, port, token, limits) {
|
|
|
192
208
|
// the stream reports that reason as a `problem` event.
|
|
193
209
|
const exists = (caseId) => isCaseId(caseId) && existsSync(store.logPath(caseId));
|
|
194
210
|
const NO_CASE = "no such case";
|
|
195
|
-
web.get("/", async (c) => htmlResponse(indexPage((await cases.list()).cases, { state: c.req.query("state"), search: c.req.query("search") },
|
|
211
|
+
web.get("/", async (c) => htmlResponse(indexPage((await cases.list()).cases, { state: c.req.query("state"), search: c.req.query("search") }, chromeOf(c.req.header("cookie")))));
|
|
196
212
|
web.get("/cases/:id", async (c) => {
|
|
197
213
|
const caseId = c.req.param("id");
|
|
198
214
|
if (!exists(caseId))
|
|
199
215
|
return c.text(NO_CASE, 404);
|
|
200
|
-
return htmlResponse(casePage(caseModel(caseId, await store.read(caseId), reviewBudget(store)), (await cases.list()).cases,
|
|
216
|
+
return htmlResponse(casePage(caseModel(caseId, await store.read(caseId), reviewBudget(store)), (await cases.list()).cases, chromeOf(c.req.header("cookie"))));
|
|
201
217
|
});
|
|
202
218
|
web.get("/fragments/sidebar", (c) => {
|
|
203
219
|
const active = c.req.query("active");
|
|
204
|
-
return fragmentResponse(c, (list) => sideList(list.cases, active && isCaseId(active) ? active : null));
|
|
220
|
+
return fragmentResponse(c, (list) => sideList(list.cases, active && isCaseId(active) ? active : null, collapsedSections(c.req.header("cookie"))));
|
|
205
221
|
});
|
|
206
222
|
web.get("/fragments/cases", (c) => fragmentResponse(c, (list) => caseRows(list.cases)));
|
|
207
223
|
web.get("/assets/agents/:name{[a-z0-9-]+\\.svg}", (c) => {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
--ink-2: light-dark(#4e5766, #a3adbb);
|
|
16
16
|
--ink-3: light-dark(#8b94a1, #6e7784);
|
|
17
17
|
--accent: light-dark(#1f4fd8, #8aa6ff);
|
|
18
|
+
--accent-weak: light-dark(#e8eefc, #16203a);
|
|
18
19
|
--alert: light-dark(#9a3412, #e0a165);
|
|
19
20
|
--alert-weak: light-dark(#fdf3ec, #221a12);
|
|
20
21
|
--ok: light-dark(#2f6b3f, #8cc79c);
|
|
@@ -139,9 +140,51 @@ button {
|
|
|
139
140
|
min-width: var(--sidebar);
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
/* A section head is a button that reads like a label: a chevron, the name and the case count. */
|
|
142
144
|
.side-section {
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
gap: 6px;
|
|
148
|
+
width: 100%;
|
|
143
149
|
padding: 14px 16px 6px;
|
|
150
|
+
border: 0;
|
|
151
|
+
border-radius: 0;
|
|
152
|
+
background: none;
|
|
144
153
|
color: var(--ink-3);
|
|
154
|
+
text-align: left;
|
|
155
|
+
|
|
156
|
+
&:hover {
|
|
157
|
+
color: var(--ink-2);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&:focus-visible {
|
|
161
|
+
outline: 2px solid var(--accent);
|
|
162
|
+
outline-offset: -2px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
& .chevron {
|
|
166
|
+
flex: none;
|
|
167
|
+
width: 5px;
|
|
168
|
+
height: 5px;
|
|
169
|
+
margin: 0 3px 2px 1px;
|
|
170
|
+
border-right: 1.5px solid currentColor;
|
|
171
|
+
border-bottom: 1.5px solid currentColor;
|
|
172
|
+
rotate: 45deg;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&[aria-expanded="false"] .chevron {
|
|
176
|
+
rotate: -45deg;
|
|
177
|
+
margin-bottom: 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
& .side-count {
|
|
181
|
+
font-weight: 400;
|
|
182
|
+
letter-spacing: 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&[aria-expanded="false"] + .side-group-body {
|
|
186
|
+
display: none;
|
|
187
|
+
}
|
|
145
188
|
}
|
|
146
189
|
|
|
147
190
|
.side-case {
|
|
@@ -154,12 +197,23 @@ button {
|
|
|
154
197
|
background: var(--hair);
|
|
155
198
|
}
|
|
156
199
|
|
|
200
|
+
/* The open case: an accent bar and tint, and its meta line at full ink. */
|
|
157
201
|
&[aria-current="page"] {
|
|
158
|
-
background: var(--
|
|
159
|
-
border-left-color: var(--
|
|
202
|
+
background: var(--accent-weak);
|
|
203
|
+
border-left-color: var(--accent);
|
|
204
|
+
|
|
205
|
+
& .side-meta {
|
|
206
|
+
color: var(--ink);
|
|
207
|
+
}
|
|
160
208
|
}
|
|
161
209
|
}
|
|
162
210
|
|
|
211
|
+
/* A link's text takes the accent on hover. A row that is a link colours its title. */
|
|
212
|
+
.side-case:hover .side-title,
|
|
213
|
+
tbody tr:hover .case-title {
|
|
214
|
+
color: var(--accent);
|
|
215
|
+
}
|
|
216
|
+
|
|
163
217
|
.side-title {
|
|
164
218
|
display: -webkit-box;
|
|
165
219
|
-webkit-line-clamp: 2;
|
|
@@ -488,10 +542,6 @@ tbody tr {
|
|
|
488
542
|
font-weight: 500;
|
|
489
543
|
letter-spacing: -0.01em;
|
|
490
544
|
text-decoration: none;
|
|
491
|
-
|
|
492
|
-
&:hover {
|
|
493
|
-
color: var(--accent);
|
|
494
|
-
}
|
|
495
545
|
}
|
|
496
546
|
|
|
497
547
|
.case-sub {
|
|
@@ -500,11 +550,6 @@ tbody tr {
|
|
|
500
550
|
color: var(--ink-3);
|
|
501
551
|
}
|
|
502
552
|
|
|
503
|
-
/* Under the open or closed filter every row has the same state, so the column says nothing. */
|
|
504
|
-
table:not([data-filter-state="all"]) .col-state {
|
|
505
|
-
display: none;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
553
|
/* The case column takes the width the other columns leave. */
|
|
509
554
|
tbody td:first-child {
|
|
510
555
|
width: 100%;
|
|
@@ -585,22 +630,6 @@ tbody td:first-child {
|
|
|
585
630
|
gap: 14px;
|
|
586
631
|
}
|
|
587
632
|
|
|
588
|
-
.title-row {
|
|
589
|
-
display: flex;
|
|
590
|
-
align-items: flex-start;
|
|
591
|
-
gap: 12px;
|
|
592
|
-
|
|
593
|
-
& .chip {
|
|
594
|
-
margin-top: 6px;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
.case-id {
|
|
599
|
-
margin-top: 7px;
|
|
600
|
-
font-size: 12px;
|
|
601
|
-
color: var(--ink-3);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
633
|
/* An agent's mark sits on the text baseline and takes the surrounding ink: its file is a mask over
|
|
605
634
|
the text colour, so one cached file serves every theme. */
|
|
606
635
|
.agent-mark {
|
|
@@ -620,9 +649,23 @@ tbody td:first-child {
|
|
|
620
649
|
white-space: nowrap;
|
|
621
650
|
}
|
|
622
651
|
|
|
623
|
-
/*
|
|
624
|
-
.case-
|
|
652
|
+
/* Under the title: the state chip, then the id and the working directory on one line (see
|
|
653
|
+
.case-where). The chip sits here, not beside the title: a balanced title keeps its full width,
|
|
654
|
+
so a chip beside it lands far from the text. */
|
|
655
|
+
.case-meta {
|
|
656
|
+
display: flex;
|
|
657
|
+
align-items: center;
|
|
658
|
+
gap: 10px;
|
|
625
659
|
margin-top: -6px;
|
|
660
|
+
|
|
661
|
+
& .chip {
|
|
662
|
+
flex: none;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
.case-path {
|
|
667
|
+
flex: 1;
|
|
668
|
+
min-width: 0;
|
|
626
669
|
font-size: 12px;
|
|
627
670
|
color: var(--ink-2);
|
|
628
671
|
}
|
|
@@ -1138,10 +1181,6 @@ tbody td:first-child {
|
|
|
1138
1181
|
grid-row: 1;
|
|
1139
1182
|
}
|
|
1140
1183
|
|
|
1141
|
-
.title-row {
|
|
1142
|
-
flex-wrap: wrap;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
1184
|
h1.title {
|
|
1146
1185
|
font-size: 20px;
|
|
1147
1186
|
}
|
|
@@ -77,6 +77,7 @@ for (const element of document.querySelectorAll("[data-refresh]")) {
|
|
|
77
77
|
// Kept only once the list is applied: a body lost to the timeout must not earn a 304.
|
|
78
78
|
const next = response.headers.get("etag");
|
|
79
79
|
apply(await response.text());
|
|
80
|
+
keepSections();
|
|
80
81
|
filterCases();
|
|
81
82
|
etag = next;
|
|
82
83
|
}
|
|
@@ -194,42 +195,90 @@ document.querySelector("[data-export]")?.addEventListener("click", (event) => {
|
|
|
194
195
|
// runs after the first paint, and applying the state here would flash the sidebar open.
|
|
195
196
|
const shell = document.querySelector(".shell");
|
|
196
197
|
const SIDEBAR_COOKIE = "sidecar_ui_sidebar";
|
|
198
|
+
const SECTIONS_COOKIE = "sidecar_ui_sections";
|
|
199
|
+
/** The sections collapsed while the cookie is absent; server.ts has the same default. */
|
|
200
|
+
const DEFAULT_COLLAPSED = ["closed"];
|
|
201
|
+
|
|
202
|
+
const readCookie = (name) => {
|
|
203
|
+
const prefix = `${name}=`;
|
|
204
|
+
return document.cookie
|
|
205
|
+
.split(";")
|
|
206
|
+
.map((c) => c.trim())
|
|
207
|
+
.find((c) => c.startsWith(prefix))
|
|
208
|
+
?.slice(prefix.length);
|
|
209
|
+
};
|
|
210
|
+
const writeCookie = (name, value) => {
|
|
211
|
+
document.cookie = `${name}=${value}; Path=/; SameSite=Strict; Max-Age=31536000`;
|
|
212
|
+
};
|
|
197
213
|
|
|
198
214
|
document.querySelector("[data-toggle-sidebar]")?.addEventListener("click", () => {
|
|
199
215
|
const collapsed = shell.classList.toggle("is-collapsed");
|
|
200
|
-
|
|
216
|
+
writeCookie(SIDEBAR_COOKIE, collapsed ? "collapsed" : "open");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const storedSections = () => {
|
|
220
|
+
const value = readCookie(SECTIONS_COOKIE);
|
|
221
|
+
return new Set(value === undefined ? DEFAULT_COLLAPSED : value.split("|").filter(Boolean));
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Each section's state on this page. A refresh renders from the cookie, and the section that holds
|
|
226
|
+
* the open case renders open; the page's own state wins over both, so a refresh never undoes a click.
|
|
227
|
+
*/
|
|
228
|
+
const sectionState = new Map();
|
|
229
|
+
const sectionHeads = () => document.querySelectorAll("button[data-section]");
|
|
230
|
+
const keepSections = () => {
|
|
231
|
+
for (const head of sectionHeads()) {
|
|
232
|
+
const expanded = sectionState.get(head.dataset.section);
|
|
233
|
+
if (expanded === undefined)
|
|
234
|
+
sectionState.set(head.dataset.section, head.getAttribute("aria-expanded") === "true");
|
|
235
|
+
else head.setAttribute("aria-expanded", String(expanded));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
keepSections();
|
|
239
|
+
|
|
240
|
+
document.addEventListener("click", (event) => {
|
|
241
|
+
const head = event.target.closest("button[data-section]");
|
|
242
|
+
if (!head) return;
|
|
243
|
+
const name = head.dataset.section;
|
|
244
|
+
const expanded = head.getAttribute("aria-expanded") !== "true";
|
|
245
|
+
head.setAttribute("aria-expanded", String(expanded));
|
|
246
|
+
sectionState.set(name, expanded);
|
|
247
|
+
const collapsed = storedSections();
|
|
248
|
+
if (expanded) collapsed.delete(name);
|
|
249
|
+
else collapsed.add(name);
|
|
250
|
+
writeCookie(SECTIONS_COOKIE, [...collapsed].join("|"));
|
|
201
251
|
});
|
|
202
252
|
|
|
203
253
|
// A page restored from the back/forward cache keeps the state it was left in, though another page
|
|
204
|
-
// may have toggled the sidebar since.
|
|
254
|
+
// may have toggled the sidebar or a section since.
|
|
205
255
|
addEventListener("pageshow", (event) => {
|
|
206
256
|
if (!event.persisted || !shell) return;
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
257
|
+
shell.classList.toggle("is-collapsed", readCookie(SIDEBAR_COOKIE) === "collapsed");
|
|
258
|
+
const collapsed = storedSections();
|
|
259
|
+
for (const head of sectionHeads()) {
|
|
260
|
+
const holdsCurrent = head.parentElement.querySelector('[aria-current="page"]') !== null;
|
|
261
|
+
const expanded = holdsCurrent || !collapsed.has(head.dataset.section);
|
|
262
|
+
head.setAttribute("aria-expanded", String(expanded));
|
|
263
|
+
sectionState.set(head.dataset.section, expanded);
|
|
264
|
+
}
|
|
214
265
|
});
|
|
215
266
|
|
|
216
267
|
/* ---------------------------------------------------------------- case index */
|
|
217
268
|
|
|
218
269
|
const search = document.querySelector("[data-search]");
|
|
219
270
|
// The server renders the filter the URL asks for, already checked.
|
|
220
|
-
let filter = document.querySelector("[data-cases]")?.dataset.filterState ?? "
|
|
271
|
+
let filter = document.querySelector("[data-cases]")?.dataset.filterState ?? "open";
|
|
221
272
|
|
|
222
273
|
/** Shows the rows that match the state filter and the search text, and keeps the URL in step. */
|
|
223
274
|
function filterCases() {
|
|
224
275
|
if (!search) return;
|
|
225
276
|
const rows = [...document.querySelectorAll("#case-rows tr")];
|
|
277
|
+
const inState = rows.filter((r) => r.dataset.state === filter);
|
|
226
278
|
const needle = search.value.trim().toLowerCase();
|
|
227
279
|
let shown = 0;
|
|
228
280
|
for (const row of rows) {
|
|
229
|
-
row.hidden = !(
|
|
230
|
-
(filter === "all" || row.dataset.state === filter) &&
|
|
231
|
-
row.dataset.haystack.includes(needle)
|
|
232
|
-
);
|
|
281
|
+
row.hidden = !(row.dataset.state === filter && row.dataset.haystack.includes(needle));
|
|
233
282
|
if (!row.hidden) shown++;
|
|
234
283
|
}
|
|
235
284
|
document.querySelector("[data-cases]").dataset.filterState = filter;
|
|
@@ -237,16 +286,22 @@ function filterCases() {
|
|
|
237
286
|
const name = button.dataset.filter;
|
|
238
287
|
button.setAttribute("aria-pressed", String(name === filter));
|
|
239
288
|
button.querySelector("[data-count]").textContent = rows.filter(
|
|
240
|
-
(r) =>
|
|
289
|
+
(r) => r.dataset.state === name,
|
|
241
290
|
).length;
|
|
242
291
|
}
|
|
243
|
-
document.querySelector("[data-result-count]").textContent = `${shown} / ${
|
|
292
|
+
document.querySelector("[data-result-count]").textContent = `${shown} / ${inState.length}`;
|
|
244
293
|
const message = document.querySelector("[data-message]");
|
|
245
294
|
message.hidden = shown > 0;
|
|
246
|
-
message.textContent =
|
|
295
|
+
message.textContent =
|
|
296
|
+
rows.length === 0
|
|
297
|
+
? "No cases yet."
|
|
298
|
+
: inState.length === 0
|
|
299
|
+
? `No ${filter === "open" ? "active" : "closed"} cases.`
|
|
300
|
+
: "No case matches this filter.";
|
|
247
301
|
|
|
248
302
|
const url = new URL(location.href);
|
|
249
|
-
|
|
303
|
+
// Active is the default, so its URL names no state.
|
|
304
|
+
if (filter === "open") url.searchParams.delete("state");
|
|
250
305
|
else url.searchParams.set("state", filter);
|
|
251
306
|
if (needle) url.searchParams.set("search", search.value.trim());
|
|
252
307
|
else url.searchParams.delete("search");
|