Skip to content

Conversation

mlopezFC
Copy link
Member

@mlopezFC mlopezFC commented Aug 26, 2025

Fixes #47

Summary by CodeRabbit

  • Refactor
    • Reworked message rendering to use a grid-based layout, enabling per-message column rendering for finer control over display.
  • Style
    • Switched to a compact, borderless message list for a cleaner look.
    • Reduced cell padding for a denser, more space-efficient layout.

@mlopezFC mlopezFC requested a review from javier-godoy August 26, 2025 22:47
Copy link

coderabbitai bot commented Aug 26, 2025

Walkthrough

Replaced VirtualList-based message rendering with a Grid-based implementation in ChatAssistant.java, added a per-column content renderer, applied Lumo no-border row theme and a compact CSS class, and added a CSS rule to remove grid cell padding.

Changes

Cohort / File(s) Summary
Rendering refactor to Grid
src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
Replaced VirtualList<T> with Grid<T> for content; added CHAT_ASSISTANT_GRID_COMPACT CSS class; configured grid theme variants LUMO_NO_BORDER and LUMO_NO_ROW_BORDERS; added a content column with a renderer; updated setMessagesRenderer to set the column renderer; removed unused padding constant and VirtualList import.
Styles for compact grid
src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css
Added rule vaadin-grid.chat-assistant-grid-compact vaadin-grid-cell-content { padding: 0px; } to reduce grid cell padding for compact appearance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Replace virtual-list with a minimal grid approach (#47)
Resolve duplicate/missing message rendering with markdown and lazy loading (#47) Change directly replaces VirtualList, but no tests or scrolling/lazy-loading handling shown to confirm issue fixed.
Ensure stable rendering during long scrolling in markdown demo (#47) No explicit lazy-loading/scrolling logic or test additions to verify stability under long-scroll conditions.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • javier-godoy

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 894f45c and 709c596.

📒 Files selected for processing (2)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java (4 hunks)
  • src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-47

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css (1)

58-61: Use ::part() to style Grid internals; current selector likely won’t pierce the shadow DOM

vaadin-grid-cell-content lives inside the Grid’s shadow root. Global CSS selectors won’t reach it. Prefer ::part selectors, which are supported by Grid, to actually zero out padding.

Apply this diff:

-vaadin-grid.chat-assistant-grid-compact vaadin-grid-cell-content {
-	padding: 0px;
-}
+vaadin-grid.chat-assistant-grid-compact::part(cell) {
+  padding: 0;
+}
+/* Optional: if a header row is visible, keep it compact as well */
+vaadin-grid.chat-assistant-grid-compact::part(header-cell) {
+  padding: 0;
+}

If you still see residual spacing, also consider making rows compact via theme variant (see Java comment) instead of relying solely on CSS.

src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java (4)

74-78: Keep a direct reference to the content column to avoid “magic key” lookups

Later you fetch the column by key "content". That’s brittle and can return null if the key changes. Store the column once and reuse it.

Apply this diff:

-  private Grid<T> content = new Grid<>();
+  private Grid<T> content = new Grid<>();
+  private Grid.Column<T> contentColumn;

151-158: Tighten Grid setup: add compact/wrap variants, disable selection, and use a pure renderer column

  • Add LUMO_COMPACT and LUMO_WRAP_CELL_CONTENT variants to reduce paddings and ensure long markdown wraps without horizontal scrollbars.
  • Disable row selection to prevent accidental selection highlight on message clicks.
  • Use addColumn(new ComponentRenderer<>(...)) directly instead of providing a value provider and then overriding it with a renderer. The value provider is unused and can affect sort defaults.

Apply this diff:

-    content.addThemeVariants(GridVariant.LUMO_NO_BORDER);
-    content.addThemeVariants(GridVariant.LUMO_NO_ROW_BORDERS);
-    content.setClassName("chat-assistant-grid-compact");
-    content.addColumn(m->m.getContent()).setKey("content").setRenderer(new ComponentRenderer<>(message -> new ChatMessage<T>(message, markdownEnabled), 
+    content.addThemeVariants(
+        GridVariant.LUMO_NO_BORDER,
+        GridVariant.LUMO_NO_ROW_BORDERS,
+        GridVariant.LUMO_COMPACT,
+        GridVariant.LUMO_WRAP_CELL_CONTENT);
+    content.setSelectionMode(Grid.SelectionMode.NONE);
+    content.setClassName("chat-assistant-grid-compact");
+    contentColumn = content.addColumn(new ComponentRenderer<>(
+        message -> new ChatMessage<T>(message, markdownEnabled),
         (component, message) -> {
           ((ChatMessage<T>) component).setMessage(message);
           return component;
-        }));
+        }))
+        .setKey("content");

Follow-up check (manual): with many long markdown messages and lazy loading enabled, scroll up/down rapidly and confirm:

  • No duplicate or missing rows.
  • No selection highlight flash on click/tap.
  • Lines wrap as expected without horizontal scrolling.

384-387: Avoid stringly-typed column lookup; use the stored reference

This prevents an NPE if the key is changed elsewhere and is marginally faster.

Apply this diff:

-    content.getColumnByKey("content").setRenderer(renderer);
+    contentColumn.setRenderer(renderer);

207-213: Update stale Javadoc: it references VirtualList but we now use Grid

Minor but could confuse users of the API.

Apply this diff:

-  /**
-   * Sets the data provider of the internal VirtualList.
-   * 
-   * @param dataProvider the data provider to be used
-   */
+  /**
+   * Sets the data provider of the internal Grid.
+   *
+   * @param dataProvider the data provider to be used
+   */
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2555525 and 894f45c.

📒 Files selected for processing (2)
  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java (4 hunks)
  • src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css:20-28
Timestamp: 2025-07-22T20:00:43.518Z
Learning: In ChatAssistant's CSS (src/main/resources/META-INF/frontend/styles/chat-assistant-styles.css), the double 180-degree rotation trick on both .chat-assistant-resizable-vertical-layout and .chat-assistant-container-vertical-layout is used to move the resize handle from the default bottom-right corner to the upper-left corner. This positioning is more suitable for resizing the chat window since the chat bubble is positioned in the bottom-right part of the viewport.
📚 Learning: 2025-07-22T19:52:28.019Z
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java:179-186
Timestamp: 2025-07-22T19:52:28.019Z
Learning: When using ReactAdapterComponent with custom React components in ChatAssistant, standard Vaadin component hierarchy methods like add() cannot be used because the component doesn't implement HasComponents, and the DOM structure is controlled by React. Direct DOM manipulation with executeJs may be necessary to integrate Vaadin components (like Avatar) into React-generated DOM structures.

Applied to files:

  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
📚 Learning: 2025-07-24T13:40:40.471Z
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java:179-186
Timestamp: 2025-07-24T13:40:40.471Z
Learning: In ChatAssistant's initializeAvatar method (src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java), direct DOM manipulation using executeJs is intentionally used to move the Avatar component to be a child of a button that is inside a div within the React-controlled web component structure. This approach is necessary because the target elements are created by React, and standard Vaadin component hierarchy methods cannot be used due to ReactAdapterComponent limitations.

Applied to files:

  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
📚 Learning: 2025-07-24T13:41:19.117Z
Learnt from: mlopezFC
PR: FlowingCode/ChatAssistant#35
File: src/main/resources/META-INF/frontend/react/animated-fab.tsx:0-0
Timestamp: 2025-07-24T13:41:19.117Z
Learning: In the ChatAssistant animated-fab React component (src/main/resources/META-INF/frontend/react/animated-fab.tsx), the Floating Action Button (FAB) appears empty in the React code but gets its icon content from the Avatar Vaadin component, which is inserted via DOM manipulation from the Java backend's initializeAvatar method.

Applied to files:

  • src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java
🔇 Additional comments (1)
src/main/java/com/flowingcode/vaadin/addons/chatassistant/ChatAssistant.java (1)

32-34: LGTM: correct switch to Grid API

Imports for Grid and GridVariant look right for the new implementation. No issues spotted here.

@mlopezFC mlopezFC marked this pull request as draft August 27, 2025 12:27
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.

Rendering problems
1 participant