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: Fixed display of 0% inside label in progress bar #326

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andreyjamer
Copy link
Contributor

@andreyjamer andreyjamer commented Sep 30, 2024

There is a bug with progress bar for small values. When the bar is too small, then the inside label is almost invisible.

Summary by CodeRabbit

  • New Features

    • Introduced an additional progress bar in the FwbProgressExampleLabelInside component.
    • Added a computed property safeProgress to ensure progress values do not exceed defined maximums.
    • Introduced a constant progressSafeSizes for mapping progress sizes to numeric values.
  • Bug Fixes

    • Adjusted progress width behavior to enhance display consistency.

Copy link

coderabbitai bot commented Sep 30, 2024

Warning

Rate limit exceeded

@andreyjamer has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 707bc93 and 00646eb.

Walkthrough

The changes involve the addition of a new <fwb-progress> component instance in the FwbProgressExampleLabelInside.vue file, configured with a progress value of 0. The existing instance retains a progress value of 50. The FwbProgress.vue component has been updated to introduce a computed property safeProgress, ensuring the displayed progress does not exceed a defined maximum based on size. Additionally, a new constant progressSafeSizes was added in useProgressClasses.ts to map progress sizes to numeric values. No alterations were made to exported or public entities.

Changes

File Change Summary
docs/components/progress/examples/FwbProgressExampleLabelInside.vue Added a new <fwb-progress> instance with progress value 0 alongside an existing instance with progress value 50. Both instances share the same properties.
src/components/FwbProgress/FwbProgress.vue Introduced a computed property safeProgress to adjust the displayed progress based on size. Updated class attributes of the inner progress bar's div to include min-w-max.
src/components/FwbProgress/composables/useProgressClasses.ts Added a new constant progressSafeSizes mapping ProgressSize values to corresponding numeric values.

Poem

In a world of progress, bright and grand,
Two bars now dance, hand in hand.
One shows zero, the other fifty,
Together they shine, oh so nifty!
With styles anew, they proudly stand,
A progress tale, crafted by hand. 🐇✨


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Sep 30, 2024

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit 00646eb
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/66fa87730079b700083656b5
😎 Deploy Preview https://deploy-preview-326--sensational-seahorse-8635f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@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)
src/components/FwbProgress/FwbProgress.vue (1)

56-59: Effective implementation of safeProgress computed property.

The safeProgress computed property is a great solution to ensure minimum visibility for small progress values. It cleverly uses the progressSafeSizes object to determine a minimum size based on the component's size prop.

This implementation effectively addresses the PR's main objective of fixing the display of small percentages in the progress bar.

Consider adding a brief comment explaining the purpose of progressSafeSizes and what values it contains. This would enhance code maintainability. For example:

// progressSafeSizes contains minimum percentage values for each size variant
// to ensure visibility of small progress values
const safeProgress = computed(() => {
  const size = progressSafeSizes[props.size]
  return props.progress <= size ? size : props.progress
})
src/components/FwbProgress/composables/useProgressClasses.ts (1)

Line range hint 1-67: Consider additional changes to address small value visibility

While the new progressSafeSizes constant is a step in the right direction, the current implementation doesn't seem to directly address the issue of displaying small values (like 0%) in progress bars. Consider the following suggestions:

  1. Implement a minimum width for the colored portion of the progress bar when the value is greater than 0% but very small.
  2. Add a class to ensure the label remains visible even when the progress bar is small.

Here's a potential implementation to consider:

// Add this function to handle minimum width
function getProgressWidth(value: number): string {
  return value > 0 && value < 1 ? '1%' : `${value}%`;
}

// Modify the useProgressClasses function to include this logic
export function useProgressClasses(props: UseProgressClassesProps) {
  // ... existing code ...

  const progressWidth = computed(() => getProgressWidth(props.value.value));
  
  const bindClasses = computed(() => {
    return classNames(
      barColorClasses[props.color.value],
      progressSizeClasses[props.size.value],
      'min-w-[1.5em]', // Ensures a minimum width for label visibility
    )
  })

  // ... rest of the function ...

  return {
    innerClasses: bindClasses,
    outerClasses,
    outsideLabelClasses,
    progressWidth,
  }
}

This suggestion ensures that:

  1. The progress bar always has a minimum width to display the label.
  2. For very small non-zero values, the progress bar will still be visible.

Please adjust the implementation as needed to fit your specific requirements and component structure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 846f6f6 and 707bc93.

📒 Files selected for processing (3)
  • docs/components/progress/examples/FwbProgressExampleLabelInside.vue (1 hunks)
  • src/components/FwbProgress/FwbProgress.vue (3 hunks)
  • src/components/FwbProgress/composables/useProgressClasses.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/components/progress/examples/FwbProgressExampleLabelInside.vue
🔇 Additional comments (2)
src/components/FwbProgress/FwbProgress.vue (2)

22-23: Excellent changes to improve small progress value visibility!

The modifications in these lines effectively address the issue of displaying small progress values:

  1. Using safeProgress instead of progress for the width ensures a minimum visible width for the progress bar.
  2. Adding the min-w-max class guarantees that the inner div will always be wide enough to display its content, solving the problem of the "0%" label being nearly invisible.

These changes align perfectly with the PR objective of fixing the display of small percentages in the progress bar.


34-34: Correct import for computed property.

Good job importing the computed function from Vue. This is necessary for defining the safeProgress computed property and follows the best practice of importing only the required functions.

Comment on lines 34 to 39
export const progressSafeSizes: Record<ProgressSize, number> = {
sm: 1,
md: 2,
lg: 3,
xl: 4,
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Action Required: progressSafeSizes is currently not utilized in the codebase.

The progressSafeSizes constant is exported in useProgressClasses.ts but is not referenced in any other files. Please verify if this constant is intended for future implementations. If it is not needed, consider removing it to keep the codebase clean and maintainable.

🔗 Analysis chain

LGTM! New constant added for progress bar size mapping.

The new progressSafeSizes constant appears to be related to the PR objective of fixing the display of small values in progress bars. It provides a numeric mapping for each progress bar size, which could be useful for determining minimum width or visibility thresholds for labels.

To ensure this constant is being utilized as intended, please run the following script to check its usage across the codebase:

If the constant is not used anywhere, consider adding a TODO comment to implement its usage or remove it if it's no longer needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in other files

# Test: Search for progressSafeSizes usage
rg --type typescript -A 5 'progressSafeSizes'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in TypeScript files by searching .ts and .tsx extensions

# Test: Search for progressSafeSizes usage in .ts and .tsx files
rg -A 5 'progressSafeSizes' --type-add 'custom_ts:(**/*.ts|**/*.tsx)' --type custom_ts

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the usage of progressSafeSizes in TypeScript files by searching .ts and .tsx extensions

# Test: Search for progressSafeSizes usage in .ts and .tsx files
rg 'progressSafeSizes' -g '*.ts' -g '*.tsx' -A 5

Length of output: 517

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.

1 participant