mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 04:46:34 +00:00
Add "m" keyboard shortcut to get to the create my link page (#12451)
This commit is contained in:
parent
8ae2d4e93a
commit
049ddd5f84
@ -12,12 +12,7 @@ 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 getRedirect = (
|
export const getMyRedirects = (hasSupervisor: boolean): Redirects => ({
|
||||||
path: string,
|
|
||||||
hasSupervisor: boolean
|
|
||||||
): Redirect | undefined =>
|
|
||||||
((
|
|
||||||
{
|
|
||||||
developer_states: {
|
developer_states: {
|
||||||
redirect: "/developer-tools/state",
|
redirect: "/developer-tools/state",
|
||||||
},
|
},
|
||||||
@ -188,8 +183,12 @@ const getRedirect = (
|
|||||||
// Moved from Supervisor panel in 2022.5
|
// Moved from Supervisor panel in 2022.5
|
||||||
redirect: "/config/info",
|
redirect: "/config/info",
|
||||||
},
|
},
|
||||||
} as Redirects
|
});
|
||||||
)[path]);
|
|
||||||
|
const getRedirect = (
|
||||||
|
path: string,
|
||||||
|
hasSupervisor: boolean
|
||||||
|
): Redirect | undefined => getMyRedirects(hasSupervisor)?.[path];
|
||||||
|
|
||||||
export type ParamType = "url" | "string";
|
export type ParamType = "url" | "string";
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import type { PropertyValues } from "lit";
|
import type { PropertyValues } from "lit";
|
||||||
import tinykeys from "tinykeys";
|
import tinykeys from "tinykeys";
|
||||||
|
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||||
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
import {
|
import {
|
||||||
QuickBarParams,
|
QuickBarParams,
|
||||||
showQuickBar,
|
showQuickBar,
|
||||||
} from "../dialogs/quick-bar/show-dialog-quick-bar";
|
} from "../dialogs/quick-bar/show-dialog-quick-bar";
|
||||||
import { Constructor, HomeAssistant } from "../types";
|
import { Constructor, HomeAssistant } from "../types";
|
||||||
import { storeState } from "../util/ha-pref-storage";
|
import { storeState } from "../util/ha-pref-storage";
|
||||||
|
import { showToast } from "../util/toast";
|
||||||
import { HassElement } from "./hass-element";
|
import { HassElement } from "./hass-element";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -32,6 +35,7 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
|
|||||||
tinykeys(window, {
|
tinykeys(window, {
|
||||||
e: (ev) => this._showQuickBar(ev),
|
e: (ev) => this._showQuickBar(ev),
|
||||||
c: (ev) => this._showQuickBar(ev, true),
|
c: (ev) => this._showQuickBar(ev, true),
|
||||||
|
m: (ev) => this._createMyLink(ev),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +47,36 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
|
|||||||
showQuickBar(this, { commandMode });
|
showQuickBar(this, { commandMode });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createMyLink(e: KeyboardEvent) {
|
||||||
|
if (!this._canOverrideAlphanumericInput(e) || !this.hass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetPath = mainWindow.location.pathname;
|
||||||
|
const myPanel = await import("../panels/my/ha-panel-my");
|
||||||
|
|
||||||
|
for (const [slug, redirect] of Object.entries(
|
||||||
|
myPanel.getMyRedirects(isComponentLoaded(this.hass, "hassio"))
|
||||||
|
)) {
|
||||||
|
if (redirect.redirect === targetPath) {
|
||||||
|
window.open(
|
||||||
|
`https://my.home-assistant.io/create-link/?redirect=${slug}`,
|
||||||
|
"_blank"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showToast(this, {
|
||||||
|
message: this.hass.localize(
|
||||||
|
"ui.notification_toast.no_matching_link_found",
|
||||||
|
{
|
||||||
|
path: targetPath,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _canShowQuickBar(e: KeyboardEvent) {
|
private _canShowQuickBar(e: KeyboardEvent) {
|
||||||
return (
|
return (
|
||||||
this.hass?.user?.is_admin &&
|
this.hass?.user?.is_admin &&
|
||||||
|
@ -1083,7 +1083,8 @@
|
|||||||
"wrapping_up_startup": "Wrapping up startup, not everything will be available until it is finished.",
|
"wrapping_up_startup": "Wrapping up startup, not everything will be available until it is finished.",
|
||||||
"integration_starting": "Starting {integration}, not everything will be available until it is finished.",
|
"integration_starting": "Starting {integration}, not everything will be available until it is finished.",
|
||||||
"triggered": "Triggered {name}",
|
"triggered": "Triggered {name}",
|
||||||
"dismiss": "Dismiss"
|
"dismiss": "Dismiss",
|
||||||
|
"no_matching_link_found": "No matching my link found for {path}"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"external_app_configuration": "App Configuration",
|
"external_app_configuration": "App Configuration",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user