polish alert operations workspace

This commit is contained in:
lingniu
2026-07-18 11:24:24 +08:00
parent 622c4398ec
commit 0802b1989a
6 changed files with 86 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { alertValue, canAct, ruleCondition, thresholdText } from './alert';
import { alertValue, canAct, formatAlertTime, ruleCondition, thresholdText } from './alert';
describe('alert domain helpers', () => {
it('keeps trigger evidence and duration explicit', () => {
@@ -23,4 +23,8 @@ describe('alert domain helpers', () => {
expect(thresholdText({ threshold: 20, thresholdHigh: 80, operator: 'between', unit: '%', durationSec: 30 })).toBe('区间内 2080 %,持续 30 秒');
expect(ruleCondition({ valueType: 'boolean', metric: 'alarm_active', operator: 'changed', durationSec: 0 } as never)).toBe('协议告警位 状态变化');
});
it('renders operational timestamps in the shared Shanghai timezone', () => {
expect(formatAlertTime('2026-07-18T02:33:00Z')).toBe('07-18 10:33:00');
});
});

View File

@@ -1,7 +1,15 @@
import type { AlertEvent, AlertRule, AlertSeverity, AlertStatus } from '../../api/types';
import { formatZhNumber } from './formatters';
const alertTimeFormatter = new Intl.DateTimeFormat('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
const alertTimeFormatter = new Intl.DateTimeFormat('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
timeZone: 'Asia/Shanghai'
});
export const severityLabels: Record<AlertSeverity, string> = { critical: '紧急', major: '重要', minor: '一般' };
export const statusLabels: Record<AlertStatus, string> = { unprocessed: '未处理', processing: '处理中', recovered: '已恢复', closed: '已关闭', ignored: '已忽略' };