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

Adds disabled state for all button view variants #4930

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

manivoxel51
Copy link
Contributor

@manivoxel51 manivoxel51 commented Oct 16, 2024

What changes are proposed in this pull request?

Adds a disabled property to the button view.

  • The main point is to make sure to handle the various button variations (outlined, contained, square, round, etc) correctly when disabled. primarily trying to keep the background color but add an opacity using mui override.

all the variations enabled / disabled state

Screen.Recording.2024-10-15.at.6.20.53.PM.mov

How is this patch tested? If it is not, please explain why.

(Details)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced a disabled property for buttons, enhancing user experience by controlling button interactivity.
    • Added IconButtonView class for icon-based buttons, enriching the UI options.
    • Enhanced various view classes with new parameters for improved layout and behavior.
  • Bug Fixes

    • Updated button styling and opacity based on the disabled state.
  • Documentation

    • Improved documentation for new and updated components and properties.

@manivoxel51 manivoxel51 added the app Issues related to App features label Oct 16, 2024
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve updates to the ButtonView component to incorporate a new disabled property, affecting its rendering and behavior. The getButtonProps and getCommonProps functions have been modified to include this new property. Additionally, a new utility function getDisabledColors has been added to determine colors for the disabled state. The IconButtonView class has been introduced, enhancing the Button class with an icon parameter, while several other view classes have been updated to improve layout and behavior.

Changes

File Path Change Summary
app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx - Added disabled property to view object (default false).
- Updated getButtonProps and getCommonProps to include disabled.
- Updated Button component to receive disabled prop.
- Added import for getDisabledColors.
app/packages/core/src/plugins/SchemaIO/utils/style.ts - Added getDisabledColors function to return CSS variables based on color code.
fiftyone/operators/types.py - Added IconButtonView class extending Button with new icon parameter.
- Updated Button and various view classes with new parameters for enhanced layout and behavior.

Possibly related PRs

Suggested reviewers

  • ritch
  • imanjra

🐇 In a world of buttons, bright and bold,
A new disabled state, a tale to be told.
With icons that sparkle and colors that shine,
Our UI grows richer, oh how divine!
So hop along, dear friends, let's celebrate,
For changes like these make our code truly great! 🌟

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review.


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.

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 (2)
app/packages/core/src/plugins/SchemaIO/utils/style.ts (1)

11-20: Approve with suggestions for improvement

The new getDisabledColors function is well-implemented and consistent with the existing color scheme. However, I have a few suggestions to enhance its robustness and readability:

  1. Consider using more descriptive variable names. For example, primaryColors instead of the first element in the returned array, and secondaryColors for the second element.

  2. Add an explicit return type for better type safety. For example:

    export function getDisabledColors(code: ColorType): [string, string] {
      // ... function body ...
    }
  3. Handle the case when code is undefined or null to prevent potential runtime errors. You could return a default value or throw a meaningful error.

Here's a refactored version incorporating these suggestions:

export function getDisabledColors(code: ColorType): [string, string] {
  if (!code) {
    return ["var(--fo-palette-primary-main)", "var(--fo-palette-text-primary)"];
  }

  const primaryColors = ["primary", "secondary", ...fiftyOneColorNames];
  if (primaryColors.includes(code)) {
    return [
      "var(--fo-palette-primary-main)",
      "var(--fo-palette-text-primary)",
    ];
  }

  return [code, "var(--fo-palette-text-primary)"];
}
app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (1)

156-159: Simplify the destructuring of view from schema

In the getColor function, you're destructuring view from schema again, which may be unnecessary since view is already available in the parent scope. This can be simplified to improve code clarity.

Apply this diff to use the already available view:

function getColor(props: ViewPropsType) {
-  const {
-    schema: { view = {} },
-  } = props;
+  const { schema } = props;
+  const { view = {} } = schema;

Alternatively, pass view directly if it's frequently used.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 62370c8 and 26bb06b.

📒 Files selected for processing (3)
  • app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx (7 hunks)
  • app/packages/core/src/plugins/SchemaIO/utils/style.ts (1 hunks)
  • fiftyone/operators/types.py (0 hunks)
💤 Files with no reviewable changes (1)
  • fiftyone/operators/types.py
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/core/src/plugins/SchemaIO/components/ButtonView.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/core/src/plugins/SchemaIO/utils/style.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.

Comment on lines +109 to +125
if (disabled) {
const [bgColor, textColor] = getDisabledColors(color);
baseProps.sx["&.Mui-disabled"] = {
backgroundColor: variant === "outlined" ? "inherit" : bgColor,
color: textColor,
};
if (variant === "square") {
baseProps.sx["&.Mui-disabled"].backgroundColor = (theme) =>
theme.palette.background.field;
}

if (variant === "outlined") {
baseProps.sx["&.Mui-disabled"].backgroundColor = (theme) =>
theme.palette.background.field;
}
}

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

Refactor disabled styles for consistency and maintainability

The disabled styles are being applied in both the getButtonProps and getCommonProps functions. This can lead to redundant code and potential style conflicts. Consolidating these styles into a single location would improve readability and maintainability.

Consider moving all disabled-related styling into getCommonProps or getButtonProps. For example, you can adjust getCommonProps as follows:

function getCommonProps(props: ViewPropsType): ButtonProps {
  const color = getColor(props);
  const disabled = props.schema.view?.disabled || false;

  return {
    sx: {
      color,
      fontSize: "1rem",
      fontWeight: "bold",
      borderColor: color,
      "&:hover": {
        borderColor: color,
      },
-     ...(disabled
-       ? {
-           opacity: 0.5,
-         }
-       : {}),
    },
+    ...(disabled && {
+      disabled: true,
+    }),
  };
}

Then, handle the disabled-specific styles in getButtonProps:

if (disabled) {
  const [bgColor, textColor] = getDisabledColors(color);
  baseProps.sx = {
    ...baseProps.sx,
    backgroundColor: variant === "outlined" ? "inherit" : bgColor,
    color: textColor,
    opacity: 0.5,
  };

  if (variant === "square" || variant === "outlined") {
    baseProps.sx.backgroundColor = (theme) => theme.palette.background.field;
  }
}

This approach centralizes the disabled styling and avoids duplication.

Also applies to: 135-150

Comment on lines +41 to +44
<TooltipProvider
title={disabled ? "" : title}
{...getComponentProps(props, "tooltip")}
>
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

Provide tooltip content even when the button is disabled

Currently, when the button is disabled, the tooltip title is set to an empty string, which prevents the tooltip from displaying. For better user experience and accessibility, it's advisable to display the tooltip regardless of the disabled state. This allows users to understand the purpose of the button and why it might be disabled.

Apply this diff to ensure the tooltip is always displayed:

<TooltipProvider
-  title={disabled ? "" : title}
+  title={title}
   {...getComponentProps(props, "tooltip")}
>

If necessary, you can provide a specific message explaining the disabled state.

📝 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
<TooltipProvider
title={disabled ? "" : title}
{...getComponentProps(props, "tooltip")}
>
<TooltipProvider
title={title}
{...getComponentProps(props, "tooltip")}
>

Copy link
Contributor

@Br2850 Br2850 left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏽

@Br2850 Br2850 merged commit 2bb80c0 into feat/fo-assistant Oct 16, 2024
9 of 13 checks passed
@Br2850 Br2850 deleted the feat/buttonView-disabled branch October 16, 2024 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants