feat(platform-web): link summary kpis to vehicle filters
This commit is contained in:
@@ -19,6 +19,7 @@ export default function App() {
|
||||
const [activeVin, setActiveVin] = useState(initialVehicleKey);
|
||||
const [analysisVin, setAnalysisVin] = useState(initialVehicleKey);
|
||||
const [activeProtocol, setActiveProtocol] = useState(initialRoute.protocol ?? '');
|
||||
const [vehicleFilters, setVehicleFilters] = useState<Record<string, string>>(initialRoute.filters ?? {});
|
||||
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
||||
const [currentVehicleStatus, setCurrentVehicleStatus] = useState<VehicleServiceStatus | undefined>();
|
||||
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
|
||||
@@ -81,14 +82,17 @@ export default function App() {
|
||||
setAnalysisVin(route.keyword);
|
||||
}
|
||||
}
|
||||
if (route.page === 'vehicles') {
|
||||
setVehicleFilters(route.filters ?? {});
|
||||
}
|
||||
setActiveProtocol(route.protocol ?? '');
|
||||
};
|
||||
window.addEventListener('hashchange', applyHashRoute);
|
||||
return () => window.removeEventListener('hashchange', applyHashRoute);
|
||||
}, []);
|
||||
|
||||
const replaceHash = (page: PageKey, keyword?: string, protocol?: string) => {
|
||||
const nextHash = buildAppHash({ page, keyword, protocol });
|
||||
const replaceHash = (page: PageKey, keyword?: string, protocol?: string, filters?: Record<string, string>) => {
|
||||
const nextHash = buildAppHash({ page, keyword, protocol, filters });
|
||||
if (window.location.hash !== nextHash) {
|
||||
window.history.replaceState(null, '', nextHash);
|
||||
}
|
||||
@@ -104,7 +108,13 @@ export default function App() {
|
||||
replaceHash(page, analysisVin, activeProtocol);
|
||||
return;
|
||||
}
|
||||
replaceHash(page);
|
||||
replaceHash(page, undefined, undefined, page === 'vehicles' ? vehicleFilters : undefined);
|
||||
};
|
||||
|
||||
const openVehicles = (filters: Record<string, string> = {}) => {
|
||||
setVehicleFilters(filters);
|
||||
setActivePage('vehicles');
|
||||
replaceHash('vehicles', undefined, undefined, filters);
|
||||
};
|
||||
|
||||
const openVehicle = async (keyword: string, protocol?: string) => {
|
||||
@@ -165,8 +175,8 @@ export default function App() {
|
||||
};
|
||||
|
||||
const pages: Record<PageKey, JSX.Element> = {
|
||||
dashboard: <Dashboard onOpenVehicle={openVehicle} onOpenQuality={() => navigatePage('quality')} />,
|
||||
vehicles: <Vehicles onOpenVehicle={openVehicle} />,
|
||||
dashboard: <Dashboard onOpenVehicle={openVehicle} onOpenQuality={() => navigatePage('quality')} onOpenVehicles={openVehicles} />,
|
||||
vehicles: <Vehicles onOpenVehicle={openVehicle} initialFilters={vehicleFilters} />,
|
||||
realtime: <Realtime onOpenVehicle={openVehicle} />,
|
||||
detail: <VehicleDetail vin={activeVin} protocol={activeProtocol} onOpenHistory={openHistoryForVehicle} onOpenMileage={openMileageForVehicle} onQueryChange={updateVehicleDetailQuery} />,
|
||||
history: <History initialVin={analysisVin} initialProtocol={activeProtocol} onOpenVehicle={openVehicle} />,
|
||||
|
||||
Reference in New Issue
Block a user