feat(platform): copy vehicle filter links

This commit is contained in:
lingniu
2026-07-04 05:03:21 +08:00
parent 4d9422a434
commit 9e35c470a9
2 changed files with 74 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import { IconCopy } from '@douyinfe/semi-icons';
import { Button, Card, Form, Select, Space, Table, Tag, Toast } from '@douyinfe/semi-ui';
import { useEffect, useMemo, useState } from 'react';
import { api } from '../api/client';
@@ -32,6 +33,15 @@ function sourceEvidenceText(row: VehicleCoverageRow) {
return `${row.onlineSourceCount}/${row.sourceCount} 来源在线`;
}
async function copyVehicleShareURL() {
try {
await navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}${window.location.hash}`);
Toast.success('已复制筛选链接');
} catch {
Toast.error('复制筛选链接失败');
}
}
export function Vehicles({
onOpenVehicle,
onFiltersChange,
@@ -158,6 +168,7 @@ export function Vehicles({
</Form.Select>
<Space>
<Button htmlType="submit" theme="solid" type="primary"></Button>
<Button icon={<IconCopy />} onClick={copyVehicleShareURL}></Button>
<Button onClick={() => {
applyFilters({});
}}></Button>

View File

@@ -337,6 +337,69 @@ test('filters vehicle list from result summary actions', async () => {
expect(window.location.hash).toBe('#/vehicles?online=online');
});
test('copies shareable vehicle service filter link', async () => {
window.history.replaceState(null, '', '/#/vehicles?keyword=%E7%B2%A4A&coverage=multi&serviceStatus=degraded');
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, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 12,
unboundVehicles: 9
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 181, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /复制筛选链接/ }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/vehicles?keyword=%E7%B2%A4A&coverage=multi&serviceStatus=degraded'));
});
test('shows resolved vehicle service status after topbar search', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {