mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-12 11:56:34 +00:00
Redirect old backup links to backup integration for non supervised (#12183)
This commit is contained in:
parent
8baa0b2a9b
commit
0b47d2c687
@ -12,158 +12,172 @@ import "../../layouts/hass-error-screen";
|
|||||||
import { HomeAssistant, Route } from "../../types";
|
import { HomeAssistant, Route } from "../../types";
|
||||||
import { documentationUrl } from "../../util/documentation-url";
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
|
|
||||||
const REDIRECTS: Redirects = {
|
const getRedirect = (
|
||||||
developer_states: {
|
path: string,
|
||||||
redirect: "/developer-tools/state",
|
hasSupervisor: boolean
|
||||||
},
|
): Redirect | undefined =>
|
||||||
developer_services: {
|
((
|
||||||
redirect: "/developer-tools/service",
|
{
|
||||||
},
|
developer_states: {
|
||||||
developer_call_service: {
|
redirect: "/developer-tools/state",
|
||||||
redirect: "/developer-tools/service",
|
},
|
||||||
params: {
|
developer_services: {
|
||||||
service: "string",
|
redirect: "/developer-tools/service",
|
||||||
},
|
},
|
||||||
},
|
developer_call_service: {
|
||||||
developer_template: {
|
redirect: "/developer-tools/service",
|
||||||
redirect: "/developer-tools/template",
|
params: {
|
||||||
},
|
service: "string",
|
||||||
developer_events: {
|
},
|
||||||
redirect: "/developer-tools/event",
|
},
|
||||||
},
|
developer_template: {
|
||||||
developer_statistics: {
|
redirect: "/developer-tools/template",
|
||||||
redirect: "/developer-tools/statistics",
|
},
|
||||||
},
|
developer_events: {
|
||||||
config: {
|
redirect: "/developer-tools/event",
|
||||||
redirect: "/config",
|
},
|
||||||
},
|
developer_statistics: {
|
||||||
cloud: {
|
redirect: "/developer-tools/statistics",
|
||||||
component: "cloud",
|
},
|
||||||
redirect: "/config/cloud",
|
config: {
|
||||||
},
|
redirect: "/config",
|
||||||
integrations: {
|
},
|
||||||
redirect: "/config/integrations",
|
cloud: {
|
||||||
},
|
component: "cloud",
|
||||||
config_flow_start: {
|
redirect: "/config/cloud",
|
||||||
redirect: "/config/integrations/add",
|
},
|
||||||
params: {
|
integrations: {
|
||||||
domain: "string",
|
redirect: "/config/integrations",
|
||||||
},
|
},
|
||||||
},
|
config_flow_start: {
|
||||||
config_mqtt: {
|
redirect: "/config/integrations/add",
|
||||||
component: "mqtt",
|
params: {
|
||||||
redirect: "/config/mqtt",
|
domain: "string",
|
||||||
},
|
},
|
||||||
config_zha: {
|
},
|
||||||
component: "zha",
|
config_mqtt: {
|
||||||
redirect: "/config/zha/dashboard",
|
component: "mqtt",
|
||||||
},
|
redirect: "/config/mqtt",
|
||||||
config_zwave_js: {
|
},
|
||||||
component: "zwave_js",
|
config_zha: {
|
||||||
redirect: "/config/zwave_js/dashboard",
|
component: "zha",
|
||||||
},
|
redirect: "/config/zha/dashboard",
|
||||||
config_energy: {
|
},
|
||||||
component: "energy",
|
config_zwave_js: {
|
||||||
redirect: "/config/energy/dashboard",
|
component: "zwave_js",
|
||||||
},
|
redirect: "/config/zwave_js/dashboard",
|
||||||
devices: {
|
},
|
||||||
redirect: "/config/devices/dashboard",
|
config_energy: {
|
||||||
},
|
component: "energy",
|
||||||
entities: {
|
redirect: "/config/energy/dashboard",
|
||||||
redirect: "/config/entities",
|
},
|
||||||
},
|
devices: {
|
||||||
energy: {
|
redirect: "/config/devices/dashboard",
|
||||||
component: "energy",
|
},
|
||||||
redirect: "/energy",
|
entities: {
|
||||||
},
|
redirect: "/config/entities",
|
||||||
areas: {
|
},
|
||||||
redirect: "/config/areas/dashboard",
|
energy: {
|
||||||
},
|
component: "energy",
|
||||||
blueprints: {
|
redirect: "/energy",
|
||||||
component: "blueprint",
|
},
|
||||||
redirect: "/config/blueprint/dashboard",
|
areas: {
|
||||||
},
|
redirect: "/config/areas/dashboard",
|
||||||
blueprint_import: {
|
},
|
||||||
component: "blueprint",
|
blueprints: {
|
||||||
redirect: "/config/blueprint/dashboard/import",
|
component: "blueprint",
|
||||||
params: {
|
redirect: "/config/blueprint/dashboard",
|
||||||
blueprint_url: "url",
|
},
|
||||||
},
|
blueprint_import: {
|
||||||
},
|
component: "blueprint",
|
||||||
automations: {
|
redirect: "/config/blueprint/dashboard/import",
|
||||||
component: "automation",
|
params: {
|
||||||
redirect: "/config/automation/dashboard",
|
blueprint_url: "url",
|
||||||
},
|
},
|
||||||
scenes: {
|
},
|
||||||
component: "scene",
|
automations: {
|
||||||
redirect: "/config/scene/dashboard",
|
component: "automation",
|
||||||
},
|
redirect: "/config/automation/dashboard",
|
||||||
scripts: {
|
},
|
||||||
component: "script",
|
scenes: {
|
||||||
redirect: "/config/script/dashboard",
|
component: "scene",
|
||||||
},
|
redirect: "/config/scene/dashboard",
|
||||||
helpers: {
|
},
|
||||||
redirect: "/config/helpers",
|
scripts: {
|
||||||
},
|
component: "script",
|
||||||
tags: {
|
redirect: "/config/script/dashboard",
|
||||||
component: "tag",
|
},
|
||||||
redirect: "/config/tags",
|
helpers: {
|
||||||
},
|
redirect: "/config/helpers",
|
||||||
lovelace_dashboards: {
|
},
|
||||||
component: "lovelace",
|
tags: {
|
||||||
redirect: "/config/lovelace/dashboards",
|
component: "tag",
|
||||||
},
|
redirect: "/config/tags",
|
||||||
lovelace_resources: {
|
},
|
||||||
component: "lovelace",
|
lovelace_dashboards: {
|
||||||
redirect: "/config/lovelace/resources",
|
component: "lovelace",
|
||||||
},
|
redirect: "/config/lovelace/dashboards",
|
||||||
backup: {
|
},
|
||||||
component: "backup",
|
lovelace_resources: {
|
||||||
redirect: "/config/backup",
|
component: "lovelace",
|
||||||
},
|
redirect: "/config/lovelace/resources",
|
||||||
people: {
|
},
|
||||||
component: "person",
|
people: {
|
||||||
redirect: "/config/person",
|
component: "person",
|
||||||
},
|
redirect: "/config/person",
|
||||||
zones: {
|
},
|
||||||
component: "zone",
|
zones: {
|
||||||
redirect: "/config/zone",
|
component: "zone",
|
||||||
},
|
redirect: "/config/zone",
|
||||||
users: {
|
},
|
||||||
redirect: "/config/users",
|
users: {
|
||||||
},
|
redirect: "/config/users",
|
||||||
general: {
|
},
|
||||||
redirect: "/config/core",
|
general: {
|
||||||
},
|
redirect: "/config/core",
|
||||||
server_controls: {
|
},
|
||||||
redirect: "/config/server_control",
|
server_controls: {
|
||||||
},
|
redirect: "/config/server_control",
|
||||||
logs: {
|
},
|
||||||
redirect: "/config/logs",
|
logs: {
|
||||||
},
|
redirect: "/config/logs",
|
||||||
info: {
|
},
|
||||||
redirect: "/config/info",
|
info: {
|
||||||
},
|
redirect: "/config/info",
|
||||||
customize: {
|
},
|
||||||
// customize was removed in 2021.12, fallback to dashboard
|
customize: {
|
||||||
redirect: "/config/dashboard",
|
// customize was removed in 2021.12, fallback to dashboard
|
||||||
},
|
redirect: "/config/dashboard",
|
||||||
profile: {
|
},
|
||||||
redirect: "/profile/dashboard",
|
profile: {
|
||||||
},
|
redirect: "/profile/dashboard",
|
||||||
logbook: {
|
},
|
||||||
component: "logbook",
|
logbook: {
|
||||||
redirect: "/logbook",
|
component: "logbook",
|
||||||
},
|
redirect: "/logbook",
|
||||||
history: {
|
},
|
||||||
component: "history",
|
history: {
|
||||||
redirect: "/history",
|
component: "history",
|
||||||
},
|
redirect: "/history",
|
||||||
media_browser: {
|
},
|
||||||
component: "media_source",
|
media_browser: {
|
||||||
redirect: "/media-browser",
|
component: "media_source",
|
||||||
},
|
redirect: "/media-browser",
|
||||||
};
|
},
|
||||||
|
backup: {
|
||||||
|
component: hasSupervisor ? "hassio" : "backup",
|
||||||
|
redirect: hasSupervisor ? "/hassio/backups" : "/config/backup",
|
||||||
|
},
|
||||||
|
supervisor_snapshots: {
|
||||||
|
component: hasSupervisor ? "hassio" : "backup",
|
||||||
|
redirect: hasSupervisor ? "/hassio/backups" : "/config/backup",
|
||||||
|
},
|
||||||
|
supervisor_backups: {
|
||||||
|
component: hasSupervisor ? "hassio" : "backup",
|
||||||
|
redirect: hasSupervisor ? "/hassio/backups" : "/config/backup",
|
||||||
|
},
|
||||||
|
} as Redirects
|
||||||
|
)[path]);
|
||||||
|
|
||||||
export type ParamType = "url" | "string";
|
export type ParamType = "url" | "string";
|
||||||
|
|
||||||
@ -184,19 +198,17 @@ class HaPanelMy extends LitElement {
|
|||||||
|
|
||||||
@state() public _error?: string;
|
@state() public _error?: string;
|
||||||
|
|
||||||
|
private _redirect?: Redirect;
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
const path = this.route.path.substring(1);
|
const path = this.route.path.substring(1);
|
||||||
|
const hasSupervisor = isComponentLoaded(this.hass, "hassio");
|
||||||
|
|
||||||
if (path === "backup" && isComponentLoaded(this.hass, "hassio")) {
|
this._redirect = getRedirect(path, hasSupervisor);
|
||||||
navigate("/hassio/backups", {
|
|
||||||
replace: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path.startsWith("supervisor")) {
|
if (path.startsWith("supervisor") && this._redirect === undefined) {
|
||||||
if (!isComponentLoaded(this.hass, "hassio")) {
|
if (!hasSupervisor) {
|
||||||
this._error = "no_supervisor";
|
this._error = "no_supervisor";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -206,16 +218,14 @@ class HaPanelMy extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const redirect = REDIRECTS[path];
|
if (!this._redirect) {
|
||||||
|
|
||||||
if (!redirect) {
|
|
||||||
this._error = "not_supported";
|
this._error = "not_supported";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
redirect.component &&
|
this._redirect.component &&
|
||||||
!isComponentLoaded(this.hass, redirect.component)
|
!isComponentLoaded(this.hass, this._redirect.component)
|
||||||
) {
|
) {
|
||||||
this._error = "no_component";
|
this._error = "no_component";
|
||||||
return;
|
return;
|
||||||
@ -223,7 +233,7 @@ class HaPanelMy extends LitElement {
|
|||||||
|
|
||||||
let url: string;
|
let url: string;
|
||||||
try {
|
try {
|
||||||
url = this._createRedirectUrl(redirect);
|
url = this._createRedirectUrl();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._error = "url_error";
|
this._error = "url_error";
|
||||||
return;
|
return;
|
||||||
@ -254,10 +264,16 @@ class HaPanelMy extends LitElement {
|
|||||||
this.hass.localize(
|
this.hass.localize(
|
||||||
"ui.panel.my.component_not_loaded",
|
"ui.panel.my.component_not_loaded",
|
||||||
"integration",
|
"integration",
|
||||||
domainToName(
|
html`<a
|
||||||
this.hass.localize,
|
target="_blank"
|
||||||
REDIRECTS[this.route.path.substr(1)].component!
|
rel="noreferrer noopener"
|
||||||
)
|
href=${documentationUrl(
|
||||||
|
this.hass,
|
||||||
|
`/integrations/${this._redirect!.component!}`
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
${domainToName(this.hass.localize, this._redirect!.component!)}
|
||||||
|
</a>`
|
||||||
) || "This redirect is not supported.";
|
) || "This redirect is not supported.";
|
||||||
break;
|
break;
|
||||||
case "no_supervisor":
|
case "no_supervisor":
|
||||||
@ -280,18 +296,18 @@ class HaPanelMy extends LitElement {
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createRedirectUrl(redirect: Redirect): string {
|
private _createRedirectUrl(): string {
|
||||||
const params = this._createRedirectParams(redirect);
|
const params = this._createRedirectParams();
|
||||||
return `${redirect.redirect}${params}`;
|
return `${this._redirect!.redirect}${params}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createRedirectParams(redirect: Redirect): string {
|
private _createRedirectParams(): string {
|
||||||
const params = extractSearchParamsObject();
|
const params = extractSearchParamsObject();
|
||||||
if (!redirect.params && !Object.keys(params).length) {
|
if (!this._redirect!.params && !Object.keys(params).length) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const resultParams = {};
|
const resultParams = {};
|
||||||
Object.entries(redirect.params || {}).forEach(([key, type]) => {
|
Object.entries(this._redirect!.params || {}).forEach(([key, type]) => {
|
||||||
if (!params[key] || !this._checkParamType(type, params[key])) {
|
if (!params[key] || !this._checkParamType(type, params[key])) {
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user