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 service filtering #19811

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/components/ha-service-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ 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();
Copy link
Member

Choose a reason for hiding this comment

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

service.name is marked optional in the original code, was that an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, any processedServices from here will always have a string with at least : in.

const lower_service = service.service.toLowerCase();
return (
split_filter.every((f) => lower_service_name.includes(f)) ||
split_filter.every((f) => lower_service.includes(f))
malkstar marked this conversation as resolved.
Show resolved Hide resolved
);
});
}
);

Expand Down
Loading