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: Plugin Action Editor navigation issue with git #37670

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Nov 25, 2024

Description

Fixes the passing of wrong id when trying to trigger a changeQuery request. The scenario fixed was passing an actionId instead of a baseActionId.

Later on, a selector is not able to find the action as it expects a baseActionId and causes a navigation bug.

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12005014920
Commit: d6786de
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Mon, 25 Nov 2024 07:52:21 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced logic for action and plugin state management in the Plugin Action Editor.
    • Improved handling of action IDs for more efficient query dispatching.
    • Updated test coverage to include new baseId property for better consistency in dispatch logic.
  • Bug Fixes

    • Simplified initial checks to improve control flow and performance.

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The useChangeActionCall hook has been modified to streamline its logic by removing initial checks for plugin.id and action. This change allows the effect to run even when these values are undefined. The hook now focuses on comparing previous and current action IDs, exiting early if they match. Additionally, the dispatch logic for non-API plugins has been updated to use action.baseId instead of action?.id, refining how the base ID is utilized in queries.

Changes

File Path Change Summary
app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts Modified logic to remove checks for plugin.id and action, focusing on action ID comparison. Updated dispatch logic to use action.baseId instead of action?.id.
app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.test.tsx Updated tests to include baseId in actionMock, ensuring dispatch functions use the new structure.

Possibly related PRs

Suggested labels

IDE Product, Task, IDE Pod, Query & JS Pod

Suggested reviewers

  • AmanAgarwal041
  • albinAppsmith
  • ankitakinger

🎉 In the code's dance, a new flow takes flight,
With checks removed, it shines so bright!
Action IDs now lead the way,
As base IDs join the fray.
Simplified logic, a cleaner call,
In the world of plugins, we stand tall! 🎶


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 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 added the ok-to-test Required label for CI label Nov 25, 2024
@github-actions github-actions bot added the Bug Something isn't working label Nov 25, 2024
albinAppsmith
albinAppsmith previously approved these changes Nov 25, 2024
ankitakinger
ankitakinger previously approved these changes Nov 25, 2024
@hetunandu hetunandu enabled auto-merge (squash) November 25, 2024 06:26
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

🧹 Outside diff range and nitpick comments (1)
app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts (1)

Line range hint 1-34: Consider adding TypeScript types for better type safety

Adding explicit types for the action object would help prevent similar issues in the future.

+ interface PluginAction {
+   id: string;
+   baseId: string;
+   pageId: string;
+   applicationId: string;
+   packageId: string;
+   moduleId: string;
+   workflowId: string;
+ }

- const { action, plugin } = usePluginActionContext();
+ const { action, plugin }: { action: PluginAction, plugin: Plugin } = usePluginActionContext();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a320605 and b4e3cb0.

📒 Files selected for processing (1)
  • app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts (1 hunks)
🔇 Additional comments (1)
app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts (1)

23-23: Verify the safety of accessing action.baseId

The change from action.id to action.baseId aligns with the PR objectives. However, we should ensure action.baseId is always defined.

✅ Verification successful

Let me search for the type definition of the action object to verify if baseId is a required field.


Let me try a different search pattern to find the type definition.


Let me try one more search with fixed regex to find the type definition.


Based on the search results, I found that baseId is a required field in the BaseAction interface which is the base interface for all action types. The change from action.id to action.baseId is safe as baseId is a required property. Additionally, the codebase shows consistent usage of baseId for identifying actions across many components and operations.

Change from action.id to action.baseId is safe and aligns with the codebase patterns

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for type definitions and usages of action.baseId
ast-grep --pattern 'interface $interface {
  $$$
  baseId: $_
  $$$
}'

# Search for null checks on baseId in other files
rg 'baseId\s*[?!]?' -A 2

Length of output: 75928


Script:

#!/bin/bash
# Search for type definitions of action object
ast-grep --pattern 'interface $interface {
  $$$
  baseId: $_
  $$$
}'

# Search for type definitions in the specific file's directory
ast-grep --pattern 'type $type = {
  $$$
  baseId: $_
  $$$
}'

Length of output: 137


Script:

#!/bin/bash
# Search for type definitions in the specific file
rg -A 10 "type.*Action.*=|interface.*Action.*{" app/client/src/PluginActionEditor/

# Search for baseId usage in the file
rg -A 5 "baseId" app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts

Length of output: 579


Script:

#!/bin/bash
# Search for Action type definitions
rg "type\s+.*Action.*=|interface\s+.*Action.*\{" -A 10

# Search for baseId property in the action object's usage context
rg "action\.(baseId|id)" -A 2 app/client/src/PluginActionEditor/

Length of output: 131195

@hetunandu hetunandu dismissed stale reviews from ankitakinger and albinAppsmith via d6786de November 25, 2024 07:10
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b4e3cb0 and d6786de.

📒 Files selected for processing (1)
  • app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.test.tsx (5 hunks)
🔇 Additional comments (2)
app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.test.tsx (2)

56-56: LGTM! Test properly validates the fix

The test correctly validates that changeQuery now uses baseId instead of id, which aligns with the PR's objective of fixing the navigation issue.

Also applies to: 76-76, 85-85


36-36: Verify if API plugins should continue using action.id

While the PR aims to fix using baseActionId instead of actionId, this test shows API plugins still using action.id. Please verify if this is intentional.

✅ Verification successful

Using action.id for API plugins is correct

The implementation confirms that API plugins should indeed use action.id while non-API plugins use action.baseId. This is the intended behavior as evidenced by:

  1. The hook explicitly uses action.id for API plugins: dispatch(changeApi(action?.id, false))
  2. The changeApi action only accepts an id parameter, not a baseId
  3. Only non-API plugins (default case) use baseId in the changeQuery call
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for changeApi usage in the codebase to verify if API plugins should use id or baseId
ast-grep --pattern 'changeApi($id, $_)'

Length of output: 41


Script:

#!/bin/bash
# Let's search for the hook implementation to understand the logic
ast-grep --pattern 'function useChangeActionCall() {
  $$$
}'

# Also search for any references to changeApi
rg "changeApi" -A 3

Length of output: 6588


Script:

#!/bin/bash
# Let's look at the hook implementation to understand the complete logic
rg -A 20 "export const useChangeActionCall = \(\) => {" app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts

Length of output: 300


Script:

#!/bin/bash
# Let's look at the hook implementation with fixed regex
rg -A 20 "export const useChangeActionCall = \(\)" app/client/src/PluginActionEditor/components/PluginActionForm/hooks/useChangeActionCall.ts

# Also check the changeApi action implementation
rg -A 10 "export const changeApi = \(" app/client/src/PluginActionEditor/store/pluginActionEditorActions.ts

Length of output: 1180

@@ -106,7 +107,7 @@ describe("useChangeActionCall hook", () => {
});

it("should not dispatch any action if the action Id has not changed", () => {
const actionMock = { id: "actionId" };
const actionMock = { id: "actionId", baseId: "baseActionId" };
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add test coverage for baseId changes

While the test covers action.id changes, it should also verify behavior when only baseId changes, especially for non-API plugins.

Add this test case:

it("should dispatch changeQuery when baseId changes for non-API plugins", () => {
  const pluginMock = { id: "pluginId", type: "OTHER_PLUGIN_TYPE" };
  
  // First mount with initial baseId
  const initialAction = { 
    id: "actionId", 
    baseId: "baseId1",
    pageId: "pageId"
  };
  (usePluginActionContext as jest.Mock).mockReturnValueOnce({
    action: initialAction,
    plugin: pluginMock,
  });
  renderHook(() => useChangeActionCall());
  
  // Change only baseId
  const updatedAction = { 
    ...initialAction, 
    baseId: "baseId2" 
  };
  (usePluginActionContext as jest.Mock).mockReturnValueOnce({
    action: updatedAction,
    plugin: pluginMock,
  });
  renderHook(() => useChangeActionCall());
  
  expect(changeQuery).toHaveBeenLastCalledWith({
    baseQueryId: "baseId2",
    basePageId: "pageId"
  });
});

@hetunandu hetunandu merged commit 36239e2 into release Nov 25, 2024
44 checks passed
@hetunandu hetunandu deleted the fix/git-navigation-issue branch November 25, 2024 08:41
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 27, 2024
## Description

Fixes the passing of wrong id when trying to trigger a changeQuery
request. The scenario fixed was passing an actionId instead of a
baseActionId.

Later on, [a
selector](https://github.com/appsmithorg/appsmith/blob/release/app/client/src/sagas/QueryPaneSagas.ts#L111)
is not able to find the action as it expects a baseActionId and causes a
navigation bug.



## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/12004477441>
> Commit: b4e3cb0
> Workflow: `PR Automation test suite`
> Tags: `@tag.Sanity`
> Spec: ``
> <hr>Mon, 25 Nov 2024 06:25:04 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced logic for action and plugin state management in the Plugin
Action Editor.
	- Improved handling of action IDs for more efficient query dispatching.

- **Bug Fixes**
	- Simplified initial checks to improve control flow and performance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants