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

Add links to backup overview settings #23368

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -103,16 +104,20 @@ class HaBackupBackupsSummary extends LitElement {
<div class="card-header">Automatic backups</div>
<div class="card-content">
<ha-md-list>
<ha-md-list-item>
<ha-md-list-item
type="link"
href="/config/backup/settings#schedule"
>
<ha-svg-icon slot="start" .path=${mdiCalendar}></ha-svg-icon>
<div slot="headline">
${this._scheduleDescription(this.config)}
</div>
<div slot="supporting-text">
Schedule and number of backups to keep
</div>
<ha-icon-next slot="end"></ha-icon-next>
</ha-md-list-item>
<ha-md-list-item>
<ha-md-list-item type="link" href="/config/backup/settings#data">
<ha-svg-icon slot="start" .path=${mdiDatabase}></ha-svg-icon>
<div slot="headline">
${this.config.create_backup.include_database
Expand All @@ -122,27 +127,34 @@ class HaBackupBackupsSummary extends LitElement {
<div slot="supporting-text">
Home Assistant data that is included
</div>
<ha-icon-next slot="end"></ha-icon-next>
</ha-md-list-item>
${isHassio
? html`
<ha-md-list-item>
<ha-md-list-item
type="link"
href="/config/backup/settings#data"
>
<ha-svg-icon slot="start" .path=${mdiPuzzle}></ha-svg-icon>
<div slot="headline">
${this._addonsDescription(this.config)}
</div>
<div slot="supporting-text">Add-ons that are included</div>
</ha-md-list-item>
<ha-md-list-item>
<ha-svg-icon slot="start" .path=${mdiUpload}></ha-svg-icon>
<div slot="headline">
${this._agentsDescription(this.config)}
</div>
<div slot="supporting-text">
Locations where backup is uploaded to
</div>
<ha-icon-next slot="end"></ha-icon-next>
</ha-md-list-item>
`
: nothing}
<ha-md-list-item
type="link"
href="/config/backup/settings#locations"
>
<ha-svg-icon slot="start" .path=${mdiUpload}></ha-svg-icon>
<div slot="headline">${this._agentsDescription(this.config)}</div>
<div slot="supporting-text">
Locations where backup is uploaded to
</div>
<ha-icon-next slot="end"></ha-icon-next>
</ha-md-list-item>
</ha-md-list>
</div>
<div class="card-actions">
Expand Down
52 changes: 49 additions & 3 deletions src/panels/config/backup/ha-config-backup-settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
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";
Expand Down Expand Up @@ -38,6 +40,47 @@ class HaConfigBackupSettings extends LitElement {
}
}

protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
this._scrollToSection();
}

private async _scrollToSection() {
const hash = window.location.hash.substring(1);
if (
hash === "locations" &&
isComponentLoaded(this.hass, "hassio") &&
!this._config?.create_backup.include_all_addons &&
this._config?.create_backup.include_addons?.length
) {
// Wait for the addons to be loaded before scrolling because the height can change and location section is below addons.
this.addEventListener("backup-addons-fetched", async () => {
await nextRender();
this._scrolltoHash();
});
// Clear hash to cancel the scroll after 500ms if addons doesn't load
setTimeout(() => {
this._clearHash();
}, 500);
return;
}
await nextRender();
this._scrolltoHash();
}

private _scrolltoHash() {
const hash = window.location.hash.substring(1);
if (hash) {
const element = this.shadowRoot!.getElementById(hash);
element?.scrollIntoView();
this._clearHash();
}
}

private _clearHash() {
history.replaceState(null, "", window.location.pathname);
}

protected render() {
if (!this._config) {
return nothing;
Expand All @@ -51,7 +94,7 @@ class HaConfigBackupSettings extends LitElement {
.header=${"Automatic backups"}
>
<div class="content">
<ha-card>
<ha-card id="schedule">
<div class="card-header">Automatic backups</div>
<div class="card-content">
<p>
Expand All @@ -65,7 +108,7 @@ class HaConfigBackupSettings extends LitElement {
></ha-backup-config-schedule>
</div>
</ha-card>
<ha-card>
<ha-card id="data">
<div class="card-header">Backup data</div>
<div class="card-content">
<ha-backup-config-data
Expand All @@ -78,7 +121,7 @@ class HaConfigBackupSettings extends LitElement {
</div>
</ha-card>

<ha-card class="agents">
<ha-card class="agents" id="locations">
<div class="card-header">Locations</div>
<div class="card-content">
<p>
Expand Down Expand Up @@ -199,6 +242,9 @@ class HaConfigBackupSettings extends LitElement {
}

static styles = css`
ha-card {
scroll-margin-top: 16px;
}
.content {
padding: 28px 20px 0;
max-width: 690px;
Expand Down
Loading