diff --git a/src/components/ha-analytics-learn-more.ts b/src/components/ha-analytics-learn-more.ts new file mode 100644 index 0000000000..8b7c756efa --- /dev/null +++ b/src/components/ha-analytics-learn-more.ts @@ -0,0 +1,10 @@ +import { html } from "lit-element"; +import { HomeAssistant } from "../types"; +import { documentationUrl } from "../util/documentation-url"; + +export const analyticsLearnMore = (hass: HomeAssistant) => html`${hass.localize("ui.panel.config.core.section.core.analytics.learn_more")}`; diff --git a/src/components/ha-analytics.ts b/src/components/ha-analytics.ts index bbc4682e27..6cf9d37b07 100644 --- a/src/components/ha-analytics.ts +++ b/src/components/ha-analytics.ts @@ -13,7 +13,6 @@ import { fireEvent } from "../common/dom/fire_event"; import { Analytics, AnalyticsPreferences } from "../data/analytics"; import { haStyle } from "../resources/styles"; import { HomeAssistant } from "../types"; -import { documentationUrl } from "../util/documentation-url"; import "./ha-checkbox"; import type { HaCheckbox } from "./ha-checkbox"; import "./ha-settings-row"; @@ -30,38 +29,30 @@ declare global { export class HaAnalytics extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @property({ attribute: false }) public analytics!: Analytics; + @property({ attribute: false }) public analytics?: Analytics; protected render(): TemplateResult { - if (!this.analytics.huuid) { - return html``; - } - - const enabled = this.analytics.preferences.base; + const loading = this.analytics === undefined; + const baseEnabled = !loading && this.analytics!.preferences.base; return html` -
- ${this.hass.localize( - "ui.panel.config.core.section.core.analytics.instance_id", - "huuid", - this.analytics.huuid - )} -
- - ${this.hass.localize( - "ui.panel.config.core.section.core.analytics.learn_more" - )} - -
`; } + protected updated(changedProps) { + super.updated(changedProps); + + this.shadowRoot!.querySelectorAll("*[data-for]").forEach((el) => { + const forEl = (el as HTMLElement).dataset.for; + delete (el as HTMLElement).dataset.for; + + el.addEventListener("click", () => { + const toFocus = this.shadowRoot!.querySelector( + `*[name=${forEl}]` + ) as HTMLElement | null; + + if (toFocus) { + toFocus.focus(); + toFocus.click(); + } + }); + }); + } + private _handleRowCheckboxClick(ev: Event) { const checkbox = ev.currentTarget as HaCheckbox; const preference = (checkbox as any).preference; - const preferences = { ...this.analytics.preferences }; + const preferences = this.analytics ? { ...this.analytics.preferences } : {}; - if (checkbox.checked) { - if (preferences[preference]) { - return; - } - preferences[preference] = true; - } else { - preferences[preference] = false; + if (preferences[preference] === checkbox.checked) { + return; + } + + preferences[preference] = checkbox.checked; + + if (ADDITIONAL_PREFERENCES.includes(preference) && checkbox.checked) { + preferences.base = true; + } else if (preference === "base" && !checkbox.checked) { + preferences.usage = false; + preferences.statistics = false; } fireEvent(this, "analytics-preferences-changed", { preferences }); @@ -176,6 +182,11 @@ export class HaAnalytics extends LitElement { ha-settings-row { padding: 0; } + + span[slot="heading"], + span[slot="description"] { + cursor: pointer; + } `, ]; } diff --git a/src/data/analytics.ts b/src/data/analytics.ts index d8e04f69a1..a4e3875b5a 100644 --- a/src/data/analytics.ts +++ b/src/data/analytics.ts @@ -9,7 +9,6 @@ export interface AnalyticsPreferences { export interface Analytics { preferences: AnalyticsPreferences; - huuid: string; } export const getAnalyticsDetails = (hass: HomeAssistant) => diff --git a/src/onboarding/onboarding-analytics.ts b/src/onboarding/onboarding-analytics.ts index 7c1ac297c6..d8615b2408 100644 --- a/src/onboarding/onboarding-analytics.ts +++ b/src/onboarding/onboarding-analytics.ts @@ -12,11 +12,8 @@ import { import { fireEvent } from "../common/dom/fire_event"; import { LocalizeFunc } from "../common/translations/localize"; import "../components/ha-analytics"; -import { - Analytics, - getAnalyticsDetails, - setAnalyticsPreferences, -} from "../data/analytics"; +import { analyticsLearnMore } from "../components/ha-analytics-learn-more"; +import { Analytics, setAnalyticsPreferences } from "../data/analytics"; import { onboardAnalyticsStep } from "../data/onboarding"; import type { HomeAssistant } from "../types"; @@ -28,20 +25,18 @@ class OnboardingAnalytics extends LitElement { @internalProperty() private _error?: string; - @internalProperty() private _analyticsDetails?: Analytics; + @internalProperty() private _analyticsDetails: Analytics = { + preferences: {}, + }; protected render(): TemplateResult { - if (!this._analyticsDetails?.huuid) { - return html``; - } - return html`- ${this.localize( - "ui.panel.page-onboarding.analytics.intro", + ${this.hass.localize( + "ui.panel.config.core.section.core.analytics.introduction", "link", html`https://analytics.home-assistant.ioanalytics.home-assistant.io` )}
@@ -53,9 +48,10 @@ class OnboardingAnalytics extends LitElement { ${this._error ? html`${this.hass.localize( "ui.panel.config.core.section.core.analytics.introduction", "link", html`https://analytics.home-assistant.ioanalytics.home-assistant.io` )}
@@ -69,6 +72,7 @@ class ConfigAnalytics extends LitElement { "ui.panel.config.core.section.core.core_config.save_button" )} + ${analyticsLearnMore(this.hass)}