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

Replace paper-listbox in cast frontend #19954

Merged
merged 8 commits into from
Jun 21, 2024

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Mar 3, 2024

Proposed change

Replace paper-listbox in cast frontend. Please check visually before approval since I was not able to test this fully.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • Refactor

    • Improved list items structure in the HcCast class for better performance and maintainability.
    • Updated event handling for picking views to enhance user interaction.
  • Style

    • Updated styles related to list items for a more consistent and modern appearance.

@github-actions github-actions bot added the Cast Related to Home Assistant Cast UI label Mar 3, 2024
@silamon silamon changed the title Replace paper-list in cast Replace paper-listbox in cast frontend Mar 3, 2024
@silamon silamon marked this pull request as draft March 6, 2024 20:05
@silamon
Copy link
Contributor Author

silamon commented Apr 3, 2024

Monthly revisit: I'm going to keep this in draft until #19955 passes through since both PR's are similar and may receive the same comments.

@silamon silamon marked this pull request as ready for review May 9, 2024 12:20
attr-for-selected="data-path"
.selected=${this.castManager.status.lovelacePath || ""}
>
<mwc-list @action=${this._handlePickView} activatable>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldnt this use the selected event?

Suggested change
<mwc-list @action=${this._handlePickView} activatable>
<mwc-list @selected=${this._handlePickView} activatable>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't work until you have a selectable list (list item with checkboxes): https://www.npmjs.com/package/@material/mwc-list#mwc-list-2

bramkragten
bramkragten previously approved these changes May 29, 2024
Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

Walkthrough

The changes primarily focus on updating plugin configurations and refactoring list item structures. In the webpack.cjs build script, adjustments were made to the StatsWriterPlugin and TransformAsyncModulesPlugin configurations, as well as improvements to the source URL handling logic. In the hc-cast.ts file, the list items were refactored to use mwc-list and ha-list-item instead of paper-listbox and paper-icon-item, along with updates to event handling and styles.

Changes

File Path Change Summary
build-scripts/webpack.cjs Updated StatsWriterPlugin and TransformAsyncModulesPlugin configurations, and revised source URL handling logic.
cast/src/launcher/layout/hc-cast.ts Refactored list items to use mwc-list and ha-list-item, modified event handling for picking views, and updated styles.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant HcCast
    participant MWCList
    participant HAListItem
    
    User->>HcCast: Select a view
    HcCast->>MWCList: Handle view selection
    MWCList->>HAListItem: Update list item
    HAListItem-->>HcCast: Return updated item
    HcCast-->>User: Display selected view
Loading

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits Files that changed from the base of the PR and between c0e0480 and f17aa2e.
Files selected for processing (1)
  • cast/src/launcher/layout/hc-cast.ts (5 hunks)
Additional Context Used
Biome (9)
cast/src/launcher/layout/hc-cast.ts (9)

189-189: Forbidden non-null assertion.


190-190: Forbidden non-null assertion.


190-190: Forbidden non-null assertion.


203-203: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


3-4: All these imports are only used as types.


4-5: Some named imports are only used as types.


6-7: All these imports are only used as types.


25-26: All these imports are only used as types.

Additional comments not posted (4)
cast/src/launcher/layout/hc-cast.ts (4)

30-30: The import of ha-list-item is correctly added to support the new mwc-list component.


86-86: Ensure accessibility by handling keyboard navigation.

It's important to ensure that the list can be navigated using the keyboard. Consider adding keyboard event handlers or using a component that inherently supports keyboard navigation.


252-253: The styling for icons within ha-list-item is correctly updated to reflect the new component structure.


258-259: The new style for hiding icons based on a host attribute is a good use of CSS to conditionally display elements.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added the Build Related to building the code label May 29, 2024
@github-actions github-actions bot removed the Build Related to building the code label May 29, 2024
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: 4

Outside diff range comments (1)
cast/src/launcher/layout/hc-cast.ts (1)

Line range hint 203-203: Specify a more precise type than any.

Using any can lead to maintenance issues and bugs as it bypasses TypeScript's type checking. It's recommended to specify a more precise type.

attr-for-selected="data-path"
.selected=${this.castManager.status.lovelacePath || ""}
>
<mwc-list @action=${this._handlePickView} activatable>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure accessibility by handling keyboard navigation.

It's important to ensure that the list can be navigated using the keyboard. Consider adding keyboard event handlers or using a component that inherently supports keyboard navigation.

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: 3

Comment on lines +188 to 190
private async _handlePickView(ev: CustomEvent<ActionDetail>) {
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
await ensureConnectedCastSession(this.castManager!, this.auth!);
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using non-null assertions as they can lead to runtime errors.

- const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
+ const path = this.lovelaceViews?.[ev.detail.index].path ?? ev.detail.index;

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.

Suggested change
private async _handlePickView(ev: CustomEvent<ActionDetail>) {
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
await ensureConnectedCastSession(this.castManager!, this.auth!);
private async _handlePickView(ev: CustomEvent<ActionDetail>) {
const path = this.lovelaceViews?.[ev.detail.index].path ?? ev.detail.index;
await ensureConnectedCastSession(this.castManager!, this.auth!);

Comment on lines +189 to 190
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
await ensureConnectedCastSession(this.castManager!, this.auth!);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that castManager and auth are checked for null before usage to prevent potential runtime errors.

- await ensureConnectedCastSession(this.castManager!, this.auth!);
+ if (this.castManager && this.auth) {
+   await ensureConnectedCastSession(this.castManager, this.auth);
+ }

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.

Suggested change
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
await ensureConnectedCastSession(this.castManager!, this.auth!);
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
if (this.castManager && this.auth) {
await ensureConnectedCastSession(this.castManager, this.auth);
}

@@ -1,7 +1,6 @@
import "@material/mwc-button/mwc-button";
import { ActionDetail } from "@material/mwc-list/mwc-list";
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using type-only imports for type-only used imports to optimize the build.

- import { ActionDetail } from "@material/mwc-list/mwc-list";
+ import type { ActionDetail } from "@material/mwc-list/mwc-list";

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.

Suggested change
import { ActionDetail } from "@material/mwc-list/mwc-list";
import type { ActionDetail } from "@material/mwc-list/mwc-list";

@bramkragten bramkragten self-assigned this May 30, 2024
@bramkragten bramkragten merged commit 2e5cce5 into home-assistant:dev Jun 21, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cast Related to Home Assistant Cast UI cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants