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

Improve user and person dialogs #21162

Merged
merged 4 commits into from
Jun 26, 2024
Merged

Improve user and person dialogs #21162

merged 4 commits into from
Jun 26, 2024

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Jun 25, 2024

Proposed change

With the introduction of username edition (#21152), buttons didn't fit the different dialogs.
I used ha-settings-row component as form elements to have consistent UI for each dialog.
We have room for improvement to merge person/user or at least makes the UX better but that PR only changes the UI, not the UX.

Person dialog (without user access)

CleanShot 2024-06-25 at 11 58 37

Person dialog (with user access)

CleanShot 2024-06-25 at 11 58 16

Add user dialog

CleanShot 2024-06-25 at 12 00 06

Delete user dialog

CleanShot 2024-06-25 at 11 58 26

Advanced user dialog (normal user)

CleanShot 2024-06-25 at 11 59 06

Advanced user dialog (system user)

CleanShot 2024-06-25 at 11 59 13

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

    • Enhanced user settings and detail dialogs with improved layout and new functionalities.
    • Added new components for button and settings row, enhancing user interaction.
    • Introduced alerts and conditional rendering for better user feedback.
  • Bug Fixes

    • Fixed layout issues by transitioning to consistent settings row components.
  • Documentation

    • Updated translation strings for user management, including new fields and descriptions.
  • Refactor

    • Reorganized import statements and updated method structures for better code maintenance.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

Walkthrough

The overall changes focus on importing custom components to enhance the UI, restructuring layouts for better organization, and updating user interaction elements across several dialog components. Specific improvements include integrating settings rows, refining button functionalities, adding user privileges control, and providing better descriptive text in the UI.

Changes

File Change Summary
src/panels/config/person/dialog-person-detail.ts Imported new components (ha-button, ha-icon-button, ha-settings-row), restructured form fields, updated button components, and added user settings functionality.
src/panels/config/users/dialog-add-user.ts Updated to use custom components (ha-alert, ha-button, ha-icon-button, ha-settings-row), restructured form layout, and made text adjustments for user privileges.
src/panels/config/users/dialog-user-detail.ts Reorganized layout, added conditional rendering, improved user interaction elements, imported custom components, and added new settings rows for user details.
src/translations/en.json Restructured text keys related to user management and added descriptions and confirmation messages for user settings.
src/panels/config/users/dialog-admin-change-password.ts Changed the primary action button to a secondary action button in the DialogAdminChangePassword dialog.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DialogAddUser
    participant CustomComponents
    participant Backend
    
    User->>DialogAddUser: Open Add User Dialog
    DialogAddUser->>CustomComponents: Load ha-settings-row
    DialogAddUser->>CustomComponents: Load ha-button
    DialogAddUser->>CustomComponents: Load ha-icon-button
    DialogAddUser->>CustomComponents: Load ha-alert
    CustomComponents-->>DialogAddUser: Components Loaded
    User->>DialogAddUser: Fill in User Details
    User->>DialogAddUser: Click Create User
    DialogAddUser->>Backend: Submit User Details
    Backend-->>DialogAddUser: User Created
    DialogAddUser-->>User: Display Success Message
Loading
sequenceDiagram
    participant User
    participant DialogPersonDetail
    participant CustomComponents
    
    User->>DialogPersonDetail: Open Person Detail Dialog
    DialogPersonDetail->>CustomComponents: Load ha-button
    DialogPersonDetail->>CustomComponents: Load ha-icon-button
    DialogPersonDetail->>CustomComponents: Load ha-settings-row
    CustomComponents-->>DialogPersonDetail: Components Loaded
    User->>DialogPersonDetail: Update Person Details
    DialogPersonDetail-->>User: Display Updated Details
Loading
sequenceDiagram
    participant User
    participant DialogUserDetail
    participant CustomComponents
    participant Backend
    
    User->>DialogUserDetail: Open User Detail Dialog
    DialogUserDetail->>CustomComponents: Load ha-settings-row
    DialogUserDetail->>CustomComponents: Load ha-button
    DialogUserDetail->>CustomComponents: Load ha-icon-button
    DialogUserDetail->>CustomComponents: Load ha-alert
    CustomComponents-->>DialogUserDetail: Components Loaded
    User->>DialogUserDetail: Modify User Settings
    DialogUserDetail->>Backend: Submit Changes
    Backend-->>DialogUserDetail: Confirm Changes
    DialogUserDetail-->>User: Display Updated Settings
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e9e75c2 and e9bb6dc.

Files selected for processing (1)
  • src/panels/config/users/dialog-admin-change-password.ts (1 hunks)
Additional context used
Biome
src/panels/config/users/dialog-admin-change-password.ts

[error] 75-75: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 80-81: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 163-163: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 167-167: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

Additional comments not posted (1)
src/panels/config/users/dialog-admin-change-password.ts (1)

135-135: Change the button slot to align with new functionality.

The change from a primary action to a secondary action for the cancel button is appropriate given the context of the operation. This helps in distinguishing between the primary operation (changing the password) and secondary operations (like canceling the operation).


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.

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

Outside diff range comments (4)
src/panels/config/users/dialog-add-user.ts (2)

Line range hint 272-272: Type safety issue with the use of 'any'.

Using 'any' type can lead to potential bugs and maintenance issues as it bypasses TypeScript's static type checking. Consider specifying more appropriate types to enhance code robustness and maintainability.

- catch (err: any) {
+ catch (err: Error) {

Also applies to: 285-285


Line range hint 293-293: Avoid non-null assertions when not absolutely necessary.

Using non-null assertions bypasses TypeScript's nullability checks, which can lead to runtime errors. Consider using optional chaining or proper checks before accessing properties.

- this._params!.userAddedCallback(user);
+ this._params?.userAddedCallback(user);
src/panels/config/users/dialog-user-detail.ts (1)

Line range hint 57-57: Function complexity exceeds recommended limit.

The render method's complexity is too high, which can make the code harder to maintain and understand. Consider refactoring into smaller, more manageable functions.

src/panels/config/person/dialog-person-detail.ts (1)

Line range hint 118-118: Multiple instances of unsafe non-null assertions and recommended use of optional chaining.

The frequent use of non-null assertions (!) could lead to runtime errors if the objects turn out to be null. It's recommended to use optional chaining (?.) to safely access properties.

- this._params!.entry.name
+ this._params?.entry?.name
- this._params!.removeEntry()
+ this._params?.removeEntry()
- this._params!.entry.username!
+ this._params?.entry?.username
- this._params!.updateEntry(values)
+ this._params?.updateEntry(values)
- this._params!.entry.user_id
+ this._params?.entry?.user_id
- this._params!.refreshUsers()
+ this._params?.refreshUsers()

Also applies to: 128-128, 129-129, 145-145, 150-150, 188-188, 201-201, 211-211, 226-226, 229-229, 239-239, 240-240, 356-356, 357-357, 371-371, 374-374, 378-378, 379-379, 445-445, 457-457

src/panels/config/users/dialog-user-detail.ts Show resolved Hide resolved
silamon
silamon previously approved these changes Jun 25, 2024
Copy link
Contributor

@silamon silamon left a comment

Choose a reason for hiding this comment

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

Great to have some improvements in this area.

Just had a few problems while testing with the change password dialog (dialog-admin-change-password):

  • There's a duplicate primaryAction there (so hitting enter doesn't save). Cancel should be secondaryAction.
  • You can escape the dialog or click in the scrimaction

The escape / scrim action is enabled for the change-username dialog, not for the dialog-admin-change-password.

@piitaya
Copy link
Member Author

piitaya commented Jun 25, 2024

Thank you @silamon, I will address the feedbacks 🙂

c0ffeeca7 added a commit to home-assistant/home-assistant.io that referenced this pull request Jun 25, 2024
- add procedure to refelct current software
- related to home-assistant/frontend#21162
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: 0

Outside diff range comments (4)
src/panels/config/users/dialog-admin-change-password.ts (4)

Line range hint 75-75: Avoid using any type for error handling.

Using any type can lead to potential bugs and maintainability issues as it disables TypeScript's static type checking. Consider specifying a more explicit type for the error handling.

- catch (err: any) {
+ catch (err: Error) {

Line range hint 80-81: Consider using optional chaining for better safety and readability.

Optional chaining (?.) can be used here to safely access nested properties. This will prevent runtime errors if some properties are not available.

- if (!this._userId || !this._data?.new_password) return;
+ if (!this._userId || !this._data?.new_password?) return;

Line range hint 163-163: Remove non-null assertion to ensure type safety.

The non-null assertion operator (!) bypasses TypeScript's strict null checks, which can lead to unexpected runtime errors. Consider handling potential null or undefined values explicitly.

- this._userId!,
+ this._userId ?? throw new Error("User ID is required");

Line range hint 167-167: Specify a more precise type instead of any.

Using any for the error type in the catch block reduces the effectiveness of TypeScript's type system. Specifying a more detailed type can help catch errors at compile time.

- catch (err: any) {
+ catch (err: Error) {

@bramkragten bramkragten merged commit 1acada6 into dev Jun 26, 2024
13 checks passed
@bramkragten bramkragten deleted the user-person-dialog branch June 26, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants