mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-02 14:07:55 +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 "./controls/more-info-content";
|
||||||
|
|
||||||
|
import { navigate } from "../../common/navigate";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
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";
|
import { showConfirmationDialog } from "../confirmation/show-dialog-confirmation";
|
||||||
|
|
||||||
const DOMAINS_NO_INFO = ["camera", "configurator", "history_graph"];
|
const DOMAINS_NO_INFO = ["camera", "configurator", "history_graph"];
|
||||||
|
const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation"];
|
||||||
|
const EDITABLE_DOMAINS = ["script"];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @appliesMixin EventsMixin
|
* @appliesMixin EventsMixin
|
||||||
*/
|
*/
|
||||||
@ -90,6 +94,13 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
on-click="_gotoSettings"
|
on-click="_gotoSettings"
|
||||||
></paper-icon-button>
|
></paper-icon-button>
|
||||||
</template>
|
</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>
|
</app-toolbar>
|
||||||
|
|
||||||
<template is="dom-if" if="[[_computeShowStateInfo(stateObj)]]" restamp="">
|
<template is="dom-if" if="[[_computeShowStateInfo(stateObj)]]" restamp="">
|
||||||
@ -209,6 +220,16 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
return stateObj ? computeStateName(stateObj) : "";
|
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) {
|
_stateObjChanged(newVal) {
|
||||||
if (!newVal) {
|
if (!newVal) {
|
||||||
return;
|
return;
|
||||||
@ -241,6 +262,19 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
this.fire("more-info-page", { page: "settings" });
|
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) {
|
_computeRTL(hass) {
|
||||||
return computeRTL(hass);
|
return computeRTL(hass);
|
||||||
}
|
}
|
||||||
|
@ -572,6 +572,7 @@
|
|||||||
"more_info_control": {
|
"more_info_control": {
|
||||||
"dismiss": "Dismiss dialog",
|
"dismiss": "Dismiss dialog",
|
||||||
"settings": "Entity settings",
|
"settings": "Entity settings",
|
||||||
|
"edit": "Edit entity",
|
||||||
"script": {
|
"script": {
|
||||||
"last_action": "Last Action"
|
"last_action": "Last Action"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user