mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Exp. UI: Add error card (#1298)
* Exp. UI: Add error card * Cleanup * Lint * Typo * Requested changes
This commit is contained in:
parent
2a8462951b
commit
dc9a227aa3
30
src/panels/experimental-ui/hui-error-card.js
Normal file
30
src/panels/experimental-ui/hui-error-card.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||||
|
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||||
|
|
||||||
|
class HuiErrorCard extends PolymerElement {
|
||||||
|
static get template() {
|
||||||
|
return html`
|
||||||
|
<style>
|
||||||
|
:host {
|
||||||
|
background-color: red;
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
[[config.error]]
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get properties() {
|
||||||
|
return {
|
||||||
|
config: Object
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getCardSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define('hui-error-card', HuiErrorCard);
|
@ -3,6 +3,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|||||||
|
|
||||||
import './hui-entities-card.js';
|
import './hui-entities-card.js';
|
||||||
import './hui-entity-filter-card.js';
|
import './hui-entity-filter-card.js';
|
||||||
|
import './hui-error-card.js';
|
||||||
|
|
||||||
import applyThemesOnElement from '../../common/dom/apply_themes_on_element.js';
|
import applyThemesOnElement from '../../common/dom/apply_themes_on_element.js';
|
||||||
|
|
||||||
@ -96,16 +97,22 @@ class HUIView extends PolymerElement {
|
|||||||
const elements = [];
|
const elements = [];
|
||||||
|
|
||||||
for (let i = 0; i < cards.length; i++) {
|
for (let i = 0; i < cards.length; i++) {
|
||||||
const cardConfig = cards[i];
|
let error = null;
|
||||||
const tag = cardElement(cardConfig.type);
|
let cardConfig = cards[i];
|
||||||
if (!tag) {
|
let tag;
|
||||||
// eslint-disable-next-line
|
if (!cardConfig.type) {
|
||||||
console.error('Unknown type encountered:', cardConfig.type);
|
error = 'Card type not configured.';
|
||||||
continue;
|
} else {
|
||||||
} else if (!customElements.get(tag)) {
|
tag = cardElement(cardConfig.type);
|
||||||
// eslint-disable-next-line
|
if (tag === null) {
|
||||||
console.error('Custom element doesn\'t exist:', tag);
|
error = `Unknown card type encountered: "${cardConfig.type}".`;
|
||||||
continue;
|
} else if (!customElements.get(tag)) {
|
||||||
|
error = `Custom element doesn't exist: "${tag}".`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
tag = 'hui-error-card';
|
||||||
|
cardConfig = { error };
|
||||||
}
|
}
|
||||||
const element = document.createElement(tag);
|
const element = document.createElement(tag);
|
||||||
element.config = cardConfig;
|
element.config = cardConfig;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user