mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Populate integration domain My link (#25322)
* Populate integration domain My link * break out of loop * Actually just return from function * Consolidate code
This commit is contained in:
parent
7434b12d9f
commit
c7882f3926
@ -16,6 +16,7 @@ import { extractSearchParamsObject } from "../common/url/search-params";
|
|||||||
import { showVoiceCommandDialog } from "../dialogs/voice-command-dialog/show-ha-voice-command-dialog";
|
import { showVoiceCommandDialog } from "../dialogs/voice-command-dialog/show-ha-voice-command-dialog";
|
||||||
import { canOverrideAlphanumericInput } from "../common/dom/can-override-input";
|
import { canOverrideAlphanumericInput } from "../common/dom/can-override-input";
|
||||||
import { showShortcutsDialog } from "../dialogs/shortcuts/show-shortcuts-dialog";
|
import { showShortcutsDialog } from "../dialogs/shortcuts/show-shortcuts-dialog";
|
||||||
|
import type { Redirects } from "../panels/my/ha-panel-my";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
@ -143,49 +144,44 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const targetPath = mainWindow.location.pathname;
|
const targetPath = mainWindow.location.pathname;
|
||||||
const isHassio = isComponentLoaded(this.hass, "hassio");
|
|
||||||
const myParams = new URLSearchParams();
|
const myParams = new URLSearchParams();
|
||||||
|
|
||||||
if (isHassio && targetPath.startsWith("/hassio")) {
|
let redirects: Redirects;
|
||||||
|
|
||||||
|
if (targetPath.startsWith("/hassio")) {
|
||||||
const myPanelSupervisor = await import(
|
const myPanelSupervisor = await import(
|
||||||
"../../hassio/src/hassio-my-redirect"
|
"../../hassio/src/hassio-my-redirect"
|
||||||
);
|
);
|
||||||
for (const [slug, redirect] of Object.entries(
|
redirects = myPanelSupervisor.REDIRECTS;
|
||||||
myPanelSupervisor.REDIRECTS
|
} else {
|
||||||
)) {
|
const myPanel = await import("../panels/my/ha-panel-my");
|
||||||
if (targetPath.startsWith(redirect.redirect)) {
|
redirects = myPanel.getMyRedirects();
|
||||||
myParams.append("redirect", slug);
|
|
||||||
if (redirect.redirect === "/hassio/addon") {
|
|
||||||
myParams.append("addon", targetPath.split("/")[3]);
|
|
||||||
}
|
|
||||||
window.open(
|
|
||||||
`https://my.home-assistant.io/create-link/?${myParams.toString()}`,
|
|
||||||
"_blank"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const myPanel = await import("../panels/my/ha-panel-my");
|
for (const [slug, redirect] of Object.entries(redirects)) {
|
||||||
|
if (!targetPath.startsWith(redirect.redirect)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
myParams.append("redirect", slug);
|
||||||
|
|
||||||
for (const [slug, redirect] of Object.entries(myPanel.getMyRedirects())) {
|
if (redirect.params) {
|
||||||
if (targetPath.startsWith(redirect.redirect)) {
|
const params = extractSearchParamsObject();
|
||||||
myParams.append("redirect", slug);
|
for (const key of Object.keys(redirect.params)) {
|
||||||
if (redirect.params) {
|
if (key in params) {
|
||||||
const params = extractSearchParamsObject();
|
myParams.append(key, params[key]);
|
||||||
for (const key of Object.keys(redirect.params)) {
|
|
||||||
if (key in params) {
|
|
||||||
myParams.append(key, params[key]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.open(
|
|
||||||
`https://my.home-assistant.io/create-link/?${myParams.toString()}`,
|
|
||||||
"_blank"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (redirect.redirect === "/config/integrations/integration") {
|
||||||
|
myParams.append("domain", targetPath.split("/")[4]);
|
||||||
|
} else if (redirect.redirect === "/hassio/addon") {
|
||||||
|
myParams.append("addon", targetPath.split("/")[3]);
|
||||||
|
}
|
||||||
|
window.open(
|
||||||
|
`https://my.home-assistant.io/create-link/?${myParams.toString()}`,
|
||||||
|
"_blank"
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize(
|
message: this.hass.localize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user