Skip to content

Commit

Permalink
Improve service filtering (#19811)
Browse files Browse the repository at this point in the history
* Improve service filtering

Split filter term by space and match if each word is individually present

* Prettier formatting

* Fix un-necessary toLowerCase() call

Co-authored-by: karwosts <[email protected]>

* Combine filter check conditions into the same loop

* Prettier formatting

---------

Co-authored-by: karwosts <[email protected]>
  • Loading branch information
malkstar and karwosts authored Feb 28, 2024
1 parent 83190c2 commit 401bbed
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/ha-service-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ class HaServicePicker extends LitElement {
if (!filter) {
return processedServices;
}
return processedServices.filter(
(service) =>
service.service.toLowerCase().includes(filter) ||
service.name?.toLowerCase().includes(filter)
);
const split_filter = filter.split(" ");
return processedServices.filter((service) => {
const lower_service_name = service.name.toLowerCase();
const lower_service = service.service.toLowerCase();
return split_filter.every(
(f) => lower_service_name.includes(f) || lower_service.includes(f)
);
});
}
);

Expand Down

0 comments on commit 401bbed

Please sign in to comment.