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: Updating some states related to action execution #36801

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

ankitakinger
Copy link
Contributor

@ankitakinger ankitakinger commented Oct 10, 2024

Description

Updating some states related to action execution under modularised flow: isRunning, isRunDisabled, onDebugClick, actionResponse.

Fixes #36802

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/11275569168
Commit: 2b23612
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Thu, 10 Oct 2024 14:38:26 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced context management in the Plugin Action Editor to include action response data.
    • Introduced a new click handler for the "Run" button in the Plugin Action Toolbar with improved state management.
    • Improved logic for action execution blocking based on running state and user permissions.
    • Added a custom hook to determine whether plugin action execution should be blocked.
  • Bug Fixes

    • Ensured the context value updates correctly when action response changes.
  • Documentation

    • Updated context type declarations to reflect new properties.

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces modifications to the PluginActionContextProvider, enhancing its context value by including the actionResponse property. Additionally, a new function onRunClick is added to the PluginActionToolbar, which refines the button's click handling. The usePluginActionResponseTabs hook is also updated to incorporate action running state checks and manage execution blocking logic based on user permissions and data source URLs.

Changes

File Path Change Summary
app/client/src/PluginActionEditor/PluginActionContext.tsx Modified PluginActionContextProvider to include actionResponse in context value and updated useMemo dependencies. Added actionResponse to context type.
app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx Introduced onRunClick function to encapsulate handleRunClick for the "Run" button's onClick event. No changes to exported entities.
app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx Enhanced hook with new imports and logic to manage action running state and execution blocking. Updated onRunClick and integrated onDebugClick functionality.
app/client/src/PluginActionEditor/hooks/index.ts Added export for the new useBlockExecution hook to enhance accessibility.
app/client/src/PluginActionEditor/hooks/useBlockExecution.ts Introduced useBlockExecution hook to determine if action execution should be blocked based on conditions.
app/client/src/ee/PluginActionEditor/hooks/useBlockExecution.ts Re-exported all entities from ce/PluginActionEditor/hooks/useBlockExecution for improved accessibility.

Assessment against linked issues

Objective Addressed Explanation
Update actionResponse
Update isRunning Changes do not explicitly address this state.
Update isRunDisabled No modifications were made to this state.
Implement onDebugClick Integrated onDebugClick in components.

Possibly related PRs

Suggested labels

Bug

Suggested reviewers

  • hetunandu

🎉 In the realm of code, changes take flight,
With actionResponse now shining bright.
A button to run, a hook with new flair,
Plugin actions improved, with utmost care!
So let’s celebrate, with joy and cheer,
For every small change brings progress near! 🎈


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.

@github-actions github-actions bot added skip-changelog Adding this label to a PR prevents it from being listed in the changelog IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Oct 10, 2024
@ankitakinger ankitakinger added the ok-to-test Required label for CI label Oct 10, 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: 1

🧹 Outside diff range and nitpick comments (2)
app/client/src/PluginActionEditor/PluginActionContext.tsx (1)

31-51: A suggestion for extra credit: Add some explanatory comments!

Great job on making these focused changes! To make your code even more understandable for your classmates, consider adding a brief comment explaining the purpose of actionResponse in this context. For example:

// actionResponse: Contains the result of the most recent action execution

This will help future developers (or yourself when you come back to this code later) understand why this property is important in the context. Remember, good documentation is like leaving clear instructions for a substitute teacher!

app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (1)

20-22: Class, let's examine this new function, shall we?

Now, children, we have a new function called onRunClick. Can anyone tell me what it does? That's right, it simply calls handleRunClick.

While this abstraction might seem unnecessary at first glance, it's actually a good practice. It gives us a clear, named function for our button's click handler. This can make our code more readable and easier to understand.

However, we must ask ourselves: is this abstraction truly needed? If we don't plan to add more logic to onRunClick in the future, it might be overkill.

So, class, what do you think? Should we keep this function or simplify our code? Let's have a thoughtful discussion about the pros and cons.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a63c91 and 14550f9.

📒 Files selected for processing (3)
  • app/client/src/PluginActionEditor/PluginActionContext.tsx (1 hunks)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (2 hunks)
  • app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx (5 hunks)
🧰 Additional context used
🔇 Additional comments (13)
app/client/src/PluginActionEditor/PluginActionContext.tsx (3)

31-39: Well done, class! You've correctly updated the props destructuring.

I'm pleased to see that you've added actionResponse to the list of destructured props. This change allows us to pass the action response data through our context, which is an excellent way to share this information with child components. Remember, sharing is caring in React!


45-51: Excellent work on updating the context value and dependencies!

Class, pay attention to how actionResponse has been added both to the contextValue object and the dependency array of useMemo. This is a crucial step in React context management. By including actionResponse in the context, we're making it available to all the components that consume this context. And by adding it to the dependency array, we're ensuring that our context value is recalculated whenever the action response changes. This is like updating our class bulletin board whenever we have new information!


Line range hint 1-78: Class dismissed with an A+ for this assignment!

You've done an excellent job updating the PluginActionContext to include the actionResponse. Your changes are consistent, focused, and enhance the functionality of the context provider. The addition of actionResponse to the context will allow child components to access this important information easily.

Remember, clear communication is key in both coding and teaching. Consider adding some comments to explain the purpose of new additions like actionResponse. This will make your code even more accessible to your fellow developers.

Keep up the great work, and don't forget to raise your hand if you have any questions!

app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (1)

34-34: Excellent update to our button's click handler!

Class, pay attention to line 34. We've updated our "Run" button's onClick handler to use our new onRunClick function. This is a perfect example of how we can improve code readability.

By using a clearly named function like onRunClick, anyone reading our code can immediately understand what this button does when clicked. It's like labeling our desk drawers - it makes everything easier to find and understand!

Remember, good code isn't just about functionality; it's also about clarity. This change doesn't alter what the button does, but it makes our intentions crystal clear. Well done!

app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx (9)

22-25: Good job adding necessary imports.

You have correctly imported getPluginActionDebuggerState and isActionRunning from "PluginActionEditor/store", which are essential for managing debugger state and action execution status.


33-37: Well done incorporating additional dependencies.

Including useDebuggerTriggerClick, useFeatureFlag, FEATURE_FLAG, getHasExecuteActionPermission, and DEFAULT_DATASOURCE_NAME enhances the functionality related to debugging, feature flags, permission checks, and constant values.


52-54: Nice work initializing onDebugClick and isRunning.

You've properly set up onDebugClick using useDebuggerTriggerClick() and retrieved isRunning with useSelector, which will help in handling debugger triggers and monitoring action execution state effectively.


55-60: Effective use of feature flags and permission handling.

By utilizing useFeatureFlag with FEATURE_FLAG.license_gac_enabled and determining isExecutePermitted, you've ensured that action execution respects feature enablement and user permissions appropriately.


67-75: Logical conditions are thoughtfully designed.

Your implementation of blockExecution correctly determines when to prevent action execution based on the datasource URL, path, and user permissions. This ensures robust control over action execution flow.


78-81: Function onRunClick is properly defined.

Defining onRunClick to call handleRunClick() encapsulates the run click behavior neatly, promoting code readability and maintainability.


107-109: Props passed to ApiResponse are accurate.

Passing isRunDisabled, isRunning, and onRunClick ensures that the ApiResponse component functions as expected with the updated execution logic, enhancing the user experience.


121-124: Updated props enhance ApiResponseHeaders functionality.

Including isRunDisabled, isRunning, onDebugClick, and onRunClick will improve user interaction with the ApiResponseHeaders component, providing better control over debugging and execution.


170-171: QueryResponseTab receives necessary execution state props.

Providing isRunning and onRunClick to QueryResponseTab ensures it has the required context for action execution, which is essential for accurate response rendering.

Comment on lines 67 to 74
// if the url is empty and the action's datasource name is the default datasource name (this means the api does not have a datasource attached)
// or the user does not have permission,
// we block action execution.
const blockExecution =
(!actionDatasourceUrl &&
!actionDatasourceUrlPath &&
actionDatasourceName === DEFAULT_DATASOURCE_NAME) ||
!isExecutePermitted;
Copy link
Member

Choose a reason for hiding this comment

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

This is only related to API actions and should be extracted out into its own hook. Also should this condition not be applied at the toolbar run level as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're correct. It will be needed there too. Although, I just checked, both Query and Api uses different conditions for blocking execution. Should we return the value from the hook based on action type?

Copy link
Member

Choose a reason for hiding this comment

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

If they rely on completely different logic to decide this, it should be extracted out into separate utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've kept it in the same hook because PluginActionToolbar is common between Api and Query and so we will end up having Action type checked there if we have 2 separate hooks.

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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 14550f9 and 67b4a47.

📒 Files selected for processing (5)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (3 hunks)
  • app/client/src/PluginActionEditor/hooks/index.ts (1 hunks)
  • app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx (5 hunks)
  • app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts (1 hunks)
  • app/client/src/ee/PluginActionEditor/hooks/useBlockExecution.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/src/ee/PluginActionEditor/hooks/useBlockExecution.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx
  • app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx
🧰 Additional context used
🪛 Biome
app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts

[error] 29-29: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

🔇 Additional comments (1)
app/client/src/PluginActionEditor/hooks/index.ts (1)

4-4: Excellent addition, class! Let's discuss its significance.

Well done on adding the export for the useBlockExecution hook. This addition aligns perfectly with our lesson on modular code organization. Can anyone tell me how this new hook might contribute to our action execution flow?

Remember, students, when we introduce new hooks like this, it's crucial to consider how they interact with existing functionality. In your homework, I want you to think about how useBlockExecution might work alongside useHandleRunClick. Any thoughts on that?

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

Files that changed from the base of the PR and between 67b4a47 and 2b23612.

📒 Files selected for processing (3)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx (3 hunks)
  • app/client/src/PluginActionEditor/hooks/index.ts (1 hunks)
  • app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/PluginActionEditor/components/PluginActionToolbar.tsx
  • app/client/src/PluginActionEditor/hooks/index.ts
🧰 Additional context used
🔇 Additional comments (6)
app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/usePluginActionResponseTabs.tsx (6)

22-25: Excellent inclusion of necessary selectors and state management imports.

Adding getPluginActionDebuggerState and isActionRunning from "PluginActionEditor/store" is a wise step to ensure that the component accurately reflects the current state of the action debugger and running status. This will enhance the responsiveness of your UI based on the action's execution state.


33-36: Thoughtful integration of custom hooks for execution control and analytics.

By importing useBlockExecution, useHandleRunClick, and useAnalyticsOnRunClick from "PluginActionEditor/hooks", you are effectively modularizing the code and promoting reuse. This approach not only simplifies the component but also adheres to best practices in hook utilization.


37-37: Great addition of the debugger trigger hook.

Incorporating useDebuggerTriggerClick enhances the debugging capabilities of your component. This will allow users to seamlessly access debugging features, improving the overall developer experience.


89-90: Verify that the isRunDisabled and isRunning props are correctly handled in ApiResponse.

Please ensure that the ApiResponse component accepts isRunDisabled and isRunning as props and utilizes them appropriately to reflect the action's execution state and control the run functionality.


103-105: Confirm prop compatibility with ApiResponseHeaders.

It's important to verify that ApiResponseHeaders can handle the new props isRunDisabled, isRunning, and onDebugClick. This will ensure that the component behaves as expected when the action's execution is blocked or in progress, and when the debug functionality is triggered.


152-152: Ensure isRunning prop is utilized correctly in QueryResponseTab.

Double-check that the QueryResponseTab component is designed to accept the isRunning prop and that it uses this prop to manage its internal state or UI elements accordingly.

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]: Update the following states for Actions under modularised flow
3 participants