fix(web): 收敛控制台列表主按钮、报警可读性与焦点环

按 UI 评审闭环 UI-02~UI-07(查询降权、对象/处理人可读化、筛选分层、数据源名映射、焦点外环);概览与登录壳按约定暂缓。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
unknownandCursor committed 2026-11-19 19:04:54 +08:00
1 parent c7a23837f4
commit 9dffeae667
25 files changed
+1057 -94

No files matched your search

+3 -1
View File
@@ -477,7 +477,9 @@
"forbidden": "No permission to view alarms",
"objectInvalid": "The object id must be a full id",
"timeOrder": "The start time cannot be later than the end time",
"resultSep": " · "
"resultSep": " · ",
"moreFilters": "More filters",
"fewerFilters": "Fewer filters"
},
"columns": {
"module": "Module",
+3 -1
View File
@@ -477,7 +477,9 @@
"forbidden": "ไม่มีสิทธิ์ดูการแจ้งเตือน",
"objectInvalid": "รหัสวัตถุต้องเป็นรหัสเต็ม",
"timeOrder": "เวลาเริ่มต้องไม่ช้ากว่าเวลาสิ้นสุด",
"resultSep": " · "
"resultSep": " · ",
"moreFilters": "ตัวกรองเพิ่มเติม",
"fewerFilters": "ย่อตัวกรอง"
},
"columns": {
"module": "โมดูล",
+3 -1
View File
@@ -478,7 +478,9 @@
"forbidden": "没有查看报警的权限",
"objectInvalid": "对象编号需要是完整的编号",
"timeOrder": "开始时间不能晚于结束时间",
"resultSep": " · "
"resultSep": " · ",
"moreFilters": "更多筛选",
"fewerFilters": "收起筛选"
},
"columns": {
"module": "模块",
+3 -1
View File
@@ -477,7 +477,9 @@
"forbidden": "沒有查看警報的權限",
"objectInvalid": "物件編號需要是完整的編號",
"timeOrder": "開始時間不能晚於結束時間",
"resultSep": " · "
"resultSep": " · ",
"moreFilters": "更多篩選",
"fewerFilters": "收起篩選"
},
"columns": {
"module": "模組",
@@ -0,0 +1,161 @@
/**
* UI review evidence capture. Credentials via env only; never log password.
* WATCHMAN_UI_USER / WATCHMAN_UI_PASSWORD
*/
import { chromium } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const user = process.env.WATCHMAN_UI_USER;
const password = process.env.WATCHMAN_UI_PASSWORD;
if (!user || !password) {
console.error("Missing WATCHMAN_UI_USER or WATCHMAN_UI_PASSWORD");
process.exit(1);
}
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../");
const outDir = path.join(root, "docs/evidence/ui-review/2026-11-19-console-full/screenshots");
fs.mkdirSync(outDir, { recursive: true });
const routes = [
{ key: "home", path: "/#/" },
{ key: "datasources", path: "/#/datasources" },
{ key: "queries", path: "/#/queries" },
{ key: "mappings", path: "/#/mappings" },
{ key: "alarms", path: "/#/alarms" },
];
const viewports = [
{ name: "1440x900", width: 1440, height: 900 },
{ name: "1280x800", width: 1280, height: 800 },
];
async function login(page) {
await page.goto("http://127.0.0.1:5173/", { waitUntil: "networkidle" });
await page.getByTestId("login-username").locator("input").fill(user);
await page.getByTestId("login-password").locator("input").fill(password);
await page.getByTestId("login-submit").click();
await page.getByTestId("logout").waitFor({ timeout: 20000 });
}
async function shot(page, name) {
await page.waitForTimeout(400);
await page.screenshot({ path: path.join(outDir, name), fullPage: false });
}
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext();
const page = await context.newPage();
await page.setViewportSize(viewports[0]);
await login(page);
await shot(page, "home-1440x900-data-01.png");
// keyboard focus on home then datasources filter
await page.goto("http://127.0.0.1:5173/#/datasources", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
await shot(page, "datasources-1440x900-data-02.png");
const nameFilter = page.getByTestId("datasource-filter-name").locator("input");
if (await nameFilter.count()) {
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
// focus name filter explicitly via real Tab from a known start
await page.locator("body").click({ position: { x: 5, y: 5 } });
for (let i = 0; i < 12; i++) {
await page.keyboard.press("Tab");
const active = await page.evaluate(() => {
const el = document.activeElement;
return {
tag: el?.tagName,
testid: el?.closest("[data-testid]")?.getAttribute("data-testid") || null,
placeholder: el?.getAttribute("placeholder"),
};
});
if (active.testid === "datasource-filter-name" || active.placeholder === "名称") {
await shot(page, "datasources-1440x900-keyboard-focus-03.png");
const styles = await page.evaluate(() => {
const el = document.activeElement;
const wrap = el?.closest(".el-input__wrapper") || el;
const cs = getComputedStyle(wrap);
return { outline: cs.outline, boxShadow: cs.boxShadow, borderColor: cs.borderColor };
});
fs.writeFileSync(
path.join(outDir, "..", "focus-styles.json"),
JSON.stringify(styles, null, 2),
"utf8",
);
break;
}
}
await nameFilter.fill("__no_match_ui_review__");
await page.getByRole("button", { name: "查询" }).click();
await page.waitForTimeout(500);
await shot(page, "datasources-1440x900-empty-filter-04.png");
await page.getByRole("button", { name: "重置" }).click();
await page.waitForTimeout(500);
}
await page.goto("http://127.0.0.1:5173/#/queries", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
await shot(page, "queries-1440x900-data-05.png");
await page.goto("http://127.0.0.1:5173/#/mappings", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
await shot(page, "mappings-1440x900-data-06.png");
await page.goto("http://127.0.0.1:5173/#/alarms", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
await shot(page, "alarms-1440x900-data-07.png");
// second viewport sweep
await page.setViewportSize(viewports[1]);
for (const r of routes) {
await page.goto(`http://127.0.0.1:5173${r.path}`, { waitUntil: "networkidle" });
await page.waitForTimeout(500);
await shot(page, `${r.key}-1280x800-data-08.png`.replace("data-08", `data-${r.key}-08`));
}
// open first datasource detail if row exists
await page.setViewportSize(viewports[0]);
await page.goto("http://127.0.0.1:5173/#/datasources", { waitUntil: "networkidle" });
await page.waitForTimeout(500);
const openBtn = page.getByRole("button", { name: "打开" }).first();
if (await openBtn.count()) {
await openBtn.click();
await page.waitForTimeout(700);
await shot(page, "datasource-detail-1440x900-data-09.png");
}
const alarmOpen = page.locator("a, button").filter({ hasText: /打开|详情/ }).first();
await page.goto("http://127.0.0.1:5173/#/alarms", { waitUntil: "networkidle" });
await page.waitForTimeout(500);
const alarmRowOpen = page.getByRole("button", { name: "打开" }).first();
if (await alarmRowOpen.count()) {
await alarmRowOpen.click();
await page.waitForTimeout(700);
await shot(page, "alarm-detail-1440x900-data-10.png");
}
// scroll metrics
const metrics = {};
for (const r of routes) {
await page.goto(`http://127.0.0.1:5173${r.path}`, { waitUntil: "networkidle" });
await page.waitForTimeout(300);
metrics[r.key] = await page.evaluate(() => ({
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
scrollHeight: document.documentElement.scrollHeight,
clientHeight: document.documentElement.clientHeight,
bodyScroll: document.body.scrollHeight === document.body.clientHeight,
}));
}
fs.writeFileSync(path.join(outDir, "..", "viewport-metrics.json"), JSON.stringify(metrics, null, 2), "utf8");
await browser.close();
console.log("capture complete");
@@ -0,0 +1,22 @@
import { chromium } from "@playwright/test";
import path from "node:path";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../");
const outDir = path.join(root, "docs/evidence/ui-review/2026-11-19-console-full/screenshots");
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto("http://127.0.0.1:5173/", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
await page.screenshot({ path: path.join(outDir, "login-1440x900-default-01.png"), fullPage: true });
await page.setViewportSize({ width: 1280, height: 800 });
await page.screenshot({ path: path.join(outDir, "login-1280x800-default-02.png"), fullPage: true });
const theme = page.getByRole("button", { name: "切换昼夜" });
if (await theme.count()) {
await theme.click();
await page.waitForTimeout(400);
await page.screenshot({ path: path.join(outDir, "login-1280x800-dark-03.png"), fullPage: true });
}
await browser.close();
console.log("login screenshots ok");
@@ -0,0 +1,118 @@
/**
* Post-fix UI recheck. Credentials via env only.
* WATCHMAN_UI_USER / WATCHMAN_UI_PASSWORD
*/
import { chromium } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const user = process.env.WATCHMAN_UI_USER;
const password = process.env.WATCHMAN_UI_PASSWORD;
if (!user || !password) {
console.error("Missing WATCHMAN_UI_USER or WATCHMAN_UI_PASSWORD");
process.exit(1);
}
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../");
const outDir = path.join(root, "docs/evidence/ui-review/2026-11-19-console-recheck/screenshots");
fs.mkdirSync(outDir, { recursive: true });
async function shot(page, name) {
await page.waitForTimeout(350);
await page.screenshot({ path: path.join(outDir, name), fullPage: false });
}
async function buttonTone(page, testId) {
const loc = page.getByTestId(testId);
if ((await loc.count()) === 0) return null;
return loc.evaluate((el) => ({
testId: el.getAttribute("data-testid"),
classes: el.className,
isPrimary: el.classList.contains("el-button--primary"),
}));
}
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto("http://127.0.0.1:5173/", { waitUntil: "networkidle" });
await page.getByTestId("login-username").locator("input").fill(user);
await page.getByTestId("login-password").locator("input").fill(password);
await page.getByTestId("login-submit").click();
await page.getByTestId("logout").waitFor({ timeout: 20000 });
await page.goto("http://127.0.0.1:5173/#/", { waitUntil: "networkidle" });
await shot(page, "home-1440x900-01.png");
await page.goto("http://127.0.0.1:5173/#/datasources", { waitUntil: "networkidle" });
await page.waitForTimeout(500);
const dsButtons = {
search: await buttonTone(page, "datasource-filter-search"),
create: await buttonTone(page, "datasource-create"),
};
await shot(page, "datasources-1440x900-02.png");
// keyboard focus on name filter
await page.getByTestId("datasource-filter-name").locator("input").focus();
await page.waitForTimeout(200);
const focusStyles = await page.evaluate(() => {
const el = document.activeElement;
const wrap = el?.closest(".el-input__wrapper") || el;
const cs = getComputedStyle(wrap);
return { outline: cs.outline, boxShadow: cs.boxShadow };
});
await shot(page, "datasources-1440x900-focus-03.png");
await page.goto("http://127.0.0.1:5173/#/queries", { waitUntil: "networkidle" });
await page.waitForTimeout(800);
const qButtons = {
search: await buttonTone(page, "query-filter-search"),
create: await buttonTone(page, "query-create"),
};
const dsCellSample = await page.locator("[data-testid=query-table] tbody tr").first().locator("td").nth(1).innerText().catch(() => "");
await shot(page, "queries-1440x900-04.png");
await page.goto("http://127.0.0.1:5173/#/mappings", { waitUntil: "networkidle" });
await page.waitForTimeout(500);
await shot(page, "mappings-1440x900-05.png");
await page.goto("http://127.0.0.1:5173/#/alarms", { waitUntil: "networkidle" });
await page.waitForTimeout(600);
const moreVisible = await page.getByTestId("alarm-filter-more").isVisible();
const moduleHidden = (await page.getByTestId("alarm-filter-module").count()) === 0;
await shot(page, "alarms-1440x900-default-06.png");
await page.getByTestId("alarm-filter-more").click();
await page.waitForTimeout(200);
const moduleVisible = await page.getByTestId("alarm-filter-module").isVisible();
await shot(page, "alarms-1440x900-more-07.png");
const objectText = await page.locator("[data-testid=alarm-object-label]").first().innerText().catch(() => "");
const objectTitle = await page.locator("[data-testid=alarm-object-label]").first().getAttribute("title").catch(() => "");
await page.getByTestId("alarm-open").first().click();
await page.waitForTimeout(700);
const identityText = await page.getByTestId("alarm-identity").innerText().catch(() => "");
const identityTitle = await page.getByTestId("alarm-identity").getAttribute("title").catch(() => "");
const handlerText = await page.getByTestId("alarm-handler").innerText().catch(() => "");
await shot(page, "alarm-detail-1440x900-08.png");
const notes = {
dsButtons,
qButtons,
focusStyles,
dsCellSample: dsCellSample.trim(),
alarms: {
moreVisible,
moduleHiddenBeforeMore: moduleHidden,
moduleVisibleAfterMore: moduleVisible,
objectText: objectText.trim(),
objectTitle,
identityText: identityText.trim(),
identityTitle,
handlerText: handlerText.trim(),
},
};
fs.writeFileSync(path.join(outDir, "..", "recheck-notes.json"), JSON.stringify(notes, null, 2), "utf8");
console.log(JSON.stringify(notes, null, 2));
await browser.close();
+99 -50
View File
@@ -35,7 +35,7 @@ import {
} from "./actions";
import { appendProgress, claimAlarm, closeAlarm, getAlarm, listEvidence, listHistory, listOccurrences } from "./client";
import { describeAlarmError, isAlarmConflict, isAlarmForbidden, isAlarmNotFound } from "./errors";
import { formatDateTime } from "./format";
import { formatDateTime, formatHandlerLabel, formatIdentityLabel } from "./format";
import type { AlarmRecord, ClosedBasis, EvidenceBundle, HistoryEvent, OccurrenceList } from "./types";
const { t, te } = useI18n();
@@ -98,6 +98,19 @@ function textOrNone(value: string | null | undefined): string {
return value;
}
function objectLabel(identityKey: string): string {
return formatIdentityLabel(identityKey) || t("alarm.detail.fields.none");
}
function handlerDisplay(subject: string | null | undefined): { label: string; title?: string } {
const short = formatHandlerLabel(subject);
if (!short) {
return { label: t("alarm.detail.fields.none") };
}
const full = subject?.trim() ?? short;
return { label: short, title: full !== short ? full : undefined };
}
function statusText(status: string): string {
const key = `alarm.status.${status}`;
return te(key) ? t(key) : status;
@@ -393,76 +406,112 @@ onMounted(() => {
<section class="wm-form-section" data-testid="alarm-summary">
<h3 class="mb-3 text-[14.5px] font-semibold">{{ t("alarm.detail.summary") }}</h3>
<dl class="grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-2">
<div class="sm:col-span-2 rounded-lg border border-[var(--border-subtle)] bg-[var(--bg-surface-soft)] p-3">
<div class="grid grid-cols-1 gap-3 sm:grid-cols-3">
<div>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.status") }}</dt>
<dd class="mt-1 font-semibold text-[var(--text-primary)]">
<ElTag :type="statusTag(alarm.status)" effect="light" data-testid="alarm-detail-status">
{{ statusText(alarm.status) }}
</ElTag>
<span v-if="alarm.close_result" class="ml-1 text-[13px] font-medium">
{{ t("alarm.list.resultSep") }}{{ named("closeResult", alarm.close_result) }}
</span>
</dd>
</div>
<div>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.scenario") }}</dt>
<dd class="mt-1 text-[15px] font-semibold text-[var(--text-primary)]">{{ alarm.scenario_name }}</dd>
</div>
<div>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.object") }}</dt>
<dd
class="mt-1 text-[15px] font-semibold text-[var(--text-primary)]"
data-testid="alarm-identity"
:title="alarm.identity_key"
>
{{ objectLabel(alarm.identity_key) }}
</dd>
<p
v-if="objectLabel(alarm.identity_key) !== alarm.identity_key"
class="mt-0.5 truncate text-[12px] text-[var(--text-muted)]"
data-testid="alarm-identity-raw"
:title="alarm.identity_key"
>
{{ alarm.identity_key }}
</p>
</div>
</div>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.status") }}</dt>
<dd>
<ElTag :type="statusTag(alarm.status)" effect="light" data-testid="alarm-detail-status">
{{ statusText(alarm.status) }}
</ElTag>
<span v-if="alarm.close_result">
{{ t("alarm.list.resultSep") }}{{ named("closeResult", alarm.close_result) }}
</span>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.module") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">{{ alarm.module_key }}</dd>
</div>
<div>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.count") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">{{ alarm.occurrence_count }}</dd>
</div>
<div>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.firstOccurred") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.first_occurred_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.scenario") }}</dt>
<dd>{{ alarm.scenario_name }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.lastOccurred") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.last_occurred_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.module") }}</dt>
<dd>{{ alarm.module_key }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.handler") }}</dt>
<dd
class="mt-0.5 font-medium text-[var(--text-primary)]"
data-testid="alarm-handler"
:title="handlerDisplay(alarm.current_handler).title"
>
{{ handlerDisplay(alarm.current_handler).label }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.scenarioKey") }}</dt>
<dd>{{ alarm.scenario_key }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.claimedAt") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.claimed_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.object") }}</dt>
<dd data-testid="alarm-identity">{{ alarm.identity_key }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.closedAt") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.closed_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.count") }}</dt>
<dd>{{ alarm.occurrence_count }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.openedAt") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.opened_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.firstOccurred") }}</dt>
<dd>{{ formatDateTime(alarm.first_occurred_at) || t("alarm.detail.fields.none") }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.updatedAt") }}</dt>
<dd class="mt-0.5 font-medium text-[var(--text-primary)]">
{{ formatDateTime(alarm.updated_at) || t("alarm.detail.fields.none") }}
</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.lastOccurred") }}</dt>
<dd>{{ formatDateTime(alarm.last_occurred_at) || t("alarm.detail.fields.none") }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.scenarioKey") }}</dt>
<dd class="mt-0.5 text-[var(--text-secondary)]">{{ alarm.scenario_key }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.handler") }}</dt>
<dd data-testid="alarm-handler">{{ textOrNone(alarm.current_handler) }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.cycle") }}</dt>
<dd class="mt-0.5 text-[var(--text-secondary)]">{{ textOrNone(alarm.cycle_key) }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.claimedAt") }}</dt>
<dd>{{ formatDateTime(alarm.claimed_at) || t("alarm.detail.fields.none") }}</dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.event") }}</dt>
<dd class="mt-0.5 text-[var(--text-secondary)]">{{ textOrNone(alarm.event_key) }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.closedAt") }}</dt>
<dd>{{ formatDateTime(alarm.closed_at) || t("alarm.detail.fields.none") }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.cycle") }}</dt>
<dd>{{ textOrNone(alarm.cycle_key) }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.event") }}</dt>
<dd>{{ textOrNone(alarm.event_key) }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.openedAt") }}</dt>
<dd>{{ formatDateTime(alarm.opened_at) || t("alarm.detail.fields.none") }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.updatedAt") }}</dt>
<dd>{{ formatDateTime(alarm.updated_at) || t("alarm.detail.fields.none") }}</dd>
</div>
<div>
<dt class="text-[var(--text-muted)]">{{ t("alarm.detail.fields.previous") }}</dt>
<dd>
<dt class="text-[12px] text-[var(--text-muted)]">{{ t("alarm.detail.fields.previous") }}</dt>
<dd class="mt-0.5">
<ElButton
v-if="alarm.previous_alarm_id"
link
@@ -472,7 +521,7 @@ onMounted(() => {
>
{{ alarm.previous_alarm_id }}
</ElButton>
<span v-else>{{ t("alarm.detail.fields.none") }}</span>
<span v-else class="text-[var(--text-secondary)]">{{ t("alarm.detail.fields.none") }}</span>
</dd>
</div>
</dl>
+37 -14
View File
@@ -34,7 +34,7 @@ import {
emptyAlarmFilters,
type AlarmFilterDraft,
} from "./filters";
import { formatDateTime } from "./format";
import { formatDateTime, formatIdentityLabel } from "./format";
import type { AlarmRecord } from "./types";
const { t, te } = useI18n();
@@ -46,6 +46,8 @@ const total = ref(0);
const phase = ref<"loading" | "ready" | "error" | "forbidden">("loading");
const loadError = ref("");
const filterIssue = ref<"object" | "time-order" | null>(null);
/** Extra filters (module / object) stay collapsed until opened or they hold draft values. */
const moreFiltersOpen = ref(false);
const draft = reactive<AlarmFilterDraft>(emptyAlarmFilters());
const applied = reactive<AlarmFilterDraft>(emptyAlarmFilters());
@@ -124,10 +126,19 @@ function resetFilters(): void {
copyFilters(draft, blank);
copyFilters(applied, blank);
filterIssue.value = null;
moreFiltersOpen.value = false;
page.value = 1;
void load();
}
const moreFiltersActive = computed(
() => draft.moduleKey.trim() !== "" || draft.objectId.trim() !== "",
);
function toggleMoreFilters(): void {
moreFiltersOpen.value = !moreFiltersOpen.value;
}
function onSortChange(payload: { prop: string | null; order: string | null }): void {
const sortable = new Set(["module_key", "scenario_name", "last_occurred_at", "status"]);
if (!payload.prop || !payload.order || !sortable.has(payload.prop)) {
@@ -189,15 +200,16 @@ onMounted(() => {
<ListPageShell test-id="alarm-list">
<template #filters>
<div data-testid="alarm-list-toolbar" class="contents">
<div class="w-[9rem]" data-testid="alarm-filter-module">
<ElInput v-model="draft.moduleKey" clearable :placeholder="t('alarm.list.filterModule')" />
<div class="w-[7.5rem]" data-testid="alarm-filter-status">
<ElSelect v-model="draft.status" clearable class="w-full" :placeholder="t('alarm.list.filterStatus')">
<ElOption :label="t('alarm.status.pending')" value="pending" />
<ElOption :label="t('alarm.status.processing')" value="processing" />
<ElOption :label="t('alarm.status.closed')" value="closed" />
</ElSelect>
</div>
<div class="w-[12rem]" data-testid="alarm-filter-scenario">
<ElInput v-model="draft.scenarioName" clearable :placeholder="t('alarm.list.filterScenario')" />
</div>
<div class="w-[14rem]" data-testid="alarm-filter-object">
<ElInput v-model="draft.objectId" clearable :placeholder="t('alarm.list.filterObject')" />
</div>
<div class="w-[12.5rem]" data-testid="alarm-filter-from">
<ElDatePicker
v-model="draft.from"
@@ -214,19 +226,24 @@ onMounted(() => {
:placeholder="t('alarm.list.filterTo')"
/>
</div>
<div class="w-[7.5rem]" data-testid="alarm-filter-status">
<ElSelect v-model="draft.status" clearable class="w-full" :placeholder="t('alarm.list.filterStatus')">
<ElOption :label="t('alarm.status.pending')" value="pending" />
<ElOption :label="t('alarm.status.processing')" value="processing" />
<ElOption :label="t('alarm.status.closed')" value="closed" />
</ElSelect>
</div>
<template v-if="moreFiltersOpen">
<div class="w-[9rem]" data-testid="alarm-filter-module">
<ElInput v-model="draft.moduleKey" clearable :placeholder="t('alarm.list.filterModule')" />
</div>
<div class="w-[14rem]" data-testid="alarm-filter-object">
<ElInput v-model="draft.objectId" clearable :placeholder="t('alarm.list.filterObject')" />
</div>
</template>
<ElButton type="primary" data-testid="alarm-filter-search" @click="applyFilters">
{{ t("alarm.list.filterSearch") }}
</ElButton>
<ElButton data-testid="alarm-filter-reset" @click="resetFilters">
{{ t("alarm.list.filterReset") }}
</ElButton>
<ElButton data-testid="alarm-filter-more" @click="toggleMoreFilters">
{{ moreFiltersOpen ? t("alarm.list.fewerFilters") : t("alarm.list.moreFilters") }}
<span v-if="!moreFiltersOpen && moreFiltersActive" data-testid="alarm-filter-more-dot"> ·</span>
</ElButton>
</div>
</template>
@@ -298,7 +315,13 @@ onMounted(() => {
min-width="160"
sortable="custom"
/>
<ElTableColumn prop="identity_key" :label="t('alarm.columns.object')" min-width="140" />
<ElTableColumn prop="identity_key" :label="t('alarm.columns.object')" min-width="140" show-overflow-tooltip>
<template #default="{ row }">
<span :title="row.identity_key" data-testid="alarm-object-label">
{{ formatIdentityLabel(row.identity_key) }}
</span>
</template>
</ElTableColumn>
<ElTableColumn
prop="last_occurred_at"
:label="t('alarm.columns.lastOccurred')"
@@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import { formatHandlerLabel, formatIdentityLabel } from "./format";
describe("formatIdentityLabel", () => {
it("extracts serial from identity:v1 JSON", () => {
expect(formatIdentityLabel('identity:v1:{"serial":"DEMO-298ce536"}')).toBe("DEMO-298ce536");
});
it("falls back to the raw key when JSON is absent", () => {
expect(formatIdentityLabel("plain-object-1")).toBe("plain-object-1");
});
it("returns empty for blank input", () => {
expect(formatIdentityLabel("")).toBe("");
expect(formatIdentityLabel(null)).toBe("");
});
});
describe("formatHandlerLabel", () => {
it("keeps short subjects", () => {
expect(formatHandlerLabel("26110002")).toBe("26110002");
});
it("truncates UUID subjects", () => {
expect(formatHandlerLabel("550e8400-e29b-41d4-a716-446655440000")).toBe("550e8400…");
});
it("returns null for empty", () => {
expect(formatHandlerLabel(null)).toBeNull();
expect(formatHandlerLabel(" ")).toBeNull();
});
});
+58 -3
View File
@@ -1,7 +1,7 @@
/**
* Alarm timestamps for tables. Empty or invalid values stay blank.
* Boundary: display only. It does not parse filter input.
* Depends on the browser time zone.
* Alarm timestamps and display labels for tables/detail.
* Boundary: display only. Does not parse filter input or call APIs.
* Depends on the browser time zone for datetime formatting.
*/
function pad(value: number): string {
@@ -19,3 +19,58 @@ export function formatDateTime(iso: string | null | undefined): string {
}
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
const UUID_RE =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/**
* Prefer a short object id (e.g. serial) from identity keys like
* `identity:v1:{"serial":"DEMO-1"}`. Falls back to the raw key when unknown.
*/
export function formatIdentityLabel(identityKey: string | null | undefined): string {
if (!identityKey) {
return "";
}
const raw = identityKey.trim();
if (!raw) {
return "";
}
const jsonStart = raw.indexOf("{");
if (jsonStart >= 0) {
try {
const parsed = JSON.parse(raw.slice(jsonStart)) as unknown;
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
const record = parsed as Record<string, unknown>;
for (const key of ["serial", "id", "code", "name"]) {
const value = record[key];
if (typeof value === "string" && value.trim()) {
return value.trim();
}
}
for (const value of Object.values(record)) {
if (typeof value === "string" && value.trim()) {
return value.trim();
}
}
}
} catch {
// keep raw
}
}
return raw;
}
/** Short label for handler subjects; full value stays available via title. */
export function formatHandlerLabel(subject: string | null | undefined): string | null {
if (subject === null || subject === undefined) {
return null;
}
const value = subject.trim();
if (!value) {
return null;
}
if (UUID_RE.test(value)) {
return `${value.slice(0, 8)}…`;
}
return value;
}
@@ -249,7 +249,7 @@ onMounted(load);
<ElOption :label="t('datasource.status.disabled')" value="disabled" />
</ElSelect>
</div>
<ElButton type="primary" data-testid="datasource-filter-search" @click="applyFilters">
<ElButton data-testid="datasource-filter-search" @click="applyFilters">
{{ t("datasource.list.filterSearch") }}
</ElButton>
<ElButton data-testid="datasource-filter-reset" @click="resetFilters">
@@ -110,7 +110,7 @@ onMounted(() => {
<div class="w-[12rem]">
<ElInput v-model="query" clearable placeholder="查询" />
</div>
<ElButton type="primary" @click="applyFilters">查询</ElButton>
<ElButton @click="applyFilters">查询</ElButton>
<ElButton @click="resetFilters">重置</ElButton>
<div class="ml-auto">
<ElButton type="primary" @click="openCreate">新建</ElButton>
+18 -4
View File
@@ -62,9 +62,23 @@ const switchError = ref("");
async function loadOptions(): Promise<void> {
try {
// Option lists need a wide page; not the table page size.
const sources = await listDatasources({ page: 1, page_size: 100, sort_by: "name", sort_order: "asc" });
datasources.value = sources.items;
// Name map + filter options: page through the datasource API (max 100/page).
const all: Datasource[] = [];
let pageNo = 1;
for (;;) {
const sources = await listDatasources({
page: pageNo,
page_size: 100,
sort_by: "name",
sort_order: "asc",
});
all.push(...sources.items);
if (all.length >= sources.total || sources.items.length === 0 || pageNo > 50) {
break;
}
pageNo += 1;
}
datasources.value = all;
} catch {
datasources.value = [];
}
@@ -235,7 +249,7 @@ onMounted(async () => {
<ElOption :label="t('query.status.disabled')" value="disabled" />
</ElSelect>
</div>
<ElButton type="primary" data-testid="query-filter-search" @click="applyFilters">
<ElButton data-testid="query-filter-search" @click="applyFilters">
{{ t("query.list.filterSearch") }}
</ElButton>
<ElButton data-testid="query-filter-reset" @click="resetFilters">
@@ -54,3 +54,23 @@ html.dark {
flex: none;
vertical-align: middle;
}
/*
* Keyboard focus: EP default inset can be a 1px hue-only change.
* Add a visible outer ring (color + shape) without fighting page styles.
*/
.el-input__wrapper.is-focus,
.el-textarea__inner:focus,
.el-select__wrapper.is-focused,
.el-date-editor.el-input__wrapper.is-focus {
box-shadow:
0 0 0 1px var(--el-color-primary) inset,
0 0 0 3px color-mix(in srgb, var(--el-color-primary) 28%, transparent) !important;
}
.el-button:focus-visible,
.el-pager li:focus-visible,
.el-pagination button:focus-visible {
outline: 2px solid var(--el-color-primary);
outline-offset: 2px;
}