Skip to content

Commit

Permalink
Disable resource panel in safe mode (#18437)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Oct 27, 2023
1 parent 951b88a commit 1a23124
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { mdiPlus } from "@mdi/js";
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import memoize from "memoize-one";
import { stringCompare } from "../../../../common/string/compare";
import {
DataTableColumnContainer,
RowClickedEvent,
} from "../../../../components/data-table/ha-data-table";
import "../../../../components/ha-card";
import "../../../../components/ha-fab";
import "../../../../components/ha-svg-icon";
import {
Expand All @@ -21,7 +29,9 @@ import {
showConfirmationDialog,
} from "../../../../dialogs/generic/show-dialog-box";
import "../../../../layouts/hass-loading-screen";
import "../../../../layouts/hass-subpage";
import "../../../../layouts/hass-tabs-subpage-data-table";
import { haStyle } from "../../../../resources/styles";
import { HomeAssistant, Route } from "../../../../types";
import { loadLovelaceResources } from "../../../lovelace/common/load-resources";
import { lovelaceTabs } from "../ha-config-lovelace";
Expand Down Expand Up @@ -72,6 +82,36 @@ export class HaConfigLovelaceRescources extends LitElement {
return html` <hass-loading-screen></hass-loading-screen> `;
}

if (this.hass.config.safe_mode) {
return html`
<hass-subpage
.hass=${this.hass}
.narrow=${this.narrow}
back-path="/config"
.header=${this.hass.localize(
"ui.panel.config.lovelace.resources.caption"
)}
>
<div class="content">
<ha-card outlined>
<div class="card-content">
<h2>
${this.hass.localize(
"ui.panel.config.lovelace.resources.unavailable"
)}
</h2>
<p>
${this.hass.localize(
"ui.panel.config.lovelace.resources.unavailable_safe_mode"
)}
</p>
</div>
</ha-card>
</div>
</hass-subpage>
`;
}

return html`
<hass-tabs-subpage-data-table
.hass=${this.hass}
Expand Down Expand Up @@ -192,4 +232,24 @@ export class HaConfigLovelaceRescources extends LitElement {
},
});
}

static get styles(): CSSResultGroup {
return [
haStyle,
css`
.content {
padding: 28px 20px 0;
max-width: 1040px;
margin: 0 auto;
}
h2 {
margin-top: 0;
margin-bottom: 12px;
}
p {
margin: 0;
}
`,
];
}
}
5 changes: 0 additions & 5 deletions src/panels/lovelace/common/load-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ export const loadLovelaceResources = (
resources: NonNullable<LovelaceResource[]>,
hass: HomeAssistant
) => {
// Don't load ressources on safe mode
// Sometimes, hass.config is null but it should not.
if (hass.config?.safe_mode) {
return;
}
resources.forEach((resource) => {
const normalizedUrl = new URL(
resource.url,
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,8 @@
"js": "JavaScript file (deprecated)",
"module": "JavaScript module"
},
"unavailable": "Resources unavailable",
"unavailable_safe_mode": "Resources are not available in safe mode",
"picker": {
"headers": {
"url": "URL",
Expand Down

0 comments on commit 1a23124

Please sign in to comment.