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

feat: added titles a11y in buttons of uc-activity-header #748

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

egordidenko
Copy link
Contributor

@egordidenko egordidenko commented Oct 4, 2024

Description

Checklist

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced camera selection options and improved permission handling for a better user experience.
    • Added functionality to handle file selection and iframe management in the external source component.
    • Improved URL upload handling with new event management and localization support.
  • Bug Fixes

    • Resolved issues with button accessibility and visibility in various components.
  • Refactor

    • Streamlined the Icon class by removing unnecessary title properties for cleaner code.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes involve updates to multiple classes within the codebase, enhancing their functionality and structure. The CameraSource class now includes improved camera selection management and permission handling. The ExternalSource class has been refined to better handle user interactions and iframe management, with new methods for file selection and iframe lifecycle. The Icon class has had the title property removed from its structure. Finally, the UrlSource class has been updated to improve event handling and localization support in its template.

Changes

File Path Change Summary
blocks/CameraSource/CameraSource.js - Updated init$ with cameraSelectOptions and cameraSelectHidden.
- Added onCameraSelectChange method.
- Modified initCallback for camera options filtering.
- Refined _setPermissionsState method.
- Updated modal close button for accessibility.
blocks/ExternalSource/ExternalSource.js - Updated init$ with onDone callback for file processing.
- Refined activityParams getter for validation.
- Expanded initCallback for state monitoring.
- Updated mountIframe and unmountIframe methods.
- Minor template adjustments for accessibility.
blocks/Icon/Icon.js - Removed title property from init$ and template.
- Updated bindAttributes to exclude title.
blocks/UrlSource/UrlSource.js - Updated init$ with onUpload method for URL handling.
- Modified button elements in the template for localization.
- Adjusted onInput method for state updates.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CameraSource
    participant API

    User->>CameraSource: Select Camera
    CameraSource-->>User: Update Camera Selection UI
    User->>CameraSource: Confirm Selection
    CameraSource->>API: _capture() with selected camera
Loading
sequenceDiagram
    participant User
    participant ExternalSource
    participant API
    participant IFrame

    User->>ExternalSource: Select File
    ExternalSource->>API: onDone with file URLs
    ExternalSource->>IFrame: mountIframe()
    IFrame-->>ExternalSource: File Selected
    ExternalSource->>API: Add file to API
Loading
sequenceDiagram
    participant User
    participant UrlSource
    participant API

    User->>UrlSource: Input URL
    UrlSource->>UrlSource: onInput() updates state
    User->>UrlSource: Upload URL
    UrlSource->>API: addFileFromUrl() with URL
Loading

Poem

🐇 In the garden of code we play,
With cameras and files, we brighten the day.
Icons now simpler, with no title to show,
While URLs dance, making uploads flow.
A hop and a skip, through changes we cheer,
For every new feature, brings joy near! 🌼


🪧 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.

@nd0ut nd0ut self-requested a review October 4, 2024 13:03
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 (4)
blocks/UrlSource/UrlSource.js (2)

Line range hint 6-29: LGTM with suggestions for improvement

The changes to the UrlSource class look good overall. The onUpload and onInput methods have been implemented correctly to handle user interactions.

However, I have a few suggestions:

  1. Could you please clarify the purpose of the new couldBeCtxOwner property? Adding a comment explaining its role would be helpful for future maintainers.

  2. Consider adding brief comments to explain the purpose of the new methods in the init$ object. This would improve code readability and maintainability.


48-55: Excellent accessibility improvement and code formatting

The changes to the close button are great improvements:

  1. The button has been reformatted to span multiple lines, enhancing code readability.
  2. The addition of the l10n="@title:a11y-activity-header-button-close" attribute significantly improves accessibility by providing a translatable title for the close button.

These changes align perfectly with the PR's objective of enhancing accessibility in the uc-activity-header component.

Minor suggestion for consistency:
Consider reordering the attributes to match the order used in other buttons (e.g., move l10n attribute to the end).

blocks/CameraSource/CameraSource.js (2)

Line range hint 218-223: Handle case when no cameras are available

In the initCallback method, if cameraSelectOptions is empty (no cameras are found), this._selectedCameraId will be undefined, which may cause issues in _capture(). Consider handling the scenario where no cameras are available to prevent unexpected behavior.

Apply this diff to handle the case when no cameras are available:

 try {
   let deviceList = await navigator.mediaDevices.enumerateDevices();
   let cameraSelectOptions = deviceList
     .filter((info) => {
       return info.kind === 'videoinput';
     })
     .map((info, idx) => {
       return {
         text: info.label.trim() || `${this.l10n('caption-camera')} ${idx + 1}`,
         value: info.deviceId,
       };
     });
+  if (cameraSelectOptions.length > 0) {
     if (cameraSelectOptions.length > 1) {
       this.$.cameraSelectOptions = cameraSelectOptions;
       this.$.cameraSelectHidden = false;
     }
     this._selectedCameraId = cameraSelectOptions[0]?.value;
+  } else {
+    this.$.l10nMessage = 'camera-no-device-found';
+    this.set$({
+      videoHidden: true,
+      shotBtnDisabled: true,
+      messageHidden: false,
+    });
+    // Optionally, you might want to navigate back or inform the user further.
+  }
 } catch (err) {
   // mediaDevices isn't available for HTTP
   // TODO: handle this case
 }

Line range hint 218-223: Offer assistance for unhandled TODO

There's a // TODO: handle this case comment in the catch block when mediaDevices isn't available (e.g., in HTTP contexts). This scenario might lead to unhandled exceptions or a poor user experience.

Would you like assistance in implementing error handling for this case? For example, displaying an informative message to the user about the unsupported context.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d0bb581 and 6827b7c.

📒 Files selected for processing (4)
  • blocks/CameraSource/CameraSource.js (2 hunks)
  • blocks/ExternalSource/ExternalSource.js (1 hunks)
  • blocks/Icon/Icon.js (0 hunks)
  • blocks/UrlSource/UrlSource.js (1 hunks)
💤 Files with no reviewable changes (1)
  • blocks/Icon/Icon.js
🔇 Additional comments (5)
blocks/UrlSource/UrlSource.js (2)

41-43: Great addition of localization attribute

The addition of the l10n="@title:back" attribute to the back button is an excellent improvement. This change enhances accessibility by providing a translatable title for the button, which aligns perfectly with the PR's objective of improving accessibility in the uc-activity-header component.


Line range hint 1-70: Summary: Excellent accessibility improvements and code enhancements

Overall, the changes in this file are well-implemented and align perfectly with the PR's objective of enhancing accessibility in the uc-activity-header component. The addition of localization attributes to buttons significantly improves the component's accessibility.

Key improvements:

  1. Added localization attributes to buttons for better accessibility.
  2. Enhanced code readability through reformatting.
  3. Updated onUpload and onInput methods for improved functionality.

Minor suggestions have been made for further improvement, including adding clarifying comments and maintaining consistent attribute ordering.

Great work on enhancing the accessibility of the UrlSource component!

blocks/CameraSource/CameraSource.js (2)

Line range hint 218-223: Verify the visibility logic of camera selection elements

In the template, the div containing the camera icon and caption uses set="@hidden: !cameraSelectHidden", while the uc-select element uses set="@hidden: cameraSelectHidden". Ensure that the visibility logic is intentional and that these elements show or hide correctly based on cameraSelectHidden.


230-235: Great job enhancing accessibility with localization

Adding l10n="@title:a11y-activity-header-button-close" to the close button improves accessibility by providing a localized title attribute for screen readers and assistive technologies.

blocks/ExternalSource/ExternalSource.js (1)

259-264: Confirm the click handler for the close button

The close button uses set="onclick: *historyBack", the same as the back button. Please verify whether this is intentional. Typically, a close button might have a different handler to close the modal or perform a separate action.

blocks/ExternalSource/ExternalSource.js Show resolved Hide resolved
blocks/ExternalSource/ExternalSource.js Show resolved Hide resolved
@egordidenko egordidenko merged commit 97f13e3 into main Oct 4, 2024
1 check passed
@egordidenko egordidenko deleted the feat/a11y-buttons-header branch October 4, 2024 13:22
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