feat(chat): add 'metadata' to chat sub widgets#7123
Draft
shaejaz wants to merge 2 commits into
Draft
Conversation
Up to standards ✅🟢 Issues
|
More templates
algoliasearch-helper
instantsearch-ui-components
instantsearch.css
instantsearch.js
react-instantsearch
react-instantsearch-core
react-instantsearch-nextjs
react-instantsearch-router-nextjs
vue-instantsearch
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a consistent metadata object that is injected into Chat “sub-widgets” (tools, messages, loader/error/empty/actions overrides) across the shared UI layer, InstantSearch.js widget, and React wrapper, so custom components/templates can access common chat state and callbacks from one place.
Changes:
- Added
ChatComponentMetadata/ChatComponentPropsWithMetadataand refactored chat override points to receivemetadatainstead of multiple ad-hoc props (e.g.,onClose). - Updated Chat tool layout components (e.g., search index tool) and template typing in
instantsearch.jsto align with the new metadata contract. - Updated and extended tests to pass/verify
metadataforwarding.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-instantsearch/src/widgets/chat/tools/SearchIndexTool.tsx | Reads onClose from metadata for the search carousel tool layout. |
| packages/react-instantsearch/src/widgets/chat/tools/tests/SearchIndexTool.test.tsx | Updates tests to provide metadata instead of onClose prop. |
| packages/react-instantsearch/src/widgets/chat/tools/tests/DisplayResultsTool.test.tsx | Updates tests to provide metadata instead of onClose prop. |
| packages/react-instantsearch/src/widgets/Chat.tsx | Ensures error is correctly included in messagesProps (avoids duplication). |
| packages/instantsearch.js/src/widgets/chat/chat.tsx | Types templates/components to accept ChatComponentPropsWithMetadata and threads those through the renderer wrappers. |
| packages/instantsearch.js/src/templates/chat-message-loader.tsx | Updates loader template helper typing to accept props-with-metadata. |
| packages/instantsearch.js/src/templates/chat-greeting/chat-greeting.tsx | Updates greeting template helper typing to accept props-with-metadata. |
| packages/instantsearch-ui-components/src/components/chat/types.ts | Introduces ChatComponentMetadata + ChatComponentPropsWithMetadata; updates tool props typing and removes ChatEmptyProps. |
| packages/instantsearch-ui-components/src/components/chat/ChatMessages.tsx | Constructs and forwards metadata to all overridable components (message/loader/error/empty/actions). |
| packages/instantsearch-ui-components/src/components/chat/ChatMessageLoader.tsx | Accepts props-with-metadata and strips metadata from DOM props. |
| packages/instantsearch-ui-components/src/components/chat/ChatMessageError.tsx | Accepts props-with-metadata and strips metadata from DOM props. |
| packages/instantsearch-ui-components/src/components/chat/ChatMessage.tsx | Reads status/tools from metadata and forwards metadata into tool layouts/actions overrides. |
| packages/instantsearch-ui-components/src/components/chat/ChatGreeting.tsx | Accepts props-with-metadata (empty/greeting state now relies on metadata). |
| packages/instantsearch-ui-components/src/components/chat/tests/ChatMessages.test.tsx | Adds coverage to assert metadata is forwarded to overridable components. |
| packages/instantsearch-ui-components/src/components/chat/tests/ChatMessage.test.tsx | Updates tests to pass metadata and validates tool rendering with metadata-provided tools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+25
to
29
| return function ChatMessageLoader( | ||
| userProps: ChatComponentPropsWithMetadata<ChatMessageLoaderProps> | ||
| ) { | ||
| const { translations: userTranslations, metadata, ...props } = userProps; | ||
| const translations: Required<ChatMessageLoaderTranslations> = { |
Comment on lines
+64
to
75
| return function ChatMessageError( | ||
| userProps: ChatComponentPropsWithMetadata<ChatMessageErrorProps> | ||
| ) { | ||
| const { | ||
| errorMessage, | ||
| onReload, | ||
| onNewConversation, | ||
| actions, | ||
| translations: userTranslations, | ||
| metadata, | ||
| ...props | ||
| } = userProps; |
Comment on lines
+56
to
65
| return function ChatGreeting( | ||
| userProps: ChatComponentPropsWithMetadata<ChatGreetingProps> | ||
| ) { | ||
| const { | ||
| translations: userTranslations, | ||
| classNames = {}, | ||
| sendMessage: _sendMessage, | ||
| status: _status, | ||
| onClose: _onClose, | ||
| setInput: _setInput, | ||
| metadata, | ||
| banner, | ||
| ...props | ||
| } = userProps; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.