From 13898129b3643a1de86a731598a32ffb530ab8ff Mon Sep 17 00:00:00 2001 From: Naveen-Goud Date: Tue, 25 Jun 2024 16:05:10 +0530 Subject: [PATCH 1/5] fix: TASK-#15126 Airtable queries able to show the total count of records. --- .../Editor/QueryEditor/QueryDebuggerTabs.tsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx index 8903a0d1a91a..9e18d7c43e2b 100644 --- a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx +++ b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx @@ -152,7 +152,15 @@ function QueryDebuggerTabs({ if (isString(actionResponse.body)) { try { // Try to parse response as JSON array to be displayed in the Response tab - output = JSON.parse(actionResponse.body); + const parsedOutput = JSON.parse(actionResponse.body); + console.log("Parsed output:", parsedOutput); + if (Array.isArray(parsedOutput)) { + output = parsedOutput; + } else if (parsedOutput.records && Array.isArray(parsedOutput.records)) { + output = parsedOutput.records; + } else { + output = [parsedOutput]; + } } catch (e) { // In case the string is not a JSON, wrap it in a response object output = [ @@ -162,7 +170,15 @@ function QueryDebuggerTabs({ ]; } } else { - output = actionResponse.body as any; + if (typeof actionResponse.body === "object" && actionResponse.body !== null) { + if (Array.isArray(actionResponse.body)) { + output = actionResponse.body; + } else if ('records' in actionResponse.body && Array.isArray((actionResponse.body as any).records)) { + output = (actionResponse.body as any).records; + } else { + output = [actionResponse.body]; + } + } } } From 74b7b081adb7537bdbdb60c0ebb4c940a4fbc536 Mon Sep 17 00:00:00 2001 From: Naveen-Goud Date: Tue, 25 Jun 2024 17:03:59 +0530 Subject: [PATCH 2/5] fix: removed duplicate code --- .../src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx index 9e18d7c43e2b..c76dad93db85 100644 --- a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx +++ b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx @@ -152,15 +152,7 @@ function QueryDebuggerTabs({ if (isString(actionResponse.body)) { try { // Try to parse response as JSON array to be displayed in the Response tab - const parsedOutput = JSON.parse(actionResponse.body); - console.log("Parsed output:", parsedOutput); - if (Array.isArray(parsedOutput)) { - output = parsedOutput; - } else if (parsedOutput.records && Array.isArray(parsedOutput.records)) { - output = parsedOutput.records; - } else { - output = [parsedOutput]; - } + output = JSON.parse(actionResponse.body); } catch (e) { // In case the string is not a JSON, wrap it in a response object output = [ From d49ebe5a2cd712a9e16c950cabed6680490492a6 Mon Sep 17 00:00:00 2001 From: Naveen-Goud Date: Wed, 26 Jun 2024 10:25:02 +0530 Subject: [PATCH 3/5] fix: added a function to avoid code duplication --- .../Editor/QueryEditor/QueryDebuggerTabs.tsx | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx index c76dad93db85..3bd514601de2 100644 --- a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx +++ b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx @@ -51,6 +51,27 @@ interface QueryDebuggerTabsProps { onRunClick: () => void; showSchema?: boolean; } +const parseResponseBody = (body: any): any[] => { + let parsedOutput: any; + + if (typeof body === "string") { + try { + parsedOutput = JSON.parse(body); + } catch (e) { + return [{ response: body }]; + } + } else { + parsedOutput = body; + } + + if (Array.isArray(parsedOutput)) { + return parsedOutput; + } else if (parsedOutput.records && Array.isArray(parsedOutput.records)) { + return parsedOutput.records; + } else { + return [parsedOutput]; + } +}; function QueryDebuggerTabs({ actionName, @@ -152,7 +173,7 @@ function QueryDebuggerTabs({ if (isString(actionResponse.body)) { try { // Try to parse response as JSON array to be displayed in the Response tab - output = JSON.parse(actionResponse.body); + output = parseResponseBody(actionResponse.body); } catch (e) { // In case the string is not a JSON, wrap it in a response object output = [ @@ -162,15 +183,7 @@ function QueryDebuggerTabs({ ]; } } else { - if (typeof actionResponse.body === "object" && actionResponse.body !== null) { - if (Array.isArray(actionResponse.body)) { - output = actionResponse.body; - } else if ('records' in actionResponse.body && Array.isArray((actionResponse.body as any).records)) { - output = (actionResponse.body as any).records; - } else { - output = [actionResponse.body]; - } - } + output = parseResponseBody(actionResponse.body); } } From c2b4caf8c9c25bb1a1c94d31b17cb0d9cfb4a51b Mon Sep 17 00:00:00 2001 From: Naveen-Goud Date: Wed, 26 Jun 2024 10:39:58 +0530 Subject: [PATCH 4/5] fix: updated the function ParseResponseBody --- .../src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx index 3bd514601de2..be83d0516371 100644 --- a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx +++ b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx @@ -68,9 +68,9 @@ const parseResponseBody = (body: any): any[] => { return parsedOutput; } else if (parsedOutput.records && Array.isArray(parsedOutput.records)) { return parsedOutput.records; - } else { - return [parsedOutput]; - } + } + return [parsedOutput]; + }; function QueryDebuggerTabs({ From 28468bb51eb764b972073e4c10c4b9f18f3d394f Mon Sep 17 00:00:00 2001 From: Naveen-Goud Date: Thu, 27 Jun 2024 16:16:02 +0530 Subject: [PATCH 5/5] fix:removed else block from function --- app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx index be83d0516371..bf76f032b0d4 100644 --- a/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx +++ b/app/client/src/pages/Editor/QueryEditor/QueryDebuggerTabs.tsx @@ -66,11 +66,11 @@ const parseResponseBody = (body: any): any[] => { if (Array.isArray(parsedOutput)) { return parsedOutput; - } else if (parsedOutput.records && Array.isArray(parsedOutput.records)) { + } + if (parsedOutput.records && Array.isArray(parsedOutput.records)) { return parsedOutput.records; } return [parsedOutput]; - }; function QueryDebuggerTabs({