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

Add Debounce to filter selection #2104

Merged
merged 6 commits into from
Feb 8, 2023
Merged

Add Debounce to filter selection #2104

merged 6 commits into from
Feb 8, 2023

Conversation

anton202
Copy link
Contributor

Fixes

Fixes #505 by @sarayourfriend

Description

as described in the issue by @sarayourfriend, currently when selecting several filters one after the other
a query will be excuted for each filter selection.
so, as suggested in the issue i added a debounce of 500ms to filter selection (basically switched the watch function to watchDebounced )

Staging

staging-filter.mp4

This PR

staging-filter.mp4

Testing Instructions

follow the steps in the video :)

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update index.md).
  • My pull request targets the default branch of the repository (main) or
    a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible
    errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@anton202 anton202 requested a review from a team as a code owner January 18, 2023 12:29
@anton202 anton202 requested review from zackkrida and dhruvkb January 18, 2023 12:29
@openverse-bot openverse-bot added ✨ goal: improvement Improvement to an existing user-facing feature 🕹 aspect: interface Concerns end-users' experience with the software 🟨 priority: medium Not blocking but should be addressed soon labels Jan 18, 2023
@anton202
Copy link
Contributor Author

anton202 commented Jan 19, 2023

Hi, @zackkrida
i`m having a wierd thing with e2e/mobile-menu-old.spec.ts test.
currently it fails, it fails also when i run it locally.
but, if i set the new_header:{status:{staging:disabled}} at features-flags.json
the test does pass.
maybe its something related to enableOldHeader function at the e2e/mobile-menu-old.spec.ts test ?

i see that it also happened here #2090

@sarayourfriend
Copy link
Contributor

@obulat would probably know best how to debug this issue quickly 🤞

@obulat
Copy link
Contributor

obulat commented Jan 20, 2023

@anton202, I think you opened this PR before the new_header flag was set to be on by default in the staging environment. So, in your branch, new_header.status.staging in features-flags.json is set to switchable, and the defaultValue is off, but in main it was changed to on. You will probably need to rebase onto (updated) main branch to fix the problems.

If there are still problems with the e2e remaining, I think we will also need to change the enableOldHeader function, just like you mentioned.

I tried rebasing your branch onto main, and changing the functions to what's listed below, and didn't get any errors in e2e tests locally.

--- a/test/playwright/utils/navigation.ts
+++ b/test/playwright/utils/navigation.ts
@@ -464,19 +464,12 @@ export const enableNewHeader = async (page: Page) => {
 
 export const enableOldHeader = async (page: Page) => {
   // Add the new_header cookie
-  await page.context().addCookies([
-    {
-      name: "features",
-      value: "%7B%22new_header%22%3A%22off%22%7D",
-      domain: "localhost",
-      path: "/",
-    },
-  ])
+  await setCookies(page.context(), { features: { new_header: "off" } })
 }
 
 export const setCookies = async (
   context: BrowserContext,
-  cookies: Record<string, string | boolean | string[]>
+  cookies: Record<string, string | boolean | string[] | Record<string, string>>
 ) => {
   await context.addCookies(
     Object.entries(cookies).map(([name, value]) => ({

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your fix, @anton202, it works perfectly! I've added notes about the tests, and I'll approve after they are fixed.

@anton202
Copy link
Contributor Author

@obulat Thank you for the help. i`ll adress that on sunday :)

@anton202
Copy link
Contributor Author

@obulat i`ve tried your suggestion but the test still didnt pass :(
i did noticed though that on this branch and on the main branch new_header.status.staging is set to enabled
i changed it to switchable and now the test passing.
btw, right now we can`t toggle betwen the new and old header on staging. i think beacuse new_header.status.staging is set to enabled

@anton202
Copy link
Contributor Author

weird. all the tests pass when i run them locally
debounce-tests

@sarayourfriend
Copy link
Contributor

sarayourfriend commented Jan 24, 2023

@anton202 Sorry for the delay in responses on this PR, folks have been travelling the past week and doing work offline. Most will be back later in the week and someone will be able to help debug more closely. We appreciate the patience 🙏

@anton202
Copy link
Contributor Author

sure, no problem :)

@openverse-bot
Copy link
Contributor

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@dhruvkb
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was updated 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@anton202, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and it works. But I have a question about the wait numbers. A code comment // explaining them would be good.

() => searchStore.searchQueryParams,
(newQuery: ApiQueryParams, oldQuery: ApiQueryParams) => {
if (!areQueriesEqual(newQuery, oldQuery)) {
router.push(searchStore.getSearchPath())
}
}
},
{ debounce: 800, maxWait: 5000 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind these values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see @zackkrida wanted to raise it from 500. 800 seemed a very specific, very arbitrary choice to start with.

@obulat obulat merged commit d2926b7 into WordPress:main Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🕹 aspect: interface Concerns end-users' experience with the software ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debounce filter selection
6 participants