web/src/components/things/ChangelogTimeline.svelte
655 lines · 17036 bytes
1<script lang="ts">
2 import type {
3 ChangelogEntry,
4 ServiceChange,
5 Rejection,
6 ChangelogPr,
7 } from '../../utils/fetch-changelog';
8 import { slugify } from '@utils/fetch-data';
9
10 interface Props {
11 entries?: ChangelogEntry[];
12 rejections?: Rejection[];
13 }
14 const { entries = [], rejections = [] }: Props = $props();
15
16 type Filter = 'added' | 'removed' | 'modified' | 'rejected';
17
18 const filterDefs: { key: Filter; label: string; icon: string }[] = [
19 { key: 'added', label: 'Additions', icon: '+' },
20 { key: 'removed', label: 'Removals', icon: '−' },
21 { key: 'modified', label: 'Amendments', icon: '✎' },
22 { key: 'rejected', label: 'Rejections', icon: '✕' },
23 ];
24
25 let on: Record<Filter, boolean> = $state({
26 added: true,
27 removed: true,
28 modified: true,
29 rejected: true,
30 });
31 let searchQuery = $state('');
32
33 function toggle(key: Filter) {
34 on = { ...on, [key]: !on[key] };
35 }
36
37 type TimelineItem =
38 | {
39 kind: 'entry';
40 date: string;
41 sha: string;
42 pr?: ChangelogPr | null;
43 data: ChangelogEntry;
44 }
45 | {
46 kind: 'rejection';
47 date: string;
48 sha: string;
49 pr: ChangelogPr;
50 data: Rejection;
51 };
52
53 const svc = (e: ChangelogEntry) => {
54 const s = e.changes?.services;
55 return {
56 added: s?.added || [],
57 removed: s?.removed || [],
58 modified: s?.modified || [],
59 moved: s?.moved || [],
60 renamed: s?.renamed || [],
61 };
62 };
63 const sec = (e: ChangelogEntry) => {
64 const s = e.changes?.sections;
65 return {
66 added: s?.added || [],
67 removed: s?.removed || [],
68 moved: s?.moved || [],
69 };
70 };
71 const cat = (e: ChangelogEntry) => {
72 const c = e.changes?.categories;
73 return { added: c?.added || [], removed: c?.removed || [] };
74 };
75
76 function matchesFilters(
77 item: TimelineItem,
78 f: Record<Filter, boolean>,
79 ): boolean {
80 if (item.kind === 'rejection') return f.rejected;
81 const s = svc(item.data),
82 sc = sec(item.data),
83 ct = cat(item.data);
84 return (
85 (f.added &&
86 (s.added.length > 0 || sc.added.length > 0 || ct.added.length > 0)) ||
87 (f.removed &&
88 (s.removed.length > 0 ||
89 sc.removed.length > 0 ||
90 ct.removed.length > 0)) ||
91 (f.modified &&
92 (s.modified.length > 0 ||
93 s.moved.length > 0 ||
94 s.renamed.length > 0 ||
95 sc.moved.length > 0))
96 );
97 }
98
99 function matchesSearch(item: TimelineItem, query: string): boolean {
100 if (!query) return true;
101 const q = query.toLowerCase();
102 if (item.kind === 'rejection') {
103 return (
104 item.data.title.toLowerCase().includes(q) ||
105 (item.pr.author?.toLowerCase().includes(q) ?? false)
106 );
107 }
108 const s = svc(item.data);
109 const all = [
110 ...s.added,
111 ...s.removed,
112 ...s.modified,
113 ...s.moved.flatMap((m) => [
114 { name: m.name, category: m.from.category, section: m.from.section },
115 { name: m.name, category: m.to.category, section: m.to.section },
116 ]),
117 ...s.renamed.flatMap((m) => [
118 {
119 name: m.previousName,
120 category: m.from.category,
121 section: m.from.section,
122 },
123 { name: m.name, category: m.to.category, section: m.to.section },
124 ]),
125 ];
126 return (
127 all.some(
128 (c) =>
129 c.name.toLowerCase().includes(q) ||
130 `${c.category} ${c.section}`.toLowerCase().includes(q),
131 ) ||
132 (item.pr?.author?.toLowerCase().includes(q) ?? false)
133 );
134 }
135
136 const pl = (n: number, word: string) => `${n} ${word}${n > 1 ? 's' : ''}`;
137
138 function summarize(entry: ChangelogEntry): string {
139 const s = svc(entry),
140 sc = sec(entry);
141 const parts: string[] = [];
142 if (s.added.length) parts.push(pl(s.added.length, 'addition'));
143 if (s.removed.length) parts.push(pl(s.removed.length, 'removal'));
144 if (s.modified.length) parts.push(pl(s.modified.length, 'amendment'));
145 if (s.moved.length) parts.push(pl(s.moved.length, 'move'));
146 if (s.renamed.length) parts.push(pl(s.renamed.length, 'rename'));
147 if (sc.added.length) parts.push(pl(sc.added.length, 'new section'));
148 if (sc.removed.length) parts.push(pl(sc.removed.length, 'section removal'));
149 if (sc.moved.length) parts.push(pl(sc.moved.length, 'section rename'));
150 return parts.join(', ') || 'Changes';
151 }
152
153 function serviceLink(s: ServiceChange, isRemoval: boolean): string {
154 const c = slugify(s.category),
155 sc = slugify(s.section);
156 return isRemoval ? `/${c}/${sc}` : `/${c}/${sc}/${slugify(s.name)}`;
157 }
158
159 type ChangeRow = {
160 badge: string;
161 cls: string;
162 name: string;
163 href: string;
164 path?: string;
165 fields?: string[];
166 };
167
168 function changeRows(e: ChangelogEntry): ChangeRow[] {
169 const s = svc(e),
170 sc = sec(e),
171 ct = cat(e);
172 return [
173 ...s.added.map((v) => ({
174 badge: 'Added',
175 cls: 'add',
176 name: v.name,
177 href: serviceLink(v, false),
178 path: `into ${v.category} › ${v.section}`,
179 })),
180 ...s.removed.map((v) => ({
181 badge: 'Removed',
182 cls: 'rem',
183 name: v.name,
184 href: serviceLink(v, true),
185 path: `from ${v.category} › ${v.section}`,
186 })),
187 ...s.modified.map((v) => ({
188 badge: 'Amended',
189 cls: 'mod',
190 name: v.name,
191 href: serviceLink(v, false),
192 path: `in ${v.category} › ${v.section}`,
193 fields: v.fields,
194 })),
195 ...s.moved.map((v) => ({
196 badge: 'Moved',
197 cls: 'mod',
198 name: v.name,
199 href: serviceLink(
200 { name: v.name, category: v.to.category, section: v.to.section },
201 false,
202 ),
203 path: `from ${v.from.category} › ${v.from.section} → ${v.to.category} › ${v.to.section}`,
204 })),
205 ...s.renamed.map((v) => {
206 const sameLoc =
207 v.from.category === v.to.category && v.from.section === v.to.section;
208 return {
209 badge: 'Renamed',
210 cls: 'mod',
211 name: `${v.previousName} → ${v.name}`,
212 href: serviceLink(
213 { name: v.name, category: v.to.category, section: v.to.section },
214 false,
215 ),
216 path: sameLoc
217 ? `in ${v.to.category} › ${v.to.section}`
218 : `from ${v.from.category} › ${v.from.section} → ${v.to.category} › ${v.to.section}`,
219 };
220 }),
221 ...sc.added.map((v) => ({
222 badge: 'New Section',
223 cls: 'add',
224 name: v.name,
225 href: `/${slugify(v.category)}/${slugify(v.name)}`,
226 })),
227 ...sc.removed.map((v) => ({
228 badge: 'Section Removed',
229 cls: 'rem',
230 name: v.name,
231 href: '',
232 })),
233 ...sc.moved.map((v) => ({
234 badge: 'Section Renamed',
235 cls: 'mod',
236 name: `${v.from.section} → ${v.to.section}`,
237 href: `/${slugify(v.to.category)}/${slugify(v.to.section)}`,
238 path:
239 v.from.category === v.to.category
240 ? `in ${v.to.category}`
241 : `from ${v.from.category} to ${v.to.category}`,
242 })),
243 ...ct.added.map((v) => ({
244 badge: 'New Category',
245 cls: 'add',
246 name: v,
247 href: '',
248 })),
249 ...ct.removed.map((v) => ({
250 badge: 'Category Removed',
251 cls: 'rem',
252 name: v,
253 href: '',
254 })),
255 ];
256 }
257
258 const allItems = $derived(
259 [
260 ...entries.map(
261 (e): TimelineItem => ({
262 kind: 'entry',
263 date: e.date,
264 sha: e.sha,
265 pr: e.pr,
266 data: e,
267 }),
268 ),
269 ...rejections.map(
270 (r): TimelineItem => ({
271 kind: 'rejection',
272 date: r.date,
273 sha: `rej-${r.pr.number}`,
274 pr: r.pr,
275 data: r,
276 }),
277 ),
278 ].sort((a, b) => b.date.localeCompare(a.date)),
279 );
280
281 const filtered = $derived(
282 allItems.filter(
283 (item) => matchesFilters(item, on) && matchesSearch(item, searchQuery),
284 ),
285 );
286
287 const grouped = $derived(
288 filtered.reduce<Record<string, TimelineItem[]>>((acc, item) => {
289 const d = new Date(item.date + 'T00:00:00Z');
290 const key = d.toLocaleDateString('en-US', {
291 year: 'numeric',
292 month: 'long',
293 timeZone: 'UTC',
294 });
295 (acc[key] ??= []).push(item);
296 return acc;
297 }, {}),
298 );
299
300 function formatDate(dateStr: string): string {
301 return new Date(dateStr + 'T00:00:00Z').toLocaleDateString('en-US', {
302 month: 'short',
303 day: 'numeric',
304 year: 'numeric',
305 timeZone: 'UTC',
306 });
307 }
308</script>
309
310<details class="controls">
311 <summary>Search & Filter</summary>
312 <div class="controls-body">
313 <input
314 class="search"
315 type="text"
316 placeholder="Filter by service, category, user.."
317 bind:value={searchQuery}
318 />
319 <div class="filters">
320 {#each filterDefs as f (f.key)}
321 <button
322 class="pill {f.key}"
323 class:active={on[f.key]}
324 onclick={() => toggle(f.key)}
325 >
326 <span class="icon">{f.icon}</span>{f.label}
327 </button>
328 {/each}
329 </div>
330 </div>
331</details>
332
333{#if filtered.length === 0}
334 <p class="empty">No matching changes found.</p>
335{/if}
336
337{#each Object.entries(grouped) as [month, monthItems] (month)}
338 <h3 class="month-header">{month}</h3>
339 {#each monthItems as item (item.sha)}
340 <article class="entry">
341 <time class="entry-date">{formatDate(item.date)}</time>
342 <div class="entry-body">
343 <div class="summary">
344 {#if item.pr?.authorAvatar}
345 <a
346 href={`https://github.com/${item.pr.author}`}
347 target="_blank"
348 rel="noreferrer"
349 >
350 <img
351 class="avatar"
352 src={item.pr.authorAvatar}
353 alt=""
354 width="20"
355 height="20"
356 loading="lazy"
357 />
358 </a>
359 {/if}
360 {#if item.pr?.author}
361 <span class="author"
362 ><a
363 href={`https://github.com/${item.pr.author}`}
364 target="_blank"
365 rel="noreferrer">@{item.pr.author}</a
366 ></span
367 >
368 {/if}
369 <span class="summary-text">
370 {item.kind === 'rejection'
371 ? 'Submission Reviewed'
372 : summarize(item.data)}
373 </span>
374 {#if item.pr}
375 <a
376 class="pr-link"
377 href={item.pr.url}
378 target="_blank"
379 rel="noreferrer">#{item.pr.number}</a
380 >
381 {/if}
382 </div>
383
384 <div class="changes">
385 {#if item.kind === 'rejection'}
386 <div class="change">
387 <span class="badge rej">Rejected</span>
388 <a
389 class="svc-name"
390 href={item.pr.url}
391 target="_blank"
392 rel="noreferrer">{item.data.title}</a
393 >
394 <span class="path">Not merged</span>
395 </div>
396 {:else}
397 {#each changeRows(item.data) as row (`${row.cls}/${row.path}/${row.name}`)}
398 <div class="change">
399 <span class="badge {row.cls}">{row.badge}</span>
400 {#if row.href}
401 <a
402 class="svc-name"
403 class:removed={row.cls === 'rem'}
404 href={row.href}>{row.name}</a
405 >
406 {:else}
407 <strong>{row.name}</strong>
408 {/if}
409 {#if row.fields}<span class="fields"
410 >updated {row.fields.join(', ')}</span
411 >{/if}
412 {#if row.path && !row.fields}<span class="path">{row.path}</span
413 >{/if}
414 </div>
415 {/each}
416 {/if}
417 </div>
418 </div>
419 </article>
420 {/each}
421{/each}
422
423<style lang="scss">
424 @use '../../styles/mixins' as *;
425 .controls {
426 margin-bottom: var(--space-md);
427
428 summary {
429 cursor: pointer;
430 width: fit-content;
431 font-family: var(--font-subtitle);
432 opacity: var(--opacity-muted);
433 &:hover {
434 opacity: 1;
435 }
436 }
437
438 .controls-body {
439 display: flex;
440 align-items: flex-end;
441 justify-content: space-between;
442 gap: var(--space-md);
443 margin-top: var(--space-sm);
444 }
445
446 .search {
447 width: 200px;
448 padding: 0.35rem 0.75rem;
449 border: var(--border-heavy);
450 border-radius: var(--curve-lg);
451 box-shadow: var(--shadow-xs);
452 background: var(--accent-fg);
453 color: var(--foreground);
454 &:focus {
455 outline: none;
456 border-color: var(--accent);
457 box-shadow: 2px 2px 0 var(--accent);
458 }
459 &::placeholder {
460 opacity: var(--opacity-dim);
461 }
462 }
463
464 .filters {
465 display: flex;
466 gap: 0.3rem;
467 flex-wrap: wrap;
468 }
469
470 .pill {
471 display: flex;
472 align-items: center;
473 gap: var(--space-xs);
474 padding: 0.15rem var(--space-sm);
475 border: 1px solid transparent;
476 border-radius: var(--curve-md);
477 background: var(--background);
478 color: var(--foreground);
479 cursor: pointer;
480 font-family: var(--font-subtitle);
481 font-size: var(--text-xs);
482 opacity: var(--opacity-dim);
483 transition: var(--transition-normal);
484
485 .icon {
486 font-size: var(--text-sm);
487 line-height: 1;
488 }
489 &.active {
490 opacity: 1;
491 border-color: currentColor;
492 }
493 &.added {
494 &.active {
495 color: var(--changelog-add);
496 }
497 &:hover {
498 background: color-mix(in srgb, var(--changelog-add) 10%, transparent);
499 }
500 }
501 &.removed {
502 &.active {
503 color: var(--changelog-rem);
504 }
505 &:hover {
506 background: color-mix(in srgb, var(--changelog-rem) 10%, transparent);
507 }
508 }
509 &.modified {
510 &.active {
511 color: var(--changelog-mod);
512 }
513 &:hover {
514 background: color-mix(in srgb, var(--changelog-mod) 10%, transparent);
515 }
516 }
517 &.rejected {
518 &.active {
519 color: var(--changelog-rej);
520 }
521 &:hover {
522 background: color-mix(in srgb, var(--changelog-rej) 10%, transparent);
523 }
524 }
525 }
526 }
527
528 .empty {
529 text-align: center;
530 opacity: var(--opacity-muted);
531 margin: var(--space-lg) 0;
532 }
533
534 .month-header {
535 font-size: var(--text-lg);
536 margin: 1.5rem 0 var(--space-sm) 0;
537 padding-bottom: 0.3rem;
538 border-bottom: 1px solid var(--accent-3);
539 color: var(--accent-3);
540 font-family: var(--font-subtitle);
541 }
542
543 .entry {
544 display: flex;
545 gap: var(--space-md);
546 padding: 0.6rem 0;
547 border-bottom: 1px solid var(--background-hr-color);
548 &:last-child {
549 border-bottom: none;
550 }
551
552 .entry-date {
553 min-width: 7rem;
554 opacity: 0.75;
555 padding-top: 0.15rem;
556 font-family: var(--font-subtitle);
557 }
558
559 .entry-body {
560 flex: 1;
561 min-width: 0;
562 }
563 }
564
565 .summary {
566 display: flex;
567 align-items: center;
568 gap: 0.4rem;
569 flex-wrap: wrap;
570 margin-bottom: 0.3rem;
571 font-size: var(--text-sm);
572 opacity: var(--opacity-subtle);
573 .author a {
574 color: var(--foreground);
575 &:hover {
576 color: var(--accent);
577 }
578 }
579 .avatar {
580 border-radius: 50%;
581 }
582 .pr-link {
583 padding: 0 0.4rem;
584 border-radius: var(--curve-sm);
585 background: var(--accent-3);
586 color: var(--bright);
587 text-decoration: none;
588 font-family: var(--font-subtitle);
589 &:hover {
590 opacity: 0.85;
591 }
592 }
593 }
594
595 .changes {
596 display: flex;
597 flex-direction: column;
598 gap: 0.2rem;
599 .change {
600 display: flex;
601 align-items: baseline;
602 gap: 0.4rem;
603 flex-wrap: wrap;
604 }
605 }
606
607 .badge {
608 @include changelog-badge;
609 &.add {
610 background: color-mix(in srgb, var(--changelog-add) 33%, transparent);
611 color: var(--changelog-add);
612 }
613 &.rem {
614 background: color-mix(in srgb, var(--changelog-rej) 33%, transparent);
615 color: var(--changelog-rej);
616 }
617 &.mod {
618 background: color-mix(in srgb, var(--changelog-mod) 33%, transparent);
619 color: var(--changelog-mod);
620 }
621 &.rej {
622 background: color-mix(in srgb, var(--changelog-rem) 33%, transparent);
623 color: var(--changelog-rem);
624 }
625 }
626
627 .svc-name {
628 font-weight: 500;
629 color: var(--foreground);
630 text-decoration: none;
631 }
632 a.svc-name:hover {
633 color: var(--accent);
634 text-decoration: underline;
635 }
636
637 .path,
638 .fields {
639 font-size: var(--text-sm);
640 opacity: var(--opacity-muted);
641 }
642 .fields {
643 font-style: italic;
644 }
645
646 @media (max-width: 768px) {
647 .entry {
648 flex-direction: column;
649 gap: 0.2rem;
650 .entry-date {
651 min-width: unset;
652 }
653 }
654 }
655</style>