Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the user that made the change in logbook #6173

Merged
merged 5 commits into from
Jun 16, 2020

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jun 15, 2020

Proposed change

Show the user that made the change in logbook

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
private async _fetchUsers() {
const users = await fetchUsers(this.hass);
users.forEach((user) => {
this._userid_to_name[user.id] = user.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't update now after the users are loaded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this is a temporary object and after the forEach set it to this._userid_to_name that will make sure we do a re-render.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following. Is the concern that we remove users and then the user ids are still in this._userid_to_name ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, LitElement only re-render if a property is changed, it does this with a strict check, if we add things to this._userid_to_name it will not change this._userid_to_name.

So the LitElement will not re-render, thus not showing names until something else changed that will make it rerender.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This btw would only be a problem if the logbook data is loaded before the user data, that is probably never going to happen but you are well on your way...

private async _fetchUsers() {
const users = await fetchUsers(this.hass);
users.forEach((user) => {
this._userid_to_name[user.id] = user.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other option would be to copy it: this._userid_to_name = { ...this._userid_to_name, user.id: user.name }; But that is making a lot of copies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WE should make it a @property, create a new object here and just assign it to this._userid_to_name = userid_to_name`

@bramkragten bramkragten merged commit f15cc0b into home-assistant:dev Jun 16, 2020
@lock lock bot locked and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants