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 helpful message when uploading duplicate firmware #1627

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

nshoes
Copy link
Contributor

@nshoes nshoes commented Oct 31, 2024

Fixes #1473.

This adds an error clause to provide helpful feedback when uploading firmware that has already been uploaded. There's already a test for this constraint, but let me know if a LiveView test is wanted/needed.

CleanShot 2024-11-01 at 08 35 36

[constraint: :unique, constraint_name: "firmwares_product_id_uuid_index"]}
]
}} ->
error_feedback(socket, "Duplicate firmware uploads are not allowed")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we get the uuid back in that changeset somewhere? It would be really cool to say something like Duplicate firmware - <link-to-firmware>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good idea! I'll try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Updated the gif in the PR description.

@nshoes nshoes force-pushed the show-helpful-error-duplicate-firmware-upload branch from b0c00ca to 9d68cfd Compare November 1, 2024 15:36

error_feedback(
socket,
"Duplicate firmware - <a href='#{route}' target='blank'>View Firmware</a>"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to find a way to not include an <a href> in a string error message, and then also use raw for displaying the message.

It might require a little refactoring, eg. instead of line 164 adding an error message to the assigns, maybe we add an error_code, like :duplicate_firmware and then use a helper function in the template which uses a case statement to define the long form message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that a lot more, I'll implement!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes pushed. I think instead of handling this scenario in a pattern-match with error_feedback, it could just be handled inline since we have to pattern-match on the UUID error and then pattern-match it again which feels weird. Lmk what you think!

@nshoes nshoes force-pushed the show-helpful-error-duplicate-firmware-upload branch 2 times, most recently from 02de318 to 3936a85 Compare November 4, 2024 22:40
Comment on lines 171 to 175
|> assign(:error_code, :duplicate_firmware)
|> assign(
:firmware_path,
"/org/#{socket.assigns.org.name}/#{socket.assigns.product.name}/firmware/#{changeset.changes.uuid}"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
|> assign(:error_code, :duplicate_firmware)
|> assign(
:firmware_path,
"/org/#{socket.assigns.org.name}/#{socket.assigns.product.name}/firmware/#{changeset.changes.uuid}"
)
|> assign(:error_code, {:duplicate_firmware, uuid})

Since we have control of this structure, we could just include the duplicate UUID and let the case handling of that view build the URL for it (or whatever else). That way we're not so coupled to 2 independent pieces of data having to exist in the assigns (@error_code and @firmware_path)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point. Fixed. We still need to keep track of the uuid to create the path, however. But I like constructing the path in the view more.

@nshoes nshoes force-pushed the show-helpful-error-duplicate-firmware-upload branch from 3936a85 to 6cce83d Compare November 5, 2024 15:09
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.

This generally looks good to me

@nshoes nshoes merged commit 00f29c6 into main Nov 5, 2024
2 checks passed
@nshoes nshoes deleted the show-helpful-error-duplicate-firmware-upload branch November 5, 2024 23:03
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.

Uploading duplicate firmware gives unfriendly error message
3 participants