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 refresh token dialogs #20917

Merged
merged 2 commits into from
May 30, 2024
Merged

Conversation

silamon
Copy link
Contributor

@silamon silamon commented May 30, 2024

Proposed change

Fix #20911. The issue mentions:

Consistent dialogs

  • All dialogs should have red "Delete" buttons since it's destructive action.
  • For last two examples instead of the dialog titles being "Are you sure?" it should maybe be more descriptive like "Delete all refresh tokens?" and "Delete this long-lived access token?"

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

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

    • Added confirmation dialogs with localized titles and texts for deleting long-lived access tokens and refresh tokens in profile panels.
    • Enhanced user interaction by providing clearer prompts for deletion operations.
  • Localization

    • Updated confirmation messages and added new prompts for user actions related to multiselect functionality and token deletions.

@silamon silamon added this to the 2024.6 milestone May 30, 2024
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

Walkthrough

The changes enhance the user experience for deleting tokens in the profile panel by adding confirmation dialogs with localized titles, confirmation texts, and a more descriptive destructive action indication. This ensures consistency across different dialogs for deleting refresh tokens and long-lived access tokens.

Changes

File Path Change Summary
src/panels/profile/ha-long-lived-access-tokens-card.ts Added confirmation dialog with title, confirm text, and destructive action indication for deleting long-lived access tokens.
src/panels/profile/ha-refresh-tokens-card.ts Added localized titles and confirmation text for deletion operations in the profile panel.
src/translations/en.json Updated messages for multiselect functionality and added new prompts for deleting refresh and long-lived access tokens.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant ProfilePanel
    participant ConfirmationDialog
    participant Localization

    User ->> ProfilePanel: Request to delete a token
    ProfilePanel ->> Localization: Fetch localized title and confirm text
    Localization -->> ProfilePanel: Return localized strings
    ProfilePanel ->> ConfirmationDialog: Open with localized title and confirm text
    ConfirmationDialog -->> User: Display confirmation dialog
    User ->> ConfirmationDialog: Confirms deletion
    ConfirmationDialog ->> ProfilePanel: Confirm deletion action
    ProfilePanel ->> User: Token deleted
Loading

Assessment against linked issues

Objective Addressed Explanation
Consistent dialogs for deleting refresh tokens and long-lived tokens (#20911)
Descriptive titles for deletion confirmation dialogs (#20911)
Red "Delete" buttons for destructive actions (#20911)
Localized confirmation messages for better user interaction (#20911)

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between c00287c and 7503e30.

Files selected for processing (3)
  • src/panels/profile/ha-long-lived-access-tokens-card.ts (1 hunks)
  • src/panels/profile/ha-refresh-tokens-card.ts (1 hunks)
  • src/translations/en.json (3 hunks)
Additional context used
Biome
src/panels/profile/ha-long-lived-access-tokens-card.ts

[error] 35-35: Forbidden non-null assertion.


[error] 63-63: Forbidden non-null assertion.


[error] 124-124: Unexpected any. Specify a different type.


[error] 135-135: Unexpected any. Specify a different type.


[error] 157-157: Unexpected any. Specify a different type.


[error] 2-3: Some named imports are only used as types.


[error] 10-11: All these imports are only used as types.


[error] 17-18: All these imports are only used as types.

src/panels/profile/ha-refresh-tokens-card.ts

[error] 211-211: Unexpected any. Specify a different type.


[error] 285-285: Unexpected any. Specify a different type.


[error] 313-313: Unexpected any. Specify a different type.


[error] 11-19: Some named imports are only used as types.


[error] 29-30: All these imports are only used as types.


[error] 35-36: All these imports are only used as types.

Additional comments not posted (5)
src/panels/profile/ha-long-lived-access-tokens-card.ts (1)

138-146: The updated confirmation dialog for deleting long-lived access tokens now includes a descriptive title and a red "Delete" button, aligning with the PR objectives to enhance clarity and consistency in user prompts. This change effectively addresses the user experience issue outlined in the linked issue.

src/panels/profile/ha-refresh-tokens-card.ts (1)

298-304: The confirmation dialog for deleting all refresh tokens has been updated to include a descriptive title and a red "Delete" button, consistent with the PR's goal to standardize destructive action prompts. This change enhances user understanding and decision-making.

src/translations/en.json (3)

1891-1893: The addition of new entries under the "updates" key aligns well with the PR objectives to enhance clarity and consistency in user dialogs.


6410-6410: The new localization keys for deleting refresh tokens are clear and descriptive, enhancing user understanding of the actions being taken.

Also applies to: 6421-6421


6420-6421: The new localization keys for deleting long-lived access tokens are appropriately descriptive and align with the PR's goal of improving clarity in user dialogs.


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

Outside diff range comments (3)
src/panels/profile/ha-long-lived-access-tokens-card.ts (2)

Line range hint 35-35: Consider replacing non-null assertions with more robust error handling or conditional checks. Non-null assertions can lead to runtime errors if assumptions about data presence are incorrect.

// Example refactor for non-null assertion
const accessTokens = this._accessTokens(this.refreshTokens ?? []);

Also applies to: 63-63


Line range hint 124-124: The use of any type for error handling reduces type safety and can obscure the underlying data structure of errors. It's recommended to define a more specific error type or interface.

// Example of specifying a more detailed error type
interface CustomError extends Error {
  code?: string;
}

catch (err: CustomError) {
  showAlertDialog(this, {
    title: this.hass.localize("ui.panel.profile.long_lived_access_tokens.delete_failed"),
    text: err.message,
  });
}

Also applies to: 135-135, 157-157

src/panels/profile/ha-refresh-tokens-card.ts (1)

Line range hint 211-211: Similar to the previous file, using any for error handling is not recommended due to the lack of type safety. Consider defining a more specific error type to improve code clarity and error management.

// Example of specifying a more detailed error type
interface CustomError extends Error {
  code?: string;
}

catch (err: CustomError) {
  showAlertDialog(this, {
    title: this.hass.localize("ui.panel.profile.refresh_tokens.delete_failed"),
    text: err.message,
  });
}

Also applies to: 285-285, 313-313

@matthiasdebaat
Copy link
Collaborator

Thanks creating this PR! We've written some guidelines about dialogs. May I suggest the following text, @piitaya can you check if this text is correct?

image
Only change the last sentence to: This associated device will not have access anymore.
[Cancel] [Delete]

image

Delete all refresh tokens?
[number of tokens] wil be permanently deleted. These associated devices will not have access anymore. Your current session and long-lived access tokens will not be deleted.
[Cancel] [Delete all]

image

Delete long-lived access token?
The long-lived access token for '[identifier]' will be permanently deleted. This associated device will not have access anymore.
[Cancel] [Delete]

@piitaya
Copy link
Member

piitaya commented May 30, 2024

Thank you @silamon 👍
The wording is ok for now. As discussed with @matthiasdebaat and @bramkragten, we should rework on the wording by using the word device or client. Refresh token is a bit too technical for most users. But that should be another PR.

@piitaya piitaya merged commit f97971f into home-assistant:dev May 30, 2024
13 checks passed
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.

Inconsistent dialogs for deleting refresh tokens and long-lived tokens
4 participants