Skip to content

Commit 1f28ca8

Browse files
authored
refactor(input-bar): use assistantName from LeafyGreenChatContext for loading message (#3148)
* refactor(input-bar): revert loadingMessage prop addition and use assistantName context value * test(input-bar): custom assistantName value
1 parent 67e1205 commit 1f28ca8

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

.changeset/sixty-hoops-accept.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'@lg-chat/input-bar': minor
2+
'@lg-chat/input-bar': patch
33
---
44

5-
Add support for configurable loadingMessage prop to InputBar
5+
Use `assistantName` value from `LeafyGreenChatContext` for loading message

chat/input-bar/README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,20 @@ return (
5656

5757
## Properties
5858

59-
| Prop | Type | Description | Default |
60-
| ----------------------------- | ---------------------------------------------- | ----------------------------------------------------------- | ------------------------------- |
61-
| `badgeText` | `string` | Determines the text inside the rendered Badge | |
62-
| `darkMode` | `boolean` | Determines if the component will render in dark mode | `false` |
63-
| `disabled` | `boolean` | Determines whether the user can interact with the InputBar | `false` |
64-
| `disableSend` | `boolean` | When defined as `true`, disables the send action and button | |
65-
| `loadingMessage` | `ReactNode` | Custom loading message to display when `state='loading'` | `MongoDB Assistant is thinking` |
66-
| `errorMessage` | `ReactNode` | Custom error message to display when `state='error'` | |
67-
| `onMessageSend` | `(messageBody: string, e?: FormEvent) => void` | Submit event handler. | |
68-
| `shouldRenderGradient` | `boolean` | Toggles the gradient animation around the input | `true` |
69-
| `shouldRenderHotkeyIndicator` | `boolean` | Toggles the hotkey indicator on the right side of the input | `false` |
70-
| `textareaProps` | `TextareaAutosizeProps` | Props passed to the TextareaAutosize component. | |
71-
| `textareaRef` | `RefObject<HTMLTextAreaElement>` | Ref object to access the textarea element directly | |
72-
| `state` | `'unset' \| 'error' \| 'loading'` | The current state of the InputBar. | |
73-
| `...` | `HTMLElementProps<'form'>` | Props spread on the root element | |
59+
| Prop | Type | Description | Default |
60+
| ----------------------------- | ---------------------------------------------- | ----------------------------------------------------------- | ------- |
61+
| `badgeText` | `string` | Determines the text inside the rendered Badge | |
62+
| `darkMode` | `boolean` | Determines if the component will render in dark mode | `false` |
63+
| `disabled` | `boolean` | Determines whether the user can interact with the InputBar | `false` |
64+
| `disableSend` | `boolean` | When defined as `true`, disables the send action and button | |
65+
| `errorMessage` | `ReactNode` | Custom error message to display when `state='error'` | |
66+
| `onMessageSend` | `(messageBody: string, e?: FormEvent) => void` | Submit event handler. | |
67+
| `shouldRenderGradient` | `boolean` | Toggles the gradient animation around the input | `true` |
68+
| `shouldRenderHotkeyIndicator` | `boolean` | Toggles the hotkey indicator on the right side of the input | `false` |
69+
| `textareaProps` | `TextareaAutosizeProps` | Props passed to the TextareaAutosize component. | |
70+
| `textareaRef` | `RefObject<HTMLTextAreaElement>` | Ref object to access the textarea element directly | |
71+
| `state` | `'unset' \| 'error' \| 'loading'` | The current state of the InputBar. | |
72+
| `...` | `HTMLElementProps<'form'>` | Props spread on the root element | |
7473

7574
## TextareaAutosizeProps
7675

chat/input-bar/src/InputBar.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const meta: StoryMetaType<typeof InputBar> = {
2424
darkMode: [false, true],
2525
disabled: [false, true],
2626
disableSend: [false, true],
27-
loadingMessage: [undefined, 'Custom loading message'],
2827
state: Object.values(State),
2928
textareaProps: [
3029
{ value: '' },

chat/input-bar/src/InputBar/InputBar.spec.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,27 @@ describe('packages/input-bar', () => {
302302
});
303303

304304
describe('status states', () => {
305-
test('renders loading state with default message when state is "loading"', () => {
305+
test('renders loading state with default assistantName when state is "loading"', () => {
306306
renderInputBar({ state: State.Loading });
307307

308308
expect(
309309
screen.getByText(/MongoDB Assistant is thinking/i),
310310
).toBeInTheDocument();
311311
});
312312

313-
test('renders loading state with custom message when state is "loading" and loadingMessage provided', () => {
314-
renderInputBar({
315-
state: State.Loading,
316-
loadingMessage: 'Custom loading message',
317-
});
313+
test('renders loading state with custom assistantName when state is "loading"', () => {
314+
render(
315+
<LeafyGreenChatProvider
316+
variant={Variant.Compact}
317+
assistantName="Custom Assistant"
318+
>
319+
<InputBar state={State.Loading} />
320+
</LeafyGreenChatProvider>,
321+
);
318322

319-
expect(screen.getByText(/Custom loading message/i)).toBeInTheDocument();
323+
expect(
324+
screen.getByText(/Custom Assistant is thinking/i),
325+
).toBeInTheDocument();
320326
});
321327

322328
test('renders error state with default message when state is "error" and no message provided', () => {

chat/input-bar/src/InputBar/InputBar.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export const InputBar = forwardRef<HTMLFormElement, InputBarProps>(
7474
dropdownFooterSlot,
7575
dropdownProps,
7676
errorMessage,
77-
loadingMessage,
7877
onMessageSend,
7978
onSubmit,
8079
shouldRenderGradient: shouldRenderGradientProp = true,
@@ -434,11 +433,7 @@ export const InputBar = forwardRef<HTMLFormElement, InputBarProps>(
434433
{...rest}
435434
>
436435
{isCompact && (
437-
<InputBarFeedback
438-
errorMessage={errorMessage}
439-
loadingMessage={loadingMessage}
440-
state={state}
441-
/>
436+
<InputBarFeedback errorMessage={errorMessage} state={state} />
442437
)}
443438
<div className={outerFocusContainerStyles}>
444439
<div

chat/input-bar/src/InputBar/InputBarFeedback.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { forwardRef } from 'react';
2+
import { useLeafyGreenChatContext } from '@lg-chat/leafygreen-chat-provider';
23

34
import { AssistantAvatar } from '@leafygreen-ui/avatar';
45
import Banner from '@leafygreen-ui/banner';
@@ -18,7 +19,6 @@ import { State } from './shared.types';
1819

1920
const messages = {
2021
defaultError: 'Oops... Something went wrong.',
21-
loading: 'MongoDB Assistant is thinking',
2222
retryButton: 'Retry',
2323
} as const;
2424

@@ -32,13 +32,13 @@ export const InputBarFeedback = forwardRef<
3232
className,
3333
darkMode: darkModeProp,
3434
errorMessage,
35-
loadingMessage,
3635
state,
3736
...rest
3837
},
3938
fwdRef,
4039
) => {
4140
const { darkMode, theme } = useDarkMode(darkModeProp);
41+
const { assistantName } = useLeafyGreenChatContext();
4242

4343
return (
4444
<div
@@ -52,7 +52,7 @@ export const InputBarFeedback = forwardRef<
5252
<div className={loadingContainerStyles}>
5353
<AssistantAvatar darkMode={darkMode} size={20} />
5454
<Body className={getLoadingTextStyles(theme)}>
55-
{loadingMessage || messages.loading}
55+
{`${assistantName} is thinking`}
5656
</Body>
5757
</div>
5858
)}

chat/input-bar/src/InputBar/shared.types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,4 @@ export interface SharedInputBarProps {
1919
* @remarks This prop is only considered when the parent `LeafyGreenChatProvider` has `variant="compact"`.
2020
*/
2121
state?: State;
22-
23-
/**
24-
* Custom loading message to display when `state='loading'`
25-
* @remarks This prop is only considered when the parent `LeafyGreenChatProvider` has `variant="compact"`.
26-
*/
27-
loadingMessage?: ReactNode;
2822
}

0 commit comments

Comments
 (0)