Fix Logbook Icons, Card Editor Close/Cancel buttons, View Editor Dirty (#11153)

This commit is contained in:
Zack Barett 2022-01-24 10:36:49 -06:00 committed by GitHub
parent 3ddcd2d0f6
commit 1a7164b466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import { formatTimeWithSeconds } from "../../common/datetime/format_time";
import { restoreScroll } from "../../common/decorators/restore-scroll";
import { fireEvent } from "../../common/dom/fire_event";
import { computeDomain } from "../../common/entity/compute_domain";
import { domainIcon } from "../../common/entity/domain_icon";
import { computeRTL, emitRTLDirection } from "../../common/util/compute_rtl";
import "../../components/entity/state-badge";
import "../../components/ha-circular-progress";
@ -150,7 +151,10 @@ class HaLogbook extends LitElement {
html`
<state-badge
.hass=${this.hass}
.overrideIcon=${item.icon}
.overrideIcon=${item.icon ||
(item.domain && !stateObj
? domainIcon(item.domain!)
: undefined)}
.overrideImage=${DOMAINS_WITH_DYNAMIC_PICTURE.has(domain)
? ""
: stateObj?.attributes.entity_picture_local ||

View File

@ -245,7 +245,7 @@ export class HuiDialogEditCard
<mwc-button @click=${this._cancel}>
${this.hass!.localize("ui.common.cancel")}
</mwc-button>
${this._cardConfig !== undefined
${this._cardConfig !== undefined && this._dirty
? html`
<mwc-button
?disabled=${!this._canSave || this._saving}
@ -259,9 +259,7 @@ export class HuiDialogEditCard
size="small"
></ha-circular-progress>
`
: this._dirty
? this.hass!.localize("ui.common.save")
: this.hass!.localize("ui.common.close")}
: this.hass!.localize("ui.common.save")}
</mwc-button>
`
: ``}

View File

@ -36,6 +36,7 @@ import {
PANEL_VIEW_LAYOUT,
VIEWS_NO_BADGE_SUPPORT,
} from "../../views/const";
import { deepEqual } from "../../../../common/util/deep-equal";
@customElement("hui-dialog-edit-view")
export class HuiDialogEditView extends LitElement {
@ -53,6 +54,8 @@ export class HuiDialogEditView extends LitElement {
@state() private _curTab?: string;
@state() private _dirty = false;
private _curTabIndex = 0;
get _type(): string {
@ -71,6 +74,7 @@ export class HuiDialogEditView extends LitElement {
this._config = {};
this._badges = [];
this._cards = [];
this._dirty = false;
} else {
const { cards, badges, ...viewConfig } =
this._params.lovelace!.config.views[this._params.viewIndex];
@ -85,6 +89,7 @@ export class HuiDialogEditView extends LitElement {
this._params = undefined;
this._config = {};
this._badges = [];
this._dirty = false;
fireEvent(this, "dialog-closed", { dialog: this.localName });
}
@ -214,7 +219,7 @@ export class HuiDialogEditView extends LitElement {
>
<mwc-button
slot="primaryAction"
?disabled=${!this._config || this._saving}
?disabled=${!this._config || this._saving || !this._dirty}
@click=${this._save}
>
${this._saving
@ -316,8 +321,13 @@ export class HuiDialogEditView extends LitElement {
}
private _viewConfigChanged(ev: ViewEditEvent): void {
if (ev.detail && ev.detail.config) {
if (
ev.detail &&
ev.detail.config &&
!deepEqual(this._config, ev.detail.config)
) {
this._config = ev.detail.config;
this._dirty = true;
}
}
@ -327,6 +337,7 @@ export class HuiDialogEditView extends LitElement {
if (ev.detail.visible && this._config) {
this._config.visible = ev.detail.visible;
}
this._dirty = true;
}
private _badgesChanged(ev: EntitiesEditorEvent): void {
@ -334,6 +345,7 @@ export class HuiDialogEditView extends LitElement {
return;
}
this._badges = processEditorEntities(ev.detail.entities);
this._dirty = true;
}
private _isConfigChanged(): boolean {