feat(platform): copy quality alert notification
This commit is contained in:
@@ -236,6 +236,20 @@ function priorityIssueRows(rows: QualityIssueRow[]): PriorityIssueRow[] {
|
|||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function priorityIssueNotificationText(row: PriorityIssueRow) {
|
||||||
|
return [
|
||||||
|
`【${row.priority} 告警通知】${qualityIssueLabel(row.issueType)}`,
|
||||||
|
`车辆:${row.vehicleLabel}`,
|
||||||
|
`数据来源:${qualityProtocolLabel(row.protocol)}`,
|
||||||
|
`问题:${qualityIssueLabel(row.issueType)}`,
|
||||||
|
`建议动作:${row.actionLabel}`,
|
||||||
|
`SLA:${row.sla}`,
|
||||||
|
`最后时间:${row.lastSeen || '-'}`,
|
||||||
|
`详情:${row.detail || '-'}`,
|
||||||
|
`证据入口:${qualityShareURL()}`
|
||||||
|
].join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
function ruleStatusColor(count: number, level: string): 'green' | 'orange' | 'red' | 'grey' {
|
function ruleStatusColor(count: number, level: string): 'green' | 'orange' | 'red' | 'grey' {
|
||||||
if (count <= 0) return 'green';
|
if (count <= 0) return 'green';
|
||||||
if (level === 'P0') return 'red';
|
if (level === 'P0') return 'red';
|
||||||
@@ -485,6 +499,7 @@ export function Quality({
|
|||||||
<Button size="small" disabled={!lookup.key || !onOpenRealtime} onClick={() => openIssueRealtime(row)}>实时定位</Button>
|
<Button size="small" disabled={!lookup.key || !onOpenRealtime} onClick={() => openIssueRealtime(row)}>实时定位</Button>
|
||||||
<Button size="small" disabled={!lookup.key || !onOpenHistory} onClick={() => openIssueHistory(row)}>轨迹证据</Button>
|
<Button size="small" disabled={!lookup.key || !onOpenHistory} onClick={() => openIssueHistory(row)}>轨迹证据</Button>
|
||||||
<Button size="small" disabled={!lookup.key || !onOpenRaw} onClick={() => openIssueRaw(row)}>RAW证据</Button>
|
<Button size="small" disabled={!lookup.key || !onOpenRaw} onClick={() => openIssueRaw(row)}>RAW证据</Button>
|
||||||
|
<Button size="small" onClick={() => copyText(priorityIssueNotificationText(row), '告警通知')}>复制通知</Button>
|
||||||
<Button size="small" disabled={!lookup.key} onClick={() => onOpenVehicle(lookup.key, row.protocol)}>进入车辆服务</Button>
|
<Button size="small" disabled={!lookup.key} onClick={() => onOpenVehicle(lookup.key, row.protocol)}>进入车辆服务</Button>
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2413,6 +2413,91 @@ test('shows actionable priority queue on quality page', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('copies notification text from quality priority queue', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/quality');
|
||||||
|
const writeText = vi.fn(() => Promise.resolve());
|
||||||
|
Object.defineProperty(navigator, 'clipboard', {
|
||||||
|
configurable: true,
|
||||||
|
value: { writeText }
|
||||||
|
});
|
||||||
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
const path = String(input);
|
||||||
|
if (path.includes('/api/ops/health')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/quality/summary')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
issueVehicleCount: 1,
|
||||||
|
issueRecordCount: 1,
|
||||||
|
errorCount: 1,
|
||||||
|
warningCount: 0,
|
||||||
|
protocols: [{ name: 'JT808', count: 1 }],
|
||||||
|
issueTypes: [{ name: 'VIN_MISSING', count: 1 }]
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/quality/issues')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
items: [{
|
||||||
|
vin: '',
|
||||||
|
plate: '粤A通知1',
|
||||||
|
phone: '13307795425',
|
||||||
|
sourceEndpoint: '115.231.168.135:43625',
|
||||||
|
protocol: 'JT808',
|
||||||
|
issueType: 'VIN_MISSING',
|
||||||
|
severity: 'error',
|
||||||
|
lastSeen: '2026-07-03 20:12:10',
|
||||||
|
detail: '手机号未映射 VIN,需要维护 binding'
|
||||||
|
}],
|
||||||
|
total: 1,
|
||||||
|
limit: 20,
|
||||||
|
offset: 0
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { items: [], total: 0, limit: 20, offset: 0 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
|
||||||
|
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
|
||||||
|
fireEvent.click(await screen.findByRole('button', { name: '复制通知' }));
|
||||||
|
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('【P0 告警通知】'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆:粤A通知1 / 13307795425'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('问题:VIN 缺失'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('SLA:2 小时修复'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('最后时间:2026-07-03 20:12:10'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('详情:手机号未映射 VIN,需要维护 binding'));
|
||||||
|
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/quality'));
|
||||||
|
});
|
||||||
|
|
||||||
test('opens realtime map context from quality priority queue', async () => {
|
test('opens realtime map context from quality priority queue', async () => {
|
||||||
window.history.replaceState(null, '', '/#/quality');
|
window.history.replaceState(null, '', '/#/quality');
|
||||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user