mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Add edit btn to more info for scene, script and automation (#4476)
This commit is contained in:
parent
da25701dca
commit
bc731a9dc3
@ -12,6 +12,7 @@ import "../../state-summary/state-card-content";
|
||||
|
||||
import "./controls/more-info-content";
|
||||
|
||||
import { navigate } from "../../common/navigate";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
@ -23,6 +24,9 @@ import { removeEntityRegistryEntry } from "../../data/entity_registry";
|
||||
import { showConfirmationDialog } from "../confirmation/show-dialog-confirmation";
|
||||
|
||||
const DOMAINS_NO_INFO = ["camera", "configurator", "history_graph"];
|
||||
const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation"];
|
||||
const EDITABLE_DOMAINS = ["script"];
|
||||
|
||||
/*
|
||||
* @appliesMixin EventsMixin
|
||||
*/
|
||||
@ -90,6 +94,13 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
on-click="_gotoSettings"
|
||||
></paper-icon-button>
|
||||
</template>
|
||||
<template is="dom-if" if="[[_computeEdit(hass, stateObj)]]">
|
||||
<paper-icon-button
|
||||
aria-label$="[[localize('ui.dialogs.more_info_control.edit')]]"
|
||||
icon="hass:pencil"
|
||||
on-click="_gotoEdit"
|
||||
></paper-icon-button>
|
||||
</template>
|
||||
</app-toolbar>
|
||||
|
||||
<template is="dom-if" if="[[_computeShowStateInfo(stateObj)]]" restamp="">
|
||||
@ -209,6 +220,16 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
return stateObj ? computeStateName(stateObj) : "";
|
||||
}
|
||||
|
||||
_computeEdit(hass, stateObj) {
|
||||
const domain = this._computeDomain(stateObj);
|
||||
return (
|
||||
stateObj &&
|
||||
hass.user.is_admin &&
|
||||
((EDITABLE_DOMAINS_WITH_ID.includes(domain) && stateObj.attributes.id) ||
|
||||
EDITABLE_DOMAINS.includes(domain))
|
||||
);
|
||||
}
|
||||
|
||||
_stateObjChanged(newVal) {
|
||||
if (!newVal) {
|
||||
return;
|
||||
@ -241,6 +262,19 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
||||
this.fire("more-info-page", { page: "settings" });
|
||||
}
|
||||
|
||||
_gotoEdit() {
|
||||
const domain = this._computeDomain(this.stateObj);
|
||||
navigate(
|
||||
this,
|
||||
`/config/${domain}/edit/${
|
||||
EDITABLE_DOMAINS_WITH_ID.includes(domain)
|
||||
? this.stateObj.attributes.id
|
||||
: this.stateObj.entity_id
|
||||
}`
|
||||
);
|
||||
this.fire("hass-more-info", { entityId: null });
|
||||
}
|
||||
|
||||
_computeRTL(hass) {
|
||||
return computeRTL(hass);
|
||||
}
|
||||
|
@ -572,6 +572,7 @@
|
||||
"more_info_control": {
|
||||
"dismiss": "Dismiss dialog",
|
||||
"settings": "Entity settings",
|
||||
"edit": "Edit entity",
|
||||
"script": {
|
||||
"last_action": "Last Action"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user