Skip to content

Commit 48ab220

Browse files
CopilotRaubzeug
andcommitted
fix: conditionally show threads tab based on API response data
Co-authored-by: Raubzeug <[email protected]>
1 parent 2787b86 commit 48ab220

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/containers/Node/Node.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ export function Node() {
7575
if (isDiskPagesAvailable) {
7676
actulaNodeTabs = actulaNodeTabs.filter((el) => el.id !== 'structure');
7777
}
78+
// Filter out threads tab if there's no thread data in the API response
79+
if (!node?.Threads || node.Threads.length === 0) {
80+
actulaNodeTabs = actulaNodeTabs.filter((el) => el.id !== 'threads');
81+
}
7882

7983
const actualActiveTab =
8084
actulaNodeTabs.find(({id}) => id === activeTabId) ?? actulaNodeTabs[0];
8185

8286
return {activeTab: actualActiveTab, nodeTabs: actulaNodeTabs};
83-
}, [isStorageNode, isDiskPagesAvailable, activeTabId]);
87+
}, [isStorageNode, isDiskPagesAvailable, activeTabId, node?.Threads]);
8488

8589
const tenantName = node?.Tenants?.[0] || tenantNameFromQuery?.toString();
8690

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {NODE_TABS} from '../NodePages';
2+
3+
describe('Node tab filtering logic', () => {
4+
it('should filter out threads tab when no thread data is provided', () => {
5+
// Simulate the filtering logic that happens in the Node component
6+
const isStorageNode = false;
7+
const isDiskPagesAvailable = false;
8+
const node: {Threads?: any[]} = {
9+
// No Threads property
10+
};
11+
12+
let actualNodeTabs = isStorageNode
13+
? NODE_TABS
14+
: NODE_TABS.filter((el) => el.id !== 'storage');
15+
16+
if (isDiskPagesAvailable) {
17+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
18+
}
19+
20+
// Filter out threads tab if there's no thread data in the API response
21+
if (!node.Threads || node.Threads.length === 0) {
22+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
23+
}
24+
25+
// Should not include threads tab
26+
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false);
27+
// Should include other tabs
28+
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
29+
});
30+
31+
it('should include threads tab when thread data is provided', () => {
32+
// Simulate the filtering logic that happens in the Node component
33+
const isStorageNode = false;
34+
const isDiskPagesAvailable = false;
35+
const node: {Threads?: any[]} = {
36+
Threads: [{Name: 'TestPool', Threads: 4}],
37+
};
38+
39+
let actualNodeTabs = isStorageNode
40+
? NODE_TABS
41+
: NODE_TABS.filter((el) => el.id !== 'storage');
42+
43+
if (isDiskPagesAvailable) {
44+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
45+
}
46+
47+
// Filter out threads tab if there's no thread data in the API response
48+
if (!node.Threads || node.Threads.length === 0) {
49+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
50+
}
51+
52+
// Should include threads tab
53+
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(true);
54+
// Should include other tabs
55+
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
56+
});
57+
58+
it('should filter out threads tab when thread data is empty array', () => {
59+
// Simulate the filtering logic that happens in the Node component
60+
const isStorageNode = false;
61+
const isDiskPagesAvailable = false;
62+
const node: {Threads?: any[]} = {
63+
Threads: [], // Empty array
64+
};
65+
66+
let actualNodeTabs = isStorageNode
67+
? NODE_TABS
68+
: NODE_TABS.filter((el) => el.id !== 'storage');
69+
70+
if (isDiskPagesAvailable) {
71+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
72+
}
73+
74+
// Filter out threads tab if there's no thread data in the API response
75+
if (!node.Threads || node.Threads.length === 0) {
76+
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
77+
}
78+
79+
// Should not include threads tab
80+
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false);
81+
// Should include other tabs
82+
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
83+
});
84+
});

0 commit comments

Comments
 (0)