mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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-entity-filter-card.js';
|
||||
import './hui-error-card.js';
|
||||
|
||||
import applyThemesOnElement from '../../common/dom/apply_themes_on_element.js';
|
||||
|
||||
@ -96,16 +97,22 @@ class HUIView extends PolymerElement {
|
||||
const elements = [];
|
||||
|
||||
for (let i = 0; i < cards.length; i++) {
|
||||
const cardConfig = cards[i];
|
||||
const tag = cardElement(cardConfig.type);
|
||||
if (!tag) {
|
||||
// eslint-disable-next-line
|
||||
console.error('Unknown type encountered:', cardConfig.type);
|
||||
continue;
|
||||
} else if (!customElements.get(tag)) {
|
||||
// eslint-disable-next-line
|
||||
console.error('Custom element doesn\'t exist:', tag);
|
||||
continue;
|
||||
let error = null;
|
||||
let cardConfig = cards[i];
|
||||
let tag;
|
||||
if (!cardConfig.type) {
|
||||
error = 'Card type not configured.';
|
||||
} else {
|
||||
tag = cardElement(cardConfig.type);
|
||||
if (tag === null) {
|
||||
error = `Unknown card type encountered: "${cardConfig.type}".`;
|
||||
} 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);
|
||||
element.config = cardConfig;
|
||||
|
Loading…
x
Reference in New Issue
Block a user