Skip to content

Commit

Permalink
20240626.2 (#21181)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Jun 26, 2024
2 parents 530745d + ccad1af commit 5bc3ad4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
3 changes: 2 additions & 1 deletion hassio/src/components/hassio-filter-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import type { IFuseOptions } from "fuse.js";
import Fuse from "fuse.js";
import { stripDiacritics } from "../../../src/common/string/strip-diacritics";
import { StoreAddon } from "../../../src/data/supervisor/store";
import { getStripDiacriticsFn } from "../../../src/util/fuse";

export function filterAndSort(addons: StoreAddon[], filter: string) {
const options: IFuseOptions<StoreAddon> = {
keys: ["name", "description", "slug"],
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
getFn: (obj, path) => stripDiacritics(Fuse.config.getFn(obj, path)),
getFn: getStripDiacriticsFn,
};
const fuse = new Fuse(addons, options);
return fuse.search(stripDiacritics(filter)).map((result) => result.item);
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "home-assistant-frontend"
version = "20240626.0"
version = "20240626.2"
license = {text = "Apache-2.0"}
description = "The Home Assistant frontend"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/common/string/strip-diacritics.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const stripDiacritics = (str) =>
export const stripDiacritics = (str: string) =>
str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
5 changes: 3 additions & 2 deletions src/panels/config/automation/add-automation-element-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import memoizeOne from "memoize-one";
import { fireEvent } from "../../../common/dom/fire_event";
import { computeDomain } from "../../../common/entity/compute_domain";
import { stringCompare } from "../../../common/string/compare";
import { stripDiacritics } from "../../../common/string/strip-diacritics";
import { LocalizeFunc } from "../../../common/translations/localize";
import { deepEqual } from "../../../common/util/deep-equal";
import "../../../components/ha-dialog";
Expand Down Expand Up @@ -50,11 +51,11 @@ import { TRIGGER_GROUPS, TRIGGER_ICONS } from "../../../data/trigger";
import { HassDialog } from "../../../dialogs/make-dialog-manager";
import { haStyle, haStyleDialog } from "../../../resources/styles";
import { HomeAssistant } from "../../../types";
import { getStripDiacriticsFn } from "../../../util/fuse";
import {
AddAutomationElementDialogParams,
PASTE_VALUE,
} from "./show-add-automation-element-dialog";
import { stripDiacritics } from "../../../common/string/strip-diacritics";

const TYPES = {
trigger: { groups: TRIGGER_GROUPS, icons: TRIGGER_ICONS },
Expand Down Expand Up @@ -209,7 +210,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
getFn: (obj, path) => stripDiacritics(Fuse.config.getFn(obj, path)),
getFn: getStripDiacriticsFn,
};
const fuse = new Fuse(items, options);
return fuse.search(stripDiacritics(filter)).map((result) => result.item);
Expand Down
3 changes: 2 additions & 1 deletion src/panels/config/integrations/dialog-add-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
} from "./show-add-integration-dialog";
import { getConfigEntries } from "../../../data/config_entries";
import { stripDiacritics } from "../../../common/string/strip-diacritics";
import { getStripDiacriticsFn } from "../../../util/fuse";

export interface IntegrationListItem {
name: string;
Expand Down Expand Up @@ -256,7 +257,7 @@ class AddIntegrationDialog extends LitElement {
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
getFn: (obj, path) => stripDiacritics(Fuse.config.getFn(obj, path)),
getFn: getStripDiacriticsFn,
};
const helpers = Object.entries(h).map(([domain, integration]) => ({
domain,
Expand Down
25 changes: 13 additions & 12 deletions src/panels/config/integrations/ha-config-integrations-dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { ActionDetail } from "@material/mwc-list";
import { mdiFilterVariant, mdiPlus } from "@mdi/js";
import Fuse from "fuse.js";
import type { IFuseOptions } from "fuse.js";
import Fuse from "fuse.js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import {
css,
CSSResultGroup,
html,
LitElement,
nothing,
PropertyValues,
css,
html,
nothing,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import memoizeOne from "memoize-one";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import {
protocolIntegrationPicked,
PROTOCOL_INTEGRATIONS,
protocolIntegrationPicked,
} from "../../../common/integrations/protocolIntegrationPicked";
import { navigate } from "../../../common/navigate";
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
import { stripDiacritics } from "../../../common/string/strip-diacritics";
import { extractSearchParam } from "../../../common/url/search-params";
import { nextRender } from "../../../common/util/render-status";
import "../../../components/ha-button-menu";
Expand All @@ -29,6 +31,7 @@ import "../../../components/ha-fab";
import "../../../components/ha-icon-button";
import "../../../components/ha-svg-icon";
import "../../../components/search-input";
import "../../../components/search-input-outlined";
import { ConfigEntry, getConfigEntries } from "../../../data/config_entries";
import { getConfigFlowInProgressCollection } from "../../../data/config_flow";
import { fetchDiagnosticHandlers } from "../../../data/diagnostics";
Expand All @@ -37,11 +40,11 @@ import {
subscribeEntityRegistry,
} from "../../../data/entity_registry";
import {
IntegrationLogInfo,
IntegrationManifest,
domainToName,
fetchIntegrationManifest,
fetchIntegrationManifests,
IntegrationLogInfo,
IntegrationManifest,
subscribeLogInfo,
} from "../../../data/integration";
import {
Expand All @@ -59,19 +62,17 @@ import "../../../layouts/hass-tabs-subpage";
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
import { haStyle } from "../../../resources/styles";
import type { HomeAssistant, Route } from "../../../types";
import { getStripDiacriticsFn } from "../../../util/fuse";
import { configSections } from "../ha-panel-config";
import { isHelperDomain } from "../helpers/const";
import "./ha-config-flow-card";
import { DataEntryFlowProgressExtended } from "./ha-config-integrations";
import "./ha-disabled-config-entry-card";
import "./ha-ignored-config-entry-card";
import "./ha-integration-card";
import type { HaIntegrationCard } from "./ha-integration-card";
import "./ha-integration-overflow-menu";
import { showAddIntegrationDialog } from "./show-add-integration-dialog";
import "./ha-disabled-config-entry-card";
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
import "../../../components/search-input-outlined";
import { stripDiacritics } from "../../../common/string/strip-diacritics";

export interface ConfigEntryExtended extends ConfigEntry {
localized_domain_name?: string;
Expand Down Expand Up @@ -209,7 +210,7 @@ class HaConfigIntegrationsDashboard extends SubscribeMixin(LitElement) {
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
getFn: (obj, path) => stripDiacritics(Fuse.config.getFn(obj, path)),
getFn: getStripDiacriticsFn,
};
const fuse = new Fuse(configEntriesInProgress, options);
filteredEntries = fuse
Expand Down
2 changes: 2 additions & 0 deletions src/panels/lovelace/cards/hui-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export class HuiCard extends ReactiveElement {
"ll-upgrade",
(ev: Event) => {
ev.stopPropagation();
element.hass = this.hass;
element.preview = this.preview;
fireEvent(this, "card-updated");
},
{ once: true }
Expand Down
3 changes: 2 additions & 1 deletion src/panels/lovelace/editor/card-editor/hui-card-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getCustomCardEntry,
} from "../../../../data/lovelace_custom_cards";
import type { HomeAssistant } from "../../../../types";
import { getStripDiacriticsFn } from "../../../../util/fuse";
import {
calcUnusedEntities,
computeUsedEntities,
Expand Down Expand Up @@ -87,7 +88,7 @@ export class HuiCardPicker extends LitElement {
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
getFn: (obj, path) => stripDiacritics(Fuse.config.getFn(obj, path)),
getFn: getStripDiacriticsFn,
};
const fuse = new Fuse(cards, options);
cards = fuse.search(stripDiacritics(filter)).map((result) => result.item);
Expand Down
12 changes: 12 additions & 0 deletions src/util/fuse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Fuse from "fuse.js";
import { stripDiacritics } from "../common/string/strip-diacritics";

type GetFn = typeof Fuse.config.getFn;

export const getStripDiacriticsFn: GetFn = (obj, path) => {
const value = Fuse.config.getFn(obj, path);
if (Array.isArray(value)) {
return value.map((v) => stripDiacritics(v ?? ""));
}
return stripDiacritics((value as string | undefined) ?? "");
};

0 comments on commit 5bc3ad4

Please sign in to comment.