refactor(webui): centralize notification selection

This commit is contained in:
2026-07-21 13:31:46 +02:00
parent 0e62e6df8f
commit 9c2dc3efbf
4 changed files with 47 additions and 37 deletions

View File

@@ -14,10 +14,11 @@
"./styles/notifications.css": "./src/styles/notifications.css"
},
"scripts": {
"test:action-url": "rm -rf .component-test-build && mkdir -p .component-test-build && printf '{\"type\":\"commonjs\"}\\n' > .component-test-build/package.json && tsc -p tsconfig.tests.json && node .component-test-build/tests/action-url.test.js"
"test:action-url": "rm -rf .component-test-build && mkdir -p .component-test-build && printf '{\"type\":\"commonjs\"}\\n' > .component-test-build/package.json && tsc -p tsconfig.tests.json && node .component-test-build/tests/action-url.test.js",
"test:ui-structure": "node scripts/test-notification-page-structure.mjs"
},
"peerDependencies": {
"@govoplan/core-webui": "^0.1.8",
"@govoplan/core-webui": "^0.1.9",
"lucide-react": "^1.23.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",

View File

@@ -0,0 +1,18 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const pagePath = fileURLToPath(new URL("../src/features/notifications/NotificationCenterPage.tsx", import.meta.url));
const stylesPath = fileURLToPath(new URL("../src/styles/notifications.css", import.meta.url));
const page = readFileSync(pagePath, "utf8");
const styles = readFileSync(stylesPath, "utf8");
assert.match(page, /SelectionList,[\s\S]*SelectionListItem,[\s\S]*from "@govoplan\/core-webui"/);
assert.match(page, /<SelectionList label="Notifications" className="notifications-selection-list">/);
assert.match(page, /<SelectionListItem[\s\S]*selected=\{selected\?\.id === notification\.id\}/);
assert.match(page, /className=\{`notifications-list-item \$\{notification\.read_at \? "is-read" : ""\}`\}/);
assert.doesNotMatch(page, /<button[\s\S]{0,160}notifications-list-item/);
assert.doesNotMatch(styles, /\.notifications-list-item:(?:hover|focus-visible)/);
assert.doesNotMatch(styles, /\.notifications-list-item\.is-selected/);
console.log("Notification rows use the central selection-list contract.");

View File

@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from "react";
import { Bell, Check, ExternalLink, RefreshCw, Send, XCircle } from "lucide-react";
import { AdminIconButton, Button, DismissibleAlert, SegmentedControl, StatusBadge, hasScope, type ApiSettings, type AuthInfo } from "@govoplan/core-webui";
import { AdminIconButton, Button, DismissibleAlert, SegmentedControl, SelectionList, SelectionListItem, StatusBadge, hasScope, type ApiSettings, type AuthInfo } from "@govoplan/core-webui";
import { deliverPendingNotifications, listNotifications, updateNotification, type NotificationMessage } from "../../api/notifications";
import { safeNotificationActionUrl } from "../../security/actionUrl";
@@ -112,11 +112,13 @@ export default function NotificationCenterPage({ settings, auth }: { settings: A
<div className="notifications-list">
{loading ? <div className="notifications-note">Loading notifications</div> : null}
{!loading && notifications.length === 0 ? <div className="notifications-note">No notifications in this view.</div> : null}
{notifications.length > 0 ? (
<SelectionList label="Notifications" className="notifications-selection-list">
{notifications.map((notification) => (
<button
<SelectionListItem
key={notification.id}
type="button"
className={`notifications-list-item ${selected?.id === notification.id ? "is-selected" : ""} ${notification.read_at ? "is-read" : ""}`}
selected={selected?.id === notification.id}
className={`notifications-list-item ${notification.read_at ? "is-read" : ""}`}
onClick={() => setSelectedId(notification.id)}
>
<span className="notifications-list-heading">
@@ -127,8 +129,10 @@ export default function NotificationCenterPage({ settings, auth }: { settings: A
<span>{notification.source_module}</span>
<span>{formatDate(notification.created_at)}</span>
</span>
</button>
</SelectionListItem>
))}
</SelectionList>
) : null}
</div>
</aside>
<section className="notifications-workspace">

View File

@@ -79,27 +79,14 @@
padding: 8px;
}
.notifications-selection-list {
gap: 4px;
}
.notifications-list-item {
width: 100%;
display: grid;
gap: 4px;
min-height: 58px;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--text);
cursor: pointer;
padding: 9px;
text-align: left;
}
.notifications-list-item:hover,
.notifications-list-item.is-selected {
background: var(--sidebar-hover-bg);
}
.notifications-list-item.is-selected {
box-shadow: inset 3px 0 var(--accent);
}
.notifications-list-item.is-read {