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

Ignore diacritics (accents) in search #21150

Merged
merged 2 commits into from
Jun 26, 2024
Merged

Ignore diacritics (accents) in search #21150

merged 2 commits into from
Jun 26, 2024

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Jun 24, 2024

Proposed change

Searching with accents will now match in filter/search.
This will work for automation editor dialog, data table, quick bar, etc...

I also created a PR on Fuse repository to add this option and then avoid workaround when we use Fuse : krisk/Fuse#773

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 search functionality by incorporating diacritic stripping for more accurate and case-insensitive search results across multiple components.
  • Bug Fixes

    • Improved string matching logic to handle diacritics, ensuring consistent filtering and sorting behavior.

@github-actions github-actions bot added the Supervisor Related to the supervisor panel label Jun 24, 2024
Copy link
Contributor

coderabbitai bot commented Jun 24, 2024

Walkthrough

Walkthrough

The updates aim to enhance search functionality across various components by incorporating the stripDiacritics function. This ensures that searches become diacritic insensitive, leading to more accurate and user-friendly results. This change spans multiple files, adjusting filtering processes in components where string matching is essential, especially where user input is involved.

Changes

File(s) Change Summary
hassio/src/components/hassio-filter-addons.ts Imported stripDiacritics and applied it in the filterAndSort function to use with Fuse.config.getFn.
src/common/string/filter/sequence-matching.ts Utilized stripDiacritics in fuzzySequentialMatch for improved string matching.
src/common/string/strip-diacritics.ts Introduced the new stripDiacritics function for diacritic removal in strings.
src/components/data-table/sort-filter-worker.ts Applied stripDiacritics in filterData for normalizing strings before filtering.
src/panels/config/automation/add-automation-element-dialog.ts Modified getFn in DialogAddAutomationElement to use stripDiacritics.
src/panels/config/integrations/dialog-add-integration.ts Improved search logic by using stripDiacritics in filterWithAccents and getFn.
src/panels/config/integrations/ha-config-integrations-dashboard.ts Enhanced search by using stripDiacritics in getFn and filter processing.
src/panels/lovelace/editor/card-editor/hui-card-picker.ts Updated getFn and search functionality to include stripDiacritics for better search results.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 945e361 and 11f1c08.

Files selected for processing (1)
  • src/panels/config/integrations/dialog-add-integration.ts (3 hunks)
Additional context used
Biome
src/panels/config/integrations/dialog-add-integration.ts

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

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 192-192: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 26 to the max allowed complexity 15.


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


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


[error] 537-537: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 18 to the max allowed complexity 15.

Additional comments not posted (2)
src/panels/config/integrations/dialog-add-integration.ts (2)

58-58: Import stripDiacritics function

The import statement for stripDiacritics is correctly placed and follows project standards for relative path imports.


259-259: Use of stripDiacritics in getFn

The integration of stripDiacritics within the getFn method is a good practice as it ensures that diacritic characters do not affect the search functionality. However, ensure that Fuse.config.getFn can handle the modified input without any issues.


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

Outside diff range comments (5)
src/panels/lovelace/editor/card-editor/hui-card-picker.ts (1)

Line range hint 162-162: Replace non-null assertions with optional chaining.

The usage of non-null assertions (!) is risky as it assumes the existence of an object without validation. Replace these with optional chaining (?) to prevent runtime errors.

- this.hass!.localize(...)
+ this.hass?.localize(...)

- this.shadowRoot!.getElementById("content")
+ this.shadowRoot?.getElementById("content")

- fireEvent(this, "config-changed", { config });
+ fireEvent(this, "config-changed", { config });

Also applies to: 175-175, 187-187, 205-205, 210-210, 226-226, 243-243, 244-244, 248-248, 249-249, 257-257, 260-260, 324-324, 327-327, 353-353, 372-372, 403-403, 426-426, 427-427

src/panels/config/integrations/dialog-add-integration.ts (4)

Line range hint 157-157: Replace non-null assertion with optional chaining

Using non-null assertions can lead to runtime errors if the object is null. Replace it with optional chaining for safer code.

- this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect();
+ this.shadowRoot?.querySelector("mwc-list")?.getBoundingClientRect();

Line range hint 192-192: Refactor due to excessive cognitive complexity

The function has a high cognitive complexity. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.

Consider extracting parts of the function into separate methods or using more descriptive helper functions to handle specific parts of the logic.


Line range hint 297-297: Replace non-null assertions with optional chaining

Using non-null assertions can lead to runtime errors if the object is null. Replace it with optional chaining for safer code.

- this.shadowRoot!.querySelector(`[data-domain=${domain}]`)
+ this.shadowRoot?.querySelector(`[data-domain=${domain}]`)

Also applies to: 298-298


Line range hint 537-537: Refactor due to excessive cognitive complexity

The function has a high cognitive complexity. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.

Consider extracting parts of the function into separate methods or using more descriptive helper functions to handle specific parts of the logic.

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/integrations/dialog-add-integration.ts (4)

Line range hint 157-157: Replace non-null assertion with optional chaining

The non-null assertion operator is used, which might lead to runtime errors if not handled properly. Replace with optional chaining for safer access.

- this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect();
+ this.shadowRoot?.querySelector("mwc-list")?.getBoundingClientRect();

Line range hint 192-192: Reduce complexity in _filterIntegrations function

The _filterIntegrations function is flagged for excessive complexity. Consider breaking it down into smaller, more manageable functions or simplifying the logic.

Consider extracting parts of the logic into separate methods or using more streamlined logic constructs.


Line range hint 297-298: Replace non-null assertion with optional chaining

The non-null assertion operator is used multiple times, which might lead to runtime errors if not handled properly. Replace with optional chaining for safer access.

- this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect();
- this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect();
+ this.shadowRoot?.querySelector("mwc-list")?.getBoundingClientRect();
+ this.shadowRoot?.querySelector("mwc-list")?.getBoundingClientRect();

Line range hint 537-537: Reduce complexity in _handleIntegrationPicked function

The _handleIntegrationPicked function is flagged for excessive complexity. Consider breaking it down into smaller, more manageable functions or simplifying the logic.

Consider extracting parts of the logic into separate methods or using more streamlined logic constructs.

@bramkragten bramkragten merged commit f42a9ac into dev Jun 26, 2024
13 checks passed
@bramkragten bramkragten deleted the ignore_diacritics branch June 26, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Supervisor Related to the supervisor panel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants