-
Notifications
You must be signed in to change notification settings - Fork 70
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
socket = | ||
socket | ||
|> general_assigns(device) | ||
|> assign(:device_connection, Connections.get_latest_for_device(device.id)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Thank you 🙇
Yes! On it. |
No description provided.