-
Notifications
You must be signed in to change notification settings - Fork 77
[LG-5932, LG-5934] refactor,feature(chat) Compound MessageFeed #3488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shaneeza
merged 14 commits into
s/initial-message-integration
from
LG-5932-message-feed-compound
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
45120ed
refactor(MessageFeed): convert to CompoundComponent and temp remove a…
shaneeza 1277ed5
Merge branch 's/initial-message-integration' of github.com:mongodb/le…
shaneeza defdad3
refactor(MessageFeed): enhance component structure
shaneeza 958d58a
feat(MessageFeed): add MessageFeedContext
shaneeza c701f84
docs(MessageFeed): add changeset
shaneeza a6d7616
fix(MessageFeed): update error message for context provider
shaneeza e427185
refactor(Message): undo message changes
shaneeza 0d9295d
chore(MessageFeed): add compound-component dependency
shaneeza eb31dd4
chore(pnpm-lock): add compound-component to dependencies
shaneeza 478ee3c
refactor(MessageFeed): move shared types
shaneeza bd83d5f
chore(changeset): update dependency version for @lg-chat/message-feed
shaneeza 6441471
fix(tsconfig): add missing newline at end of file
shaneeza 9e0a42e
fix(MessageFeedContext): handle error boundary for React 17 in contex…
shaneeza 5681c08
testing
shaneeza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@lg-chat/message-feed': minor | ||
| --- | ||
|
|
||
| - [LG-5932](https://jira.mongodb.org/browse/LG-5932): Refactor to use `CompoundComponent` pattern | ||
| - [LG-5934](https://jira.mongodb.org/browse/LG-5934): add `MessageFeedProvider` and `useMessageFeedContext` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
chat/message-feed/src/MessageFeedContext/MessageFeedContext.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { isReact17, renderHook } from '@leafygreen-ui/testing-lib'; | ||
|
|
||
| import { | ||
| MessageFeedProvider, | ||
| useMessageFeedContext, | ||
| } from './MessageFeedContext'; | ||
| import { MessageFeedProviderProps } from './MessageFeedContext.types'; | ||
|
|
||
| const renderMessageFeedProvider = ( | ||
| props?: Partial<MessageFeedProviderProps>, | ||
| ) => { | ||
| const defaultProps: MessageFeedProviderProps = { | ||
| shouldHideInitialMessage: false, | ||
| }; | ||
|
|
||
| const { result } = renderHook(() => useMessageFeedContext(), { | ||
| wrapper: ({ children }: { children?: React.ReactNode }) => ( | ||
| <MessageFeedProvider {...defaultProps} {...props}> | ||
| {children} | ||
| </MessageFeedProvider> | ||
| ), | ||
| }); | ||
|
|
||
| return { result }; | ||
| }; | ||
| describe('useMessageFeedContext', () => { | ||
shaneeza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test('should return the correct context', () => { | ||
| const { result } = renderMessageFeedProvider(); | ||
| expect(result.current.shouldHideInitialMessage).toBe(false); | ||
| }); | ||
|
|
||
| test('should return the correct context when props are provided', () => { | ||
| const { result } = renderMessageFeedProvider({ | ||
| shouldHideInitialMessage: true, | ||
| }); | ||
| expect(result.current.shouldHideInitialMessage).toBe(true); | ||
| }); | ||
|
|
||
| test('should throw an error when used outside the provider', () => { | ||
| /** | ||
| * The version of `renderHook` imported from "@testing-library/react-hooks" (used in React 17) | ||
| * has an error boundary, and doesn't throw errors as expected: | ||
| * https://github.com/testing-library/react-hooks-testing-library/blob/main/src/index.ts#L5 | ||
| */ | ||
| if (isReact17()) { | ||
| const { result } = renderHook(() => useMessageFeedContext()); | ||
| expect(result.error.message).toEqual( | ||
| 'useMessageFeedContext must be used within a MessageFeedProvider', | ||
| ); | ||
| } else { | ||
| expect(() => { | ||
| renderHook(() => useMessageFeedContext()); | ||
| }).toThrow( | ||
| 'useMessageFeedContext must be used within a MessageFeedProvider', | ||
| ); | ||
| } | ||
| }); | ||
| }); | ||
33 changes: 33 additions & 0 deletions
33
chat/message-feed/src/MessageFeedContext/MessageFeedContext.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import React, { createContext, useContext } from 'react'; | ||
|
|
||
| import { | ||
| MessageFeedContextType, | ||
| MessageFeedProviderProps, | ||
| } from './MessageFeedContext.types'; | ||
|
|
||
| export const MessageFeedContext = createContext<MessageFeedContextType | null>( | ||
| null, | ||
| ); | ||
|
|
||
| export const MessageFeedProvider = ({ | ||
| children, | ||
| shouldHideInitialMessage = false, | ||
| }: MessageFeedProviderProps) => { | ||
| return ( | ||
| <MessageFeedContext.Provider value={{ shouldHideInitialMessage }}> | ||
| {children} | ||
| </MessageFeedContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const useMessageFeedContext = () => { | ||
| const context = useContext(MessageFeedContext); | ||
|
|
||
| if (!context) { | ||
| throw new Error( | ||
| 'useMessageFeedContext must be used within a MessageFeedProvider', | ||
| ); | ||
| } | ||
|
|
||
| return context; | ||
| }; |
8 changes: 8 additions & 0 deletions
8
chat/message-feed/src/MessageFeedContext/MessageFeedContext.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { PropsWithChildren } from 'react'; | ||
|
|
||
| export interface MessageFeedContextType { | ||
| shouldHideInitialMessage: boolean; | ||
| } | ||
|
|
||
| export interface MessageFeedProviderProps | ||
| extends PropsWithChildren<MessageFeedContextType> {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export { | ||
| MessageFeedProvider, | ||
| useMessageFeedContext, | ||
| } from './MessageFeedContext'; | ||
| export type { | ||
| MessageFeedContextType, | ||
| MessageFeedProviderProps, | ||
| } from './MessageFeedContext.types'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Static property names used to identify MessageFeed compound components. | ||
| * These are implementation details for the compound component pattern and should not be exported. | ||
| */ | ||
| export const MessageFeedSubcomponentProperty = { | ||
| InitialMessage: 'isLGMessageFeedInitialMessage', | ||
| } as const; | ||
|
|
||
| /** | ||
| * Type representing the possible static property names for MessageFeed subcomponents. | ||
| */ | ||
| export type MessageFeedSubcomponentProperty = | ||
| (typeof MessageFeedSubcomponentProperty)[keyof typeof MessageFeedSubcomponentProperty]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add a key here? I dont have too much context on the larger project but im not sure where
MessageFeedSubcomponentProperty.InitialMessageshould be goingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I will add it in the next PR.