From 3f363bf1f6bfe32a7fb1e0962570126ab21a747d Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Wed, 12 Jun 2024 23:51:38 -0300 Subject: [PATCH] refactor: Handle array log results in switchOutputView component Update the switchOutputView component to handle array log results. If the log results are an array, an error message is logged and the component returns early. This change ensures proper handling of different types of log results and improves the reliability of the component. --- .../outputModal/components/switchOutputView/index.tsx | 7 +++++-- src/frontend/src/types/api/index.ts | 7 ++++++- src/frontend/src/utils/buildUtils.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index c5585d116..48352f7a9 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -25,8 +25,11 @@ const SwitchOutputView: React.FC = ({ const flowPoolNode = (flowPool[nodeId] ?? [])[ (flowPool[nodeId]?.length ?? 1) - 1 ]; - - const results = flowPoolNode?.data?.logs[outputName] ?? ""; + let results = flowPoolNode?.data?.logs[outputName] ?? ""; + if (Array.isArray(results)) { + console.error("Log results are an array", results); + return; + } const resultType = results?.type; let resultMessage = results?.message; const RECORD_TYPES = ["data", "object", "array", "message"]; diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index 273455bfd..49d94a350 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -179,11 +179,16 @@ export type VertexBuildTypeAPI = { messages: ChatOutputType[] | ChatInputType[]; }; +export type LogType = { + message: any; + type: string; +}; + // data is the object received by the API // it has results, artifacts, timedelta, duration export type VertexDataTypeAPI = { results: { [key: string]: string }; - logs: { message: any; type: string }[]; + logs: { [key: string]: LogType | LogType[] }; messages: ChatOutputType[] | ChatInputType[]; inactive?: boolean; timedelta?: number; diff --git a/src/frontend/src/utils/buildUtils.ts b/src/frontend/src/utils/buildUtils.ts index 8f008e149..f12d582a7 100644 --- a/src/frontend/src/utils/buildUtils.ts +++ b/src/frontend/src/utils/buildUtils.ts @@ -266,9 +266,18 @@ async function buildVertex({ const buildData: VertexBuildTypeAPI = buildRes.data; if (onBuildUpdate) { if (!buildData.valid) { + // lots is a dictionary with the key the output field name and the value the log object + // logs: { [key: string]: { message: any; type: string }[] }; + const errorMessages = Object.keys(buildData.data.logs).map((key) => { + const logs = buildData.data.logs[key]; + if (Array.isArray(logs)) { + return logs.map((log) => log.message); + } + return [logs.message]; + }); onBuildError!( "Error Building Component", - buildData.data.logs.map((log) => log.message), + errorMessages, verticesIds.map((id) => ({ id })) ); stopBuild();