From 36cdcc681d4b049815b99a42d48c22d30c49fafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20CG?= Date: Fri, 1 Nov 2024 09:58:19 +0100 Subject: [PATCH] feat: create related prompts module (#1642) --- packages/x-components/src/__stubs__/index.ts | 1 + .../related-prompts-stubs.factory.ts | 43 +++ .../src/adapter/mocked-responses.ts | 6 +- .../x-components/src/components/base-grid.vue | 3 +- packages/x-components/src/index.ts | 1 + packages/x-components/src/views/home/Home.vue | 171 ++++++--- packages/x-components/src/views/home/types.ts | 3 + .../x-components/src/wiring/events.types.ts | 5 +- .../related-prompts/components/index.ts | 2 + .../components/related-prompt.vue | 102 +++++ .../components/related-prompts-list.vue | 362 ++++++++++++++++++ .../x-modules/related-prompts/events.types.ts | 16 + .../src/x-modules/related-prompts/index.ts | 5 + .../store/__tests__/actions.spec.ts | 118 ++++++ .../store/__tests__/getters.spec.ts | 37 ++ .../related-prompts/store/__tests__/utils.ts | 21 + .../fetch-and-save-related-prompts.action.ts | 34 ++ .../actions/fetch-related-prompts.action.ts | 21 + .../related-prompts/store/emitters.ts | 11 + .../store/getters/request.getter.ts | 15 + .../x-modules/related-prompts/store/index.ts | 6 + .../x-modules/related-prompts/store/module.ts | 44 +++ .../x-modules/related-prompts/store/types.ts | 103 +++++ .../src/x-modules/related-prompts/types.ts | 10 + .../src/x-modules/related-prompts/wiring.ts | 97 +++++ .../src/x-modules/related-prompts/x-module.ts | 28 ++ .../src/x-modules/x-modules.types.ts | 2 + 27 files changed, 1212 insertions(+), 55 deletions(-) create mode 100644 packages/x-components/src/__stubs__/related-prompts-stubs.factory.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/components/index.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/components/related-prompt.vue create mode 100644 packages/x-components/src/x-modules/related-prompts/components/related-prompts-list.vue create mode 100644 packages/x-components/src/x-modules/related-prompts/events.types.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/index.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/__tests__/actions.spec.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/__tests__/getters.spec.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/__tests__/utils.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/actions/fetch-related-prompts.action.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/emitters.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/getters/request.getter.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/index.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/module.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/store/types.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/types.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/wiring.ts create mode 100644 packages/x-components/src/x-modules/related-prompts/x-module.ts diff --git a/packages/x-components/src/__stubs__/index.ts b/packages/x-components/src/__stubs__/index.ts index 2a437254f3..aeab9517d3 100644 --- a/packages/x-components/src/__stubs__/index.ts +++ b/packages/x-components/src/__stubs__/index.ts @@ -15,3 +15,4 @@ export * from './results-stubs.factory'; export * from './search-response-stubs.factory'; export * from './semantic-queries-stubs.factory'; export * from './tagging-response-stubs.factory'; +export * from './related-prompts-stubs.factory'; diff --git a/packages/x-components/src/__stubs__/related-prompts-stubs.factory.ts b/packages/x-components/src/__stubs__/related-prompts-stubs.factory.ts new file mode 100644 index 0000000000..ce47147c43 --- /dev/null +++ b/packages/x-components/src/__stubs__/related-prompts-stubs.factory.ts @@ -0,0 +1,43 @@ +import { RelatedPrompt } from '@empathyco/x-types'; + +/** + * Creates a {@link @empathyco/x-types#RelatedPrompt | related prompts} stub. + * + * @param amount - Number of stubbed related prompts to create. + * + * @returns Array of related prompts stub. + * + * @internal + */ +export function getRelatedPromptsStub(amount = 12): RelatedPrompt[] { + return Array.from({ length: amount }, (_, index) => + createRelatedPromptStub(`Related Prompt ${index + 1}`) + ); +} + +/** + * Creates a related prompt stub with the provided options. + * + * @param suggestionText - The suggested text of the related prompt. + * + * @returns A related prompt. + */ +export function createRelatedPromptStub(suggestionText: string): RelatedPrompt { + return { + suggestionText, + nextQueries: createNextQueriesArrayStub(10), + modelName: 'RelatedPrompt', + type: Math.random() < 0.5 ? 'CURATED' : 'SYNTHETIC' + }; +} + +/** + * Creates an array of next queries. + * + * @param amount - Number of next queries to create. + * + * @returns Array of next queries. + */ +function createNextQueriesArrayStub(amount: number): string[] { + return Array.from({ length: amount }, (_, index) => `Next query ${index + 1}`); +} diff --git a/packages/x-components/src/adapter/mocked-responses.ts b/packages/x-components/src/adapter/mocked-responses.ts index 768ee3443a..23d8049ff3 100644 --- a/packages/x-components/src/adapter/mocked-responses.ts +++ b/packages/x-components/src/adapter/mocked-responses.ts @@ -10,7 +10,8 @@ import { createSimpleFacetStub, getFacetsStub, getRelatedTagsStub, - getResultsStub + getResultsStub, + getRelatedPromptsStub } from '../__stubs__/index'; export const mockedApiUrl = 'https://api.empathy.co'; @@ -198,6 +199,9 @@ export const mockedResponses = { }, 'related-tags': { relatedTags: getRelatedTagsStub() + }, + 'related-prompts': { + relatedPrompts: getRelatedPromptsStub() } }; diff --git a/packages/x-components/src/components/base-grid.vue b/packages/x-components/src/components/base-grid.vue index 6f57d626e4..967fcbc41a 100644 --- a/packages/x-components/src/components/base-grid.vue +++ b/packages/x-components/src/components/base-grid.vue @@ -219,7 +219,8 @@ } .x-base-grid__banner, - .x-base-grid__next-queries-group { + .x-base-grid__next-queries-group, + .x-base-grid__related-prompts-group { grid-column-start: 1; grid-column-end: -1; } diff --git a/packages/x-components/src/index.ts b/packages/x-components/src/index.ts index c32bee25e7..f215f3c1ba 100644 --- a/packages/x-components/src/index.ts +++ b/packages/x-components/src/index.ts @@ -26,6 +26,7 @@ export * from './x-modules/popular-searches'; export * from './x-modules/queries-preview'; export * from './x-modules/query-suggestions'; export * from './x-modules/recommendations'; +export * from './x-modules/related-prompts'; export * from './x-modules/related-tags'; export * from './x-modules/scroll'; export * from './x-modules/search'; diff --git a/packages/x-components/src/views/home/Home.vue b/packages/x-components/src/views/home/Home.vue index 9de9623b72..a8f42d5ab9 100644 --- a/packages/x-components/src/views/home/Home.vue +++ b/packages/x-components/src/views/home/Home.vue @@ -76,7 +76,7 @@
  • -
  • +
  • + +