Add supervisor redirects to quickbar (#12557)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Joakim Sørensen 2022-05-03 13:57:09 +02:00 committed by GitHub
parent 45c7e0eeeb
commit bd8e15bdd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 11 deletions

View File

@ -17,6 +17,7 @@ import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { canShowPage } from "../../common/config/can_show_page"; import { canShowPage } from "../../common/config/can_show_page";
import { componentsWithService } from "../../common/config/components_with_service"; import { componentsWithService } from "../../common/config/components_with_service";
import { isComponentLoaded } from "../../common/config/is_component_loaded";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain"; import { computeDomain } from "../../common/entity/compute_domain";
import { computeStateName } from "../../common/entity/compute_state_name"; import { computeStateName } from "../../common/entity/compute_state_name";
@ -33,6 +34,7 @@ import "../../components/ha-circular-progress";
import "../../components/ha-header-bar"; import "../../components/ha-header-bar";
import "../../components/ha-icon-button"; import "../../components/ha-icon-button";
import "../../components/ha-textfield"; import "../../components/ha-textfield";
import { fetchHassioSupervisorInfo } from "../../data/hassio/supervisor";
import { domainToName } from "../../data/integration"; import { domainToName } from "../../data/integration";
import { getPanelNameTranslationKey } from "../../data/panel"; import { getPanelNameTranslationKey } from "../../data/panel";
import { PageNavigation } from "../../layouts/hass-tabs-subpage"; import { PageNavigation } from "../../layouts/hass-tabs-subpage";
@ -245,9 +247,10 @@ export class QuickBar extends LitElement {
`; `;
} }
private _initializeItemsIfNeeded() { private async _initializeItemsIfNeeded() {
if (this._commandMode) { if (this._commandMode) {
this._commandItems = this._commandItems || this._generateCommandItems(); this._commandItems =
this._commandItems || (await this._generateCommandItems());
} else { } else {
this._entityItems = this._entityItems || this._generateEntityItems(); this._entityItems = this._entityItems || this._generateEntityItems();
} }
@ -485,11 +488,11 @@ export class QuickBar extends LitElement {
); );
} }
private _generateCommandItems(): CommandItem[] { private async _generateCommandItems(): Promise<CommandItem[]> {
return [ return [
...this._generateReloadCommands(), ...this._generateReloadCommands(),
...this._generateServerControlCommands(), ...this._generateServerControlCommands(),
...this._generateNavigationCommands(), ...(await this._generateNavigationCommands()),
].sort((a, b) => ].sort((a, b) =>
caseInsensitiveStringCompare(a.strings.join(" "), b.strings.join(" ")) caseInsensitiveStringCompare(a.strings.join(" "), b.strings.join(" "))
); );
@ -578,11 +581,40 @@ export class QuickBar extends LitElement {
}); });
} }
private _generateNavigationCommands(): CommandItem[] { private async _generateNavigationCommands(): Promise<CommandItem[]> {
const panelItems = this._generateNavigationPanelCommands(); const panelItems = this._generateNavigationPanelCommands();
const sectionItems = this._generateNavigationConfigSectionCommands(); const sectionItems = this._generateNavigationConfigSectionCommands();
const supervisorItems: BaseNavigationCommand[] = [];
if (isComponentLoaded(this.hass, "hassio")) {
const supervisorInfo = await fetchHassioSupervisorInfo(this.hass);
supervisorItems.push({
path: "/hassio/store",
primaryText: this.hass.localize(
"ui.dialogs.quick-bar.commands.navigation.addon_store"
),
});
supervisorItems.push({
path: "/hassio/dashboard",
primaryText: this.hass.localize(
"ui.dialogs.quick-bar.commands.navigation.addon_dashboard"
),
});
for (const addon of supervisorInfo.addons) {
supervisorItems.push({
path: `/hassio/addon/${addon.slug}`,
primaryText: this.hass.localize(
"ui.dialogs.quick-bar.commands.navigation.addon_info",
{ addon: addon.name }
),
});
}
}
return this._finalizeNavigationCommands([...panelItems, ...sectionItems]); return this._finalizeNavigationCommands([
...panelItems,
...sectionItems,
...supervisorItems,
]);
} }
private _generateNavigationPanelCommands(): BaseNavigationCommand[] { private _generateNavigationPanelCommands(): BaseNavigationCommand[] {
@ -636,11 +668,14 @@ export class QuickBar extends LitElement {
let name = path.substring(path.indexOf("/") + 1); let name = path.substring(path.indexOf("/") + 1);
name = name.indexOf("/") > -1 ? name.substring(0, name.indexOf("/")) : name; name = name.indexOf("/") > -1 ? name.substring(0, name.indexOf("/")) : name;
const caption = this.hass.localize( const caption =
`ui.dialogs.quick-bar.commands.navigation.${name}` (name &&
); this.hass.localize(
`ui.dialogs.quick-bar.commands.navigation.${name}`
)) ||
(page.translationKey && this.hass.localize(page.translationKey));
if (page.translationKey && caption) { if (caption) {
return { ...page, primaryText: caption }; return { ...page, primaryText: caption };
} }

View File

@ -695,7 +695,11 @@
"analytics": "[%key:ui::panel::config::analytics::caption%]", "analytics": "[%key:ui::panel::config::analytics::caption%]",
"system_health": "[%key:ui::panel::config::system_health::caption%]", "system_health": "[%key:ui::panel::config::system_health::caption%]",
"blueprint": "[%key:ui::panel::config::blueprint::caption%]", "blueprint": "[%key:ui::panel::config::blueprint::caption%]",
"system": "[%key:ui::panel::config::dashboard::system::main%]" "server_control": "[%key:ui::panel::developer-tools::tabs::yaml::title%]",
"system": "[%key:ui::panel::config::dashboard::system::main%]",
"addon_dashboard": "Add-on Dashboard",
"addon_store": "Add-on Store",
"addon_info": "{addon} Info"
} }
}, },
"filter_placeholder": "Entity Filter", "filter_placeholder": "Entity Filter",