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 858e1484a fix(web): keep mock instance counts consistent with
withCounts (#7235)
858e1484a is described below
commit 858e1484a041be1eb02118d6d698c6dcbbb996bf
Author: Yexi Xiang <[email protected]>
AuthorDate: Fri Nov 27 12:10:36 2026 +0800
fix(web): keep mock instance counts consistent with withCounts (#7235)
---
web/src/services/instanceService.test.ts | 12 ++++++++++++
web/src/services/instanceService.ts | 12 +++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/web/src/services/instanceService.test.ts
b/web/src/services/instanceService.test.ts
index 00ccf0ff7..f8d6132ee 100644
--- a/web/src/services/instanceService.test.ts
+++ b/web/src/services/instanceService.test.ts
@@ -57,6 +57,18 @@ describe('instanceService mock instances', () => {
expect(fresh[0]).not.toBe(instances[0]);
});
+ it('matches the API count availability contract when counts are omitted',
async () => {
+ dataModeMock.isMockMode.mockReturnValue(true);
+
+ const instances = await listInstances({ withCounts: false });
+
+ expect(instances[0]).toMatchObject({
+ topicCount: 0,
+ consumerGroupCount: 0,
+ resourceCountsAvailable: false,
+ });
+ });
+
it('filters mock instances with the same type and search semantics as the
API', async () => {
const byType = await listInstances({ type: 'DIRECT' });
expect(byType.map((instance) => instance.id)).toEqual([1, 2]);
diff --git a/web/src/services/instanceService.ts
b/web/src/services/instanceService.ts
index a1c83b2f2..546c95f94 100644
--- a/web/src/services/instanceService.ts
+++ b/web/src/services/instanceService.ts
@@ -72,7 +72,7 @@ export function listInstances(query: InstanceQuery = {}):
Promise<Instance[]> {
async function fetchInstances(query: InstanceQuery, mockMode: boolean):
Promise<Instance[]> {
if (mockMode) {
const search = query.search?.trim().toLowerCase();
- return mockInstances
+ const matches = mockInstances
.filter((instance) => matchesType(instance, query.type))
.filter(
(instance) =>
@@ -82,6 +82,16 @@ async function fetchInstances(query: InstanceQuery,
mockMode: boolean): Promise<
),
)
.map(copyInstance);
+ return matches.map((instance) =>
+ query.withCounts
+ ? { ...instance, resourceCountsAvailable: true }
+ : {
+ ...instance,
+ topicCount: 0,
+ consumerGroupCount: 0,
+ resourceCountsAvailable: false,
+ },
+ );
}
return instanceApi.listInstances(query);
}