refactor(webui): centralize notification selection
This commit is contained in:
@@ -14,10 +14,11 @@
|
|||||||
"./styles/notifications.css": "./src/styles/notifications.css"
|
"./styles/notifications.css": "./src/styles/notifications.css"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"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": {
|
"peerDependencies": {
|
||||||
"@govoplan/core-webui": "^0.1.8",
|
"@govoplan/core-webui": "^0.1.9",
|
||||||
"lucide-react": "^1.23.0",
|
"lucide-react": "^1.23.0",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
|
|||||||
18
webui/scripts/test-notification-page-structure.mjs
Normal file
18
webui/scripts/test-notification-page-structure.mjs
Normal 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.");
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { Bell, Check, ExternalLink, RefreshCw, Send, XCircle } from "lucide-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 { deliverPendingNotifications, listNotifications, updateNotification, type NotificationMessage } from "../../api/notifications";
|
||||||
import { safeNotificationActionUrl } from "../../security/actionUrl";
|
import { safeNotificationActionUrl } from "../../security/actionUrl";
|
||||||
|
|
||||||
@@ -112,11 +112,13 @@ export default function NotificationCenterPage({ settings, auth }: { settings: A
|
|||||||
<div className="notifications-list">
|
<div className="notifications-list">
|
||||||
{loading ? <div className="notifications-note">Loading notifications</div> : null}
|
{loading ? <div className="notifications-note">Loading notifications</div> : null}
|
||||||
{!loading && notifications.length === 0 ? <div className="notifications-note">No notifications in this view.</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) => (
|
{notifications.map((notification) => (
|
||||||
<button
|
<SelectionListItem
|
||||||
key={notification.id}
|
key={notification.id}
|
||||||
type="button"
|
selected={selected?.id === notification.id}
|
||||||
className={`notifications-list-item ${selected?.id === notification.id ? "is-selected" : ""} ${notification.read_at ? "is-read" : ""}`}
|
className={`notifications-list-item ${notification.read_at ? "is-read" : ""}`}
|
||||||
onClick={() => setSelectedId(notification.id)}
|
onClick={() => setSelectedId(notification.id)}
|
||||||
>
|
>
|
||||||
<span className="notifications-list-heading">
|
<span className="notifications-list-heading">
|
||||||
@@ -127,8 +129,10 @@ export default function NotificationCenterPage({ settings, auth }: { settings: A
|
|||||||
<span>{notification.source_module}</span>
|
<span>{notification.source_module}</span>
|
||||||
<span>{formatDate(notification.created_at)}</span>
|
<span>{formatDate(notification.created_at)}</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</SelectionListItem>
|
||||||
))}
|
))}
|
||||||
|
</SelectionList>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<section className="notifications-workspace">
|
<section className="notifications-workspace">
|
||||||
|
|||||||
@@ -79,27 +79,14 @@
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notifications-selection-list {
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.notifications-list-item {
|
.notifications-list-item {
|
||||||
width: 100%;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
min-height: 58px;
|
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 {
|
.notifications-list-item.is-read {
|
||||||
|
|||||||
Reference in New Issue
Block a user