From 45123d45e7775f8edb221c3530c6641f8ab6fcc3 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 09:21:11 +0530 Subject: [PATCH 1/6] BUG#PWA-3161 [Cloud] Search Term Redirect not working in PWA --- .../lib/talons/SearchPage/searchPage.gql.js | 11 ++++++++++ .../lib/talons/SearchPage/useSearchPage.js | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js b/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js index 1c11774d16..d97eff7f99 100644 --- a/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js +++ b/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js @@ -27,6 +27,16 @@ export const GET_PRODUCT_FILTERS_BY_SEARCH = gql` } `; +export const GET_SEARCH_TERM_DATA = gql` + query getSearchTermData($search: String) { + searchTerm(Search : $search) { + query_text + redirect + popularity + } + } +`; + export const PRODUCT_SEARCH = gql` query ProductSearch( $currentPage: Int = 1 @@ -106,6 +116,7 @@ export const GET_SEARCH_AVAILABLE_SORT_METHODS = gql` export default { getFilterInputsQuery: GET_FILTER_INPUTS, getPageSize: GET_PAGE_SIZE, + getSearchTermData:GET_SEARCH_TERM_DATA, getProductFiltersBySearchQuery: GET_PRODUCT_FILTERS_BY_SEARCH, getSearchAvailableSortMethods: GET_SEARCH_AVAILABLE_SORT_METHODS, productSearchQuery: PRODUCT_SEARCH diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 279fe12377..44f00e75eb 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -26,6 +26,7 @@ export const useSearchPage = (props = {}) => { const { getFilterInputsQuery, getPageSize, + getSearchTermData, getProductFiltersBySearchQuery, getSearchAvailableSortMethods, productSearchQuery @@ -36,6 +37,15 @@ export const useSearchPage = (props = {}) => { nextFetchPolicy: 'cache-first' }); + const [getSearchTermMethod,{data:SearchTerm } ] = useLazyQuery( + getSearchTermData + ); + + if (SearchTerm !==undefined && SearchTerm.redirect!==null){ + const [...redirectData]= [SearchTerm] + window.location.replace(redirectData[0].searchTerm.redirect); + } + const [getSortMethods, { data: sortData }] = useLazyQuery( getSearchAvailableSortMethods, { @@ -231,6 +241,16 @@ export const useSearchPage = (props = {}) => { }; }, [data, setTotalPages]); + useEffect(() => { + if (inputText) { + getSearchTermMethod({ + variables: { + search: inputText + } + }); + } + }, [inputText, getSearchTermMethod]); + useEffect(() => { if (inputText) { getSortMethods({ From 0f077d700c30bb2d52bd9d561accbe0ab71c07ab Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 09:47:21 +0530 Subject: [PATCH 2/6] BUG#PWA-3161 [Cloud] Search Term Redirect not working in PWA --- .../peregrine/lib/talons/SearchPage/searchPage.gql.js | 10 +++++----- .../peregrine/lib/talons/SearchPage/useSearchPage.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js b/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js index d97eff7f99..3d67fed9a4 100644 --- a/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js +++ b/packages/peregrine/lib/talons/SearchPage/searchPage.gql.js @@ -29,10 +29,10 @@ export const GET_PRODUCT_FILTERS_BY_SEARCH = gql` export const GET_SEARCH_TERM_DATA = gql` query getSearchTermData($search: String) { - searchTerm(Search : $search) { - query_text - redirect - popularity + searchTerm(Search: $search) { + query_text + redirect + popularity } } `; @@ -116,7 +116,7 @@ export const GET_SEARCH_AVAILABLE_SORT_METHODS = gql` export default { getFilterInputsQuery: GET_FILTER_INPUTS, getPageSize: GET_PAGE_SIZE, - getSearchTermData:GET_SEARCH_TERM_DATA, + getSearchTermData: GET_SEARCH_TERM_DATA, getProductFiltersBySearchQuery: GET_PRODUCT_FILTERS_BY_SEARCH, getSearchAvailableSortMethods: GET_SEARCH_AVAILABLE_SORT_METHODS, productSearchQuery: PRODUCT_SEARCH diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 44f00e75eb..99d6963df2 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -37,12 +37,12 @@ export const useSearchPage = (props = {}) => { nextFetchPolicy: 'cache-first' }); - const [getSearchTermMethod,{data:SearchTerm } ] = useLazyQuery( + const [getSearchTermMethod, { data: SearchTerm }] = useLazyQuery( getSearchTermData - ); + ); - if (SearchTerm !==undefined && SearchTerm.redirect!==null){ - const [...redirectData]= [SearchTerm] + if (SearchTerm !== undefined && SearchTerm.redirect !== null) { + const [...redirectData] = [SearchTerm]; window.location.replace(redirectData[0].searchTerm.redirect); } From b5b61249a7f7d562d92419708be5c36c0793b5f5 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 11:50:16 +0530 Subject: [PATCH 3/6] BUG#PWA-3161 [Cloud] Search Term Redirect not working in PWA --- .../peregrine/lib/talons/SearchPage/useSearchPage.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 99d6963df2..ebd6d76a37 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -37,13 +37,16 @@ export const useSearchPage = (props = {}) => { nextFetchPolicy: 'cache-first' }); - const [getSearchTermMethod, { data: SearchTerm }] = useLazyQuery( + const [getSearchTermMethod, { data: SearchTermQueryData }] = useLazyQuery( getSearchTermData ); - if (SearchTerm !== undefined && SearchTerm.redirect !== null) { - const [...redirectData] = [SearchTerm]; - window.location.replace(redirectData[0].searchTerm.redirect); + if (SearchTermQueryData !== undefined) { + const [...redirectData] = [SearchTermQueryData]; + const redirectUrl = redirectData[0].searchTerm; + if (redirectUrl !== null ) { + window.location.replace(redirectUrl.redirect); + } } const [getSortMethods, { data: sortData }] = useLazyQuery( From 99178252f61d5d43099d1fb1de759c36a1a7ccf3 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 12:59:10 +0530 Subject: [PATCH 4/6] BUG#PWA-3161 [Cloud] Search Term Redirect not working in PWA --- .../__tests__/__snapshots__/useSearchPage.spec.js.snap | 7 +------ packages/peregrine/lib/talons/SearchPage/useSearchPage.js | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/peregrine/lib/talons/SearchPage/__tests__/__snapshots__/useSearchPage.spec.js.snap b/packages/peregrine/lib/talons/SearchPage/__tests__/__snapshots__/useSearchPage.spec.js.snap index 46e5500b7d..4017f1d4dd 100644 --- a/packages/peregrine/lib/talons/SearchPage/__tests__/__snapshots__/useSearchPage.spec.js.snap +++ b/packages/peregrine/lib/talons/SearchPage/__tests__/__snapshots__/useSearchPage.spec.js.snap @@ -2,12 +2,7 @@ exports[`searchCategory returns the correct shape 1`] = ` Object { - "availableSortMethods": Array [ - Object { - "label": "Position", - "value": "position", - }, - ], + "availableSortMethods": undefined, "currentStoreName": "Store 1", "data": Object { "products": Object { diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index ebd6d76a37..0783035718 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -43,9 +43,9 @@ export const useSearchPage = (props = {}) => { if (SearchTermQueryData !== undefined) { const [...redirectData] = [SearchTermQueryData]; - const redirectUrl = redirectData[0].searchTerm; - if (redirectUrl !== null ) { - window.location.replace(redirectUrl.redirect); + const redirectUrl = redirectData[0].searchTerm?.redirect; + if (redirectUrl !== null) { + window.location.replace(redirectUrl); } } @@ -296,7 +296,7 @@ export const useSearchPage = (props = {}) => { useScrollTopOnChange(currentPage); const availableSortMethods = sortData - ? sortData.products.sort_fields.options + ? sortData.products.sort_fields?.options : null; return { From f50c4d796152e013b08578d3c1f5dfbed14b947f Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 16:02:19 +0530 Subject: [PATCH 5/6] BUG#PWA-3161 --- packages/peregrine/lib/talons/SearchPage/useSearchPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 0783035718..4739677e56 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -273,6 +273,8 @@ export const useSearchPage = (props = {}) => { } ); + + useEffect(() => { if (inputText) { getFilters({ From 76b73b57b41ade551bc0b3103d622750555e049b Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Wed, 20 Sep 2023 16:21:11 +0530 Subject: [PATCH 6/6] BUG#PWA-3161 --- packages/peregrine/lib/talons/SearchPage/useSearchPage.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js index 4739677e56..0783035718 100644 --- a/packages/peregrine/lib/talons/SearchPage/useSearchPage.js +++ b/packages/peregrine/lib/talons/SearchPage/useSearchPage.js @@ -273,8 +273,6 @@ export const useSearchPage = (props = {}) => { } ); - - useEffect(() => { if (inputText) { getFilters({