Add "m" keyboard shortcut to get to the create my link page (#12451)

This commit is contained in:
Joakim Sørensen 2022-04-27 00:11:09 +02:00 committed by GitHub
parent 8ae2d4e93a
commit 049ddd5f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 210 additions and 176 deletions

View File

@ -12,184 +12,183 @@ import "../../layouts/hass-error-screen";
import { HomeAssistant, Route } from "../../types";
import { documentationUrl } from "../../util/documentation-url";
export const getMyRedirects = (hasSupervisor: boolean): Redirects => ({
developer_states: {
redirect: "/developer-tools/state",
},
developer_services: {
redirect: "/developer-tools/service",
},
developer_call_service: {
redirect: "/developer-tools/service",
params: {
service: "string",
},
},
developer_template: {
redirect: "/developer-tools/template",
},
developer_events: {
redirect: "/developer-tools/event",
},
developer_statistics: {
redirect: "/developer-tools/statistics",
},
config: {
redirect: "/config",
},
cloud: {
component: "cloud",
redirect: "/config/cloud",
},
integrations: {
redirect: "/config/integrations",
},
config_flow_start: {
redirect: "/config/integrations/add",
params: {
domain: "string",
},
},
config_mqtt: {
component: "mqtt",
redirect: "/config/mqtt",
},
config_zha: {
component: "zha",
redirect: "/config/zha/dashboard",
},
config_zwave_js: {
component: "zwave_js",
redirect: "/config/zwave_js/dashboard",
},
config_energy: {
component: "energy",
redirect: "/config/energy/dashboard",
},
devices: {
redirect: "/config/devices/dashboard",
},
entities: {
redirect: "/config/entities",
},
energy: {
component: "energy",
redirect: "/energy",
},
areas: {
redirect: "/config/areas/dashboard",
},
blueprints: {
component: "blueprint",
redirect: "/config/blueprint/dashboard",
},
blueprint_import: {
component: "blueprint",
redirect: "/config/blueprint/dashboard/import",
params: {
blueprint_url: "url",
},
},
automations: {
component: "automation",
redirect: "/config/automation/dashboard",
},
scenes: {
component: "scene",
redirect: "/config/scene/dashboard",
},
scripts: {
component: "script",
redirect: "/config/script/dashboard",
},
helpers: {
redirect: "/config/helpers",
},
tags: {
component: "tag",
redirect: "/config/tags",
},
lovelace_dashboards: {
component: "lovelace",
redirect: "/config/lovelace/dashboards",
},
lovelace_resources: {
component: "lovelace",
redirect: "/config/lovelace/resources",
},
people: {
component: "person",
redirect: "/config/person",
},
zones: {
component: "zone",
redirect: "/config/zone",
},
users: {
redirect: "/config/users",
},
general: {
redirect: "/config/core",
},
server_controls: {
redirect: "/config/server_control",
},
logs: {
redirect: "/config/logs",
},
info: {
redirect: "/config/info",
},
customize: {
// customize was removed in 2021.12, fallback to dashboard
redirect: "/config/dashboard",
},
profile: {
redirect: "/profile/dashboard",
},
logbook: {
component: "logbook",
redirect: "/logbook",
},
history: {
component: "history",
redirect: "/history",
},
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",
},
supervisor_system: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/system",
},
supervisor_logs: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/logs",
},
supervisor_info: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/info",
},
});
const getRedirect = (
path: string,
hasSupervisor: boolean
): Redirect | undefined =>
((
{
developer_states: {
redirect: "/developer-tools/state",
},
developer_services: {
redirect: "/developer-tools/service",
},
developer_call_service: {
redirect: "/developer-tools/service",
params: {
service: "string",
},
},
developer_template: {
redirect: "/developer-tools/template",
},
developer_events: {
redirect: "/developer-tools/event",
},
developer_statistics: {
redirect: "/developer-tools/statistics",
},
config: {
redirect: "/config",
},
cloud: {
component: "cloud",
redirect: "/config/cloud",
},
integrations: {
redirect: "/config/integrations",
},
config_flow_start: {
redirect: "/config/integrations/add",
params: {
domain: "string",
},
},
config_mqtt: {
component: "mqtt",
redirect: "/config/mqtt",
},
config_zha: {
component: "zha",
redirect: "/config/zha/dashboard",
},
config_zwave_js: {
component: "zwave_js",
redirect: "/config/zwave_js/dashboard",
},
config_energy: {
component: "energy",
redirect: "/config/energy/dashboard",
},
devices: {
redirect: "/config/devices/dashboard",
},
entities: {
redirect: "/config/entities",
},
energy: {
component: "energy",
redirect: "/energy",
},
areas: {
redirect: "/config/areas/dashboard",
},
blueprints: {
component: "blueprint",
redirect: "/config/blueprint/dashboard",
},
blueprint_import: {
component: "blueprint",
redirect: "/config/blueprint/dashboard/import",
params: {
blueprint_url: "url",
},
},
automations: {
component: "automation",
redirect: "/config/automation/dashboard",
},
scenes: {
component: "scene",
redirect: "/config/scene/dashboard",
},
scripts: {
component: "script",
redirect: "/config/script/dashboard",
},
helpers: {
redirect: "/config/helpers",
},
tags: {
component: "tag",
redirect: "/config/tags",
},
lovelace_dashboards: {
component: "lovelace",
redirect: "/config/lovelace/dashboards",
},
lovelace_resources: {
component: "lovelace",
redirect: "/config/lovelace/resources",
},
people: {
component: "person",
redirect: "/config/person",
},
zones: {
component: "zone",
redirect: "/config/zone",
},
users: {
redirect: "/config/users",
},
general: {
redirect: "/config/core",
},
server_controls: {
redirect: "/config/server_control",
},
logs: {
redirect: "/config/logs",
},
info: {
redirect: "/config/info",
},
customize: {
// customize was removed in 2021.12, fallback to dashboard
redirect: "/config/dashboard",
},
profile: {
redirect: "/profile/dashboard",
},
logbook: {
component: "logbook",
redirect: "/logbook",
},
history: {
component: "history",
redirect: "/history",
},
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",
},
supervisor_system: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/system",
},
supervisor_logs: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/logs",
},
supervisor_info: {
// Moved from Supervisor panel in 2022.5
redirect: "/config/info",
},
} as Redirects
)[path]);
): Redirect | undefined => getMyRedirects(hasSupervisor)?.[path];
export type ParamType = "url" | "string";

View File

@ -1,11 +1,14 @@
import type { PropertyValues } from "lit";
import tinykeys from "tinykeys";
import { isComponentLoaded } from "../common/config/is_component_loaded";
import { mainWindow } from "../common/dom/get_main_window";
import {
QuickBarParams,
showQuickBar,
} from "../dialogs/quick-bar/show-dialog-quick-bar";
import { Constructor, HomeAssistant } from "../types";
import { storeState } from "../util/ha-pref-storage";
import { showToast } from "../util/toast";
import { HassElement } from "./hass-element";
declare global {
@ -32,6 +35,7 @@ export default <T extends Constructor<HassElement>>(superClass: T) =>
tinykeys(window, {
e: (ev) => this._showQuickBar(ev),
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 });
}
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) {
return (
this.hass?.user?.is_admin &&

View File

@ -1083,7 +1083,8 @@
"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.",
"triggered": "Triggered {name}",
"dismiss": "Dismiss"
"dismiss": "Dismiss",
"no_matching_link_found": "No matching my link found for {path}"
},
"sidebar": {
"external_app_configuration": "App Configuration",