From 86a46f48dcbfdb91f127bfd9379247a565beb4fd Mon Sep 17 00:00:00 2001 From: Guillermo Date: Wed, 3 Jan 2024 12:56:50 +0100 Subject: [PATCH 1/6] feat(search): handle display tagging from search response --- .../src/schemas/responses/search-response.schema.ts | 3 ++- .../src/types/responses/search-response.model.ts | 1 + .../x-components/src/x-modules/search/store/module.ts | 7 +++++++ packages/x-components/src/x-modules/search/store/types.ts | 8 ++++++++ packages/x-types/src/response/search-response.model.ts | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts index 5dd2867302..81083dd90d 100644 --- a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts +++ b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts @@ -41,5 +41,6 @@ export const searchResponseSchema = createMutableSchema getTaggingInfoFromUrl(catalog?.tagging?.query) + queryTagging: ({ catalog }) => getTaggingInfoFromUrl(catalog?.tagging?.query), + displayTagging: ({ catalog }) => getTaggingInfoFromUrl(catalog?.tagging?.display) }); diff --git a/packages/x-adapter-platform/src/types/responses/search-response.model.ts b/packages/x-adapter-platform/src/types/responses/search-response.model.ts index fb3563c45b..a93b9c9bb3 100644 --- a/packages/x-adapter-platform/src/types/responses/search-response.model.ts +++ b/packages/x-adapter-platform/src/types/responses/search-response.model.ts @@ -22,6 +22,7 @@ export interface PlatformSearchResponse { partials: PlatformPartialResult[]; tagging: { query: string; + display: string; }; }; direct: { diff --git a/packages/x-components/src/x-modules/search/store/module.ts b/packages/x-components/src/x-modules/search/store/module.ts index 20dcf349e6..8430c7920b 100644 --- a/packages/x-components/src/x-modules/search/store/module.ts +++ b/packages/x-components/src/x-modules/search/store/module.ts @@ -106,6 +106,9 @@ export const searchXStoreModule: SearchXStoreModule = { setQueryTagging(state, queryTagging) { state.queryTagging = queryTagging; }, + setDisplayTagging(state, displayTagging) { + state.displayTagging = displayTagging; + }, updateResult(state, result) { const stateResult = state.results.find(stateResult => result.id === stateResult.id); if (stateResult) { @@ -153,6 +156,10 @@ export function resettableState() { queryTagging: { url: '', params: {} + }, + displayTagging: { + url: '', + params: {} } }; } diff --git a/packages/x-components/src/x-modules/search/store/types.ts b/packages/x-components/src/x-modules/search/store/types.ts index d8ad39084a..848532f4da 100644 --- a/packages/x-components/src/x-modules/search/store/types.ts +++ b/packages/x-components/src/x-modules/search/store/types.ts @@ -52,6 +52,8 @@ export interface SearchState extends StatusState, QueryState { promoteds: Promoted[]; /** The query tagging used to track the search events. */ queryTagging: TaggingRequest; + /** The display tagging used to track the search events. */ + displayTagging: TaggingRequest; /** The redirections associated to the `query`. */ redirections: Redirection[]; /** The list of the related tags, related to the `query` property of the state. */ @@ -172,6 +174,12 @@ export interface SearchMutations * @param queryTagging - The new query tagging object to save to the state. */ setQueryTagging(queryTagging: TaggingRequest): void; + /** + * Sets the display tagging of the module. + * + * @param displayTagging - The new display tagging object to save to the state. + */ + setDisplayTagging(DisplayTagging: TaggingRequest): void; /** * Sets the redirection of the module. * diff --git a/packages/x-types/src/response/search-response.model.ts b/packages/x-types/src/response/search-response.model.ts index 7c22354b76..7b6a32ff36 100644 --- a/packages/x-types/src/response/search-response.model.ts +++ b/packages/x-types/src/response/search-response.model.ts @@ -17,6 +17,7 @@ export interface SearchResponse { partialResults?: PartialResult[]; promoteds?: Promoted[]; queryTagging?: TaggingRequest; + displayTagging?: TaggingRequest; redirections?: Redirection[]; results: Result[]; spellcheck?: string; From 9a6ba785c9bee8361847b2f0613a92ceed79bd4f Mon Sep 17 00:00:00 2001 From: Guillermo Date: Wed, 3 Jan 2024 15:08:35 +0100 Subject: [PATCH 2/6] display functions and test fixing --- .../src/__tests__/__fixtures__/search.response.ts | 2 ++ .../search-response.mapper.spec.ts.snap | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/x-adapter-platform/src/__tests__/__fixtures__/search.response.ts b/packages/x-adapter-platform/src/__tests__/__fixtures__/search.response.ts index 72c7ec3496..a37c3425d7 100644 --- a/packages/x-adapter-platform/src/__tests__/__fixtures__/search.response.ts +++ b/packages/x-adapter-platform/src/__tests__/__fixtures__/search.response.ts @@ -101,6 +101,8 @@ export const platformSearchResponse = { } ], tagging: { + display: + 'https://api.staging.empathy.co/tagging/v1/track/empathy/display?q=jeans&lang=en&scope=desktop&totalHits=686&page=1&origin=url%3Aexternal&filtered=true&spellcheck=false', query: 'https://api.staging.empathy.co/tagging/v1/track/empathy/query?q=jeans&lang=en&scope=desktop&totalHits=686&page=1&origin=url%3Aexternal&filtered=true&spellcheck=false' }, diff --git a/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap b/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap index dcca26cf5a..494cf16138 100644 --- a/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap +++ b/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap @@ -30,6 +30,20 @@ Object { "url": "https://assets.empathy.co/", }, ], + "displayTagging": Object { + "params": Object { + "filtered": "true", + "follow": false, + "lang": "en", + "origin": "url:external", + "page": "1", + "q": "jeans", + "scope": "desktop", + "spellcheck": "false", + "totalHits": "686", + }, + "url": "https://api.staging.empathy.co/tagging/v1/track/empathy/display", + }, "facets": Array [ Object { "filters": Array [ From cec0e6e7e1468c9bb4b1b48ae772e26ce2997e1d Mon Sep 17 00:00:00 2001 From: Guillermo Date: Wed, 3 Jan 2024 15:09:20 +0100 Subject: [PATCH 3/6] display functions and test fixing --- .../src/__stubs__/empty-search-response-stubs.factory.ts | 4 ++++ .../src/__stubs__/search-response-stubs.factory.ts | 1 + packages/x-components/src/adapter/mocked-responses.ts | 4 ++++ packages/x-components/src/x-modules/search/store/emitters.ts | 1 + 4 files changed, 10 insertions(+) diff --git a/packages/x-components/src/__stubs__/empty-search-response-stubs.factory.ts b/packages/x-components/src/__stubs__/empty-search-response-stubs.factory.ts index 660642c3a1..96303db2ad 100644 --- a/packages/x-components/src/__stubs__/empty-search-response-stubs.factory.ts +++ b/packages/x-components/src/__stubs__/empty-search-response-stubs.factory.ts @@ -17,6 +17,10 @@ export function getEmptySearchResponseStub(): SearchResponse { params: {}, url: '' }, + displayTagging: { + params: {}, + url: '' + }, redirections: [], results: [], spellcheck: '', diff --git a/packages/x-components/src/__stubs__/search-response-stubs.factory.ts b/packages/x-components/src/__stubs__/search-response-stubs.factory.ts index ac5b1c100e..ae0117e99e 100644 --- a/packages/x-components/src/__stubs__/search-response-stubs.factory.ts +++ b/packages/x-components/src/__stubs__/search-response-stubs.factory.ts @@ -20,6 +20,7 @@ export function getSearchResponseStub(): SearchResponse { partialResults: [], promoteds: getPromotedsStub(), queryTagging: getTaggingResponseStub(), + displayTagging: getTaggingResponseStub(), redirections: getRedirectionsStub(), results: getResultsStub(), spellcheck: '', diff --git a/packages/x-components/src/adapter/mocked-responses.ts b/packages/x-components/src/adapter/mocked-responses.ts index 6d05f12937..aebfb2890e 100644 --- a/packages/x-components/src/adapter/mocked-responses.ts +++ b/packages/x-components/src/adapter/mocked-responses.ts @@ -221,6 +221,10 @@ export function createSearchResponse(partial?: Partial): SearchR url: `${trackEndpoint}/query`, params: { page: 1 } }, + displayTagging: { + url: `${trackEndpoint}/display`, + params: { page: 1 } + }, spellcheck: '', ...partial }; diff --git a/packages/x-components/src/x-modules/search/store/emitters.ts b/packages/x-components/src/x-modules/search/store/emitters.ts index 119dbfdf20..3e0fc5fc5d 100644 --- a/packages/x-components/src/x-modules/search/store/emitters.ts +++ b/packages/x-components/src/x-modules/search/store/emitters.ts @@ -28,6 +28,7 @@ export const searchEmitters = createStoreEmitters(searchXStoreModule, { partialResults: state.partialResults, promoteds: state.promoteds, queryTagging: state.queryTagging, + displayTagging: state.displayTagging, redirections: state.redirections, results: state.results, spellcheck: state.spellcheckedQuery, From 25b8e0a8416bacabefeb4b4461fd6f909db1b99a Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 4 Jan 2024 13:57:26 +0100 Subject: [PATCH 4/6] use display tagging functionfor the tagging info url --- .../src/mappers/__tests__/url.spec.ts | 12 ++++++++---- packages/x-adapter-platform/src/mappers/url.utils.ts | 2 +- .../src/schemas/models/result.schema.ts | 4 ++-- .../src/schemas/responses/search-response.schema.ts | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/x-adapter-platform/src/mappers/__tests__/url.spec.ts b/packages/x-adapter-platform/src/mappers/__tests__/url.spec.ts index 6e2895cda0..8bff8346dc 100644 --- a/packages/x-adapter-platform/src/mappers/__tests__/url.spec.ts +++ b/packages/x-adapter-platform/src/mappers/__tests__/url.spec.ts @@ -1,4 +1,8 @@ -import { extractUrlParameters, getDisplayClickTagging, getTaggingInfoFromUrl } from '../url.utils'; +import { + extractUrlParameters, + getDisplayTaggingInfoFromUrl, + getTaggingInfoFromUrl +} from '../url.utils'; describe('url utils methods tests', () => { describe('extractUrlParameters', () => { @@ -45,14 +49,14 @@ describe('url utils methods tests', () => { describe('getDisplayClickTagging', () => { it('should not break when dealing with bad urls', () => { - expect(getDisplayClickTagging('null')).toStrictEqual({ + expect(getDisplayTaggingInfoFromUrl('null')).toStrictEqual({ url: 'null', params: { displayId: 'no_query', follow: false } }); }); it('should retrieve the tagging info from the url, replacing q with displayId', () => { - const { url, params } = getDisplayClickTagging( + const { url, params } = getDisplayTaggingInfoFromUrl( 'https://api.empathy.co/?q=chips&env=mobile&lang=english&lang=spanish' ); expect(url).toBe('https://api.empathy.co/'); @@ -65,7 +69,7 @@ describe('url utils methods tests', () => { }); it('should set no_query tagging info when no q param exist as in topclicked response', () => { - const { url, params } = getDisplayClickTagging( + const { url, params } = getDisplayTaggingInfoFromUrl( 'https://api.empathy.co/?env=mobile&lang=english&lang=spanish' ); expect(url).toBe('https://api.empathy.co/'); diff --git a/packages/x-adapter-platform/src/mappers/url.utils.ts b/packages/x-adapter-platform/src/mappers/url.utils.ts index 9f2aa88fef..ad9607ba3b 100644 --- a/packages/x-adapter-platform/src/mappers/url.utils.ts +++ b/packages/x-adapter-platform/src/mappers/url.utils.ts @@ -28,7 +28,7 @@ export function getTaggingInfoFromUrl(taggingUrl: string): TaggingRequest { * * @public */ -export function getDisplayClickTagging(displayTaggingUrl: string): TaggingRequest { +export function getDisplayTaggingInfoFromUrl(displayTaggingUrl: string): TaggingRequest { const displayClickTagging = getTaggingInfoFromUrl(displayTaggingUrl); const displayClickTaggingParams = displayClickTagging.params; diff --git a/packages/x-adapter-platform/src/schemas/models/result.schema.ts b/packages/x-adapter-platform/src/schemas/models/result.schema.ts index 365a61574d..8bdcb6e97d 100644 --- a/packages/x-adapter-platform/src/schemas/models/result.schema.ts +++ b/packages/x-adapter-platform/src/schemas/models/result.schema.ts @@ -1,6 +1,6 @@ import { createMutableSchema } from '@empathyco/x-adapter'; import { Result } from '@empathyco/x-types'; -import { getDisplayClickTagging, getTaggingInfoFromUrl } from '../../mappers/url.utils'; +import { getDisplayTaggingInfoFromUrl, getTaggingInfoFromUrl } from '../../mappers/url.utils'; import { PlatformResult } from '../../types/models/result.model'; /** @@ -36,7 +36,7 @@ export const resultSchema = createMutableSchema({ add2cart: ({ add2cart }) => getTaggingInfoFromUrl(add2cart), checkout: ({ checkout }) => getTaggingInfoFromUrl(checkout), click: ({ click }) => getTaggingInfoFromUrl(click), - displayClick: ({ displayClick }) => getDisplayClickTagging(displayClick) + displayClick: ({ displayClick }) => getDisplayTaggingInfoFromUrl(displayClick) } } }); diff --git a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts index 81083dd90d..eee6ceb8e4 100644 --- a/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts +++ b/packages/x-adapter-platform/src/schemas/responses/search-response.schema.ts @@ -1,6 +1,6 @@ import { createMutableSchema } from '@empathyco/x-adapter'; import { SearchResponse } from '@empathyco/x-types'; -import { getTaggingInfoFromUrl } from '../../mappers/url.utils'; +import { getDisplayTaggingInfoFromUrl, getTaggingInfoFromUrl } from '../../mappers/url.utils'; import { PlatformSearchResponse } from '../../types/responses/search-response.model'; import { bannerSchema } from '../models/banner.schema'; import { facetSchema } from '../models/facet.schema'; @@ -42,5 +42,5 @@ export const searchResponseSchema = createMutableSchema getTaggingInfoFromUrl(catalog?.tagging?.query), - displayTagging: ({ catalog }) => getTaggingInfoFromUrl(catalog?.tagging?.display) + displayTagging: ({ catalog }) => getDisplayTaggingInfoFromUrl(catalog?.tagging?.display) }); From 270543cc2cd01a4d5e75e29a6fdda2bff8eca04a Mon Sep 17 00:00:00 2001 From: Guillermo Date: Fri, 12 Jan 2024 09:34:15 +0100 Subject: [PATCH 5/6] store display in search module and renaming of utils function --- packages/x-adapter-platform/src/mappers/url.utils.ts | 10 +++++----- .../store/actions/save-search-response.action.ts | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/x-adapter-platform/src/mappers/url.utils.ts b/packages/x-adapter-platform/src/mappers/url.utils.ts index ad9607ba3b..1ece334b3a 100644 --- a/packages/x-adapter-platform/src/mappers/url.utils.ts +++ b/packages/x-adapter-platform/src/mappers/url.utils.ts @@ -29,13 +29,13 @@ export function getTaggingInfoFromUrl(taggingUrl: string): TaggingRequest { * @public */ export function getDisplayTaggingInfoFromUrl(displayTaggingUrl: string): TaggingRequest { - const displayClickTagging = getTaggingInfoFromUrl(displayTaggingUrl); - const displayClickTaggingParams = displayClickTagging.params; + const displayTagging = getTaggingInfoFromUrl(displayTaggingUrl); + const displayTaggingParams = displayTagging.params; - displayClickTaggingParams.displayId = displayClickTaggingParams.q ?? 'no_query'; - delete displayClickTaggingParams.q; + displayTaggingParams.displayId = displayTaggingParams.q ?? 'no_query'; + delete displayTaggingParams.q; - return displayClickTagging; + return displayTagging; } /** diff --git a/packages/x-components/src/x-modules/search/store/actions/save-search-response.action.ts b/packages/x-components/src/x-modules/search/store/actions/save-search-response.action.ts index 464ca11fc3..9774a2f4c0 100644 --- a/packages/x-components/src/x-modules/search/store/actions/save-search-response.action.ts +++ b/packages/x-components/src/x-modules/search/store/actions/save-search-response.action.ts @@ -20,7 +20,8 @@ export const saveSearchResponse: SearchXStoreModule['actions']['saveSearchRespon totalResults, spellcheck, redirections, - queryTagging + queryTagging, + displayTagging } ) => { if (totalResults === 0) { @@ -50,6 +51,11 @@ export const saveSearchResponse: SearchXStoreModule['actions']['saveSearchRespon if (queryTagging) { commit('setQueryTagging', queryTagging); } + + if (displayTagging) { + commit('setDisplayTagging', displayTagging); + } + commit('setTotalResults', totalResults); commit('setSpellcheck', spellcheck ?? ''); }; From d4036c8b1e2ee2baa1af805babdb7a575f57c833 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Fri, 12 Jan 2024 09:49:54 +0100 Subject: [PATCH 6/6] update search snapshot --- .../__tests__/__snapshots__/search-response.mapper.spec.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap b/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap index 494cf16138..a12ebfbae5 100644 --- a/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap +++ b/packages/x-adapter-platform/src/mappers/responses/__tests__/__snapshots__/search-response.mapper.spec.ts.snap @@ -32,12 +32,12 @@ Object { ], "displayTagging": Object { "params": Object { + "displayId": "jeans", "filtered": "true", "follow": false, "lang": "en", "origin": "url:external", "page": "1", - "q": "jeans", "scope": "desktop", "spellcheck": "false", "totalHits": "686",