fix(platform): keep vehicle list source filter
This commit is contained in:
@@ -20,7 +20,9 @@ export default function App() {
|
|||||||
const [analysisVin, setAnalysisVin] = useState(initialVehicleKey);
|
const [analysisVin, setAnalysisVin] = useState(initialVehicleKey);
|
||||||
const [activeProtocol, setActiveProtocol] = useState(initialRoute.protocol ?? '');
|
const [activeProtocol, setActiveProtocol] = useState(initialRoute.protocol ?? '');
|
||||||
const [historyTab, setHistoryTab] = useState(initialRoute.filters?.tab ?? 'location');
|
const [historyTab, setHistoryTab] = useState(initialRoute.filters?.tab ?? 'location');
|
||||||
const [vehicleFilters, setVehicleFilters] = useState<Record<string, string>>(initialRoute.filters ?? {});
|
const [vehicleFilters, setVehicleFilters] = useState<Record<string, string>>(
|
||||||
|
initialRoute.page === 'vehicles' ? vehicleFiltersFromRoute(initialRoute) : {}
|
||||||
|
);
|
||||||
const [qualityFilters, setQualityFilters] = useState<Record<string, string>>(
|
const [qualityFilters, setQualityFilters] = useState<Record<string, string>>(
|
||||||
initialRoute.page === 'quality' ? qualityFiltersFromRoute(initialRoute) : {}
|
initialRoute.page === 'quality' ? qualityFiltersFromRoute(initialRoute) : {}
|
||||||
);
|
);
|
||||||
@@ -89,7 +91,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (route.page === 'vehicles') {
|
if (route.page === 'vehicles') {
|
||||||
setVehicleFilters(route.filters ?? {});
|
setVehicleFilters(vehicleFiltersFromRoute(route));
|
||||||
}
|
}
|
||||||
if (route.page === 'quality') {
|
if (route.page === 'quality') {
|
||||||
setQualityFilters(qualityFiltersFromRoute(route));
|
setQualityFilters(qualityFiltersFromRoute(route));
|
||||||
@@ -122,18 +124,27 @@ export default function App() {
|
|||||||
replaceQualityHash(qualityFilters);
|
replaceQualityHash(qualityFilters);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
replaceHash(page, undefined, undefined, page === 'vehicles' ? vehicleFilters : undefined);
|
if (page === 'vehicles') {
|
||||||
|
replaceVehicleHash(vehicleFilters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
replaceHash(page);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openVehicles = (filters: Record<string, string> = {}) => {
|
const openVehicles = (filters: Record<string, string> = {}) => {
|
||||||
setVehicleFilters(filters);
|
setVehicleFilters(filters);
|
||||||
setActivePage('vehicles');
|
setActivePage('vehicles');
|
||||||
replaceHash('vehicles', undefined, undefined, filters);
|
replaceVehicleHash(filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateVehicleFilters = (filters: Record<string, string> = {}) => {
|
const updateVehicleFilters = (filters: Record<string, string> = {}) => {
|
||||||
setVehicleFilters(filters);
|
setVehicleFilters(filters);
|
||||||
replaceHash('vehicles', undefined, undefined, filters);
|
replaceVehicleHash(filters);
|
||||||
|
};
|
||||||
|
|
||||||
|
const replaceVehicleHash = (filters: Record<string, string> = {}) => {
|
||||||
|
const { keyword, protocol, ...restFilters } = filters;
|
||||||
|
replaceHash('vehicles', keyword, protocol, restFilters);
|
||||||
};
|
};
|
||||||
|
|
||||||
const replaceQualityHash = (filters: Record<string, string> = {}) => {
|
const replaceQualityHash = (filters: Record<string, string> = {}) => {
|
||||||
@@ -247,6 +258,14 @@ function qualityFiltersFromRoute(route: ReturnType<typeof parseAppHash>): Record
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function vehicleFiltersFromRoute(route: ReturnType<typeof parseAppHash>): Record<string, string> {
|
||||||
|
return {
|
||||||
|
...(route.keyword ? { keyword: route.keyword } : {}),
|
||||||
|
...(route.protocol ? { protocol: route.protocol } : {}),
|
||||||
|
...(route.filters ?? {})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function serviceStatusFromOverview(overview: VehicleServiceOverview): VehicleServiceStatus {
|
function serviceStatusFromOverview(overview: VehicleServiceOverview): VehicleServiceStatus {
|
||||||
const sourceCount = overview.sourceCount;
|
const sourceCount = overview.sourceCount;
|
||||||
const onlineSourceCount = overview.onlineSourceCount;
|
const onlineSourceCount = overview.onlineSourceCount;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export function Vehicles({
|
|||||||
onFiltersChange,
|
onFiltersChange,
|
||||||
initialFilters = {}
|
initialFilters = {}
|
||||||
}: {
|
}: {
|
||||||
onOpenVehicle: (vin: string) => void;
|
onOpenVehicle: (vin: string, protocol?: string) => void;
|
||||||
onFiltersChange?: (filters: Record<string, string>) => void;
|
onFiltersChange?: (filters: Record<string, string>) => void;
|
||||||
initialFilters?: Record<string, string>;
|
initialFilters?: Record<string, string>;
|
||||||
}) {
|
}) {
|
||||||
@@ -158,7 +158,7 @@ export function Vehicles({
|
|||||||
{ title: '在线', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <StatusTag status={row.online ? 'ok' : 'offline'} /> },
|
{ title: '在线', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <StatusTag status={row.online ? 'ok' : 'offline'} /> },
|
||||||
{ title: '最后在线', dataIndex: 'lastSeen', width: 170 },
|
{ title: '最后在线', dataIndex: 'lastSeen', width: 170 },
|
||||||
{ title: '绑定', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <Tag color={row.bindingStatus === 'bound' ? 'green' : 'orange'}>{row.bindingStatus === 'bound' ? '已绑定' : '未绑定'}</Tag> },
|
{ title: '绑定', width: 90, render: (_: unknown, row: VehicleCoverageRow) => <Tag color={row.bindingStatus === 'bound' ? 'green' : 'orange'}>{row.bindingStatus === 'bound' ? '已绑定' : '未绑定'}</Tag> },
|
||||||
{ title: '操作', width: 110, render: (_: unknown, row: VehicleCoverageRow) => <Button onClick={() => onOpenVehicle(row.vin)}>车辆服务</Button> }
|
{ title: '操作', width: 110, render: (_: unknown, row: VehicleCoverageRow) => <Button onClick={() => onOpenVehicle(row.vin, filters.protocol)}>车辆服务</Button> }
|
||||||
],
|
],
|
||||||
[filters, onOpenVehicle]
|
[filters, onOpenVehicle]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2447,6 +2447,80 @@ test('shows vehicle service status in vehicle list', async () => {
|
|||||||
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
|
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('opens vehicle service from source-filtered vehicle list with source evidence', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/vehicles?protocol=JT808');
|
||||||
|
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
const path = String(input);
|
||||||
|
if (path.includes('/api/vehicles/coverage')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
items: [{
|
||||||
|
vin: 'VIN-LIST-JT808',
|
||||||
|
plate: '粤A列表1',
|
||||||
|
phone: '13307795425',
|
||||||
|
oem: 'G7s',
|
||||||
|
protocols: ['JT808'],
|
||||||
|
sourceCount: 1,
|
||||||
|
onlineSourceCount: 1,
|
||||||
|
online: true,
|
||||||
|
lastSeen: '2026-07-03 20:12:10',
|
||||||
|
bindingStatus: 'bound'
|
||||||
|
}],
|
||||||
|
total: 1,
|
||||||
|
limit: 20,
|
||||||
|
offset: 0
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/vehicle-service/overview')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
vin: 'VIN-LIST-JT808',
|
||||||
|
plate: '粤A列表1',
|
||||||
|
sourceCount: 1,
|
||||||
|
onlineSourceCount: 1,
|
||||||
|
coverageStatus: 'online',
|
||||||
|
primaryProtocol: 'JT808',
|
||||||
|
lastSeen: '2026-07-03 20:12:10',
|
||||||
|
historyCount: 0,
|
||||||
|
rawCount: 0,
|
||||||
|
mileageCount: 0,
|
||||||
|
qualityIssueCount: 0
|
||||||
|
},
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: path.includes('/api/ops/health')
|
||||||
|
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
|
||||||
|
: { items: [], total: 0, limit: 20, offset: 0 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
|
||||||
|
expect(await screen.findByText('VIN-LIST-JT808')).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(window.location.hash).toBe('#/detail?keyword=VIN-LIST-JT808&protocol=JT808');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('filters vehicle list by service status', async () => {
|
test('filters vehicle list by service status', async () => {
|
||||||
window.history.replaceState(null, '', '/#/vehicles');
|
window.history.replaceState(null, '', '/#/vehicles');
|
||||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user