mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Co-authored-by: Zack Barett <zackbarett@hey.com>
This commit is contained in:
parent
426a7ac8dd
commit
0405adcd16
@ -40,7 +40,14 @@ import "./ha-more-info-logbook";
|
||||
import "./controls/more-info-default";
|
||||
|
||||
const DOMAINS_NO_INFO = ["camera", "configurator"];
|
||||
/**
|
||||
* Entity domains that should be editable *if* they have an id present;
|
||||
* {@see shouldShowEditIcon}.
|
||||
* */
|
||||
const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation"];
|
||||
/**
|
||||
* Entity Domains that should always be editable; {@see shouldShowEditIcon}.
|
||||
* */
|
||||
const EDITABLE_DOMAINS = ["script"];
|
||||
|
||||
export interface MoreInfoDialogParams {
|
||||
@ -73,6 +80,20 @@ export class MoreInfoDialog extends LitElement {
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
|
||||
protected shouldShowEditIcon(domain, stateObj): boolean {
|
||||
if (EDITABLE_DOMAINS_WITH_ID.includes(domain) && stateObj.attributes.id) {
|
||||
return true;
|
||||
}
|
||||
if (EDITABLE_DOMAINS.includes(domain)) {
|
||||
return true;
|
||||
}
|
||||
if (domain === "person" && stateObj.attributes.editable !== "false") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected updated(changedProperties) {
|
||||
if (!this.hass || !this._entityId || !changedProperties.has("_entityId")) {
|
||||
return;
|
||||
@ -137,10 +158,7 @@ export class MoreInfoDialog extends LitElement {
|
||||
</mwc-icon-button>
|
||||
`
|
||||
: ""}
|
||||
${this.hass.user!.is_admin &&
|
||||
((EDITABLE_DOMAINS_WITH_ID.includes(domain) &&
|
||||
stateObj.attributes.id) ||
|
||||
EDITABLE_DOMAINS.includes(domain))
|
||||
${this.shouldShowEditIcon(domain, stateObj)
|
||||
? html`
|
||||
<mwc-icon-button
|
||||
slot="actionItems"
|
||||
@ -283,14 +301,12 @@ export class MoreInfoDialog extends LitElement {
|
||||
private _gotoEdit() {
|
||||
const stateObj = this.hass.states[this._entityId!];
|
||||
const domain = computeDomain(this._entityId!);
|
||||
navigate(
|
||||
this,
|
||||
`/config/${domain}/edit/${
|
||||
EDITABLE_DOMAINS_WITH_ID.includes(domain)
|
||||
? stateObj.attributes.id
|
||||
: stateObj.entity_id
|
||||
}`
|
||||
);
|
||||
let idToPassThroughUrl = stateObj.entity_id;
|
||||
if (EDITABLE_DOMAINS_WITH_ID.includes(domain) || domain === "person") {
|
||||
idToPassThroughUrl = stateObj.attributes.id;
|
||||
}
|
||||
|
||||
navigate(this, `/config/${domain}/edit/${idToPassThroughUrl}`);
|
||||
this.closeDialog();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,10 @@ import {
|
||||
updatePerson,
|
||||
} from "../../../data/person";
|
||||
import { fetchUsers, User } from "../../../data/user";
|
||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||
import {
|
||||
showConfirmationDialog,
|
||||
showAlertDialog,
|
||||
} from "../../../dialogs/generic/show-dialog-box";
|
||||
import "../../../layouts/hass-loading-screen";
|
||||
import "../../../layouts/hass-tabs-subpage";
|
||||
import { HomeAssistant, Route } from "../../../types";
|
||||
@ -158,6 +161,31 @@ class HaConfigPerson extends LitElement {
|
||||
this._configItems = personData.config.sort((ent1, ent2) =>
|
||||
compare(ent1.name, ent2.name)
|
||||
);
|
||||
this._openDialogIfPersonSpecifiedInRoute();
|
||||
}
|
||||
|
||||
private _openDialogIfPersonSpecifiedInRoute() {
|
||||
if (!this.route.path.includes("/edit/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const routeSegments = this.route.path.split("/edit/");
|
||||
const personId = routeSegments.length > 1 ? routeSegments[1] : null;
|
||||
if (!personId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const personToEdit = this._storageItems!.find((p) => p.id === personId);
|
||||
if (personToEdit) {
|
||||
this._openDialog(personToEdit);
|
||||
} else {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass?.localize(
|
||||
"ui.panel.config.person.person_not_found_title"
|
||||
),
|
||||
text: this.hass?.localize("ui.panel.config.person.person_not_found"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _createPerson() {
|
||||
|
@ -1697,6 +1697,8 @@
|
||||
"add_person": "Add Person",
|
||||
"confirm_delete": "Are you sure you want to delete this person?",
|
||||
"confirm_delete2": "All devices belonging to this person will become unassigned.",
|
||||
"person_not_found_title": "Person Not Found",
|
||||
"person_not_found": "We couldn't find the person you were trying to edit.",
|
||||
"detail": {
|
||||
"new_person": "New Person",
|
||||
"name": "Name",
|
||||
|
Loading…
x
Reference in New Issue
Block a user