Skip to content

Commit 14446a3

Browse files
committed
fix: review fixes
1 parent 54770e0 commit 14446a3

File tree

1 file changed

+44
-13
lines changed
  • src/containers/Tenant/Diagnostics/Network/Nodes

1 file changed

+44
-13
lines changed

src/containers/Tenant/Diagnostics/Network/Nodes/Nodes.tsx

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ interface RackColumnProps {
110110
onClickNode: (node: TNetNodeInfo | undefined) => void;
111111
onShowNodeTooltip: (anchor: HTMLDivElement, data: NodeTooltipData) => void;
112112
onHideNodeTooltip: () => void;
113-
onNodeRendered: () => void;
114113
}
115114

116115
function RackColumn({
@@ -124,7 +123,6 @@ function RackColumn({
124123
onClickNode,
125124
onShowNodeTooltip,
126125
onHideNodeTooltip,
127-
onNodeRendered,
128126
}: RackColumnProps) {
129127
return (
130128
<div key={rackIndex} className={b('rack-column')}>
@@ -133,7 +131,6 @@ function RackColumn({
133131
const {capacity, connected} = getNodeCapacityAndConnected(nodeInfo, isRight, true);
134132

135133
if (shouldShowNode(withProblems, isRight, capacity, connected)) {
136-
onNodeRendered();
137134
return (
138135
<NodeItem
139136
key={index}
@@ -165,7 +162,6 @@ interface FlatNodesListProps {
165162
onClickNode: (node: TNetNodeInfo | undefined) => void;
166163
onShowNodeTooltip: (anchor: HTMLDivElement, data: NodeTooltipData) => void;
167164
onHideNodeTooltip: () => void;
168-
onNodeRendered: () => void;
169165
}
170166

171167
function FlatNodesList({
@@ -177,7 +173,6 @@ function FlatNodesList({
177173
onClickNode,
178174
onShowNodeTooltip,
179175
onHideNodeTooltip,
180-
onNodeRendered,
181176
}: FlatNodesListProps) {
182177
return (
183178
<React.Fragment>
@@ -186,7 +181,6 @@ function FlatNodesList({
186181
const {capacity, connected} = getNodeCapacityAndConnected(nodeInfo, isRight, false);
187182

188183
if (shouldShowNode(withProblems, isRight, capacity, connected)) {
189-
onNodeRendered();
190184
return (
191185
<NodeItem
192186
key={index}
@@ -209,6 +203,45 @@ function FlatNodesList({
209203
);
210204
}
211205

206+
function countDisplayedNodes(
207+
nodes: NodesProps['nodes'],
208+
withProblems: boolean,
209+
isRight?: boolean,
210+
showRacks?: boolean,
211+
) {
212+
let count = 0;
213+
214+
Object.keys(nodes).forEach((nodeTypeKey) => {
215+
if (showRacks) {
216+
const nodesGroupedByRack = groupNodesByField(nodes[nodeTypeKey], 'Rack');
217+
218+
Object.keys(nodesGroupedByRack).forEach((rackKey) => {
219+
nodesGroupedByRack[rackKey].forEach((nodeInfo) => {
220+
const {capacity, connected} = getNodeCapacityAndConnected(
221+
nodeInfo,
222+
isRight,
223+
true,
224+
);
225+
226+
if (shouldShowNode(withProblems, isRight, capacity, connected)) {
227+
count++;
228+
}
229+
});
230+
});
231+
} else {
232+
nodes[nodeTypeKey].forEach((nodeInfo) => {
233+
const {capacity, connected} = getNodeCapacityAndConnected(nodeInfo, isRight, false);
234+
235+
if (shouldShowNode(withProblems, isRight, capacity, connected)) {
236+
count++;
237+
}
238+
});
239+
}
240+
});
241+
242+
return count;
243+
}
244+
212245
export function Nodes({
213246
nodes,
214247
isRight,
@@ -221,10 +254,10 @@ export function Nodes({
221254
}: NodesProps) {
222255
const {withProblems} = useWithProblemsQueryParam();
223256

224-
let problemNodesCount = 0;
225-
const incrementCount = () => {
226-
problemNodesCount++;
227-
};
257+
const displayedNodesCount = React.useMemo(
258+
() => countDisplayedNodes(nodes, withProblems, isRight, showRacks),
259+
[nodes, withProblems, isRight, showRacks],
260+
);
228261

229262
const result = Object.keys(nodes).map((nodeTypeKey, j) => {
230263
const nodesGroupedByRack = groupNodesByField(nodes[nodeTypeKey], 'Rack');
@@ -246,7 +279,6 @@ export function Nodes({
246279
onClickNode={onClickNode}
247280
onShowNodeTooltip={onShowNodeTooltip}
248281
onHideNodeTooltip={onHideNodeTooltip}
249-
onNodeRendered={incrementCount}
250282
/>
251283
))
252284
) : (
@@ -259,15 +291,14 @@ export function Nodes({
259291
onClickNode={onClickNode}
260292
onShowNodeTooltip={onShowNodeTooltip}
261293
onHideNodeTooltip={onHideNodeTooltip}
262-
onNodeRendered={incrementCount}
263294
/>
264295
)}
265296
</div>
266297
</div>
267298
);
268299
});
269300

270-
if (withProblems && problemNodesCount === 0) {
301+
if (withProblems && displayedNodesCount === 0) {
271302
return <Illustration name="thumbsUp" width={200} />;
272303
}
273304

0 commit comments

Comments
 (0)