Skip to content

Commit

Permalink
feat(chatMessage): update attributes display (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko authored Aug 30, 2023
1 parent ba123fe commit 23b2102
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const useChatContextMock = vi.fn(() => ({
assistant: "Test assistant message",
message_id: "123",
user_message: "Test user message",
prompt_title: "Test prompt name",
brain_name: "Test brain name",
},
],
}));
Expand All @@ -37,7 +39,8 @@ describe("ChatMessages", () => {
it("should render chat messages correctly", () => {
const { getAllByTestId } = render(<ChatMessages />);

expect(getAllByTestId("brain-prompt-tags")).toBeDefined();
expect(getAllByTestId("brain-tags")).toBeDefined();
expect(getAllByTestId("prompt-tags")).toBeDefined();

expect(getAllByTestId("chat-message-text")).toBeDefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import ReactMarkdown from "react-markdown";

import { cn } from "@/lib/utils";

import { QuestionBrain } from "./components/QuestionBrain";
import { QuestionPrompt } from "./components/QuestionPrompt";

type ChatMessageProps = {
speaker: string;
text: string;
brainName?: string;
promptName?: string;
brainName?: string | null;
promptName?: string | null;
};

export const ChatMessage = React.forwardRef(
Expand Down Expand Up @@ -36,13 +39,9 @@ export const ChatMessage = React.forwardRef(
<div className={containerWrapperClasses}>
{" "}
<div ref={ref} className={containerClasses}>
<div className="w-full">
<span
data-testid="brain-prompt-tags"
className="text-gray-400 mb-1 text-xs"
>
@{brainName ?? "-"} #{promptName ?? "-"}
</span>
<div className="w-full gap-1 flex">
<QuestionBrain brainName={brainName} />
<QuestionPrompt promptName={promptName} />
</div>
<div data-testid="chat-message-text">
<ReactMarkdown className={markdownClasses}>{text}</ReactMarkdown>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Fragment } from "react";

type QuestionBrainProps = {
brainName?: string | null;
};
export const QuestionBrain = ({
brainName,
}: QuestionBrainProps): JSX.Element => {
if (brainName === undefined || brainName === null) {
return <Fragment />;
}

return (
<span data-testid="brain-tags" className="text-gray-400 mb-1 text-xs">
@{brainName}
</span>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Fragment } from "react";

type QuestionProptProps = {
promptName?: string | null;
};
export const QuestionPrompt = ({
promptName,
}: QuestionProptProps): JSX.Element => {
if (promptName === undefined || promptName === null) {
return <Fragment />;
}

return (
<span data-testid="prompt-tags" className="text-gray-400 mb-1 text-xs">
#{promptName}
</span>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ChatMessage";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ChatMessage";
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./components/ChatMessage";
export * from "./components/ChatMessage/ChatMessage";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ChatMessage'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";

import { useChatContext } from "@/lib/context";

import { ChatMessage } from "./components/ChatMessage/components/ChatMessage";
import { ChatMessage } from "./components";
import { useChatMessages } from "./hooks/useChatMessages";

export const ChatMessages = (): JSX.Element => {
Expand Down

0 comments on commit 23b2102

Please sign in to comment.