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(external-sources): done button loading state behaviour #770

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nd0ut
Copy link
Member

@nd0ut nd0ut commented Dec 24, 2024

Description

Checklist

Summary by CodeRabbit

  • New Features

    • Introduced a new spinner component for improved loading feedback.
    • Enhanced the "Done" button functionality with dynamic enabling and visibility states.
  • Bug Fixes

    • Improved control flow for file selection feedback and button states.
  • Style

    • Added new styles for the spinner and updated styles for the "Done" button.
  • Documentation

    • Updated import statements to include the new spinner styles in the theme.

@nd0ut nd0ut requested a review from egordidenko December 24, 2024 12:32
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces a new Spinner component and enhances the ExternalSource class with improved file selection interaction. The changes include creating a new Spinner class with associated CSS animations, updating the ExternalSource component to manage button states more dynamically, and adding spinner-related styles to the basic theme. The modifications aim to provide better visual feedback and user interaction during file selection processes.

Changes

File Change Summary
blocks/ExternalSource/ExternalSource.js - Added isDoneBtnEnabled and doneBtnTextClass properties
- Updated handleSelectedFilesChange method to manage button state
- Modified button interaction logic
blocks/ExternalSource/external-source.css - Added CSS rules for hidden button text
- Styled spinner positioning within done button
blocks/Spinner/Spinner.js - Created new Spinner class extending BaseComponent
- Defined static template for spinner element
blocks/Spinner/spinner.css - Added keyframe animation for spinner rotation
- Defined .uc-spinner class styling
blocks/themes/uc-basic/index.css - Imported spinner CSS styles
index.js - Added export for Spinner component

Sequence Diagram

sequenceDiagram
    participant User
    participant ExternalSource
    participant Spinner
    
    User->>ExternalSource: Select files
    ExternalSource->>ExternalSource: Validate file selection
    alt Files Selected
        ExternalSource->>Spinner: Show loading indicator
        ExternalSource->>ExternalSource: Enable "Done" button
    else No Files
        ExternalSource->>Spinner: Hide loading indicator
        ExternalSource->>ExternalSource: Disable "Done" button
    end
Loading

Possibly related PRs

Poem

🐰 A spinner twirls, files take flight,
Buttons dance with newfound might!
Code leaps forward, smooth and neat,
User experience now complete.
Rabbit's magic makes UI bright! 🎉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
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

🧹 Nitpick comments (3)
blocks/Spinner/Spinner.js (1)

3-3: Class definition looks good
Defining Spinner as a subclass of BaseComponent appears appropriate. Consider adding documentation if you foresee more functionality in the future.

blocks/ExternalSource/ExternalSource.js (1)

36-36: doneBtnTextClass naming
Using a dedicated property for toggling text visibility is fine. Consider naming it to reflect its purpose (e.g., doneBtnTextVisibility) to improve clarity.

blocks/ExternalSource/external-source.css (1)

82-85: LGTM! Consider using CSS custom properties for visibility states.

The implementation correctly uses visibility: hidden to preserve layout spacing while hiding content. The addition of pointer-events: none is a good practice for hidden elements.

Consider defining these visibility states using CSS custom properties for better maintainability:

 uc-external-source .uc-done-btn > span.uc-hidden {
-  visibility: hidden;
+  visibility: var(--uc-visibility-hidden, hidden);
   pointer-events: none;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ab42a and c0d0cd3.

📒 Files selected for processing (6)
  • blocks/ExternalSource/ExternalSource.js (4 hunks)
  • blocks/ExternalSource/external-source.css (1 hunks)
  • blocks/Spinner/Spinner.js (1 hunks)
  • blocks/Spinner/spinner.css (1 hunks)
  • blocks/themes/uc-basic/index.css (1 hunks)
  • index.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • blocks/Spinner/spinner.css
🔇 Additional comments (8)
blocks/Spinner/Spinner.js (2)

1-2: Import statement and file structure look solid
No issues found; the import from @symbiotejs/symbiote is correct, and the file's initial structure is clean.


5-5: Template definition is concise
The inline HTML for the spinner is straightforward and reusable. Ensure that any additional spinner markup variants are documented if you plan to extend functionality.

index.js (1)

35-35: Export statement is properly added
Exporting Spinner from this file correctly centralizes component exports. This increases discoverability and consistency in your component library.

blocks/ExternalSource/ExternalSource.js (4)

31-31: New property for done button state is well introduced
isDoneBtnEnabled clarifies the condition for enabling the "Done" button. Keep it up-to-date with the selection logic to avoid confusion.


151-153: Conditional logic for the selection
These lines ensure the spinner and text states are synchronized with isSelectionReady. The approach is correct, but remember to thoroughly test edge cases (e.g., single-file selection, empty selection).


247-247: Reset logic
Clearing isDoneBtnEnabled to false on reset is consistent with overall state management. This helps ensure no stale UI states remain.


275-278: Button layout and spinner usage
The button uses the spinner element alongside toggling text visibility. This provides clear user feedback while loading. The implementation is cohesive and follows good UI/UX practices.

blocks/themes/uc-basic/index.css (1)

33-33: CSS import for spinner
Importing spinner.css here is consistent with the theme structure. Ensure the file path remains valid if the folder layout changes in the future.

Comment on lines +87 to +94
uc-external-source .uc-done-btn > uc-spinner {
position: absolute;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

ARIA attributes are needed for loading state

The code review was correct. The ExternalSource component uses a spinner but doesn't implement the recommended ARIA attributes for loading state. Specific findings:

  • The button with class uc-done-btn contains a <uc-spinner> component
  • The spinner visibility is controlled by isSelectionReady binding
  • No ARIA attributes are set when the loading state changes

To improve accessibility, add these attributes when the spinner is shown:

  • In the button element, add aria-busy="true" when !isSelectionReady
  • Add an appropriate aria-label to indicate the loading state

Example implementation:

<button type="button" class="uc-done-btn uc-primary-btn" 
  set="onclick: onDone; 
       @disabled: !isDoneBtnEnabled;
       @aria-busy: !isSelectionReady;
       @aria-label: !isSelectionReady ? 'Loading, please wait...' : null">
🔗 Analysis chain

Consider adding ARIA attributes for loading state.

The spinner positioning and centering implementation is solid. However, to improve accessibility, ensure the button has appropriate ARIA attributes when in loading state.

The CSS looks good, but verify that the JavaScript implementation includes these ARIA attributes on the button when loading:

button.setAttribute('aria-busy', 'true');
button.setAttribute('aria-label', 'Loading, please wait...');

Let's verify if these ARIA attributes are already implemented:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for aria-busy attribute usage in button elements
ast-grep --pattern 'setAttribute($attr, $val)' | grep -i 'aria-busy'

# Search for loading-related ARIA labels
rg -i "aria-label.*load"

Length of output: 95


Script:

#!/bin/bash
# Let's try a broader search for ARIA attributes and loading states
# Search for any aria-busy usage
rg -i "aria-busy"

# Search for aria attribute setting in JavaScript
rg "setAttribute.*aria"

# Look for the button component implementation
fd -e js -e ts "button" --exec grep -l -i "loading\|spinner"

# Search specifically in the ExternalSource component
fd -e js -e ts "ExternalSource" --exec cat {}

Length of output: 8669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants