Skip to content

Conversation

@akanshaaa19
Copy link
Member

@akanshaaa19 akanshaaa19 commented Nov 11, 2025

Summary by CodeRabbit

  • Refactor

    • Switched to a standardized HTTP client for webhook configuration retrieval; payload extraction updated while downstream processing and displayed options remain unchanged.
    • No changes to public APIs or exported entities; no user-visible behavioral changes.
  • Tests

    • Updated tests to mock the HTTP client for deterministic webhook retrieval testing.
  • Chore

    • Bumped package version.

@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

Walkthrough

Replaces a native fetch call with axios.get and adapts response handling (response.json()response.data) in WebhookRouterForm.componentDidMount; adds an axios import and updates tests to mock axios.get. No exported/public API changes.

Changes

Cohort / File(s) Summary
HTTP client swap
src/components/flow/routers/webhook/WebhookRouterForm.tsx
Replaced fetch(endpoint) with axios.get(endpoint); replaced response.json() usage with response.data; added axios import.
Tests updated for axios
src/components/flow/routers/webhook/WebhookRouterForm.test.tsx
Added axios import, jest.mock('axios'), typed mockedAxios and a beforeEach that sets mockedAxios.get to resolve with { data: {} }.
Version bump
package.json
Incremented package version from 1.43.0-41.43.0-5.

Sequence Diagram(s)

sequenceDiagram
    participant UI as WebhookRouterForm
    participant HTTP as axios.get
    participant API as /completion-endpoint
    UI->>HTTP: axios.get(endpoint)
    HTTP->>API: GET request
    API-->>HTTP: 200 { ...payload... }
    HTTP-->>UI: { data: ...payload... }
    Note right of UI `#D6EAF8`: construct webhookOptions from response.data
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review attention:
    • Ensure axios import style and project conventions match.
    • Confirm test mock/reset patterns for axios to avoid cross-test interference.

Possibly related PRs

Suggested reviewers

  • madclaws
  • priyanshu6238

Poem

🐰 I hopped from fetch to axios with glee,

data now flows back more reliably.
Tests snugly mock the new request call,
A small clean change — I celebrate it all! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: replacing fetch with axios in WebhookRouterForm for API calls, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-for-webhook-dropdown

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acec960 and 80109c2.

📒 Files selected for processing (1)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Coverage
  • GitHub Check: Tests (16.x)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (1)

78-102: Add error handling for the API call.

Unlike fetch, axios throws on non-2xx status codes. Without error handling, failures will cause unhandled promise rejections. Consider adding a try-catch block to handle errors gracefully.

Apply this diff:

   async componentDidMount() {
-    const endpoint = this.context.config.endpoints.completion;
-    const response = await axios.get(endpoint);
-    const data = response.data;
-
-    const webhookOptions = (data.webhook || []).map((webhook: any) => ({
-      name: webhook.name,
-      value: webhook.name,
-      id: webhook.name,
-      label: webhook.name,
-      body: webhook.body
-    }));
-
-    if (this.state.method.value.value === Methods.FUNCTION && this.state.url.value) {
-      const functionName = this.state.url.value;
-      const selectedOption = webhookOptions.find((opt: any) => opt.name === functionName);
-
-      this.setState({
-        webhookOptions,
-        webhookFunction: { value: selectedOption || null }
-      });
-    } else {
-      this.setState({ webhookOptions });
-    }
+    try {
+      const endpoint = this.context.config.endpoints.completion;
+      const response = await axios.get(endpoint);
+      const data = response.data;
+
+      const webhookOptions = (data.webhook || []).map((webhook: any) => ({
+        name: webhook.name,
+        value: webhook.name,
+        id: webhook.name,
+        label: webhook.name,
+        body: webhook.body
+      }));
+
+      if (this.state.method.value.value === Methods.FUNCTION && this.state.url.value) {
+        const functionName = this.state.url.value;
+        const selectedOption = webhookOptions.find((opt: any) => opt.name === functionName);
+
+        this.setState({
+          webhookOptions,
+          webhookFunction: { value: selectedOption || null }
+        });
+      } else {
+        this.setState({ webhookOptions });
+      }
+    } catch (error) {
+      console.error('Failed to fetch webhook options:', error);
+      // Consider setting an error state or showing a user-friendly message
+    }
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0125720 and aec26b4.

📒 Files selected for processing (1)
  • src/components/flow/routers/webhook/WebhookRouterForm.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (1)
src/__mocks__/axios.ts (1)
  • axios (3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Tests (16.x)
🔇 Additional comments (1)
src/components/flow/routers/webhook/WebhookRouterForm.tsx (1)

37-37: LGTM!

The axios import is correctly added.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/flow/routers/webhook/WebhookRouterForm.test.tsx (1)

25-28: Consider adding mock cleanup for better test isolation.

The beforeEach correctly sets up the axios mock, but adding mockedAxios.get.mockClear() would prevent potential test pollution and ensure each test starts with a clean mock state.

Apply this diff:

 beforeEach(() => {
+  mockedAxios.get.mockClear();
   mockedAxios.get.mockResolvedValue({ data: {} });
 });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c894cd and acec960.

📒 Files selected for processing (1)
  • src/components/flow/routers/webhook/WebhookRouterForm.test.tsx (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/flow/routers/webhook/WebhookRouterForm.test.tsx (2)
src/test/utils.tsx (1)
  • mock (73-75)
src/__mocks__/axios.ts (1)
  • axios (3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Tests (16.x)
  • GitHub Check: Coverage
🔇 Additional comments (1)
src/components/flow/routers/webhook/WebhookRouterForm.test.tsx (1)

12-16: LGTM! Axios mock setup is correct.

The axios import, mock declaration, and typed mock instance are properly configured. The use of jest.Mocked<typeof axios> provides good type safety for the test mocks.

@akanshaaa19 akanshaaa19 merged commit 4f5aa53 into glific-master Nov 11, 2025
7 checks passed
@akanshaaa19 akanshaaa19 deleted the fix-for-webhook-dropdown branch November 11, 2025 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants