feat(platform): surface overview consistency
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Toast } from '@douyinfe/semi-ui';
|
||||
import { api } from './api/client';
|
||||
import type { VehicleServiceOverview, VehicleServiceStatus } from './api/types';
|
||||
import type { VehicleSourceConsistency, VehicleServiceOverview, VehicleServiceStatus } from './api/types';
|
||||
import { buildAppHash, parseAppHash } from './domain/appRoute';
|
||||
import { AppShell, type PageKey } from './layout/AppShell';
|
||||
import { Dashboard } from './pages/Dashboard';
|
||||
@@ -23,6 +23,7 @@ export default function App() {
|
||||
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
||||
const [currentVehicleStatus, setCurrentVehicleStatus] = useState<VehicleServiceStatus | undefined>();
|
||||
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
||||
const [currentVehicleConsistency, setCurrentVehicleConsistency] = useState<VehicleSourceConsistency | undefined>();
|
||||
|
||||
const loadVehicleContext = useCallback(async (keyword: string) => {
|
||||
const lookupKey = keyword.trim();
|
||||
@@ -34,6 +35,7 @@ export default function App() {
|
||||
const resolved = Boolean(overview.vin);
|
||||
setCurrentVehicleStatus(overview.serviceStatus ?? serviceStatusFromOverview(overview));
|
||||
setCurrentVehicleLabel(resolved ? [overview.plate, overview.vin || nextKey].filter(Boolean).join(' / ') : lookupKey);
|
||||
setCurrentVehicleConsistency(overview.sourceConsistency);
|
||||
return { resolved, nextKey, overview };
|
||||
}, []);
|
||||
|
||||
@@ -190,7 +192,7 @@ export default function App() {
|
||||
};
|
||||
|
||||
return (
|
||||
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} onChange={navigatePage} onVehicleSearch={openVehicle}>
|
||||
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onVehicleSearch={openVehicle}>
|
||||
{pages[activePage]}
|
||||
</AppShell>
|
||||
);
|
||||
|
||||
@@ -126,6 +126,7 @@ export interface VehicleServiceOverview {
|
||||
mileageCount: number;
|
||||
qualityIssueCount: number;
|
||||
serviceStatus?: VehicleServiceStatus;
|
||||
sourceConsistency?: VehicleSourceConsistency;
|
||||
}
|
||||
|
||||
export interface VehicleServiceSummary {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from '@douyinfe/semi-icons';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import type { VehicleServiceStatus } from '../api/types';
|
||||
import type { VehicleSourceConsistency, VehicleServiceStatus } from '../api/types';
|
||||
|
||||
export type PageKey = 'dashboard' | 'vehicles' | 'realtime' | 'detail' | 'history' | 'mileage' | 'quality';
|
||||
|
||||
@@ -37,6 +37,7 @@ export function AppShell({
|
||||
linkIssueCount,
|
||||
currentVehicleStatus,
|
||||
currentVehicleLabel,
|
||||
currentVehicleConsistency,
|
||||
onChange,
|
||||
onVehicleSearch,
|
||||
children
|
||||
@@ -45,6 +46,7 @@ export function AppShell({
|
||||
linkIssueCount: number | null;
|
||||
currentVehicleStatus?: VehicleServiceStatus;
|
||||
currentVehicleLabel?: string;
|
||||
currentVehicleConsistency?: VehicleSourceConsistency;
|
||||
onChange: (page: PageKey) => void;
|
||||
onVehicleSearch: (keyword: string) => void | Promise<void>;
|
||||
children: ReactNode;
|
||||
@@ -97,6 +99,11 @@ export function AppShell({
|
||||
当前车辆:{currentVehicleStatus.title}
|
||||
</Tag>
|
||||
) : null}
|
||||
{currentVehicleConsistency ? (
|
||||
<Tag color={currentVehicleConsistency.onlineSourceCount === currentVehicleConsistency.sourceCount ? 'green' : 'orange'}>
|
||||
一致性:{currentVehicleConsistency.onlineSourceCount}/{currentVehicleConsistency.sourceCount} 来源
|
||||
</Tag>
|
||||
) : null}
|
||||
<Tag color="blue">生产环境</Tag>
|
||||
<Tag color="grey">多源接入 / 一个车辆服务</Tag>
|
||||
<Button size="small" className={linkHealthClassName(linkIssueCount)} onClick={() => onChange('quality')}>
|
||||
|
||||
@@ -379,6 +379,14 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
||||
detail: '后端统一车辆服务状态',
|
||||
sourceCount: 2,
|
||||
onlineSourceCount: 1
|
||||
},
|
||||
sourceConsistency: {
|
||||
sourceCount: 2,
|
||||
onlineSourceCount: 1,
|
||||
locatedSourceCount: 2,
|
||||
mileageDeltaKm: 0,
|
||||
sourceTimeDeltaSeconds: 0,
|
||||
scope: 'all_sources'
|
||||
}
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
@@ -424,6 +432,7 @@ test('shows resolved vehicle service status after topbar search', async () => {
|
||||
|
||||
expect(await screen.findByText('当前车辆:后端判定部分离线')).toBeInTheDocument();
|
||||
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
|
||||
expect(screen.getByText('一致性:1/2 来源')).toBeInTheDocument();
|
||||
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
|
||||
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user