From 4511c8f30cfbf1eb1774ad9aac336e95de8c0d01 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 6 Apr 2021 17:59:08 +0200 Subject: [PATCH] Don't show back button when no history (#8822) * Don't show back button when no history * Update src/translations/en.json Co-authored-by: Philip Allgaier Co-authored-by: Philip Allgaier --- src/layouts/hass-error-screen.ts | 2 +- src/layouts/hass-loading-screen.ts | 2 +- src/layouts/hass-subpage.ts | 26 +++++--- src/layouts/hass-tabs-subpage.ts | 2 +- src/layouts/supervisor-error-screen.ts | 66 ++++--------------- .../automation/trace/ha-automation-trace.ts | 5 -- src/panels/config/cloud/alexa/cloud-alexa.ts | 6 +- .../cloud-google-assistant.ts | 3 +- .../mqtt/mqtt-config-panel.ts | 4 +- src/state/url-sync-mixin.ts | 3 + src/translations/en.json | 19 +++--- 11 files changed, 52 insertions(+), 86 deletions(-) diff --git a/src/layouts/hass-error-screen.ts b/src/layouts/hass-error-screen.ts index cadf6c28ed..b335218f03 100644 --- a/src/layouts/hass-error-screen.ts +++ b/src/layouts/hass-error-screen.ts @@ -28,7 +28,7 @@ class HassErrorScreen extends LitElement { return html` ${this.toolbar ? html`
- ${this.rootnav + ${this.rootnav || history.state?.root ? html` - ${this.rootnav + ${this.rootnav || history.state?.root ? html` - + ${this.mainPage || history.state?.root + ? html` + + ` + : html` + + `}
${this.header}
diff --git a/src/layouts/hass-tabs-subpage.ts b/src/layouts/hass-tabs-subpage.ts index ed4d1e57ac..fa0f873966 100644 --- a/src/layouts/hass-tabs-subpage.ts +++ b/src/layouts/hass-tabs-subpage.ts @@ -140,7 +140,7 @@ class HassTabsSubpage extends LitElement { const showTabs = tabs.length > 1 || !this.narrow; return html`
- ${this.mainPage + ${this.mainPage || history.state?.root ? html` - -
-
-
- ${this.hass.localize("ui.panel.error.supervisor.title")} -
+
  1. - ${this.hass.localize("ui.panel.error.supervisor.wait")} + ${this.hass.localize("ui.errors.supervisor.wait")}
  2. - ${this.hass.localize("ui.panel.error.supervisor.observer")} + ${this.hass.localize("ui.errors.supervisor.observer")}
  3. - ${this.hass.localize("ui.panel.error.supervisor.reboot")} + ${this.hass.localize("ui.errors.supervisor.reboot")}
  4. - ${this.hass.localize( - "ui.panel.error.supervisor.system_health" - )} + ${this.hass.localize("ui.errors.supervisor.system_health")}
  5. @@ -83,13 +74,13 @@ class SupervisorErrorScreen extends LitElement { target="_blank" rel="noreferrer" > - ${this.hass.localize("ui.panel.error.supervisor.ask")} + ${this.hass.localize("ui.errors.supervisor.ask")}
-
+ `; } @@ -125,50 +116,17 @@ class SupervisorErrorScreen extends LitElement { ); } - private _handleBack(): void { - history.back(); - } - static get styles(): CSSResultArray { return [ haStyle, css` - .toolbar { - display: flex; - align-items: center; - font-size: 20px; - height: var(--header-height); - padding: 0 16px; - pointer-events: none; - background-color: var(--app-header-background-color); - font-weight: 400; - box-sizing: border-box; - } - ha-icon-button-arrow-prev { - pointer-events: auto; - } - .content { - color: var(--primary-text-color); - display: flex; - padding: 16px; - align-items: center; - justify-content: center; - flex-direction: column; - } - .title { - font-size: 24px; - font-weight: 400; - line-height: 32px; - padding-bottom: 16px; - } - a { color: var(--mdc-theme-primary); } ha-card { width: 600px; - margin: 16px; + margin: auto; padding: 8px; } @media all and (max-width: 500px) { diff --git a/src/panels/config/automation/trace/ha-automation-trace.ts b/src/panels/config/automation/trace/ha-automation-trace.ts index 1546ad49ad..53c7131dc3 100644 --- a/src/panels/config/automation/trace/ha-automation-trace.ts +++ b/src/panels/config/automation/trace/ha-automation-trace.ts @@ -103,7 +103,6 @@ export class HaAutomationTrace extends LitElement { .hass=${this.hass} .narrow=${this.narrow} .route=${this.route} - .backCallback=${() => this._backTapped()} .tabs=${configSections.automation} > ${this.narrow @@ -388,10 +387,6 @@ export class HaAutomationTrace extends LitElement { this._trace = trace; } - private _backTapped(): void { - history.back(); - } - private _downloadTrace() { const aEl = document.createElement("a"); aEl.download = `trace ${this._entityId} ${ diff --git a/src/panels/config/cloud/alexa/cloud-alexa.ts b/src/panels/config/cloud/alexa/cloud-alexa.ts index d9bdbd1e14..079ebdef10 100644 --- a/src/panels/config/cloud/alexa/cloud-alexa.ts +++ b/src/panels/config/cloud/alexa/cloud-alexa.ts @@ -214,9 +214,9 @@ class CloudAlexa extends LitElement { } return html` - + ${ emptyFilter ? html` diff --git a/src/panels/config/cloud/google-assistant/cloud-google-assistant.ts b/src/panels/config/cloud/google-assistant/cloud-google-assistant.ts index 4582ff7a1b..3ba045e6a5 100644 --- a/src/panels/config/cloud/google-assistant/cloud-google-assistant.ts +++ b/src/panels/config/cloud/google-assistant/cloud-google-assistant.ts @@ -239,7 +239,8 @@ class CloudGoogleAssistant extends LitElement { return html` + .header=${this.hass!.localize("ui.panel.config.cloud.google.title")} + .narrow=${this.narrow}> ${ emptyFilter ? html` diff --git a/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts b/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts index 1df1f36d08..e2ec44c628 100644 --- a/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts +++ b/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts @@ -23,6 +23,8 @@ import "./mqtt-subscribe-card"; class HaPanelDevMqtt extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; + @property({ type: Boolean }) public narrow!: boolean; + @internalProperty() private topic = ""; @internalProperty() private payload = ""; @@ -41,7 +43,7 @@ class HaPanelDevMqtt extends LitElement { protected render(): TemplateResult { return html` - +
diff --git a/src/state/url-sync-mixin.ts b/src/state/url-sync-mixin.ts index 1976a06a14..b7f44f89de 100644 --- a/src/state/url-sync-mixin.ts +++ b/src/state/url-sync-mixin.ts @@ -25,6 +25,9 @@ export const urlSyncMixin = < public connectedCallback(): void { super.connectedCallback(); + if (history.length === 1) { + history.replaceState({ ...history.state, root: true }, ""); + } window.addEventListener("popstate", this._popstateChangeListener); this.addEventListener("dialog-closed", this._dialogClosedListener); } diff --git a/src/translations/en.json b/src/translations/en.json index 3315f926f1..e187f9656d 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -823,6 +823,14 @@ "key_not_expected": "Key \"{key}\" is not expected or not supported by the visual editor.", "key_wrong_type": "The provided value for \"{key}\" is not supported by the visual editor. We support ({type_correct}) but received ({type_wrong}).", "no_template_editor_support": "Templates not supported in visual editor" + }, + "supervisor": { + "title": "Could not load the Supervisor panel!", + "wait": "If you just started, make sure you have given the Supervisor enough time to start.", + "ask": "Ask for help", + "reboot": "Try a reboot of the host", + "observer": "Check the Observer", + "system_health": "Check System Health" } }, "login-form": { @@ -3521,17 +3529,6 @@ "complete_access": "It will have access to all data in Home Assistant.", "hide_message": "Check docs for the panel_custom component to hide this message" } - }, - "error": { - "go_back": "Go back", - "supervisor": { - "title": "Could not load the Supervisor panel!", - "wait": "If you just started, make sure you have given the supervisor enough time to start.", - "ask": "Ask for help", - "reboot": "Try a reboot of the host", - "observer": "Check the Observer", - "system_health": "Check System Health" - } } } },