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 polymer paper-tabs #22018

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Sep 17, 2024

Proposed change

The left and right arrows are removed. Replaces the polymer paper-tabs with the new material3 md tabs.

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

  • New Features

    • Introduced new custom tab components (ha-md-primary-tab, ha-md-secondary-tab, ha-md-tabs) for improved navigation.
    • Enhanced tab functionality with mouse-based scrolling in the HaMdTabs component.
  • Bug Fixes

    • Updated tab event handling for better responsiveness and interaction.
  • Refactor

    • Replaced Polymer's paper-tabs with new Material Design components across various panels and editors.
  • Chores

    • Removed outdated dependencies related to Polymer's tab components.

@github-actions github-actions bot added Demo Related to frontend demo content Design Related to Home Assistant design gallery labels Sep 17, 2024
@piitaya
Copy link
Member

piitaya commented Sep 18, 2024

I like it ! Good job !

I noticed 2 small thing on the dashboard tabs :

  • the scroll bar is still visible on Safari iOS (I didn't test on Android)
  • looks like there is a small grey border at the bottom.

IMG_A8E07EBD6B65-1

@silamon
Copy link
Contributor Author

silamon commented Sep 18, 2024

There's a lot of polish work to be done, I'm currently looking if the scrolling and functional behavior is close to be OK.
The divider is something that material defines, so the plan was to extend it over the whole line. It is also the reason the arrow buttons have been removed, since the component defines a column flex box with the tabs being the first row and the divider being in a second row.

@github-actions github-actions bot removed the Design Related to Home Assistant design gallery label Sep 21, 2024
@silamon silamon marked this pull request as ready for review September 21, 2024 11:00
Copy link
Contributor

coderabbitai bot commented Sep 21, 2024

Walkthrough

Walkthrough

The changes involve significant modifications to the theme configuration and the introduction of new custom components in the project. The paper-tabs-selection-bar-color property has been removed from two theme files, and the dependency on @polymer/paper-tabs has been eliminated from package.json. New components, ha-md-primary-tab, ha-md-secondary-tab, and ha-md-tabs, have been created to replace the existing Polymer tab components, enhancing the tab navigation experience. Additionally, various files have been updated to utilize these new components, changing event handling and styling accordingly.

Changes

File Path Change Summary
demo/src/configs/jimpower/theme.ts Removed property "paper-tabs-selection-bar-color" from demoThemeJimpower.
demo/src/configs/kernehed/theme.ts Removed property "paper-tabs-selection-bar-color" from demoThemeKernehed.
package.json Removed dependency "@polymer/paper-tabs": "3.1.0".
src/components/ha-md-primary-tab.ts Added new custom element HaMdPrimaryTab, extending MdPrimaryTab, and updated HTMLElementTagNameMap.
src/components/ha-md-secondary-tab.ts Added new custom element HaMdSecondaryTab, extending MdSecondaryTab, and updated HTMLElementTagNameMap.
src/components/ha-md-tabs.ts Introduced HaMdTabs component, extending MdTabs, with mouse scrolling functionality.
src/components/ha-tabs.ts Removed class HaTabs.
src/panels/developer-tools/ha-panel-developer-tools.ts Updated to use ha-md-tabs and ha-md-secondary-tab, modified tab management and event handling.
src/panels/lovelace/editor/config-elements/hui-conditional-card-editor.ts Replaced MWC tab components with ha-md-tabs and ha-md-secondary-tab, updated event handling.
src/panels/lovelace/editor/config-elements/hui-stack-card-editor.ts Transitioned to ha-md-tabs and ha-md-secondary-tab, simplified event handling and styles.
src/panels/lovelace/hui-root.ts Replaced Polymer tab components with ha-md-tabs and ha-md-secondary-tab, adjusted rendering logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PanelDeveloperTools
    participant HaMdTabs
    participant HaMdSecondaryTab

    User->>PanelDeveloperTools: Selects tab
    PanelDeveloperTools->>HaMdTabs: Update active tab index
    HaMdTabs->>HaMdSecondaryTab: Render selected tab
    HaMdSecondaryTab->>User: Display tab content
Loading

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 or @coderabbitai title 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: 4

Outside diff range and nitpick comments (5)
src/components/ha-md-tabs.ts (4)

4-5: Remove unused imports to clean up the codebase

The components ha-icon-button-prev and ha-icon-button-next are imported but not used in this file. Since the left and right arrows have been removed as per the PR objectives, these imports are no longer necessary and can be safely deleted.

Apply the following diff to remove the unused imports:

-import "./ha-icon-button-prev";
-import "./ha-icon-button-next";

10-11: Remove unused property 'hass' if it's not needed

The property hass is declared but not used within this component. If it's not required, consider removing it to simplify the code.

Apply the following diff to remove the unused property:

  export class HaMdTabs extends MdTabs {
-   @property({ attribute: false }) public hass!: HomeAssistant;

27-27: Refine type assertions to enhance type safety

In the expressions (slider! as any).offsetLeft, the use of as any and non-null assertions bypasses TypeScript's type checking, potentially hiding issues. Consider refining the type of slider to avoid casting to any and using non-null assertions.

Specify the type of slider as HTMLElement:

-    const slider = this.shadowRoot?.querySelector(".tabs");
+    const slider = this.shadowRoot?.querySelector(".tabs") as HTMLElement | null;

Then, you can remove as any and the non-null assertion:

-    startX = e.pageX - (slider! as any).offsetLeft;
+    startX = e.pageX - slider.offsetLeft;

-    const x = e.pageX - (slider! as any).offsetLeft;
+    const x = e.pageX - slider.offsetLeft;

Also applies to: 49-49


61-74: Combine duplicate ':host' selectors in CSS for cleaner code

There are two :host selectors in the styles. Consider combining them into a single :host block to improve readability and maintainability.

Apply the following diff:

 :host {
   --md-sys-color-primary: var(--primary-color);
   --md-sys-color-secondary: var(--secondary-color);
   --md-sys-color-surface: var(--card-background-color);
   --md-sys-color-on-surface: var(--primary-color);
   --md-sys-color-on-surface-variant: var(--secondary-color);
   --md-divider-thickness: 0px;
   --md-primary-tab-container-height: 56px;
   --md-secondary-tab-container-height: 56px;
+  scroll-behavior: unset;
 }

- :host {
-   scroll-behavior: unset;
- }
src/panels/lovelace/hui-root.ts (1)

466-466: Review the use of 'slot="icon"' on 'ha-icon-button'

At line 466, the ha-icon-button includes a slot="icon" attribute. Unless this button is intended to be placed into an icon slot of a parent component, the slot attribute may be unnecessary.

Apply this diff if the slot="icon" is not needed:

-<ha-icon-button
-  id="add-view"
-  @click=${this._addView}
-  .label=${this.hass!.localize(
-    "ui.panel.lovelace.editor.edit_view.add"
-  )}
-  .path=${mdiPlus}
-  slot="icon"
-></ha-icon-button>
+<ha-icon-button
+  id="add-view"
+  @click=${this._addView}
+  .label=${this.hass!.localize(
+    "ui.panel.lovelace.editor.edit_view.add"
+  )}
+  .path=${mdiPlus}
+></ha-icon-button>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3478bd3 and 0027c37.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (11)
  • demo/src/configs/jimpower/theme.ts (0 hunks)
  • demo/src/configs/kernehed/theme.ts (0 hunks)
  • package.json (0 hunks)
  • src/components/ha-md-primary-tab.ts (1 hunks)
  • src/components/ha-md-secondary-tab.ts (1 hunks)
  • src/components/ha-md-tabs.ts (1 hunks)
  • src/components/ha-tabs.ts (0 hunks)
  • src/panels/developer-tools/ha-panel-developer-tools.ts (7 hunks)
  • src/panels/lovelace/editor/config-elements/hui-conditional-card-editor.ts (4 hunks)
  • src/panels/lovelace/editor/config-elements/hui-stack-card-editor.ts (4 hunks)
  • src/panels/lovelace/hui-root.ts (10 hunks)
Files not reviewed due to no reviewable changes (4)
  • demo/src/configs/jimpower/theme.ts
  • demo/src/configs/kernehed/theme.ts
  • package.json
  • src/components/ha-tabs.ts
Additional comments not posted (21)
src/components/ha-md-primary-tab.ts (1)

1-11: LGTM!

The code correctly defines a new custom element ha-md-primary-tab that extends the MdPrimaryTab class from the @material/web library. The custom element is properly defined using the @customElement decorator and declared in the global HTMLElementTagNameMap interface.

The custom element does not add any new functionality or modify the behavior of the base class, making it a simple wrapper around the MdPrimaryTab class.

src/components/ha-md-secondary-tab.ts (1)

1-11: LGTM!

The code segment correctly defines a new custom element ha-md-secondary-tab by extending the MdSecondaryTab class from the @material/web library. It follows the proper syntax for defining custom elements using the lit library and declares the custom element in the global HTMLElementTagNameMap interface for type checking and autocompletion.

The use of the @material/web library ensures consistency with the Material Design guidelines and provides a reliable implementation of the secondary tab component.

src/panels/lovelace/editor/config-elements/hui-conditional-card-editor.ts (4)

26-26: LGTM!

The import statement for the ha-md-secondary-tab component is correctly added.


81-95: LGTM!

The tab components have been correctly replaced with the new ha-md-tabs and ha-md-secondary-tab components. The event handling and label localization are also updated accordingly.


159-160: LGTM!

The _selectTab method signature and event handling logic are correctly updated to work with the new tab component.


260-262: LGTM!

The CSS styles for the ha-md-tabs component are correctly added, including the text transformation to uppercase.

src/panels/lovelace/editor/config-elements/hui-stack-card-editor.ts (4)

42-43: LGTM!

The imports for the new custom tab components look good.


122-134: Looks good!

The transition from Polymer tab components to the new custom tab components has been implemented correctly. The usage of activeTabIndex, @change event, and ha-md-secondary-tab component is appropriate.


223-223: LGTM!

The selected card index is correctly updated based on the activeTabIndex property of the new custom tab component.


322-322: Looks good!

The toolbar width has been appropriately set to 100%.

src/panels/developer-tools/ha-panel-developer-tools.ts (4)

67-81: Implementation of ha-md-tabs enhances tab navigation

The use of the ha-md-tabs component with proper binding of activeTabIndex and event handling improves the tab navigation experience and aligns with Material Design guidelines.


91-97: Correct handling of tab change events in _handleTabChanged

The event handler appropriately updates _activeTabIndex and navigates to the new route when the selected tab changes, ensuring the UI stays in sync with the application state.


158-167: Styles for ha-md-tabs are correctly applied

The additional styles ensure that the ha-md-tabs component integrates seamlessly with the application's theme, maintaining visual consistency across different components.


16-24: Verify that tab.label matches existing localization keys

The label property in the tabs array is used to construct localization keys like ui.panel.developer-tools.tabs.${tab.label}.title. Please ensure that these keys exist for all tabs, especially for 'states' and 'actions', to guarantee that tab labels are correctly localized.

Run the following script to check for the presence of the localization keys:

Verification successful

Localization keys for developer tools tabs are present and consistent

After thorough investigation, I can confirm that the localization keys for the developer tools tabs exist in the main translation file (src/translations/en.json). The keys follow the pattern "ui.panel.developer-tools.tabs.${tab.label}.title" as expected. Specifically:

  • The 'yaml', 'states', 'actions', 'templates', 'events', 'statistics', and 'assist' labels used in the tabs array have corresponding entries in the translation file.
  • The 'states' and 'actions' labels, which were of particular concern in the original comment, are present and correctly formatted.

There's no need for manual verification as the localization structure is consistent with the implementation. The review comment's concern about ensuring the existence of these keys has been addressed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that localization keys for developer tools tabs exist.

# Test: Search for localization keys. Expect: Keys to be defined in localization files.
rg '("|\')ui\.panel\.developer-tools\.tabs\.(yaml|states|actions|templates|events|statistics|assist)\.title("|\')' -g '*.json'

Length of output: 263


Script:

#!/bin/bash
# Description: Verify that localization keys for developer tools tabs exist.

# Test: Search for localization keys. Expect: Keys to be defined in localization files.
rg "ui\.panel\.developer-tools\.tabs\.(yaml|states?|actions?|templates?|events?|statistics|assist)\.title" -g "*.json"

Length of output: 120


Script:

#!/bin/bash
# Description: Investigate localization file structure and content

# Check for JSON files
echo "Searching for JSON files:"
fd -e json

echo "\nSearching for other potential localization files:"
fd -e yaml -e yml -e po

echo "\nSearching for files with 'lang' or 'localization' in the name:"
fd -g "*lang*" -g "*localization*"

echo "\nSearching for 'developer-tools' string in all files:"
rg "developer-tools" -g "!*.{lock,svg,png,jpg}"

Length of output: 33318

src/panels/lovelace/hui-root.ts (7)

25-25: Importing 'nothing' from 'lit'

The addition of the nothing import from lit is appropriate for use in conditional rendering within templates.


51-53: Added imports for new Material Design tab components

The imports of ha-md-tabs, ha-md-primary-tab, and ha-md-secondary-tab correctly include the new Material Design tab components required for the replacement of Polymer paper-tabs.


338-338: Verify correct usage of 'ha-md-tabs' properties and events

The ha-md-tabs component is initialized with the .activeTabIndex property and the @change event handler. Ensure that:

  • The .activeTabIndex property correctly reflects the currently active tab index.
  • The @change event is the appropriate event to listen for tab changes with ha-md-tabs.
  • The _handleViewSelected method correctly handles the event.

Also applies to: 340-342


1016-1017: Defined '.flexrow' CSS class for layout

The addition of the .flexrow class with display: flex; improves the layout styling for flex container elements.


1022-1024: Updated styles for 'ha-md-tabs' in edit mode

The CSS styles for ha-md-tabs in edit mode are updated to match the editing theme, ensuring consistent appearance during editing.


1037-1039: Show edit icons only on active tabs

The CSS rule displays .edit-icon elements only when their parent ha-md-secondary-tab has the active attribute. This helps maintain a clean interface by showing edit options only for the active tab.


1095-1113: Applied custom theming to 'ha-md-tabs'

Custom CSS variables are set for ha-md-tabs to align with the application's header text and background colors, ensuring cohesive theming across the interface.

src/components/ha-md-tabs.ts Show resolved Hide resolved
src/panels/lovelace/hui-root.ts Show resolved Hide resolved
@silamon
Copy link
Contributor Author

silamon commented Oct 21, 2024

This branch has been rebased, polish work done, but now awaiting review.
I can't test this on iOS unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Demo Related to frontend demo content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants