This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e0e82f121 fix(cluster): report registry data that could not be loaded 
(#6090)
e0e82f121 is described below

commit e0e82f12108c367175f4ccc46beef0f76f80b2b6
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:54:34 2026 +0800

    fix(cluster): report registry data that could not be loaded (#6090)
---
 .../pages/cluster/__tests__/ClusterPage.test.tsx   | 19 +++++++++
 web/src/pages/cluster/index.tsx                    | 47 +++++++++++++++++++---
 2 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/web/src/pages/cluster/__tests__/ClusterPage.test.tsx 
b/web/src/pages/cluster/__tests__/ClusterPage.test.tsx
index b19dd4f15..9d373b749 100644
--- a/web/src/pages/cluster/__tests__/ClusterPage.test.tsx
+++ b/web/src/pages/cluster/__tests__/ClusterPage.test.tsx
@@ -368,6 +368,25 @@ describe('Cluster page', () => {
     );
   }, 10000);
 
+  it('reports registry data that could not be loaded instead of showing empty 
tabs', async () => {
+    clusterServiceMocks.listRegistryClusters.mockRejectedValueOnce(new 
Error('offline'));
+    const user = userEvent.setup({ pointerEventsCheck: 0 });
+    renderWithProviders(<ClusterPage />);
+
+    // The registry list feeds the Broker, Proxy and NameServer registry tabs, 
so clearing it
+    // would read as "this deployment has registered nothing".
+    expect(await screen.findByText('获取数据失败')).toBeInTheDocument();
+    // The instance list stood up, so this banner can only come from the 
registry loads.
+    expect(clusterServiceMocks.listClusters).toHaveBeenCalled();
+
+    await user.click(screen.getByRole('button', { name: /重\s*试/ }));
+
+    await waitFor(() => 
expect(clusterServiceMocks.listRegistryClusters).toHaveBeenCalledTimes(2));
+    await waitFor(() => {
+      expect(screen.queryByText('获取数据失败')).not.toBeInTheDocument();
+    });
+  });
+
   it('opens proxy detail dialog from the proxy table', async () => {
     const user = userEvent.setup({ pointerEventsCheck: 0 });
     renderWithProviders(<ClusterPage />);
diff --git a/web/src/pages/cluster/index.tsx b/web/src/pages/cluster/index.tsx
index dc114b1b4..f26e5d93f 100644
--- a/web/src/pages/cluster/index.tsx
+++ b/web/src/pages/cluster/index.tsx
@@ -214,6 +214,13 @@ const ClusterPage = () => {
 
   const [registryClusters, setRegistryClusters] = useState<ClusterInfo[]>([]);
   const [registryLoading, setRegistryLoading] = useState(true);
+  // The registry lists feed the Broker, Proxy and NameServer registry tabs, 
and the certificate
+  // list feeds the registry form's K8s ID field. A failure there used to be 
cleared into an empty
+  // list, which those views render as "this deployment has registered 
nothing".
+  const [registryClustersLoadFailed, setRegistryClustersLoadFailed] = 
useState(false);
+  const [nsRegistryLoadFailed, setNsRegistryLoadFailed] = useState(false);
+  const [k8sIdOptionsLoadFailed, setK8sIdOptionsLoadFailed] = useState(false);
+  const [registryReloadNonce, setRegistryReloadNonce] = useState(0);
   const nsRegistryRequest = useRequestGeneration();
   const registryClustersRequest = useRequestGeneration();
   const k8sCertsRequest = useRequestGeneration();
@@ -231,10 +238,12 @@ const ClusterPage = () => {
       const nextClusters = await listRegistryClusters();
       if (registryClustersRequest.isCurrent(requestId)) {
         setRegistryClusters(nextClusters);
+        setRegistryClustersLoadFailed(false);
       }
     } catch {
       if (registryClustersRequest.isCurrent(requestId)) {
         setRegistryClusters([]);
+        setRegistryClustersLoadFailed(true);
       }
     } finally {
       if (registryClustersRequest.isCurrent(requestId)) {
@@ -245,21 +254,27 @@ const ClusterPage = () => {
 
   useEffect(() => {
     void Promise.resolve().then(loadRegistryClusters);
-  }, [loadRegistryClusters]);
+  }, [loadRegistryClusters, registryReloadNonce]);
 
   const loadNsRegistry = useCallback(async () => {
     const requestId = nsRegistryRequest.begin();
     try {
       const entries = await listNameserverRegistry();
-      if (nsRegistryRequest.isCurrent(requestId)) setNsRegistry(entries);
+      if (nsRegistryRequest.isCurrent(requestId)) {
+        setNsRegistry(entries);
+        setNsRegistryLoadFailed(false);
+      }
     } catch {
-      if (nsRegistryRequest.isCurrent(requestId)) setNsRegistry([]);
+      if (nsRegistryRequest.isCurrent(requestId)) {
+        setNsRegistry([]);
+        setNsRegistryLoadFailed(true);
+      }
     }
   }, [nsRegistryRequest]);
 
   useEffect(() => {
     void Promise.resolve().then(loadNsRegistry);
-  }, [loadNsRegistry]);
+  }, [loadNsRegistry, registryReloadNonce]);
 
   useEffect(() => {
     const requestId = k8sCertsRequest.begin();
@@ -267,12 +282,16 @@ const ClusterPage = () => {
       .then((certs) => {
         if (k8sCertsRequest.isCurrent(requestId)) {
           setK8sIdOptions([...new Set(certs.map((cert) => 
cert.k8sId).filter(Boolean))]);
+          setK8sIdOptionsLoadFailed(false);
         }
       })
       .catch(() => {
-        if (k8sCertsRequest.isCurrent(requestId)) setK8sIdOptions([]);
+        if (k8sCertsRequest.isCurrent(requestId)) {
+          setK8sIdOptions([]);
+          setK8sIdOptionsLoadFailed(true);
+        }
       });
-  }, [k8sCertsRequest]);
+  }, [k8sCertsRequest, registryReloadNonce]);
 
   useEffect(
     () => () => {
@@ -1949,6 +1968,9 @@ const ClusterPage = () => {
     proxies: totalProxies,
   } = countClusterComponents(clusters);
 
+  const registryDataLoadFailed =
+    registryClustersLoadFailed || nsRegistryLoadFailed || 
k8sIdOptionsLoadFailed;
+
   return (
     <div style={{ padding: 24 }}>
       <PageHeader
@@ -2018,6 +2040,19 @@ const ClusterPage = () => {
           style={{ marginBottom: 16 }}
         />
       )}
+      {registryDataLoadFailed && (
+        <Alert
+          type="warning"
+          showIcon
+          message={t('common.fetchDataFailed')}
+          action={
+            <Button size="small" onClick={() => setRegistryReloadNonce((nonce) 
=> nonce + 1)}>
+              {t('common.retry')}
+            </Button>
+          }
+          style={{ marginBottom: 16 }}
+        />
+      )}
       <style>{`
         @keyframes livePulse {
           0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(82, 196, 26, 0.4); }

Reply via email to