Skip to content
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

fix: API editor query parameters not auto-updating URL #40133

Open
wants to merge 9 commits into
base: release
Choose a base branch
from

Conversation

vivek-appsmith
Copy link
Contributor

@vivek-appsmith vivek-appsmith commented Apr 7, 2025

API Editor Query Parameters URL Auto-Update Fix

Issue

When adding or editing query parameters in the API editor, the URL wasn't automatically being updated to reflect these changes. This creates a disconnect between the parameters in the Params tab and the actual URL being used, as reported in issue #40045.

Fix

Implemented proper synchronization between query parameters and the URL in the API editor using a two-pronged approach:

  1. Component-level solution with React hooks:

    • Added a useSyncParamsToPath hook that handles bidirectional synchronization
    • Ensures sync happens on component mount and when values change
    • Prevents update loops by checking if changes are needed
  2. Redux saga enhancement:

    • Enhanced syncApiParamsSaga to ensure the action model is updated when params change
    • Provides a failsafe at the data layer in addition to the UI layer

These changes ensure:

  • When query parameters are modified in the Params tab, the URL now updates automatically
  • When the URL is modified with query parameters, they are correctly extracted to the Params tab
  • Synchronization happens proactively rather than just reactively

Changes

  • Added new React hook for bidirectional synchronization
  • Updated syncApiParamsSaga to handle API action data updates
  • Addressed potential edge cases like empty parameters and update loops

Test Strategy

No new test cases were added for the following reasons:

  • This fix primarily addresses UI synchronization between two components
  • The fix is easily verified through manual testing
  • The functionality is already covered by existing integration tests for the API editor
  • The changes are focused on visual state synchronization rather than core business logic
  • The bug is easily reproduced and fixed by the UI components working together correctly

Related Issue

Fixes #40045

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14332565088
Commit: 6de39d5
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Tue, 08 Apr 2025 12:29:38 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Improved synchronization between URL parameters and form inputs, ensuring real-time, consistent updates during user interactions.
    • Enhanced the API configuration interface by automatically reflecting changes to action parameters for a smoother experience.

Copy link
Contributor

coderabbitai bot commented Apr 7, 2025

Walkthrough

This pull request introduces a new custom hook, useSyncParamsToPath, that synchronizes form query parameters and the URL path bidirectionally using Redux. A helper function, areParamsEquivalent, is added for comparing parameter arrays to prevent redundant updates. The TabbedControls component is updated to use this hook. In addition, the syncApiParamsSaga generator function in the API saga is modified to dispatch an update for the action's path, ensuring that the URL reflects the latest query parameters. These changes address the URL update issue reported in the linked bug.

Changes

File(s) Change Summary
app/.../CustomActionsConfigControl/index.tsx Added the useSyncParamsToPath custom hook for synchronizing query parameters and URL path; implemented areParamsEquivalent helper; updated TabbedControls usage.
app/.../ApiPaneSagas.ts Updated syncApiParamsSaga to dispatch an action updating actionConfiguration.path with the latest combined path and query parameters.

Sequence Diagram(s)

sequenceDiagram
    participant T as TabbedControls
    participant H as useSyncParamsToPath
    participant R as Redux
    participant U as URL Manager

    T->>H: Initialize with form name & config property
    H->>R: Retrieve current form state (useSelector)
    H->>U: Extract and compare URL query parameters
    alt Parameters changed
        H->>R: Dispatch state update (useDispatch)
        H->>U: Update URL with new query parameters
    end
    H-->>T: Return synchronized state
Loading
sequenceDiagram
    participant S as syncApiParamsSaga
    participant E as API Editor Form
    participant A as Action Configuration

    S->>E: Autofill API editor with current path & parameters
    S->>A: Dispatch yield put updating combined API path
    A-->>S: Confirm updated action configuration
Loading

Assessment against linked issues

Objective Addressed Explanation
Auto-update URL on adding query params (#40045)

Poem

In lines of code a rhythm's found,
Where hooks and sagas joyfully abound,
Query params dance with URL delight,
Keeping form and path in sync so right,
A digital waltz in our code tonight!
🌟🚀

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE and removed Bug Something isn't working labels Apr 7, 2025
@vivek-appsmith vivek-appsmith changed the title fixes API editor query parameters not auto-updating URL fix: API editor query parameters not auto-updating URL Apr 7, 2025
@github-actions github-actions bot added the Bug Something isn't working label Apr 7, 2025
Copy link

github-actions bot commented Apr 7, 2025

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug40045_ApiQueryParams_spec.js

1 similar comment
Copy link

github-actions bot commented Apr 7, 2025

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/BugTests/Bug40045_ApiQueryParams_spec.js

@vivek-appsmith vivek-appsmith force-pushed the fix/40045-api-query-params-url-update branch from 4755137 to ca36a96 Compare April 7, 2025 14:33
@vivek-appsmith
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Apr 7, 2025

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14312547407.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40133.
recreate: .

Copy link

github-actions bot commented Apr 7, 2025

Deploy-Preview-URL: https://ce-40133.dp.appsmith.com

@vivek-appsmith
Copy link
Contributor Author

/ok-to-test

Copy link

github-actions bot commented Apr 8, 2025

Whoops! Looks like you're using an outdated method of running the Cypress suite.
Please check this doc to learn how to correct this!

@vivek-appsmith vivek-appsmith added the ok-to-test Required label for CI label Apr 8, 2025
Copy link

github-actions bot commented Apr 8, 2025

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/API_Pane/API_Params_URL_Sync_Spec.js

1 similar comment
Copy link

github-actions bot commented Apr 8, 2025

🔴 There's new test files in JS, please port to TS and re-trigger Cypress tests:

  1. app/client/cypress/e2e/Regression/ClientSide/API_Pane/API_Params_URL_Sync_Spec.js

@vivek-appsmith vivek-appsmith force-pushed the fix/40045-api-query-params-url-update branch from 01e66c8 to 668ece1 Compare April 8, 2025 07:02
@vivek-appsmith vivek-appsmith force-pushed the fix/40045-api-query-params-url-update branch 2 times, most recently from 401d4ac to 6de39d5 Compare April 8, 2025 11:39
@vivek-appsmith vivek-appsmith marked this pull request as ready for review April 8, 2025 12:07
@vivek-appsmith
Copy link
Contributor Author

Test cases not created, can be taken up as a different task.

Copy link
Contributor

@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 (2)
app/client/src/components/formControls/CustomActionsConfigControl/index.tsx (2)

48-75: Validate duplicate keys scenario.
The mapping approach correctly checks functional equivalence but silently merges duplicate keys. Confirm if duplicates are expected or need distinct handling.


77-222: Hook logic is solid.
The ref-based checks effectively prevent loops. Consider splitting the sync logic to smaller private functions for clarity if the logic grows.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 933e968 and 6de39d5.

📒 Files selected for processing (2)
  • app/client/src/components/formControls/CustomActionsConfigControl/index.tsx (3 hunks)
  • app/client/src/sagas/ApiPaneSagas.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/client/src/sagas/ApiPaneSagas.ts (1)
app/client/src/actions/pluginActionActions.ts (1)
  • setActionProperty (315-322)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / ci-test / ci-test (16)
  • GitHub Check: perform-test / ci-test / ci-test (15)
  • GitHub Check: perform-test / ci-test / ci-test (14)
  • GitHub Check: perform-test / ci-test / ci-test (13)
  • GitHub Check: perform-test / ci-test / ci-test (10)
  • GitHub Check: perform-test / ci-test / ci-test (5)
  • GitHub Check: perform-test / ci-test / ci-test (4)
  • GitHub Check: perform-test / ci-test / ci-test (3)
  • GitHub Check: perform-test / ci-test / ci-test (2)
  • GitHub Check: perform-test / ci-test / ci-test (1)
  • GitHub Check: perform-test / ci-test / ci-test (0)
🔇 Additional comments (3)
app/client/src/sagas/ApiPaneSagas.ts (1)

127-135: Looks good.
This additional dispatch call properly synchronizes the action's path. There are no immediate concerns.

app/client/src/components/formControls/CustomActionsConfigControl/index.tsx (2)

1-17: No issues with these imports.
They accurately bring in Redux utilities, form selectors, and helper functions needed for syncing.


225-226: Great integration of the new hook.
Calling useSyncParamsToPath in TabbedControls ensures query params stay in sync with the path.

@vivek-appsmith vivek-appsmith self-assigned this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Integrations Product Issues related to a specific integration Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Adding query params should auto update the url as in postman
2 participants