From fad435ea10feb4a88e3323f8685e2be571997631 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 20 Dec 2024 18:20:20 +0100 Subject: [PATCH] Add overview settings link to backup settings sections --- .../config/ha-backup-config-data.ts | 7 ++++ .../overview/ha-backup-overview-settings.ts | 36 ++++++++++++------- .../backup/ha-config-backup-settings.ts | 34 ++++++++++++++++-- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/panels/config/backup/components/config/ha-backup-config-data.ts b/src/panels/config/backup/components/config/ha-backup-config-data.ts index 20bde138ab..0b014e7d12 100644 --- a/src/panels/config/backup/components/config/ha-backup-config-data.ts +++ b/src/panels/config/backup/components/config/ha-backup-config-data.ts @@ -53,6 +53,12 @@ export type BackupConfigData = { include_addons?: string[]; }; +declare global { + interface HASSDomEvents { + "backup-addons-fetched": void; + } +} + @customElement("ha-backup-config-data") class HaBackupConfigData extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -89,6 +95,7 @@ class HaBackupConfigData extends LitElement { private async _fetchAddons() { const { addons } = await fetchHassioAddonsInfo(this.hass); this._addons = addons; + fireEvent(this, "backup-addons-fetched"); } private _hasLocalAddons(addons: BackupAddonItem[]): boolean { diff --git a/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts b/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts index 9e3ebd0206..dc3679f1ba 100644 --- a/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts +++ b/src/panels/config/backup/components/overview/ha-backup-overview-settings.ts @@ -5,6 +5,7 @@ import { customElement, property } from "lit/decorators"; import { navigate } from "../../../../../common/navigate"; import "../../../../../components/ha-button"; import "../../../../../components/ha-card"; +import "../../../../../components/ha-icon-next"; import "../../../../../components/ha-md-list"; import "../../../../../components/ha-md-list-item"; import "../../../../../components/ha-svg-icon"; @@ -103,7 +104,10 @@ class HaBackupBackupsSummary extends LitElement {
Automatic backups
- +
${this._scheduleDescription(this.config)} @@ -111,8 +115,9 @@ class HaBackupBackupsSummary extends LitElement {
Schedule and number of backups to keep
+ - +
${this.config.create_backup.include_database @@ -122,27 +127,34 @@ class HaBackupBackupsSummary extends LitElement {
Home Assistant data that is included
+ ${isHassio ? html` - +
${this._addonsDescription(this.config)}
Add-ons that are included
-
- - -
- ${this._agentsDescription(this.config)} -
-
- Locations where backup is uploaded to -
+
` : nothing} + + +
${this._agentsDescription(this.config)}
+
+ Locations where backup is uploaded to +
+ +
diff --git a/src/panels/config/backup/ha-config-backup-settings.ts b/src/panels/config/backup/ha-config-backup-settings.ts index f1e11d67e2..2e05c60565 100644 --- a/src/panels/config/backup/ha-config-backup-settings.ts +++ b/src/panels/config/backup/ha-config-backup-settings.ts @@ -3,6 +3,7 @@ import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../common/dom/fire_event"; import { debounce } from "../../../common/util/debounce"; +import { nextRender } from "../../../common/util/render-status"; import "../../../components/ha-button"; import "../../../components/ha-card"; import "../../../components/ha-icon-next"; @@ -38,6 +39,30 @@ class HaConfigBackupSettings extends LitElement { } } + protected firstUpdated(_changedProperties: PropertyValues): void { + super.firstUpdated(_changedProperties); + this._scrollTo(); + } + + private async _scrollTo() { + const hash = window.location.hash.substring(1); + if (hash === "locations") { + // Wait for the addons to be loaded before scrolling because the height can change + this.addEventListener("backup-addons-fetched", async () => { + await nextRender(); + this._scrolltoHash(hash); + }); + return; + } + this._scrolltoHash(hash); + } + + private _scrolltoHash(hash: string) { + const element = this.shadowRoot!.getElementById(hash); + element?.scrollIntoView(); + history.replaceState(null, "", window.location.pathname); + } + protected render() { if (!this._config) { return nothing; @@ -51,7 +76,7 @@ class HaConfigBackupSettings extends LitElement { .header=${"Automatic backups"} >
- +
Automatic backups

@@ -65,7 +90,7 @@ class HaConfigBackupSettings extends LitElement { >

- +
Backup data
- +
Locations

@@ -199,6 +224,9 @@ class HaConfigBackupSettings extends LitElement { } static styles = css` + ha-card { + scroll-margin-top: 16px; + } .content { padding: 28px 20px 0; max-width: 690px;