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

chore: Plugin Action Editor Context #36187

Merged
merged 7 commits into from
Sep 12, 2024
Merged

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Sep 9, 2024

Description

  • Introduce the PluginActionEditor module structure
  • Add basic handling and states in the PluginActionContext
  • Update AppIDE to use the new Editor when the feature flag is active. This will later be updated and the component will be used from the route level itself

Fixes #36152

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/10805408539
Commit: 1b8259b
Cypress dashboard.
Tags: @tag.Datasource
Spec:


Wed, 11 Sep 2024 05:53:02 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a PluginActionEditor component for managing plugin actions.
    • Added PluginActionContext for improved state management of plugin actions.
    • Implemented feature flag checks to conditionally render the redesigned action editor interface in both the ApiEditorWrapper and QueryEditor components.
  • Documentation

    • Added centralized export files for easier access to new components and context providers.
  • Bug Fixes

    • Enhanced error handling for missing plugin settings and configurations in the PluginActionEditor.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

The pull request introduces a new Plugin Action context and a modular Plugin Action Editor component, consolidating functionalities previously split between the ApiEditor and QueryEditor. It includes the creation of several components such as PluginActionForm, PluginActionResponsePane, and PluginActionToolbar, alongside the integration of a feature flag to conditionally render the new editor interface. This architecture enhances the management and representation of plugin actions across the application.

Changes

Files Change Summary
app/client/src/PluginActionEditor/PluginActionContext.tsx, app/client/src/PluginActionEditor/PluginActionEditor.tsx, app/client/src/PluginActionEditor/components/PluginActionForm/PluginActionForm.tsx, app/client/src/PluginActionEditor/components/PluginActionResponsePane.tsx, app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx, app/client/src/PluginActionEditor/index.ts Introduced new components for managing plugin actions, including context and editor functionalities.
app/client/src/ce/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx, app/client/src/ee/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx Defined and re-exported AppPluginActionEditor as a wrapper for plugin action components.
app/client/src/pages/Editor/APIEditor/index.tsx, app/client/src/pages/Editor/QueryEditor/index.tsx Added feature flag checks to conditionally render the AppPluginActionEditor.
app/client/src/pages/Editor/AppPluginActionEditor/index.ts Exported AppPluginActionEditor for use in other parts of the application.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant APIEditor
    participant AppPluginActionEditor
    participant PluginActionEditor
    participant PluginActionContextProvider

    User->>APIEditor: Access API Editor
    APIEditor->>+AppPluginActionEditor: Check feature flag
    AppPluginActionEditor->>+PluginActionContextProvider: Provide context
    PluginActionContextProvider->>+PluginActionEditor: Render Plugin Action Editor
    PluginActionEditor-->>-AppPluginActionEditor: Return rendered component
    AppPluginActionEditor-->>-APIEditor: Return rendered editor
    User->>APIEditor: View Plugin Action Editor
Loading

Assessment against linked issues

Objective Addressed Explanation
Create a new React context called Plugin Action (#[36152])
Create a new Plugin Action Editor component that combines ApiEditor and QueryEditor (#[36153])
Create a common Plugin Action Response Pane component (#[36155]) The response pane is a placeholder and lacks functionality.

Possibly related issues

Poem

In the realm of code, a structure anew,
Plugin actions dance, with a context so true.
Editors unite, in a modular embrace,
A symphony of functions, in a seamless space.
With flags to guide, the features take flight,
In the world of plugins, everything feels right! 🎉


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fe2cda8 and 1b8259b.

Files selected for processing (2)
  • app/client/src/PluginActionEditor/PluginActionContext.tsx (1 hunks)
  • app/client/src/PluginActionEditor/PluginActionEditor.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/PluginActionEditor/PluginActionContext.tsx
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/PluginActionEditor/PluginActionEditor.tsx

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 2, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 2, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

@hetunandu hetunandu added the ok-to-test Required label for CI label Sep 9, 2024
@hetunandu hetunandu marked this pull request as ready for review September 9, 2024 09:53
@hetunandu hetunandu added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 9, 2024
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, codebase verification and nitpick comments (1)
app/client/src/PluginActionEditor/PluginActionEditor.tsx (1)

1-72: Comprehensive and robust implementation of PluginActionEditor with good use of Redux and React Router.

The PluginActionEditor.tsx file effectively uses Redux selectors and React Router to manage and render the state based on the application's current URL and state. The implementation of conditional rendering to handle different states like initialization and entity not found scenarios is well thought out. The use of PluginActionContextProvider to wrap the children with the necessary data is a good practice, ensuring that all child components have access to the required data.

However, consider handling the potential for null values in action and plugin more gracefully. Currently, the component will throw an error and stop rendering if these values are not found, which might not be the best user experience. Perhaps implementing a fallback or a more detailed error message could improve the robustness of this component.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b16be8 and fe2cda8.

Files selected for processing (12)
  • app/client/src/PluginActionEditor/PluginActionContext.tsx (1 hunks)
  • app/client/src/PluginActionEditor/PluginActionEditor.tsx (1 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionForm/PluginActionForm.tsx (1 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionForm/index.ts (1 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionResponsePane.tsx (1 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (1 hunks)
  • app/client/src/PluginActionEditor/index.ts (1 hunks)
  • app/client/src/ce/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx (1 hunks)
  • app/client/src/ee/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx (1 hunks)
  • app/client/src/pages/Editor/APIEditor/index.tsx (2 hunks)
  • app/client/src/pages/Editor/AppPluginActionEditor/index.ts (1 hunks)
  • app/client/src/pages/Editor/QueryEditor/index.tsx (2 hunks)
Files skipped from review due to trivial changes (7)
  • app/client/src/PluginActionEditor/components/PluginActionForm/PluginActionForm.tsx
  • app/client/src/PluginActionEditor/components/PluginActionForm/index.ts
  • app/client/src/PluginActionEditor/components/PluginActionResponsePane.tsx
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx
  • app/client/src/PluginActionEditor/index.ts
  • app/client/src/ee/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx
  • app/client/src/pages/Editor/AppPluginActionEditor/index.ts
Additional comments not posted (6)
app/client/src/ce/pages/Editor/AppPluginActionEditor/AppPluginActionEditor.tsx (1)

1-19: Well-structured and clean implementation for AppPluginActionEditor.

The file AppPluginActionEditor.tsx introduces a new component that uses the PluginActionEditor along with its child components PluginActionToolbar, PluginActionForm, and PluginActionResponsePane. This setup is clean and follows React's best practices for component composition. The use of explicit imports from PluginActionEditor ensures that only necessary components are bundled, which is good for performance.

app/client/src/PluginActionEditor/PluginActionContext.tsx (1)

1-62: Excellent setup of PluginActionContext with robust typing and error handling.

The PluginActionContext.tsx file does an excellent job of setting up a new React context tailored for Plugin Actions. The use of TypeScript interfaces to define the shape of the context and props adds a layer of type safety that is crucial for larger applications. The implementation of usePluginActionContext hook with error handling ensures that the context is consumed correctly within its provider, preventing runtime errors in a larger application setup.

The use of useMemo to memoize the context value is a best practice that helps in optimizing performance by preventing unnecessary re-renders. This is particularly important in a context where the values like action, datasource, and plugin might change frequently and are derived from props.

app/client/src/pages/Editor/APIEditor/index.tsx (2)

41-41: Review the import statement for AppPluginActionEditor.

The import statement correctly references the AppPluginActionEditor from its location. This is a good practice to ensure that components are modular and can be reused efficiently. However, let's ensure that the path is correctly maintained and that there are no typos or incorrect paths that could lead to runtime errors.


181-187: Examine the feature flag implementation for conditional rendering.

The implementation uses a feature flag to conditionally render the AppPluginActionEditor. This is a sound approach to manage feature releases and ensure that new features do not impact all users immediately. The use of useFeatureFlag hook is appropriate here to check the state of the feature flag.

However, it's important to ensure that the feature flag is well-documented and that its usage here aligns with how feature flags are managed across the application. Additionally, consider adding a fallback or error handling if the feature flag service fails or the flag is undefined, to improve the robustness of the code.

app/client/src/pages/Editor/QueryEditor/index.tsx (2)

44-44: Review the import statement for AppPluginActionEditor.

Just like in the APIEditor, the import statement correctly references the AppPluginActionEditor from its location. It's crucial to maintain consistency in how components are imported across different modules. This import statement appears to be correct, but always double-check for any potential typos or path errors that could lead to runtime issues.


192-197: Examine the feature flag implementation for conditional rendering.

The implementation here is similar to that in the APIEditor, using the same feature flag to conditionally render the AppPluginActionEditor. This consistency is good as it helps maintain a uniform approach across different parts of the application.

As with the APIEditor, ensure that the feature flag is well-documented and managed consistently across the application. It would also be wise to add error handling for cases where the feature flag service might fail or the flag is undefined, to prevent any disruptions in the user experience.

Verification successful

Feature Flag Usage Verified Across Application

The feature flag release_actions_redesign_enabled is consistently used across various parts of the application, including the QueryEditor, APIEditor, and other components. This consistency helps maintain a uniform approach, as highlighted in the review comment.

  • app/client/src/pages/Editor/QueryEditor/index.tsx
  • app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx
  • app/client/src/pages/Editor/IDE/EditorPane/components/ActionToolbar.tsx
  • app/client/src/pages/Editor/APIEditor/index.tsx
  • app/client/src/ce/entities/FeatureFlag.ts
  • app/client/src/components/formControls/DynamicTextFieldControl.tsx

Consider implementing error handling for scenarios where the feature flag service might fail or the flag is undefined, to enhance user experience.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the feature flag usage consistency across the application.

# Test: Search for the feature flag usage. Expect: Consistent usage across the application.
rg --type typescript "release_actions_redesign_enabled"

Length of output: 90


Script:

#!/bin/bash
# Description: Verify the feature flag usage consistency across the application.

# Test: Search for the feature flag usage. Expect: Consistent usage across the application.
rg --type ts "release_actions_redesign_enabled"

Length of output: 952

}

// No need to export this context to use it. Use the hook defined below instead
const PluginActionContext = createContext<PluginActionContext | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interface and const have same name. I suggest keeping it different.

return <EntityNotFoundPane />;
}
if (!settingsConfig || !editorConfig) {
throw Error("Plugin config for action not found");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we show the same not found component here? Or a better component to handle this error.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

}

const PluginActionEditor = (props: ChildrenProps) => {
const { pathname } = useLocation();
Copy link
Contributor

Choose a reason for hiding this comment

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

With this refactor, should we rely on the path to identify the action? Can we pass the action as a prop to the PluginActionEditor?
Reason for asking this is the path has to conform to a particular standard for this editor to work (path should have :entityId or :queryId). If we make this agnostic then this editor can be rendered anywhere and has no dependency on the url

Copy link
Contributor

Choose a reason for hiding this comment

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

Another suggestion: AFAIK each action now has a context object to define which parent it belongs to. Maybe we can use that instead of the URL. (I don't know if this functionality exists for packages however, need to confirm with someone from backend team)

Copy link
Member Author

Choose a reason for hiding this comment

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

I will make this change in the next PR to update the PluginActionEditor

datasource={datasource}
editorConfig={editorConfig}
plugin={plugin}
settingsConfig={settingsConfig}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you check ModuleQueryEditor, the settingsConfig is passed as a prop to the editor.

Copy link
Member Author

Choose a reason for hiding this comment

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

We will remove that

Copy link
Contributor

Choose a reason for hiding this comment

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

What I meant was the Module editors show only specific settings for each pluginType hence they are passed from top bottom to decouple and avoid if-else inside the editors. if the plan is to remove that then what's the plan to keep the editor config agnostic?
Check useModuleFallbackSettingsForm.ts for more info.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. Yup I have this considered. Will make this close to the PluginActionToolbar where this will be used

Copy link
Contributor

@ayushpahwa ayushpahwa left a comment

Choose a reason for hiding this comment

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

How are we planning to add the customisations for toolbars (like create module option, removing edit options etc)

}

const PluginActionEditor = (props: ChildrenProps) => {
const { pathname } = useLocation();
Copy link
Contributor

Choose a reason for hiding this comment

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

Another suggestion: AFAIK each action now has a context object to define which parent it belongs to. Maybe we can use that instead of the URL. (I don't know if this functionality exists for packages however, need to confirm with someone from backend team)

return <EntityNotFoundPane />;
}
if (!settingsConfig || !editorConfig) {
throw Error("Plugin config for action not found");
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@hetunandu
Copy link
Member Author

How are we planning to add the customisations for toolbars (like create module option, removing edit options etc)

@ayushpahwa we are planning to add that business logic closer to the actual functionality. So there will be a new component created called AppPluginActionToolbar that would wrap the PluginActionToolbar and add the changes there

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 2, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

@hetunandu hetunandu merged commit 4189a70 into release Sep 12, 2024
44 checks passed
@hetunandu hetunandu deleted the chore/plugin-action-editor branch September 12, 2024 04:41
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
## Description

- Introduce the PluginActionEditor module structure
- Add basic handling and states in the PluginActionContext
- Update AppIDE to use the new Editor when the feature flag is active.
This will later be updated and the component will be used from the route
level itself


Fixes appsmithorg#36152

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10805408539>
> Commit: 1b8259b
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10805408539&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Wed, 11 Sep 2024 05:53:02 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**
- Introduced a `PluginActionEditor` component for managing plugin
actions.
- Added `PluginActionContext` for improved state management of plugin
actions.
- Implemented feature flag checks to conditionally render the redesigned
action editor interface in both the `ApiEditorWrapper` and `QueryEditor`
components.

- **Documentation**
- Added centralized export files for easier access to new components and
context providers.

- **Bug Fixes**
- Enhanced error handling for missing plugin settings and configurations
in the `PluginActionEditor`.

<!-- 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
IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Create Plugin Action context
4 participants