-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: TASK-#15126 Airtable queries able to show the total count of rec… #34467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release
Are you sure you want to change the base?
Changes from 1 commit
1389812
74b7b08
d49ebe5
c2b4caf
28468bb
97784ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]; | |
| } | |
| } | |
| function parseResponseData(responseBody) { | |
| if (typeof responseBody === 'string') { | |
| try { | |
| return JSON.parse(responseBody); | |
| } catch (e) { | |
| return [{ response: responseBody }]; | |
| } | |
| } else if (responseBody && typeof responseBody === 'object') { | |
| if (Array.isArray(responseBody)) { | |
| return responseBody; | |
| } else if ('records' in responseBody && Array.isArray(responseBody.records)) { | |
| return responseBody.records; | |
| } | |
| return [responseBody]; | |
| } | |
| return []; | |
| } | |
| // Usage | |
| output = parseResponseData(actionResponse.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Naveen-Goud Thank you for changes.
Please update the code as per coderabbit suggestion and do comment if the suggestion is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor JSON parsing logic for clarity and error handling.
The current approach to parsing the JSON response and handling different data structures is a bit convoluted. It's great to see the handling of different formats, but this can be made cleaner and more robust.
outputbased on whether it's an array or contains arecordsarray is repeated for both parsed JSON objects and other object types.Consider refactoring this to reduce duplication and improve error visibility.
function parseResponseData(responseBody) { try { const parsed = JSON.parse(responseBody); if (Array.isArray(parsed)) { return parsed; } else if (parsed.records && Array.isArray(parsed.records)) { return parsed.records; } return [parsed]; } catch (e) { console.error("Error parsing response:", e); return [{ response: responseBody }]; } } // Usage output = parseResponseData(actionResponse.body);Committable suggestion