Skip to content

Commit

Permalink
fix(@dpc-sdp/ripple-ui-core): stop search firing on clear when initia…
Browse files Browse the repository at this point in the history
…l filters haven't changed

this also means we're resetting back to the initial URL now
  • Loading branch information
David Featherston committed Jan 29, 2024
1 parent 24858a4 commit 959e15a
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 959e15a

Please sign in to comment.