mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Add snapshot contents as secondary info for partial snapshots (#9166)
This commit is contained in:
parent
2ad2a4b198
commit
b12a10ccb5
@ -24,6 +24,7 @@ import "../../../src/components/ha-button-menu";
|
|||||||
import "../../../src/components/ha-fab";
|
import "../../../src/components/ha-fab";
|
||||||
import {
|
import {
|
||||||
fetchHassioSnapshots,
|
fetchHassioSnapshots,
|
||||||
|
friendlyFolderName,
|
||||||
HassioSnapshot,
|
HassioSnapshot,
|
||||||
reloadHassioSnapshots,
|
reloadHassioSnapshots,
|
||||||
} from "../../../src/data/hassio/snapshot";
|
} from "../../../src/data/hassio/snapshot";
|
||||||
@ -66,6 +67,33 @@ export class HassioSnapshots extends LitElement {
|
|||||||
await this.fetchSnapshots();
|
await this.fetchSnapshots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _computeSnapshotContent = (snapshot: HassioSnapshot): string => {
|
||||||
|
if (snapshot.type === "full") {
|
||||||
|
return this.supervisor.localize("snapshot.full_snapshot");
|
||||||
|
}
|
||||||
|
const content: string[] = [];
|
||||||
|
if (snapshot.content.homeassistant) {
|
||||||
|
content.push("Home Assistant");
|
||||||
|
}
|
||||||
|
if (snapshot.content.folders.length !== 0) {
|
||||||
|
for (const folder of snapshot.content.folders) {
|
||||||
|
content.push(friendlyFolderName[folder] || folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshot.content.addons.length !== 0) {
|
||||||
|
for (const addon of snapshot.content.addons) {
|
||||||
|
content.push(
|
||||||
|
this.supervisor.supervisor.addons.find(
|
||||||
|
(entry) => entry.slug === addon
|
||||||
|
)?.name || addon
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content.join(", ");
|
||||||
|
};
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
protected firstUpdated(changedProperties: PropertyValues): void {
|
||||||
super.firstUpdated(changedProperties);
|
super.firstUpdated(changedProperties);
|
||||||
if (this.hass && this.isConnected) {
|
if (this.hass && this.isConnected) {
|
||||||
@ -81,7 +109,9 @@ export class HassioSnapshots extends LitElement {
|
|||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
grows: true,
|
grows: true,
|
||||||
template: (entry: string, snapshot: any) => entry || snapshot.slug,
|
template: (entry: string, snapshot: any) =>
|
||||||
|
html`${entry || snapshot.slug}
|
||||||
|
<div class="secondary">${snapshot.secondary}</div>`,
|
||||||
},
|
},
|
||||||
date: {
|
date: {
|
||||||
title: this.supervisor?.localize("snapshot.created") || "",
|
title: this.supervisor?.localize("snapshot.created") || "",
|
||||||
@ -93,17 +123,21 @@ export class HassioSnapshots extends LitElement {
|
|||||||
template: (entry: string) =>
|
template: (entry: string) =>
|
||||||
relativeTime(new Date(entry), this.hass.localize),
|
relativeTime(new Date(entry), this.hass.localize),
|
||||||
},
|
},
|
||||||
type: {
|
secondary: {
|
||||||
title: this.supervisor?.localize("snapshot.type") || "",
|
title: "",
|
||||||
width: "15%",
|
hidden: true,
|
||||||
hidden: narrow,
|
|
||||||
filterable: true,
|
filterable: true,
|
||||||
sortable: true,
|
|
||||||
template: (entry: string) => (entry === "partial" ? "Partial" : "Full"),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _snapshotData = memoizeOne((snapshots: HassioSnapshot[]) =>
|
||||||
|
snapshots.map((snapshot) => ({
|
||||||
|
...snapshot,
|
||||||
|
secondary: this._computeSnapshotContent(snapshot),
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.supervisor) {
|
if (!this.supervisor) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -118,7 +152,7 @@ export class HassioSnapshots extends LitElement {
|
|||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.columns=${this._columns(this.narrow)}
|
.columns=${this._columns(this.narrow)}
|
||||||
.data=${this._snapshots}
|
.data=${this._snapshotData(this._snapshots || [])}
|
||||||
id="slug"
|
id="slug"
|
||||||
@row-click=${this._handleRowClicked}
|
@row-click=${this._handleRowClicked}
|
||||||
clickable
|
clickable
|
||||||
|
@ -2,12 +2,27 @@ import { atLeastVersion } from "../../common/config/version";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { hassioApiResultExtractor, HassioResponse } from "./common";
|
import { hassioApiResultExtractor, HassioResponse } from "./common";
|
||||||
|
|
||||||
|
export const friendlyFolderName = {
|
||||||
|
ssl: "SSL",
|
||||||
|
homeassistant: "Configuration",
|
||||||
|
"addons/local": "Local add-ons",
|
||||||
|
media: "Media",
|
||||||
|
share: "Share",
|
||||||
|
};
|
||||||
|
|
||||||
|
interface SnapshotContent {
|
||||||
|
homeassistant: boolean;
|
||||||
|
folders: string[];
|
||||||
|
addons: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface HassioSnapshot {
|
export interface HassioSnapshot {
|
||||||
slug: string;
|
slug: string;
|
||||||
date: string;
|
date: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: "full" | "partial";
|
type: "full" | "partial";
|
||||||
protected: boolean;
|
protected: boolean;
|
||||||
|
content: SnapshotContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HassioSnapshotDetail extends HassioSnapshot {
|
export interface HassioSnapshotDetail extends HassioSnapshot {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user