Edit Person button in the Person "more info" dialog (fixes #4706)#7208
Edit Person button in the Person "more info" dialog (fixes #4706)#7208bramkragten merged 6 commits intohome-assistant:devfrom spencerwi:dev
Conversation
…dit dialog on the Persons page after navigation
|
Hi @spencerwi, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
|
I didn't see any relevant component tests to be updated, though I admit I'm not fully familiar with the project structure yet. |
|
Are there any component tests that should be updated here? I don't see any that I could use as a "base" for writing any new tests. |
|
We dont usually run test in the Frontend. At least not yet. Not sure why that checkbox is there. I think it was from another repo |
Co-authored-by: Zack Barett <zackbarett@hey.com>
|
Hey, sorry -- I didn't mean to pester. I just noticed the empty checkbox on the template and wanted to make sure I hadn't missed a step. Thanks for the review! |
| const isPersonSpecifiedInRoute = | ||
| this.route?.path && this.route.path.includes("/edit/"); | ||
| if (isPersonSpecifiedInRoute) { | ||
| const routeSegments = this.route.path.split("/edit/"); | ||
| const personId = routeSegments.length > 1 ? routeSegments[1] : null; | ||
| if (personId) { | ||
| const personToEdit = this._storageItems!.find((p) => p.id === personId); | ||
| if (personToEdit) { | ||
| this._openDialog(personToEdit); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
| const isPersonSpecifiedInRoute = | |
| this.route?.path && this.route.path.includes("/edit/"); | |
| if (isPersonSpecifiedInRoute) { | |
| const routeSegments = this.route.path.split("/edit/"); | |
| const personId = routeSegments.length > 1 ? routeSegments[1] : null; | |
| if (personId) { | |
| const personToEdit = this._storageItems!.find((p) => p.id === personId); | |
| if (personToEdit) { | |
| this._openDialog(personToEdit); | |
| } | |
| } | |
| } | |
| if (!this.route.path.includes("/edit/")) { | |
| return; | |
| } | |
| const routeSegments = this.route.path.split("/edit/"); | |
| const personId = routeSegments[1]; | |
| if (!personId) { | |
| return; | |
| } | |
| const personToEdit = this._storageItems!.find((p) => p.id === personId); | |
| if (personToEdit) { | |
| this._openDialog(personToEdit); | |
| } |
There was a problem hiding this comment.
Try to break out as soon as possible instead of nesting if's
There was a problem hiding this comment.
And we should show a message when we can't find the person they want to edit
|
|
||
| const DOMAINS_NO_INFO = ["camera", "configurator"]; | ||
| const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation"]; | ||
| const EDITABLE_DOMAINS_WITH_ID = ["scene", "automation", "person"]; |
There was a problem hiding this comment.
The person will always have an ID, also when it is not editable (YAML).
There was a problem hiding this comment.
There is an attribute, editable: true that we should use.
There was a problem hiding this comment.
Ah, interesting. I'll update to handle that case.
Would you be alright with it if I extracted this conditional from the HTML template into a getter method so that it's a bit easier to work with?
frontend/src/dialogs/more-info/ha-more-info-dialog.ts
Lines 140 to 143 in 34c2742
There was a problem hiding this comment.
Yeah that's fine, I would not add person to the EDITABLE_DOMAINS_WITH_ID though, as it would need a different check.
There was a problem hiding this comment.
I think I understand a bit better now -- I understood EDITABLE_DOMAINS_WITH_ID to mean "domains that are editable, and have an ID parameter that should be passed along", but it seems to instead mean "domains that are only editable if an ID is present". I may add a JSDoc comment to that effect, if that's fine with you.
Proposed change
In the "more info" for a Person entity, this PR allows the quick-go-to-edit "pencil" button to be shown, which will navigate to the Person config panel. It also adds an after-data-fetch check to the Person config panel for the URL segment added by that navigation indicating a Person that is intended to be edited. If that URL segment is present, and the Person specified matches one of the Person entities that was fetched, then the page will open the "Edit Person" dialog without requiring additional user intervention.
The resulting user flow is that a user can click on a Person entity anywhere in Lovelace to view the "more info" dialog, then click the "pencil" icon (if they're an administrator), which will navigate them to the People config page and automatically open the "edit person" dialog for that Person entity.
Type of change
Example configuration
Should be verifiable from the default Lovelace view that shows all entities -- click a Person entity to launch the "more info" dialog.
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: