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 disabled schedule exec option #5219

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

ritch
Copy link
Contributor

@ritch ritch commented Dec 5, 2024

Screen.Recording.2024-12-05.at.8.06.25.AM.mov

This fixes an issue where the schedule option in the OperatorExecutionButtonView was click-able when it should be disabled. It also normalizes the display of the Execution Options in both the modal SplitButton and the OperatorExecutionButton.

Summary by CodeRabbit

  • New Features

    • Introduced the ExecutionOptionItem component for improved rendering of execution options.
    • Added a new Item component to streamline the OperatorExecutionMenu functionality.
    • Enhanced operator execution options with an isDisabledSchedule property to indicate scheduling availability.
  • Bug Fixes

    • Improved error handling in the handleSelect function to prevent issues with undefined actions.
  • Refactor

    • Removed the PrimaryWithTag function to simplify the SplitButton component.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

A new React functional component named ExecutionOptionItem has been introduced, which accepts props for label, tag, and disabled state. This component is integrated into the SplitButton and OperatorExecutionMenu, replacing the previous PrimaryWithTag and MenuItem components, respectively. Additionally, the OperatorExecutionOption type has been updated to include a new property, isDisabledSchedule, enhancing the management of operator execution options.

Changes

File Path Change Summary
app/packages/operators/src/ExecutionOptionItem.tsx New component ExecutionOptionItem added with props: { label, tag, disabled }.
app/packages/operators/src/SplitButton.tsx Removed PrimaryWithTag function; replaced with ExecutionOptionItem in dropdown rendering. Added guard clause in handleSelect.
app/packages/operators/src/components/OperatorExecutionMenu/index.tsx Introduced Item component to replace MenuItem, utilizing ExecutionOptionItem for rendering. Streamlined click handling logic.
app/packages/operators/src/state.ts Updated OperatorExecutionOption type to include isDisabledSchedule. Modified logic in useOperatorPromptSubmitOptions for scheduling options.

Possibly related PRs

Suggested labels

app, enhancement

Suggested reviewers

  • lanzhenw
  • imanjra
  • Br2850

Poem

🐰 In the garden where options bloom,
New items sprout, dispelling gloom.
A tag for each, both bright and clear,
With disabled states, we hold them dear.
Click away, but heed the sign,
For every choice, the path will shine! 🌼


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.

@@ -63,6 +63,7 @@ export default function SplitButton({
};

const handleSelect = (option) => {
if (!option.onSelect) return;
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 noticed this bug while testing. Clicking on the Schedule button in the modal threw an error. This fixes it.

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

🧹 Outside diff range and nitpick comments (5)
app/packages/operators/src/ExecutionOptionItem.tsx (2)

7-11: Consider extracting inline styles to theme or styled components

Inline styles make it harder to maintain consistent styling across the application.

Consider creating a styled component or adding these styles to the theme:

const TagSpan = styled('span')(({ theme, disabled }) => ({
  fontSize: "11px",
  color: disabled ? theme.text.secondary : theme.custom.primarySoft,
  marginLeft: "5px"
}));

17-20: Add aria-label for better accessibility

The component should provide proper accessibility attributes for screen readers.

-    <div style={{ display: "flex", alignItems: "center" }}>
+    <div 
+      style={{ display: "flex", alignItems: "center" }}
+      aria-label={`${label}${tag ? ` ${tag}` : ''}`}
+    >
app/packages/operators/src/components/OperatorExecutionMenu/index.tsx (1)

49-54: Use callback for click handler to prevent memory leaks

The click handler should be memoized to prevent unnecessary re-renders and potential memory leaks.

+  const handleClick = React.useCallback(() => {
+    if (disabled) return;
+    onClose?.();
+    onOptionClick?.(target);
+    target.onClick();
+  }, [disabled, onClose, onOptionClick, target]);

-      onClick={() => {
-        if (disabled) return;
-        onClose?.();
-        onOptionClick?.(target);
-        target.onClick();
-      }}
+      onClick={handleClick}
app/packages/operators/src/SplitButton.tsx (2)

66-68: Improve guard clause implementation

The guard clause for onSelect could be more explicit.

-    if (!option.onSelect) return;
+    if (typeof option.onSelect !== 'function') return;
     option.onSelect();
     setOpen(false);

Line range hint 146-151: Add aria-label to improve menu item accessibility

The ExecutionOptionItem implementation in the menu should include accessibility attributes.

     primary={
       <ExecutionOptionItem
         label={option.choiceLabel || option.label}
         tag={option.tag}
         disabled={option.disabled || !option.onClick}
+        aria-label={`${option.choiceLabel || option.label}${option.tag ? ` ${option.tag}` : ''}`}
       />
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 81baea4 and 68344b9.

📒 Files selected for processing (4)
  • app/packages/operators/src/ExecutionOptionItem.tsx (1 hunks)
  • app/packages/operators/src/SplitButton.tsx (3 hunks)
  • app/packages/operators/src/components/OperatorExecutionMenu/index.tsx (2 hunks)
  • app/packages/operators/src/state.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
app/packages/operators/src/ExecutionOptionItem.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/SplitButton.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/components/OperatorExecutionMenu/index.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/state.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (3)
app/packages/operators/src/components/OperatorExecutionMenu/index.tsx (1)

34-34: Verify disabled state logic aligns with PR objective

The disabled state now correctly considers both isDisabledSchedule and missing onClick handler, which aligns with the PR objective of fixing the schedule execution option.

✅ Verification successful

Disabled state implementation is correctly implemented and aligns with PR objective

The disabled state logic in OperatorExecutionMenu is properly implemented:

  • It correctly combines isDisabledSchedule and missing onClick handler conditions
  • The disabled state is consistently propagated to both MenuItem and ExecutionOptionItem
  • The click handler properly respects the disabled state
  • The implementation aligns with the type definition in state.ts where isDisabledSchedule is defined as an optional boolean
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the disabled state implementation across the codebase
rg "isDisabledSchedule" --type ts

Length of output: 305


Script:

#!/bin/bash
# Let's check the context around the state definition and usage
rg -B 3 -A 3 "isDisabledSchedule" app/packages/operators/src/state.ts

# Also check how the target prop is defined in the component
ast-grep --pattern 'interface $_ {
  $$$
  isDisabledSchedule?: $_
  $$$
}'

Length of output: 429


Script:

#!/bin/bash
# Let's check how the OperatorExecutionMenu component is using this prop
rg -B 10 -A 5 "disabled={target.isDisabledSchedule" app/packages/operators/src/components/OperatorExecutionMenu/index.tsx

# Also check if there are any tests verifying this behavior
fd "test|spec" --extension ts --extension tsx | xargs rg "isDisabledSchedule"

Length of output: 329


Script:

#!/bin/bash
# Let's try with proper escaping of the curly braces
rg -B 10 -A 5 "disabled=\{target\.isDisabledSchedule" app/packages/operators/src/components/OperatorExecutionMenu/index.tsx

# Let's also check the entire component implementation
cat app/packages/operators/src/components/OperatorExecutionMenu/index.tsx

Length of output: 2646

app/packages/operators/src/state.ts (2)

249-249: LGTM: Clean type extension

The addition of the optional isDisabledSchedule property to OperatorExecutionOption type is well-designed and maintains backward compatibility.


350-350: Verify the disabled schedule implementation

The implementation looks correct. Let's verify that this property is properly handled in all components that consume OperatorExecutionOption.

✅ Verification successful

Let me check the implementation details in these files to verify how isDisabledSchedule is handled.


Implementation of isDisabledSchedule is properly handled

The verification shows that isDisabledSchedule is correctly implemented and consumed:

  • It's defined in the OperatorExecutionOption interface in state.ts
  • It's properly set in the state management logic when scheduling is not available
  • It's correctly used in the UI to disable menu items in OperatorExecutionMenu component through the disabled prop
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all components that consume OperatorExecutionOption to ensure proper handling

# Search for files importing or using OperatorExecutionOption
rg -l "OperatorExecutionOption" 

# Search for components rendering schedule-related UI
ast-grep --pattern 'isDisabledSchedule'

Length of output: 404


Script:

#!/bin/bash
# Check implementation details in the relevant files
rg -A 5 -B 5 "isDisabledSchedule" 

# Check schedule-related UI components and their props
ast-grep --pattern 'interface OperatorExecutionOption {
  $$$
}'

# Check how schedule options are handled in the execution menu
rg -A 10 "schedule" app/packages/operators/src/components/OperatorExecutionMenu/index.tsx

Length of output: 2597

Copy link
Contributor

@imanjra imanjra left a comment

Choose a reason for hiding this comment

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

LGTM

@ritch ritch merged commit 3993e56 into release/v1.1.0 Dec 5, 2024
10 checks passed
@ritch ritch deleted the fix-exec-btn-schedule-disabled branch December 5, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants