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 860240b3a fix(cluster): keep an unmeasured TPS out of the lowest-sort 
position (#6141)
860240b3a is described below

commit 860240b3adf8db14f9f59e90dd507dd6c83bcdf8
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:50:19 2026 +0800

    fix(cluster): keep an unmeasured TPS out of the lowest-sort position (#6141)
---
 web/src/pages/studio/BrokerCluster.tsx             | 14 ++++++-
 .../pages/studio/__tests__/BrokerCluster.test.tsx  | 44 ++++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/web/src/pages/studio/BrokerCluster.tsx 
b/web/src/pages/studio/BrokerCluster.tsx
index 15c2db3d8..80f949fd6 100644
--- a/web/src/pages/studio/BrokerCluster.tsx
+++ b/web/src/pages/studio/BrokerCluster.tsx
@@ -67,6 +67,14 @@ interface BrokerRecord {
   tpsOut: number | null;
 }
 
+/**
+ * Sort key that keeps a broker whose runtime stats are unavailable (`null`, 
rendered as `-`) after
+ * every measured one in both directions: Ant Design negates the comparator 
for a descending
+ * column, so an unknown value cannot simply sort as the lowest number.
+ */
+const tpsSortValue = (value: number | null, sortOrder?: 'ascend' | 'descend' | 
null): number =>
+  value ?? (sortOrder === 'descend' ? Number.MIN_SAFE_INTEGER : 
Number.MAX_SAFE_INTEGER);
+
 interface NameServerRecord {
   key: string;
   k8sCluster: string;
@@ -401,7 +409,8 @@ const BrokerClusterPage = () => {
       render: (value: number | null) => (
         <span style={{ fontWeight: 500 }}>{value?.toLocaleString() ?? 
'-'}</span>
       ),
-      sorter: (a: BrokerRecord, b: BrokerRecord) => (a.tpsIn ?? -1) - (b.tpsIn 
?? -1),
+      sorter: (a: BrokerRecord, b: BrokerRecord, sortOrder?: 'ascend' | 
'descend' | null) =>
+        tpsSortValue(a.tpsIn, sortOrder) - tpsSortValue(b.tpsIn, sortOrder),
     },
     {
       title: t('brokerCluster.tpsOut'),
@@ -410,7 +419,8 @@ const BrokerClusterPage = () => {
       render: (value: number | null) => (
         <span style={{ fontWeight: 500 }}>{value?.toLocaleString() ?? 
'-'}</span>
       ),
-      sorter: (a: BrokerRecord, b: BrokerRecord) => (a.tpsOut ?? -1) - 
(b.tpsOut ?? -1),
+      sorter: (a: BrokerRecord, b: BrokerRecord, sortOrder?: 'ascend' | 
'descend' | null) =>
+        tpsSortValue(a.tpsOut, sortOrder) - tpsSortValue(b.tpsOut, sortOrder),
     },
   ];
 
diff --git a/web/src/pages/studio/__tests__/BrokerCluster.test.tsx 
b/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
index e03c7072b..25cc5c75f 100644
--- a/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
+++ b/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
@@ -171,6 +171,50 @@ describe('BrokerCluster Page', () => {
     expect(screen.getByText('重置')).toBeInTheDocument();
   });
 
+  it('keeps a broker without runtime stats after the measured ones when 
sorting by TPS', async () => {
+    const user = userEvent.setup({ pointerEventsCheck: 0 });
+    vi.mocked(listClusters).mockResolvedValue([
+      {
+        ...clusterFixture[0],
+        brokers: [
+          {
+            name: 'broker-unmeasured',
+            addr: '10.0.1.12:10911',
+            version: '5.3.0',
+            status: 'running',
+            diskUsage: 10,
+            tpsIn: 0,
+            tpsOut: 0,
+            runtimeStatsAvailable: false,
+          },
+          {
+            name: 'broker-measured',
+            addr: '10.0.1.13:10911',
+            version: '5.3.0',
+            status: 'running',
+            diskUsage: 20,
+            tpsIn: 900,
+            tpsOut: 5,
+          },
+        ],
+      },
+    ]);
+    renderWithProviders(<BrokerCluster />);
+
+    await screen.findByText('broker-measured');
+    // The unmeasured broker's TPS cells render the placeholder, not a zero.
+    expect(screen.getAllByText('-').length).toBeGreaterThan(0);
+
+    await user.click(screen.getByText('入站 TPS'));
+
+    const rowTexts = screen.getAllByRole('row').map((row) => row.textContent 
?? '');
+    const measuredIndex = rowTexts.findIndex((text) => 
text.includes('broker-measured'));
+    const unmeasuredIndex = rowTexts.findIndex((text) => 
text.includes('broker-unmeasured'));
+    expect(measuredIndex).toBeGreaterThanOrEqual(0);
+    // An unavailable TPS is not the lowest TPS, so the row must not lead the 
ascending order.
+    expect(unmeasuredIndex).toBeGreaterThan(measuredIndex);
+  });
+
   it('should display broker tab with data from the API', async () => {
     renderWithProviders(<BrokerCluster />);
     // Default tab is broker - data is loaded asynchronously from the service

Reply via email to