feat(platform): refresh topbar link issues from quality
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { Toast } from '@douyinfe/semi-ui';
|
import { Toast } from '@douyinfe/semi-ui';
|
||||||
import { api } from './api/client';
|
import { api } from './api/client';
|
||||||
import { AppShell, type PageKey } from './layout/AppShell';
|
import { AppShell, type PageKey } from './layout/AppShell';
|
||||||
@@ -15,14 +15,19 @@ export default function App() {
|
|||||||
const [activeVin, setActiveVin] = useState('LB9A32A24R0LS1426');
|
const [activeVin, setActiveVin] = useState('LB9A32A24R0LS1426');
|
||||||
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
const [linkIssueCount, setLinkIssueCount] = useState<number | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
const refreshOpsHealth = useCallback(() => {
|
||||||
api.opsHealth()
|
return api.opsHealth()
|
||||||
.then((health) => {
|
.then((health) => {
|
||||||
setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length);
|
setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length);
|
||||||
|
return health;
|
||||||
})
|
})
|
||||||
.catch((error: Error) => Toast.error(error.message));
|
.catch((error: Error) => Toast.error(error.message));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refreshOpsHealth();
|
||||||
|
}, [refreshOpsHealth]);
|
||||||
|
|
||||||
const openVehicle = (vin: string) => {
|
const openVehicle = (vin: string) => {
|
||||||
const nextVin = vin.trim();
|
const nextVin = vin.trim();
|
||||||
if (!nextVin) {
|
if (!nextVin) {
|
||||||
@@ -39,7 +44,7 @@ export default function App() {
|
|||||||
detail: <VehicleDetail vin={activeVin} />,
|
detail: <VehicleDetail vin={activeVin} />,
|
||||||
history: <History />,
|
history: <History />,
|
||||||
mileage: <Mileage />,
|
mileage: <Mileage />,
|
||||||
quality: <Quality />
|
quality: <Quality onHealthLoaded={(health) => setLinkIssueCount(health.linkHealth.filter((item) => item.status !== 'ok').length)} />
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function storageReadStatus(health: OpsHealth | null) {
|
|||||||
return health?.tdengineWritable && health.mysqlWritable ? 'ok' : 'error';
|
return health?.tdengineWritable && health.mysqlWritable ? 'ok' : 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Quality() {
|
export function Quality({ onHealthLoaded }: { onHealthLoaded?: (health: OpsHealth) => void }) {
|
||||||
const [issues, setIssues] = useState<QualityIssueRow[]>([]);
|
const [issues, setIssues] = useState<QualityIssueRow[]>([]);
|
||||||
const [health, setHealth] = useState<OpsHealth | null>(null);
|
const [health, setHealth] = useState<OpsHealth | null>(null);
|
||||||
const [loadingIssues, setLoadingIssues] = useState(true);
|
const [loadingIssues, setLoadingIssues] = useState(true);
|
||||||
@@ -42,7 +42,10 @@ export function Quality() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadIssues({}, 1, pagination.pageSize);
|
loadIssues({}, 1, pagination.pageSize);
|
||||||
api.opsHealth()
|
api.opsHealth()
|
||||||
.then(setHealth)
|
.then((nextHealth) => {
|
||||||
|
setHealth(nextHealth);
|
||||||
|
onHealthLoaded?.(nextHealth);
|
||||||
|
})
|
||||||
.catch((error: Error) => Toast.error(error.message));
|
.catch((error: Error) => Toast.error(error.message));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user