feat(platform): surface global alert pressure

This commit is contained in:
lingniu
2026-07-04 17:37:44 +08:00
parent 2d4b397acd
commit d266396c47
4 changed files with 131 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import { Toast } from '@douyinfe/semi-ui';
import { api } from './api/client';
import type { VehicleSourceConsistency, VehicleServiceOverview, VehicleServiceStatus } from './api/types';
import type { QualityNotificationPlan, VehicleSourceConsistency, VehicleServiceOverview, VehicleServiceStatus } from './api/types';
import { buildAppHash, parseAppHash } from './domain/appRoute';
import { AppShell, type PageKey } from './layout/AppShell';
import { Dashboard } from './pages/Dashboard';
@@ -38,6 +38,8 @@ export default function App() {
initialRoute.page === 'quality' ? qualityFiltersFromRoute(initialRoute) : {}
);
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
const [activeAlertRuleCount, setActiveAlertRuleCount] = useState<number | null>(null);
const [p0AlertRuleCount, setP0AlertRuleCount] = useState<number | null>(null);
const [platformRelease, setPlatformRelease] = useState('');
const [currentVehicleStatus, setCurrentVehicleStatus] = useState<VehicleServiceStatus | undefined>();
const [currentVehicleLabel, setCurrentVehicleLabel] = useState('');
@@ -62,11 +64,29 @@ export default function App() {
return { resolved, nextKey, overview };
}, []);
const applyNotificationPlanSummary = (plan?: QualityNotificationPlan | null) => {
if (!plan) {
return;
}
const activeCount = Number(plan.activeRuleCount);
const p0Count = Number(plan.p0RuleCount);
if (Number.isFinite(activeCount)) {
setActiveAlertRuleCount(activeCount);
}
if (Number.isFinite(p0Count)) {
setP0AlertRuleCount(p0Count);
}
};
const refreshOpsHealth = useCallback((showError = true) => {
return api.opsHealth()
.then((health) => {
return Promise.all([
api.opsHealth(),
api.qualityNotificationPlan(new URLSearchParams({ limit: '5' })).catch(() => null)
])
.then(([health, notificationPlan]) => {
setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length);
setPlatformRelease(health.runtime?.platformRelease ?? '');
applyNotificationPlanSummary(notificationPlan);
return health;
})
.catch((error: Error) => {
@@ -444,13 +464,13 @@ export default function App() {
quality: <Quality onOpenVehicle={openVehicle} onOpenRealtime={openRealtime} onOpenHistory={openHistoryWithFilters} onOpenRaw={openRawWithFilters} onOpenMileage={openMileageWithFilters} onOpenNotificationRules={() => navigatePage('notification-rules')} onHealthLoaded={(health) => {
setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length);
setPlatformRelease(health.runtime?.platformRelease ?? '');
}} onFiltersChange={updateQualityFilters} initialFilters={qualityFilters} />,
}} onNotificationPlanLoaded={applyNotificationPlanSummary} onFiltersChange={updateQualityFilters} initialFilters={qualityFilters} />,
'notification-rules': <NotificationRules />,
'ops-quality': <OpsQuality />
};
return (
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} platformRelease={platformRelease} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onVehicleSearch={openVehicle}>
<AppShell activePage={activePage} linkIssueCount={linkIssueCount} activeAlertRuleCount={activeAlertRuleCount} p0AlertRuleCount={p0AlertRuleCount} platformRelease={platformRelease} currentVehicleStatus={currentVehicleStatus} currentVehicleLabel={currentVehicleLabel} currentVehicleConsistency={currentVehicleConsistency} onChange={navigatePage} onVehicleSearch={openVehicle}>
{pages[activePage]}
</AppShell>
);