Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add Debounce to filter selection (#2104)
Browse files Browse the repository at this point in the history
* changed watch to watchDebounced

* test update

* changed debonce value

* Updatecomment

Co-authored-by: Zack Krida <[email protected]>

* Update comment

Co-authored-by: Zack Krida <[email protected]>

* update comment

---------

Co-authored-by: Zack Krida <[email protected]>
  • Loading branch information
anton202 and zackkrida authored Feb 8, 2023
1 parent f0d3d20 commit d2926b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/VFilters/VSearchGridFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ import {
ref,
useContext,
useRouter,
watch,
} from "@nuxtjs/composition-api"
import { kebab } from "case"
import { watchDebounced } from "@vueuse/core"
import { useSearchStore } from "~/stores/search"
import { areQueriesEqual, ApiQueryParams } from "~/utils/search-query-transform"
import { Focus, focusIn, getFocusableElements } from "~/utils/focus-management"
Expand Down Expand Up @@ -115,13 +116,14 @@ export default defineComponent({
* This watcher fires even when the queries are equal. We update the path only
* when the queries change.
*/
watch(
watchDebounced(
() => searchStore.searchQueryParams,
(newQuery: ApiQueryParams, oldQuery: ApiQueryParams) => {
if (!areQueriesEqual(newQuery, oldQuery)) {
router.push(searchStore.getSearchPath())
}
}
},
{ debounce: 800, maxWait: 5000 }
)
const focusableElements = computed(() =>
Expand Down
3 changes: 3 additions & 0 deletions test/playwright/e2e/search-navigation-old.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ test.describe("search history navigation", () => {

// Apply a filter
await page.click("#modification")
// There is a debounce when choosing a filter.
// we need to wait for the page to reload before running the test
await page.waitForNavigation()

// Verify the filter is applied to the URL and the checkbox is checked
// Note: Need to add that a search was actually executed with the new
Expand Down
3 changes: 3 additions & 0 deletions test/playwright/e2e/search-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ test.describe("search history navigation", () => {

// Apply a filter
await page.click("#modification")
// There is a debounce when choosing a filter.
// we need to wait for the page to reload before running the test
await page.waitForNavigation()

// Verify the filter is applied to the URL and the checkbox is checked
// Note: Need to add that a search was actually executed with the new
Expand Down

0 comments on commit d2926b7

Please sign in to comment.