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

Use tags and aliases when filtering icons in Icon Picker #10425

Merged
merged 7 commits into from
Oct 27, 2021
Merged

Use tags and aliases when filtering icons in Icon Picker #10425

merged 7 commits into from
Oct 27, 2021

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Oct 27, 2021

Breaking change

No breaking change

Proposed change

Use the available tags and aliases in mdi icon meta to improve search experience in icon picker.
If we merge that PR, we can update this PR #10399 to allow custom iconsets proposing tags and aliases too.

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:

Comment on lines 152 to 155
const getItemScore = (item: IconItem): number =>
item.icon.includes(filterString) ? 1 : 0;

filteredItems.sort((i1, i2) => getItemScore(i2) - getItemScore(i1));
Copy link
Member Author

Choose a reason for hiding this comment

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

The items are sorted to have the icon containing the filterString first. If you search home, you want icons containing home word instead of home automation tagged icons.

@piitaya piitaya changed the title Use tags and aliases for filter icons in Icon Picker Use tags and aliases when filtering icons in Icon Picker Oct 27, 2021
Comment on lines 17 to 18
aliases: string[];
tags: string[];
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this 1 array

@bramkragten
Copy link
Member

So how is performance? 😃

name: string;
aliases: string[];
tags: string[];
tagsAndAliases: string[];
Copy link
Member

Choose a reason for hiding this comment

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

Maybe name it keywords? Also for custom icons?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice ! I did not find a good name for it but you find it !

@piitaya
Copy link
Member Author

piitaya commented Oct 27, 2021

So how is performance? 😃

Performance is good (~60 ms max for the search). I optimized the search in this commit : f349749. It's more efficient than the sort.

Comment on lines 143 to 151
const filteredItems = iconItems.filter((item) =>
item.icon.includes(filterString)
);

const filteredItemsByTagsOrAliases = iconItems.filter(
(item) =>
item.icon.includes(filterString) ||
!item.icon.includes(filterString) &&
item.tagsAndAliases.some((t) => t.includes(filterString))
);
Copy link
Member

Choose a reason for hiding this comment

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

You can combine this in 1 for loop, so we don't have to loop it twice.

 iconItems.forEach((item) => {
        if (item.icon.includes(filterString)) {
          filteredItems.push(item);
          return;
        }
        if (item.keywords.some((t) => t.includes(filterString)) {
          filteredItemsByKeywords.push(item);
        }
      });

Copy link
Member Author

@piitaya piitaya Oct 27, 2021

Choose a reason for hiding this comment

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

Why return instead of else if ? Just code style ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we tend to return as quickly as possible

Comment on lines 149 to 150
tags: icon.tags.map((t) => t.toLowerCase().replace(/\s\/\s/g, " ")),
aliases: icon.aliases,
Copy link
Member

Choose a reason for hiding this comment

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

Let's combine it to keywords here already, makes the json smaller, and saves work on the client :-)

Copy link
Member

@bramkragten bramkragten left a comment

Choose a reason for hiding this comment

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

Nice! 🎉 will add it to the next beta (b1) 😃

@bramkragten
Copy link
Member

So how is performance? 😃

Performance is good (~60 ms max for the search). I optimized the search in this commit : f349749. It's more efficient than the sort.

What is the performance like now btw?

@piitaya
Copy link
Member Author

piitaya commented Oct 27, 2021

I will update the PR for custom iconsets to support keywords.

@bramkragten bramkragten enabled auto-merge (squash) October 27, 2021 20:06
@piitaya
Copy link
Member Author

piitaya commented Oct 27, 2021

So how is performance? 😃

Performance is good (~60 ms max for the search). I optimized the search in this commit : f349749. It's more efficient than the sort.

What is the performance like now btw?

I didn't notice any difference but the code is more logic.

@bramkragten bramkragten merged commit 74533ce into home-assistant:dev Oct 27, 2021
@piitaya piitaya mentioned this pull request Oct 27, 2021
9 tasks
@bramkragten bramkragten mentioned this pull request Oct 28, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants