Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 64bcf4a

Browse files
authored
(EAI-1175) Add slot to messages below message rating (#840)
* wip - message bottom content * (EAI-1175) Add slot to messages below message rating
1 parent 021bfb2 commit 64bcf4a

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

packages/mongodb-chatbot-ui/src/App.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import LeafyGreenProvider, {
55
useDarkModeContext,
66
} from "@leafygreen-ui/leafygreen-provider";
77
import { canUseServerSentEvents } from "./utils";
8-
import { Overline, Link } from "@leafygreen-ui/typography";
8+
import { Overline, Link, Body } from "@leafygreen-ui/typography";
99
import Toggle from "@leafygreen-ui/toggle";
1010
import { Chatbot } from "./Chatbot";
1111
import { DocsChatbot } from "./DocsChatbot";
1212
import { DevCenterChatbot } from "./DevCenterChatbot";
1313
import { HotkeyTrigger } from "./HotkeyTrigger";
1414
import { makePrioritizeReferenceDomain } from "./references";
1515
import { getSegmentIdHeaders } from "./segment";
16+
import Button from "@leafygreen-ui/button";
1617

1718
const prefersDarkMode = () =>
1819
window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false;
@@ -121,6 +122,17 @@ function App() {
121122
<DevCenterChatbot
122123
initialMessageSuggestedPrompts={SUGGESTED_PROMPTS}
123124
initialMessageReferences={initialMessageReferences}
125+
messageBottomContent={
126+
<div>
127+
<Body as="i">
128+
This is custom message bottom content. It can contain a{" "}
129+
<Button size="xsmall" onClick={() => alert("button clicked")}>
130+
button
131+
</Button>{" "}
132+
or any other ReactNode!
133+
</Body>
134+
</div>
135+
}
124136
/>
125137
<HotkeyTrigger onKey="/" />
126138
</Chatbot>

packages/mongodb-chatbot-ui/src/ChatMessageFeed.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ export type ChatMessageFeedProps = DarkModeProps & {
3232
disclaimer?: React.ReactNode;
3333
disclaimerHeading?: string;
3434
initialMessage?: MessageData | null;
35+
messageBottomContent?: React.ReactNode;
3536
};
3637

3738
export function ChatMessageFeed(props: ChatMessageFeedProps) {
3839
const { darkMode } = useDarkMode(props.darkMode);
39-
const { className, disclaimer, disclaimerHeading, initialMessage } = props;
40+
const {
41+
className,
42+
disclaimer,
43+
disclaimerHeading,
44+
initialMessage,
45+
messageBottomContent,
46+
} = props;
4047

4148
const {
4249
awaitingReply,
@@ -72,20 +79,23 @@ export function ChatMessageFeed(props: ChatMessageFeedProps) {
7279

7380
const isInitialMessage = idx === 0;
7481

82+
const showRatingAndBottomContent =
83+
!isLoading &&
84+
// If we've sent a request but the response hasn't started streaming yet, don't show the rating
85+
!(awaitingReply && conversation.streamingMessageId === message.id) &&
86+
// Users can rate assistant messages that have started streaming
87+
message.role === "assistant" &&
88+
// We don't want users to rate the initial message (and they can't because it's not in the database)
89+
!isInitialMessage;
90+
7591
return (
7692
<Message
7793
key={message.id}
7894
messageData={message}
7995
isLoading={isLoading}
80-
showRating={
81-
// Users can rate assistant messages that have started streaming
82-
message.role === "assistant" &&
83-
!isLoading &&
84-
!(
85-
awaitingReply && conversation.streamingMessageId === message.id
86-
) &&
87-
// We don't want users to rate the initial message (and they can't because it's not in the database)
88-
!isInitialMessage
96+
showRating={showRatingAndBottomContent}
97+
bottomContent={
98+
showRatingAndBottomContent ? messageBottomContent : null
8999
}
90100
conversation={conversation}
91101
suggestedPrompts={message.suggestedPrompts}

packages/mongodb-chatbot-ui/src/ChatWindow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function ChatWindow(props: ChatWindowProps) {
3333
initialMessageSuggestedPrompts,
3434
inputBarId = "chatbot-input-bar",
3535
inputBottomText,
36+
messageBottomContent,
3637
windowTitle,
3738
} = props;
3839

@@ -70,6 +71,7 @@ export function ChatWindow(props: ChatWindowProps) {
7071
disclaimer={disclaimer}
7172
disclaimerHeading={disclaimerHeading}
7273
initialMessage={initialMessage}
74+
messageBottomContent={messageBottomContent}
7375
/>
7476
</Suspense>
7577
<ChatInput

packages/mongodb-chatbot-ui/src/ChatbotView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export type ChatbotViewProps = DarkModeProps &
1111
inputBarId?: string;
1212
inputBarPlaceholder?: string;
1313
inputBottomText?: string;
14+
messageBottomContent?: React.ReactNode;
1415
windowTitle?: string;
1516
};

packages/mongodb-chatbot-ui/src/DevCenterChatbot.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type DevCenterChatbotProps = DarkModeProps & {
1616
initialMessageText?: string;
1717
initialMessageSuggestedPrompts?: string[];
1818
initialMessageReferences?: References;
19+
messageBottomContent?: React.ReactNode;
1920
};
2021

2122
const ModalView = lazy(() =>
@@ -34,6 +35,7 @@ export function DevCenterChatbot(props: DevCenterChatbotProps) {
3435
"Hi! I'm the MongoDB AI. What can I help you with today?",
3536
initialMessageReferences: props.initialMessageReferences,
3637
initialMessageSuggestedPrompts: props.initialMessageSuggestedPrompts ?? [],
38+
messageBottomContent: props.messageBottomContent,
3739
disclaimer: (
3840
<>
3941
<MongoDbLegalDisclosure />

packages/mongodb-chatbot-ui/src/Message.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type MessageProps = {
4444
messageData: MessageData;
4545
suggestedPrompts?: string[];
4646
showSuggestedPrompts?: boolean;
47+
bottomContent?: React.ReactNode;
4748
onReferenceClick?: (reference: Reference) => void;
4849
onSuggestedPromptClick?: (prompt: string) => void;
4950
canSubmitSuggestedPrompt?: (prompt: string) => boolean;
@@ -71,6 +72,7 @@ export const Message = ({
7172
isLoading,
7273
showRating,
7374
conversation,
75+
bottomContent,
7476
}: MessageProps) => {
7577
const { maxCommentCharacters } = useChatbotContext();
7678
const user = useUser();
@@ -171,6 +173,7 @@ export const Message = ({
171173
/>
172174
) : null}
173175
</Suspense>
176+
{bottomContent ?? null}
174177
</LGMessage>
175178
<Suspense fallback={null}>
176179
{showSuggestedPrompts && (

packages/mongodb-chatbot-ui/src/MessageRating.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ export function MessageRatingWithFeedbackComment(
5959
className={css`
6060
& > div + div {
6161
margin-top: 0.5rem;
62+
margin-bottom: 0.5rem;
6263
}
6364
`}
6465
>
6566
<MessageRating {...messageRatingProps} />
6667
{hasRating && status !== "abandoned" ? (
6768
<>
6869
<InlineMessageFeedback
70+
className={
71+
"" /* For now this is unsupported - use the > div + div selector above instead https://jira.mongodb.org/browse/LG-3965 */
72+
}
6973
ref={ratingCommentRef}
7074
cancelButtonText="Cancel"
7175
onCancel={() => abandon()}

0 commit comments

Comments
 (0)