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

Refresh device-related assigns when receiving connection online message #1738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nshoes
Copy link
Contributor

@nshoes nshoes commented Jan 7, 2025

No description provided.

Copy link
Collaborator

@joshk joshk left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of this.

Do you think we should add a test to confirm data is updated on the page when a device connects?

@@ -43,15 +43,11 @@ defmodule NervesHubWeb.Live.Devices.Show do
|> page_title("Device #{device.identifier} - #{product.name}")
|> assign(:tab_hint, :devices)
|> assign(:device, device)
|> assign(:device_connection, device_connection(device))
|> assign(:console_active?, Tracker.console_active?(device))
|> assign(:deployment, device.deployment)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this needs to move into general_assigns as well

Comment on lines +79 to +82
socket =
socket
|> general_assigns(device)
|> assign(:device_connection, Connections.get_latest_for_device(device.id))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should reload the device, then do the general_assigns, and since we will be reloading the device we won't need to do line 82, instead we can move |> assign(:device_connection, device_connection(device)) from mount into general_assigns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When setting assigns.device_connection, which should we prefer? Connections.get_latest_for_device(device.id) or device_connection(device)? I think that in the lifecycle events that we're talking about (mount, connection status inline, connection status offline) we should always fetch the latest device connection record. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are fetching the Device, the latest device connection is included, but if we aren't fetching the Device (like when the status changes to "offline") we don't need to fetch the Device, we can just use Connections.get_latest_for_device(device.id), does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Thank you 🙇

@nshoes
Copy link
Contributor Author

nshoes commented Jan 7, 2025

Do you think we should add a test to confirm data is updated on the page when a device connects?

Yes! On it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants