Skip to content

Conversation

@taylordowns2000
Copy link
Member

Description

This PR fixes #3605

Validation steps

  1. Open the AI chat on an existing workflow
  2. Try to send without any text.
  3. Note the send button is grey
  4. Note that you can still attempt to send via command+enter
  5. Note that the error message indicates you need to enter some text
  6. Note that the canvas doesn't freeze up

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@codecov
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

❌ Patch coverage is 57.14286% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.60%. Comparing base (6adbdd3) to head (2cbdcd6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/lightning_web/live/ai_assistant/component.ex 57.14% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@elias-ba elias-ba left a 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

Comment on lines +43 to +49
|> validate_required([:content],
message: "Please enter a message before sending"
)
|> validate_length(:content,
min: 1,
message: "Please enter a message before sending"
)
Copy link
Contributor

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: ""
Copy link
Contributor

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.

Comment on lines +267 to +282
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"
)}
Copy link
Contributor

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)}
Copy link
Contributor

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 ?

Copy link
Member Author

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),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same observation here ?

Comment on lines +240 to +246
|> validate_required([:content],
message: "Please enter a message before sending"
)
|> validate_length(:content,
min: 1,
message: "Please enter a message before sending"
)
Copy link
Contributor

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.

@taylordowns2000
Copy link
Member Author

taylordowns2000 commented Sep 29, 2025

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!)

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

And btw, if there's something in particular that feels like it should block this, let me know!

Copy link
Contributor

@elias-ba elias-ba left a 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 👏🏽

@mercy-ship-it
Copy link
Contributor

mercy-ship-it commented Oct 1, 2025

@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.

@elias-ba
Copy link
Contributor

elias-ba commented Oct 1, 2025

Thanks a lot @mercy-ship-it, happy we aligned. I think you need to approve the PR.

@taylordowns2000 taylordowns2000 merged commit f30ca39 into main Oct 1, 2025
6 of 8 checks passed
@taylordowns2000 taylordowns2000 deleted the 3605 branch October 1, 2025 12:06
@github-project-automation github-project-automation bot moved this from In review to Done in v2 Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

AI Assistant – “Send” button without input causes error and locks the canvas

4 participants