feat(platform): keep canonical source summary slots
This commit is contained in:
@@ -44,6 +44,13 @@ function formatCount(value?: number | null) {
|
||||
return value == null ? '0' : value.toLocaleString();
|
||||
}
|
||||
|
||||
function formatProtocolRate(row: ProtocolStat) {
|
||||
if (!Number.isFinite(row.total) || row.total <= 0) {
|
||||
return '0%';
|
||||
}
|
||||
return `${Math.round((row.online / row.total) * 100)}%`;
|
||||
}
|
||||
|
||||
function rowServiceStatus(row: { serviceStatus?: { title: string; severity: string }; onlineSourceCount: number; sourceCount: number }) {
|
||||
if (row.serviceStatus) {
|
||||
return {
|
||||
@@ -201,7 +208,7 @@ export function Dashboard({ onOpenVehicle, onOpenQuality, onOpenVehicles }: { on
|
||||
{ title: '总数', dataIndex: 'total' },
|
||||
{
|
||||
title: '在线率',
|
||||
render: (_: unknown, row: ProtocolStat) => `${Math.round((row.online / row.total) * 100)}%`
|
||||
render: (_: unknown, row: ProtocolStat) => formatProtocolRate(row)
|
||||
},
|
||||
{
|
||||
title: '缺失车辆',
|
||||
|
||||
@@ -96,7 +96,11 @@ test('dashboard renders vehicle service summary metrics', async () => {
|
||||
{ status: 'healthy', title: '服务正常', count: 161 },
|
||||
{ status: 'degraded', title: '部分来源离线', count: 41 }
|
||||
],
|
||||
protocols: [{ protocol: 'JT808', online: 157, total: 388 }]
|
||||
protocols: [
|
||||
{ protocol: 'JT808', online: 157, total: 388 },
|
||||
{ protocol: 'YUTONG_MQTT', online: 0, total: 0 }
|
||||
],
|
||||
missingSources: [{ protocol: 'YUTONG_MQTT', count: 1033 }]
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
@@ -116,7 +120,7 @@ test('dashboard renders vehicle service summary metrics', async () => {
|
||||
render(<App />);
|
||||
|
||||
expect(await screen.findByText('总车辆')).toBeInTheDocument();
|
||||
expect(screen.getByText('1,033')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('1,033').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText('单源车辆')).toBeInTheDocument();
|
||||
expect(screen.getByText('391')).toBeInTheDocument();
|
||||
expect(screen.getByText('多源车辆')).toBeInTheDocument();
|
||||
@@ -125,6 +129,9 @@ test('dashboard renders vehicle service summary metrics', async () => {
|
||||
expect(screen.getByText('461')).toBeInTheDocument();
|
||||
expect(screen.getByText('身份未绑定')).toBeInTheDocument();
|
||||
expect(screen.getByText('来源证据在线分布')).toBeInTheDocument();
|
||||
expect(screen.getByText('YUTONG_MQTT')).toBeInTheDocument();
|
||||
expect(screen.getByText('0%')).toBeInTheDocument();
|
||||
expect(screen.queryByText('NaN%')).not.toBeInTheDocument();
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/summary', undefined);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user