Skip to content

Commit

Permalink
Merge pull request #1013 from dpc-sdp/bugfix/R20-1719-view-search-res…
Browse files Browse the repository at this point in the history
…ults-re-firing

[R20-1719]: stop search firing when clearing filters without change
  • Loading branch information
lambry authored Jan 30, 2024
2 parents 9654bbf + 959e15a commit 937f5b9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Feature: Search listing - Filter
When I clear the search filters

And the search network request should be called with the "/search-listing/filters/request-clear-empty" fixture
Then the URL should reflect that the current page number is 1
Then the URL should reflect that the current page has been reset
Then the URL should reflect that the current search term is ""
Then the URL should reflect that the current active filters are as follows:
| id |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Feature: Searching listing - Pagination
When I click the search button
Given I wait 1 seconds
Then the search network request should be called with the "/search-listing/pagination/request-page-1-with-term" fixture
And the URL should reflect that the current page number is 1
And the URL should reflect that the current page has been reset
And the results counter should show 1 to 4 of 10 results
And the search listing results should have following items:
| title |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Then(
}
)

Then('the URL should reflect that the current page has been reset', () => {
cy.location().should((loc) => {
const params = new URLSearchParams(loc.search)
expect(params.get('page')).to.eq(null)
})
})

Then(
'the URL should reflect that the current sort option is {string}',
(sortId: string) => {
Expand Down
12 changes: 5 additions & 7 deletions packages/ripple-tide-search/composables/useTideSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ export default ({
return JSON.parse(JSON.stringify(obj).replace(re, escapedValue))
}

const activeTab: TideSearchListingTabKey = ref(
searchListingConfig?.displayMapTab ? 'map' : null
)
const initialTab = searchListingConfig?.displayMapTab ? 'map' : null
const activeTab: TideSearchListingTabKey = ref(initialTab)

const isBusy = ref(true)
const searchError = ref(null)
Expand Down Expand Up @@ -564,9 +563,8 @@ export default ({
await navigateTo({
path: route.path,
query: {
page: 1,
q: searchTerm.value || undefined,
activeTab: activeTab.value,
activeTab: activeTab.value !== initialTab ? activeTab.value : undefined,
...locationParams,
...filterFormValues
}
Expand All @@ -581,7 +579,7 @@ export default ({
...route,
query: {
...route.query,
page: newPage
page: newPage > 1 ? newPage : undefined
}
})
}
Expand All @@ -602,7 +600,7 @@ export default ({
...route,
query: {
...route.query,
activeTab: newActiveTab
activeTab: newActiveTab !== initialTab ? newActiveTab : undefined
}
})
}
Expand Down

0 comments on commit 937f5b9

Please sign in to comment.