-
Notifications
You must be signed in to change notification settings - Fork 58
fix #3605 #3618
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
fix #3605 #3618
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3618 +/- ##
==========================================
- Coverage 89.65% 89.60% -0.05%
==========================================
Files 410 410
Lines 17075 17086 +11
==========================================
+ Hits 15308 15310 +2
- Misses 1767 1776 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Hey @taylordowns2000 great work on this one. I have few observations. They should probably not block this PR from a functionality point of view. But I was thinking they could improve code quality. Let me know if you wanna discuss them
| |> validate_required([:content], | ||
| message: "Please enter a message before sending" | ||
| ) | ||
| |> validate_length(:content, | ||
| min: 1, | ||
| message: "Please enter a message before sending" | ||
| ) |
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.
Is both validate_required and validate_length(min: 1) necessary here? They seem to cover the same case (empty content). Could we simplify this to just one validation?
| socket | ||
| ) do | ||
| cleared_params = Map.put(params, "content", nil) | ||
| trimmed_content = if is_binary(content), do: String.trim(content), else: "" |
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.
Since content comes from a form input, it should always be a string. The is_binary check is likely unnecessary.
| trimmed_content == "" -> | ||
| changeset = socket.assigns.handler.validate_form(%{"content" => ""}) | ||
|
|
||
| changeset = | ||
| Ecto.Changeset.add_error( | ||
| changeset, | ||
| :content, | ||
| "Please enter a message before sending" | ||
| ) | ||
|
|
||
| {:noreply, | ||
| socket | ||
| |> assign( | ||
| changeset: changeset, | ||
| alert: "Please enter a message before sending" | ||
| )} |
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.
This manual empty content validation duplicates what should already be handled by the changeset validations. The current approach creates inconsistency where some validation happens in changesets and some happens in the controller. Why are we not relying entirely on changeset validation ?
| id={"ai-assistant-form-submit-btn-#{@id}"} | ||
| type="submit" | ||
| disabled={@disabled} | ||
| disabled={@disabled || form_content_empty?(@form[:content].value)} |
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.
Why isn't this part of the @disabled attribute. When the button is disabled other elements of this component should be disabled too, right ?
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.
hey @elias-ba , no, i don't think so. unless im misunderstanding what you're saying here. have you really tested this hard in the user interface? what you're asking here would be bad—we want the whole thing to be enabled but we want the submit button to be disabled. if we disab. ed the entire form when the user hasn't yet typed antyhing into the chat, you'd never be able to type anything into the chat.
have i misunderstood your request? sorry if so!
| class={[ | ||
| "p-1.5 rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 transition-all duration-200 flex items-center justify-center h-7 w-7", | ||
| if(@disabled, | ||
| if(@disabled || form_content_empty?(@form[:content].value), |
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.
Same observation here ?
| |> validate_required([:content], | ||
| message: "Please enter a message before sending" | ||
| ) | ||
| |> validate_length(:content, | ||
| min: 1, | ||
| message: "Please enter a message before sending" | ||
| ) |
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.
Same observation than before about the duplication of this validation.
2120921 to
61373f2
Compare
|
hey @elias-ba , i re-requested your review because I implemented the changes you requested but in doing so realized that the feature no longer works as desired. all changes reverted. if this functionality worked as expected in the UI when you tested it, i'd recommend approving. (you mentioned in your PR that this is merely code quality stuff, and this code will be thrown with the elixir AI chat—replaced by JS—very soon anyway!)
And btw, if there's something in particular that feels like it should block this, let me know! |
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.
@taylordowns2000 you are right we shouldn't block this PR for small code quality stuff. There's nothing in here that's a bad design. Just few stuff that caught my attention. I am going to approve this and we can always come back later and make code better. Congratulations for the great work 👏🏽
|
@elias-ba @taylordowns2000 I’ve reviewed the updates and I don’t see anything that should block this PR from being merged. Everything looks fine, and since this will be replaced by the JS version soon, no need to block over concerns issues—we can clean those up later. |
|
Thanks a lot @mercy-ship-it, happy we aligned. I think you need to approve the PR. |
Description
This PR fixes #3605
Validation steps
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy
Pre-submission checklist
:owner,:admin,:editor,:viewer)