Skip to content

feat: Add CustomMarkdownField wrapper component#9042

Merged
Cristhianzl merged 2 commits intomainfrom
cz/add-custom-markdownfield
Jul 21, 2025
Merged

feat: Add CustomMarkdownField wrapper component#9042
Cristhianzl merged 2 commits intomainfrom
cz/add-custom-markdownfield

Conversation

@Cristhianzl
Copy link
Member

@Cristhianzl Cristhianzl commented Jul 14, 2025

This pull request introduces a new CustomMarkdownField component in the frontend codebase to replace the existing MarkdownField in certain contexts. The changes primarily focus on modularizing the code and enabling customization for markdown field rendering.

Introduction of CustomMarkdownField:

  • src/frontend/src/customization/components/custom-markdown-field.tsx: Added a new CustomMarkdownField component that wraps the existing MarkdownField and accepts the same props for rendering. This allows for future customization of markdown field behavior.

Integration with existing components:

  • src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx: Replaced the MarkdownField import with CustomMarkdownField and updated its usage in the ChatMessage component to use the new wrapper for rendering markdown fields. [1] [2]

Cleanup of unused imports:

  • src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx: Removed the direct import of MarkdownField from edit-message since it is now encapsulated within CustomMarkdownField.

Summary by CodeRabbit

  • New Features
    • Introduced a new component for rendering chat messages, providing a foundation for future customization.
  • Refactor
    • Updated chat message display to use the new customizable component without changing existing functionality.

…nent to encapsulate MarkdownField with additional props

♻️ (chat-message.tsx): refactor ChatMessage component to use CustomMarkdownField instead of MarkdownField for better customization and reusability
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new CustomMarkdownField React component is introduced, which wraps and forwards props to the existing MarkdownField component. The chat message rendering logic is updated to use CustomMarkdownField instead of MarkdownField, with no changes to the rendering logic or props.

Changes

File(s) Change Summary
src/frontend/src/customization/components/custom-markdown-field.tsx Added new CustomMarkdownField component that wraps and forwards props to MarkdownField.
src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx Replaced usage and import of MarkdownField with CustomMarkdownField in chat message rendering.

Suggested labels

enhancement, lgtm

Suggested reviewers

  • mfortman11
  • lucaseduoli
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/add-custom-markdownfield

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

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

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 14, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 14, 2025
Copy link
Contributor

@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: 1

🧹 Nitpick comments (2)
src/frontend/src/customization/components/custom-markdown-field.tsx (2)

17-27: Remove unnecessary React fragment wrapper.

The React fragment doesn't add any value since you're only rendering a single child component.

  return (
-    <>
-      <MarkdownField
-        isAudioMessage={isAudioMessage}
-        chat={chat}
-        isEmpty={isEmpty}
-        chatMessage={chatMessage}
-        editedFlag={editedFlag}
-      />
-    </>
+    <MarkdownField
+      isAudioMessage={isAudioMessage}
+      chat={chat}
+      isEmpty={isEmpty}
+      chatMessage={chatMessage}
+      editedFlag={editedFlag}
+    />
  );

10-28: Consider using React.forwardRef for better component composition.

Based on the retrieved learnings, React components should use forwardRef for proper ref forwarding and compatibility with parent components.

-export const CustomMarkdownField = ({
+export const CustomMarkdownField = React.forwardRef<
+  HTMLDivElement,
+  CustomMarkdownFieldProps
+>(({
  isAudioMessage,
  chat,
  isEmpty,
  chatMessage,
  editedFlag,
-}: CustomMarkdownFieldProps) => {
+}, ref) => {
  return (
    <MarkdownField
+      ref={ref}
      isAudioMessage={isAudioMessage}
      chat={chat}
      isEmpty={isEmpty}
      chatMessage={chatMessage}
      editedFlag={editedFlag}
    />
  );
-};
+});
+
+CustomMarkdownField.displayName = 'CustomMarkdownField';
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3df1eb8 and 664bf17.

📒 Files selected for processing (2)
  • src/frontend/src/customization/components/custom-markdown-field.tsx (1 hunks)
  • src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/frontend/**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/frontend_development.mdc
src/frontend/**/*.{ts,tsx,js,jsx,css,scss}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/frontend_development.mdc
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/**/*.{ts,tsx} : Use React 18 with TypeScript for all UI components and frontend logic.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/icons.mdc:0-0
Timestamp: 2025-06-23T12:46:52.420Z
Learning: Export custom icon components in React using React.forwardRef to ensure proper ref forwarding and compatibility with parent components.
src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx (4)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/{components,hooks}/**/*.{ts,tsx} : Implement dark mode support in components and hooks where needed.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/**/*.{ts,tsx} : Use React 18 with TypeScript for all UI components and frontend logic.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/components/**/*FlowGraph.tsx : Use React Flow for flow graph visualization components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Custom React Flow node types should be implemented as memoized components, using Handle components for connection points and supporting optional icons and labels.
src/frontend/src/customization/components/custom-markdown-field.tsx (3)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/{components,hooks}/**/*.{ts,tsx} : Implement dark mode support in components and hooks where needed.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/**/*.{ts,tsx} : Use React 18 with TypeScript for all UI components and frontend logic.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/icons.mdc:0-0
Timestamp: 2025-06-30T14:40:50.846Z
Learning: Applies to src/frontend/src/icons/*/index.tsx : Create an `index.tsx` in your icon directory that exports your icon using `forwardRef` and passes the `isdark` prop.
🧬 Code Graph Analysis (1)
src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx (1)
src/frontend/src/customization/components/custom-markdown-field.tsx (1)
  • CustomMarkdownField (10-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: autofix
🔇 Additional comments (2)
src/frontend/src/modals/IOModal/components/chatView/chatMessage/chat-message.tsx (2)

3-3: LGTM: Clean import addition.

The import statement is correctly added and follows the established import pattern for customization components.


362-368: LGTM: Proper component replacement.

The replacement of MarkdownField with CustomMarkdownField is implemented correctly. All props are forwarded appropriately, maintaining the same interface while enabling future customization opportunities.

Comment on lines +3 to +9
type CustomMarkdownFieldProps = {
isAudioMessage: boolean;
chat: any;
isEmpty: boolean;
chatMessage: string;
editedFlag: React.ReactNode;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Improve TypeScript type safety by replacing any with a more specific type.

The chat prop is typed as any, which defeats the purpose of TypeScript's type checking and can lead to runtime errors.

Consider defining a proper interface or importing the existing chat type from the codebase:

+import { ChatMessageType } from "path/to/chat/types"; // Adjust path as needed

type CustomMarkdownFieldProps = {
  isAudioMessage: boolean;
-  chat: any;
+  chat: ChatMessageType;
  isEmpty: boolean;
  chatMessage: string;
  editedFlag: React.ReactNode;
};

🏁 Script executed:

#!/bin/bash
# Find the actual chat type definition in the codebase
ast-grep --pattern 'type $_ = {
  $$$
  message: $_
  $$$
}'

# Also search for chat-related interfaces
rg -A 10 "interface.*Chat" --type typescript
rg -A 10 "type.*Chat" --type typescript

Length of output: 3629


Replace any with ChatMessageType for the chat prop

The chat prop is currently typed as any, which bypasses TypeScript’s checks and can introduce runtime errors. You can import the existing ChatMessageType and update the prop:

  • In src/frontend/src/customization/components/custom-markdown-field.tsx, add:
    import type { ChatMessageType } from '../../types/chat';
  • Then update your props type:
     type CustomMarkdownFieldProps = {
       isAudioMessage: boolean;
    -  chat: any;
    +  chat: ChatMessageType;
       isEmpty: boolean;
       chatMessage: string;
       editedFlag: React.ReactNode;
     };
🤖 Prompt for AI Agents
In src/frontend/src/customization/components/custom-markdown-field.tsx around
lines 3 to 9, replace the type of the `chat` prop from `any` to the specific
`ChatMessageType`. First, import `ChatMessageType` from '../../types/chat' at
the top of the file, then update the `CustomMarkdownFieldProps` type to use
`chat: ChatMessageType` instead of `any` to enable proper type checking.

@github-actions github-actions bot added the lgtm This PR has been approved by a maintainer label Jul 18, 2025
@Cristhianzl Cristhianzl added lgtm This PR has been approved by a maintainer and removed lgtm This PR has been approved by a maintainer labels Jul 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 18, 2025
@github-actions
Copy link
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 82%
81.4% (372/457) 64.82% (223/344) 67.69% (44/65)

Unit Test Results

Tests Skipped Failures Errors Time
72 0 💤 0 ❌ 0 🔥 2.993s ⏱️

@Cristhianzl Cristhianzl added this pull request to the merge queue Jul 21, 2025
Merged via the queue into main with commit 16d34e0 Jul 21, 2025
60 of 64 checks passed
@Cristhianzl Cristhianzl deleted the cz/add-custom-markdownfield branch July 21, 2025 14:38
2getsandesh pushed a commit to 2getsandesh/langflow-IBM that referenced this pull request Aug 6, 2025
✨ (custom-markdown-field.tsx): create a new CustomMarkdownField component to encapsulate MarkdownField with additional props
♻️ (chat-message.tsx): refactor ChatMessage component to use CustomMarkdownField instead of MarkdownField for better customization and reusability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants