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: Issue with Api Body content type selection #38597

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Jan 13, 2025

Description

Simplifies the API body content type selection

Earlier it used to maintain a different state maintain the current body type,
now we are using the data field of the API Action object itself to control the selection of body type

There two sync behaviors associated with this field that has been updated:

  • The body content type updates to JSON when the request type is POST or PUT
  • The headers get an autogenerated content type when the body select is updated to a particular type

Removes Focus retention for body content type as it was no longer needed

Fixes #38066

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/12745533006
Commit: 2a3a7e3
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Mon, 13 Jan 2025 11:33:31 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Refactor

    • Simplified state management for plugin action editor.
    • Removed deprecated form data handling methods.
    • Updated content type and form data management approach.
  • Chores

    • Removed unused action types and selectors.
    • Cleaned up focus element configurations.
  • New Features

    • Added optional testId prop to dropdown and select components for improved testing.

@hetunandu hetunandu requested a review from ayushpahwa as a code owner January 13, 2025 07:09
Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Walkthrough

This pull request involves significant refactoring of the plugin action editor's state management and form handling. The changes primarily focus on removing Redux-related form data management functions, eliminating specific action types, and simplifying the component's approach to handling post body formats. The modifications streamline the state management by removing explicit dispatching and selector functions, moving towards a more form-state-driven approach.

Changes

File Change Summary
app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx Replaced useDispatch with form value retrieval, switched from direct dispatch to form state-driven approach
app/client/src/PluginActionEditor/store/pluginActionEditorActions.ts Removed updatePostBodyContentType and setExtraFormData action creators
app/client/src/PluginActionEditor/store/pluginActionEditorSelectors.ts Deleted getFormData, getPostBodyFormat, and related constants
app/client/src/PluginActionEditor/store/pluginEditorReducer.ts Removed formData property and related action handler
app/client/src/ce/constants/ReduxActionConstants.tsx Eliminated SET_EXTRA_FORMDATA and UPDATE_API_ACTION_BODY_CONTENT_TYPE action types
app/client/src/ce/navigation/FocusElements/AppIDE.ts Removed imports and focus element configuration related to form data
app/client/src/navigation/FocusElements.ts Removed PluginActionFormData from FocusElement enum
app/client/src/sagas/ApiPaneSagas.ts Updated functions to simplify handling of API content types and removed unnecessary saga
app/client/src/components/editorComponents/form/fields/DropdownFieldWrapper.tsx Changed key prop for Option component from option.id to option.value
app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx Added optional testId property and modified rendering logic for options
app/client/src/components/editorComponents/form/fields/SelectField.tsx Added optional testId property to SelectFieldProps interface

Assessment against linked issues

Objective Addressed Explanation
Ensure API body configuration retains selected type when navigating away (#38066) The changes do not directly address the bug related to API body configuration reverting to none.

Possibly related PRs

  • fix: Paddings and scrolls in Plugin Action Editor #37203: Changes in the PostBodyData component are related to the main PR as both involve modifications to the same component, specifically addressing how the component handles padding and layout.
  • fix: external saas redirection when api created and navigated #38518: The inclusion of the PluginType.EXTERNAL_SAAS in the usePluginActionResponseTabs function in this PR aligns with the changes in the main PR that involve handling different plugin types, including external SaaS, in the context of API creation and navigation.
  • fix: Show bindings hiding behind scroll #38553: The changes in the main PR that involve rendering logic based on the isPreviewMode state are related to the modifications in this PR, which also focuses on the visibility of bindings and the rendering of the property pane based on the application's state.

Suggested labels

Task

Suggested reviewers

  • ankitakinger
  • ayushpahwa

Poem

Code flows like water, Redux state fades away
Selectors vanish, form values now hold sway
Refactoring dance, complexity takes flight
Simplicity whispers, making logic light and bright 🌟
A cleaner path emerges, elegant and clean

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@hetunandu hetunandu requested review from ankitakinger and removed request for ayushpahwa January 13, 2025 07:09
@github-actions github-actions bot added Bug Something isn't working IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Integrations Product Issues related to a specific integration Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Query & JS Pod Issues related to the query & JS Pod Query Forms Isuses related to the query forms REST API plugin REST API plugin related issues labels Jan 13, 2025
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: 1

🧹 Nitpick comments (3)
app/client/src/sagas/ApiPaneSagas.ts (2)

131-135: Verify error handling for unsupported content types

The error logging for unsupported content types could be enhanced to provide more context for debugging.

Consider this improvement:

-    log.error("Display format not supported", contentType);
+    log.error(`Content type "${contentType}" is not supported. Expected one of: ${POST_BODY_FORMAT_OPTIONS_ARRAY.join(", ")}`);

Also applies to: 139-139


267-286: Simplify content type validation logic

The nested if conditions for content type validation could be simplified.

Consider this more concise approach:

-  if (apiContentType) {
-    if (Object.values(POST_BODY_FORMAT_OPTIONS).includes(apiContentType)) {
-      displayFormat = apiContentType;
-    } else {
-      displayFormat = POST_BODY_FORMAT_OPTIONS.RAW;
-    }
-  } else {
-    displayFormat = POST_BODY_FORMAT_OPTIONS.NONE;
-  }
+  displayFormat = apiContentType
+    ? Object.values(POST_BODY_FORMAT_OPTIONS).includes(apiContentType)
+      ? apiContentType
+      : POST_BODY_FORMAT_OPTIONS.RAW
+    : POST_BODY_FORMAT_OPTIONS.NONE;
app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx (1)

Line range hint 34-38: Consider removing empty CSS rules.

The empty CSS rules can be removed to improve code cleanliness.

-  .ads-v2-select {
-    max-width: 250px;
-    width: 100%;
-  }

-  /* margin: 0 30px;
-  width: 65%; */

Also applies to: 44-44

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d52a0f2 and 225c9dc.

📒 Files selected for processing (10)
  • app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx (5 hunks)
  • app/client/src/PluginActionEditor/store/pluginActionEditorActions.ts (0 hunks)
  • app/client/src/PluginActionEditor/store/pluginActionEditorSelectors.ts (0 hunks)
  • app/client/src/PluginActionEditor/store/pluginEditorReducer.ts (0 hunks)
  • app/client/src/ce/constants/ReduxActionConstants.tsx (0 hunks)
  • app/client/src/ce/navigation/FocusElements/AppIDE.ts (1 hunks)
  • app/client/src/components/editorComponents/form/fields/DropdownFieldWrapper.tsx (1 hunks)
  • app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx (1 hunks)
  • app/client/src/navigation/FocusElements.ts (0 hunks)
  • app/client/src/sagas/ApiPaneSagas.ts (4 hunks)
💤 Files with no reviewable changes (5)
  • app/client/src/navigation/FocusElements.ts
  • app/client/src/ce/constants/ReduxActionConstants.tsx
  • app/client/src/PluginActionEditor/store/pluginActionEditorSelectors.ts
  • app/client/src/PluginActionEditor/store/pluginActionEditorActions.ts
  • app/client/src/PluginActionEditor/store/pluginEditorReducer.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
🔇 Additional comments (7)
app/client/src/sagas/ApiPaneSagas.ts (2)

55-55: LGTM: New utility imports

The addition of parseUrlForQueryParams and queryParamsRegEx utilities is appropriate for URL parsing functionality.


309-312: LGTM: Simplified content type update handling

The direct call to handleUpdateBodyContentType with the payload is a cleaner approach than passing the entire action object.

app/client/src/ce/navigation/FocusElements/AppIDE.ts (2)

84-84: LGTM: Import change aligns with the refactoring.

The import of API_EDITOR_TABS is correctly maintained as it's still used in the REST API plugin configuration.


Line range hint 1-275: Verify the impact of form data management removal.

The removal of form data related configurations suggests a significant architectural change in how plugin action form state is managed. Please ensure that:

  1. All form state is properly handled in the new implementation
  2. No regressions in the API body content type selection functionality

Run this script to verify the form state management implementation:

✅ Verification successful

Form data management migration verified successfully

The form state management has been properly migrated to dedicated components under PluginActionEditor with maintained API body content type functionality. The removal from AppIDE.ts is safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for new form state management implementation
echo "Searching for new form state management..."
rg -l "formData|setFormData|useForm" "app/client/src/PluginActionEditor"

# Check for any remaining references to old form data management
echo "Checking for remnant references..."
rg -l "getFormData|setExtraFormData|POST_BODY_FORMAT_OPTIONS" "app/client/src"

Length of output: 1937

app/client/src/components/editorComponents/form/fields/DropdownFieldWrapper.tsx (1)

43-43: LGTM! Verify dropdown behavior after key prop change.

The change from option.id to option.value for the key prop is correct, as it ensures unique keys for React's reconciliation.

Run this script to verify no duplicate values exist that could cause key conflicts:

✅ Verification successful

Change from option.id to option.value is safe due to built-in validation

The codebase enforces unique values in dropdown options through validation, making option.value a reliable choice for React's key prop.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for dropdown option definitions to verify unique values
ast-grep --pattern 'options = [
  $$$
]'

Length of output: 342


Script:

#!/bin/bash
# Search for dropdown option type definitions and usage
ast-grep --pattern 'type $_ = {
  value: $_
  $$$
}'

# Search for direct option definitions
rg -U "options.*=.*\[.*\]" -A 5

# Search specifically for DropdownFieldWrapper usage
rg -U "DropdownFieldWrapper" -A 10

Length of output: 126568

app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx (1)

93-95: LGTM! Clean implementation of conditional rendering.

The conditional rendering based on showLabelOnly prop provides better control over the dropdown display.

app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx (1)

176-182: Verify SelectField integration with form state.

The switch from Select to SelectField component changes how the form state is managed. Ensure that:

  1. Form initialization works correctly
  2. Value changes are properly propagated
  3. Default selections are handled appropriately
✅ Verification successful

SelectField integration is properly implemented

The component correctly integrates with form state through redux-form, handles value propagation, and manages default selections appropriately. No issues found with the form state management implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SelectField usage patterns and initialization
ast-grep --pattern 'SelectField
  name="actionConfiguration.formData.apiContentType"
  $$$'

Length of output: 93


Script:

#!/bin/bash
# Search for SelectField component definition and usages
echo "=== SelectField Component Definition ==="
ast-grep --pattern 'export $_ SelectField = $_'

echo -e "\n=== SelectField Usages ==="
rg -l "SelectField" --type ts --type tsx

echo -e "\n=== Form Initialization and Tests ==="
rg -l "actionConfiguration.formData.apiContentType" --type ts --type tsx

echo -e "\n=== Test Files for PostBodyData ==="
fd "PostBodyData.test" -e tsx -e ts

Length of output: 77308


Script:

#!/bin/bash
# Search for SelectField component and form state management
echo "=== SelectField Component Usage ==="
rg -t typescript -t javascriptreact -t typescriptreact "SelectField.*name=\"actionConfiguration.formData.apiContentType\"" -A 2 -B 2

echo -e "\n=== Form Initialization ==="
rg -t typescript -t javascriptreact -t typescriptreact "formData.apiContentType" -A 2 -B 2

echo -e "\n=== Test Coverage ==="
rg -t typescript -t javascriptreact -t typescriptreact "test.*SelectField.*apiContentType" -A 2 -B 2

echo -e "\n=== Related Files ==="
fd "PostBodyData" -e tsx -e ts

Length of output: 936


Script:

#!/bin/bash
echo "=== PostBodyData.tsx Content ==="
cat "app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx"

echo -e "\n=== Looking for Form Context ==="
rg --type-add 'ts:*.{ts,tsx}' -t ts "FormProvider|useFormContext|initialValues.*apiContentType" -A 2 -B 2

Length of output: 25555

Comment on lines +75 to +80
const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action;
const postBodyFormat = get(
formValues,
"actionConfiguration.formData.apiContentType",
POST_BODY_FORMAT_OPTIONS.NONE,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for form values retrieval.

The form values retrieval could return undefined. Consider adding a null check or providing a fallback.

-  const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action;
+  const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action || {};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action;
const postBodyFormat = get(
formValues,
"actionConfiguration.formData.apiContentType",
POST_BODY_FORMAT_OPTIONS.NONE,
);
const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action || {};
const postBodyFormat = get(
formValues,
"actionConfiguration.formData.apiContentType",
POST_BODY_FORMAT_OPTIONS.NONE,
);

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

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

@hetunandu hetunandu added the ok-to-test Required label for CI label Jan 13, 2025
Copy link

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

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 (1)
app/client/src/components/editorComponents/form/fields/SelectField.tsx (1)

Line range hint 1-65: Consider adding JSDoc documentation for the testId prop.

While the implementation is correct, adding JSDoc documentation for the testId property would improve component documentation.

interface SelectFieldProps {
  // ... existing props ...
+ /** Test identifier for component testing purposes */
  testId?: string;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 225c9dc and 47b39f9.

📒 Files selected for processing (3)
  • app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx (5 hunks)
  • app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx (3 hunks)
  • app/client/src/components/editorComponents/form/fields/SelectField.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/PluginActionEditor/components/PluginActionForm/components/ApiEditor/PostBodyData.tsx
  • app/client/src/components/editorComponents/form/fields/DropdownWrapper.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (2)
app/client/src/components/editorComponents/form/fields/SelectField.tsx (2)

39-39: LGTM! Good addition of test identifier support.

The optional testId property follows TypeScript best practices and enhances component testability.


62-62: LGTM! Proper prop forwarding implementation.

The testId prop is correctly forwarded to the Field component, maintaining consistent prop handling patterns.

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 (1)
app/client/cypress/support/Pages/ApiPage.ts (1)

70-70: Good move on removing XPath, but let's make it more robust.

While replacing XPath with jQuery selector is a step in the right direction, we can further improve it:

  1. Consider using a data-* attribute for more reliable selection
  2. Use template literals for cleaner string interpolation
-    ".rc-select-item-option:contains(" + subTab + ")";
+    `[data-testid="t--api-body-type-${subTab}"]`;

Remember to add the corresponding data-testid attribute to the component.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 47b39f9 and 2a3a7e3.

📒 Files selected for processing (1)
  • app/client/cypress/support/Pages/ApiPage.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/support/Pages/ApiPage.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check

@hetunandu hetunandu merged commit a7f7d3f into release Jan 13, 2025
45 checks passed
@hetunandu hetunandu deleted the fix/api-body-type-persistence branch January 13, 2025 12:31
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 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 IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Integrations Product Issues related to a specific integration Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Query Forms Isuses related to the query forms Query & JS Pod Issues related to the query & JS Pod REST API plugin REST API plugin related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: When I leave an application, the API body configuration reverts to the none dropdown
2 participants