feat(platform): show active history filters
This commit is contained in:
@@ -196,7 +196,12 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
setActiveProtocol(nextFilters.protocol ?? '');
|
setActiveProtocol(nextFilters.protocol ?? '');
|
||||||
setHistoryTab(tab);
|
setHistoryTab(tab);
|
||||||
replaceHistoryHash(nextFilters, tab);
|
const { keyword, protocol, ...restFilters } = nextFilters;
|
||||||
|
const routeFilters = { ...restFilters };
|
||||||
|
if (tab && tab !== 'location') {
|
||||||
|
routeFilters.tab = tab;
|
||||||
|
}
|
||||||
|
replaceHash('history', keyword ?? analysisVin, protocol, routeFilters);
|
||||||
};
|
};
|
||||||
|
|
||||||
const replaceHistoryHash = (filters: Record<string, string> = {}, tab = historyTab) => {
|
const replaceHistoryHash = (filters: Record<string, string> = {}, tab = historyTab) => {
|
||||||
|
|||||||
@@ -139,14 +139,18 @@ export function History({
|
|||||||
loadRawFrames(nextFilters, 1, rawPagination.pageSize);
|
loadRawFrames(nextFilters, 1, rawPagination.pageSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
const reset = () => {
|
const applyFilters = (nextFilters: HistoryFilters) => {
|
||||||
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, {});
|
|
||||||
setFilters(nextFilters);
|
setFilters(nextFilters);
|
||||||
onFiltersChange?.(nextFilters, activeTab);
|
onFiltersChange?.(nextFilters, activeTab);
|
||||||
loadLocations(nextFilters, 1, locationPagination.pageSize);
|
loadLocations(nextFilters, 1, locationPagination.pageSize);
|
||||||
loadRawFrames(nextFilters, 1, rawPagination.pageSize);
|
loadRawFrames(nextFilters, 1, rawPagination.pageSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, {});
|
||||||
|
applyFilters(nextFilters);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
const nextFilters = mergeInitialFilters(initialVin, initialProtocol, initialFilters);
|
||||||
setFilters(nextFilters);
|
setFilters(nextFilters);
|
||||||
@@ -164,6 +168,18 @@ export function History({
|
|||||||
const rawFieldCount = useMemo(() => Object.keys(selectedRaw?.parsedFields ?? {}).length, [selectedRaw]);
|
const rawFieldCount = useMemo(() => Object.keys(selectedRaw?.parsedFields ?? {}).length, [selectedRaw]);
|
||||||
const currentVehicleKeyword = filters.keyword?.trim() ?? '';
|
const currentVehicleKeyword = filters.keyword?.trim() ?? '';
|
||||||
const currentProtocol = filters.protocol?.trim() ?? '';
|
const currentProtocol = filters.protocol?.trim() ?? '';
|
||||||
|
const selectedFieldCount = splitFields(filters.fields).length;
|
||||||
|
const filterSummary = [
|
||||||
|
currentVehicleKeyword ? `车辆:${currentVehicleKeyword}` : '',
|
||||||
|
currentProtocol ? `数据来源:${currentProtocol}` : '',
|
||||||
|
filters.dateFrom?.trim() ? `开始时间:${filters.dateFrom.trim()}` : '',
|
||||||
|
filters.dateTo?.trim() ? `结束时间:${filters.dateTo.trim()}` : '',
|
||||||
|
isIncludeFieldsEnabled(filters.includeFields) ? '返回解析字段' : '',
|
||||||
|
selectedFieldCount > 0 ? `字段裁剪:${selectedFieldCount} 个` : ''
|
||||||
|
].filter(Boolean);
|
||||||
|
const clearRangeFilters = () => {
|
||||||
|
applyFilters(currentVehicleKeyword ? { keyword: currentVehicleKeyword } : {});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="vp-page">
|
<div className="vp-page">
|
||||||
@@ -207,6 +223,16 @@ export function History({
|
|||||||
</Space>
|
</Space>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>
|
||||||
|
{filterSummary.length > 0 ? (
|
||||||
|
<Card bordered title="当前历史筛选" style={{ marginTop: 16 }}>
|
||||||
|
<Space wrap>
|
||||||
|
{filterSummary.map((item) => (
|
||||||
|
<Tag key={item} color="blue">{item}</Tag>
|
||||||
|
))}
|
||||||
|
<Button size="small" onClick={clearRangeFilters}>清空筛选</Button>
|
||||||
|
</Space>
|
||||||
|
</Card>
|
||||||
|
) : null}
|
||||||
<Card bordered style={{ marginTop: 16 }}>
|
<Card bordered style={{ marginTop: 16 }}>
|
||||||
<Tabs activeKey={activeTab} onChange={(key) => changeTab(String(key))}>
|
<Tabs activeKey={activeTab} onChange={(key) => changeTab(String(key))}>
|
||||||
<Tabs.TabPane tab="位置历史" itemKey="location">
|
<Tabs.TabPane tab="位置历史" itemKey="location">
|
||||||
|
|||||||
@@ -2294,6 +2294,67 @@ test('applies protocol from shareable history hash to API requests', async () =>
|
|||||||
expect(screen.getByText('当前来源:JT808')).toBeInTheDocument();
|
expect(screen.getByText('当前来源:JT808')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('shows and clears current history filters while keeping vehicle scope', async () => {
|
||||||
|
window.history.replaceState(null, '', '/#/history?keyword=VIN-HISTORY-001&protocol=JT808&dateFrom=2026-07-01+00%3A00%3A00&dateTo=2026-07-01+23%3A59%3A59&includeFields=true&fields=jt808.location.longitude%2Cjt808.location.latitude&tab=raw');
|
||||||
|
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
|
||||||
|
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/history/locations')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { items: [], total: 0, limit: 10, offset: 0 },
|
||||||
|
traceId: 'trace-test',
|
||||||
|
timestamp: 1783094400000
|
||||||
|
})
|
||||||
|
} as Response;
|
||||||
|
}
|
||||||
|
if (path.includes('/api/history/raw-frames/query')) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: { items: [], total: 0, limit: 10, 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 />);
|
||||||
|
|
||||||
|
expect(await screen.findByText('当前历史筛选')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('车辆:VIN-HISTORY-001')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('数据来源:JT808')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('开始时间:2026-07-01 00:00:00')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('结束时间:2026-07-01 23:59:59')).toBeInTheDocument();
|
||||||
|
expect(screen.getAllByText('返回解析字段').length).toBeGreaterThanOrEqual(2);
|
||||||
|
expect(screen.getByText('字段裁剪:2 个')).toBeInTheDocument();
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/history/locations?limit=10&offset=0&keyword=VIN-HISTORY-001'), undefined);
|
||||||
|
});
|
||||||
|
expect(window.location.hash).toBe('#/history?keyword=VIN-HISTORY-001&tab=raw');
|
||||||
|
});
|
||||||
|
|
||||||
test('updates history hash when vehicle history filters are submitted', async () => {
|
test('updates history hash when vehicle history filters are submitted', async () => {
|
||||||
window.history.replaceState(null, '', '/#/history');
|
window.history.replaceState(null, '', '/#/history');
|
||||||
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
|
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user