Copilot commented on code in PR #485: URL: https://github.com/apache/skywalking-booster-ui/pull/485#discussion_r2242338828
########## src/hooks/useExpressionsProcessor.ts: ########## @@ -26,10 +32,17 @@ import type { Instance, Endpoint, Service } from "@/types/selector"; import type { Node, Call } from "@/types/topology"; function chunkArray(array: any[], chunkSize: number) { + if (chunkSize === 0) { + return [array]; Review Comment: The check for chunkSize === 0 will cause an infinite loop in the for loop below since i += chunkSize would never increment i. Consider returning an empty array or throwing an error instead. ```suggestion if (chunkSize <= 0) { throw new Error("chunkSize must be greater than 0"); ``` ########## src/store/modules/topology.ts: ########## @@ -223,14 +223,14 @@ export const topologyStore = defineStore({ setNodeMetricValue(m: MetricVal) { this.nodeMetricValue = m; }, - setLegendValues(expressions: string, data: { [key: string]: any }) { + async setLegendValues(expression: string, data: Indexable) { Review Comment: The method is marked as async but doesn't contain any await statements or return a Promise. Remove the async keyword since this is a synchronous operation. ```suggestion setLegendValues(expression: string, data: Indexable) { ``` ########## src/store/modules/topology.ts: ########## @@ -223,14 +223,14 @@ export const topologyStore = defineStore({ setNodeMetricValue(m: MetricVal) { this.nodeMetricValue = m; }, - setLegendValues(expressions: string, data: { [key: string]: any }) { + async setLegendValues(expression: string, data: Indexable) { const nodeArr = this.nodes.filter((d: Node) => d.isReal); + for (let idx = 0; idx < nodeArr.length; idx++) { - for (let index = 0; index < expressions.length; index++) { - const k = "expression" + idx + index; - if (expressions[index]) { - nodeArr[idx][expressions[index]] = Number(data[k].results[0].values[0].value); - } + if (expression) { + nodeArr[idx][expression] = Number( + data[expression].values.find((d: { id: string; value: string }) => d.id === nodeArr[idx].id)?.value, Review Comment: Missing null safety check for data[expression]. If data[expression] is undefined, this will throw an error. Add optional chaining: data[expression]?.values?.find(...) ```suggestion data[expression]?.values?.find((d: { id: string; value: string }) => d.id === nodeArr[idx].id)?.value, ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@skywalking.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org