Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/dialogs/more-info/ha-more-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}

Expand Down
30 changes: 29 additions & 1 deletion src/panels/config/person/ha-config-person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,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",
Expand Down