diff --git a/packages/x-components/src/x-modules/related-prompts/store/module.ts b/packages/x-components/src/x-modules/related-prompts/store/module.ts index 91d4a6d614..ccf01bb7f9 100644 --- a/packages/x-components/src/x-modules/related-prompts/store/module.ts +++ b/packages/x-components/src/x-modules/related-prompts/store/module.ts @@ -17,6 +17,8 @@ export const relatedPromptsXStoreModule: RelatedPromptsXStoreModule = { state: () => ({ query: '', relatedPrompts: [], + selectedPrompt: -1, + selectedQuery: -1, status: 'initial', params: {} }), @@ -32,7 +34,15 @@ export const relatedPromptsXStoreModule: RelatedPromptsXStoreModule = { setRelatedPromptsProducts(state, products) { state.relatedPrompts = products; }, + setSelectedPrompt(state, selectedPrompt) { + state.selectedPrompt = selectedPrompt; + }, + setSelectedQuery(state, selectedQuery) { + state.selectedQuery = selectedQuery; + }, resetRelatedPromptsState(state) { + state.selectedQuery = -1; + state.selectedPrompt = -1; state.relatedPrompts = []; } }, diff --git a/packages/x-components/src/x-modules/related-prompts/store/types.ts b/packages/x-components/src/x-modules/related-prompts/store/types.ts index 6de258ab1d..e39b55e3b4 100644 --- a/packages/x-components/src/x-modules/related-prompts/store/types.ts +++ b/packages/x-components/src/x-modules/related-prompts/store/types.ts @@ -12,6 +12,10 @@ import { XActionContext, XStoreModule } from '../../../store'; export interface RelatedPromptsState extends StatusState, QueryState { /** The list of the related-prompts, related to the `query` property of the state. */ relatedPrompts: RelatedPrompt[]; + /** The index of the selected related-prompt. */ + selectedPrompt: number; + /** The index of the selected next query. */ + selectedQuery: number; /** The extra params property of the state. */ params: Dictionary; } @@ -47,6 +51,18 @@ export interface RelatedPromptsMutations extends StatusMutations, QueryMutations * @param relatedPrompts - The new related prompts to save to the state. */ setRelatedPromptsProducts(products: RelatedPrompt[]): void; + /** + * Sets the selected related prompt. + * + * @param index - The new selected related prompt. + */ + setSelectedPrompt(index: number): void; + /** + * Sets the selected next query. + * + * @param index - The new selected next query. + */ + setSelectedQuery(index: number): void; /** * Resets the related prompts state. */ diff --git a/packages/x-components/src/x-modules/related-prompts/wiring.ts b/packages/x-components/src/x-modules/related-prompts/wiring.ts index 72758d813f..f59b1278c5 100644 --- a/packages/x-components/src/x-modules/related-prompts/wiring.ts +++ b/packages/x-components/src/x-modules/related-prompts/wiring.ts @@ -41,6 +41,16 @@ const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleNa */ const setRelatedPromptsQuery = wireCommit('setQuery'); +/** + * Sets the related prompts state `selectedPrompt`. + */ +const setSelectedPromptWire = wireCommit('setSelectedPrompt'); + +/** + * Sets the related prompts state `selectedQuery`. + */ +const setSelectedQueryWire = wireCommit('setSelectedQuery'); + /** * Sets the related prompts state `query` from url params. */ @@ -93,5 +103,11 @@ export const relatedPromptsWiring = createWiring({ }, ExtraParamsChanged: { setRelatedPromptsExtraParams + }, + UserSelectedARelatedPrompt: { + setSelectedPromptWire + }, + UserSelectedARelatedPromptQuery: { + setSelectedQueryWire } });