Skip to content

Fix "same search query appears twice in Recent searches"#51314

Merged
luacmartins merged 7 commits intoExpensify:mainfrom
software-mansion-labs:@szymczak/fix-recent-searches-list
Nov 5, 2024
Merged

Fix "same search query appears twice in Recent searches"#51314
luacmartins merged 7 commits intoExpensify:mainfrom
software-mansion-labs:@szymczak/fix-recent-searches-list

Conversation

@SzymczakJ
Copy link
Copy Markdown
Contributor

@SzymczakJ SzymczakJ commented Oct 23, 2024

Details

Fixed Issues

$ #51044
PROPOSAL:

Tests

  1. Navigate to the Search page.
  2. Click on the search bar icon to open the search field.
  3. Enter any search query and press the Enter key to submit the query.
  4. On the search results page, change the "Sort By" column contextual filter.
  5. On the search results page, change the "Sort Order" contextual filter.
  6. On the search results page, use the workspace switcher to select a workspace.
  7. Click on the search bar icon again to open the search router.
  8. Verify that the search query (entered in step 3) will only appear once in the recent searches section (no duplicate queries)

Offline tests

QA Steps

Same as tests.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari Screenshot 2024-10-25 at 16 35 48
MacOS: Desktop

Copy link
Copy Markdown
Contributor

@289Adam289 289Adam289 left a comment

Choose a reason for hiding this comment

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

LGTM

@SzymczakJ SzymczakJ marked this pull request as ready for review October 23, 2024 22:38
@SzymczakJ SzymczakJ requested a review from a team as a code owner October 23, 2024 22:38
@melvin-bot melvin-bot bot requested review from getusha and removed request for a team October 23, 2024 22:38
@melvin-bot
Copy link
Copy Markdown

melvin-bot bot commented Oct 23, 2024

@getusha Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

Let's move this PR forward @rayane-djouah 🙏
Do we have some estimate on how long it will take to put a fix on BE side @luacmartins?

Copy link
Copy Markdown
Contributor

@rayane-d rayane-d left a comment

Choose a reason for hiding this comment

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

@SzymczakJ I think we need to exclude policyID from recentSearchHash also because searches that differ only by policyID appear multiple times in Recent searches:

Screenshot 2024-10-25 at 3 53 35 PM

WDYT?

@luacmartins luacmartins requested review from luacmartins and removed request for getusha October 25, 2024 15:39
orderedQuery += ` ${buildFilterValuesString(key, sortedFilterValues ?? [])}`;
orderedQuery += `${buildFilterValuesString(key, sortedFilterValues ?? [])}`;
});
const recentSearchHash = UserUtils.hashText(orderedQuery, 2 ** 32);
Copy link
Copy Markdown
Contributor

@luacmartins luacmartins Oct 25, 2024

Choose a reason for hiding this comment

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

Thinking more about it. What if a user explicitly types policyID:X sortOrder:asc? Should we instead just be hashing the input string instead of parts of the AST? That'd ensure anything the user types differently would be a new recent search

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We cannot hash string input. My argument: when user types policyID:X sortOrder:asc and sortOrder:asc policyID:X, we will get different hashes even though the query results will be the same.

I think we should exclude policyID like @rayane-djouah said. It may create some confusion when user types policy:X into query, but:

  1. We have a policy switcher, which is dedicated way of changing policyID, so typing policyID into SearchRouter query is the worst way to change your policyID
  2. We don't even autocomplete policyID key, so how will a user know that such option exists.
  3. It's unlikely that a real user will type something like policyID:31294891892741873, without the help of autocomplete.

What's more if user selects recentSearch with not the policyID he wanted, he can easily switch it on SearchResults page with policy switcher and it's not such a big problem(just like he switches sortOrder or sortBy). WDYT @rayane-djouah @luacmartins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can go with your current solution for now, but:

when user types policyID:X sortOrder:asc and sortOrder:asc policyID:X

TBH I'd be ok to show both of these as different recent searches, even though they are the same search at the end of the day. My argument is that the user explicitly typed both of those, so they'd probably expect to see both in the recent search area.

We don't even autocomplete policyID key, so how will a user know that such option exists.

I think we should introduce policyID autocomplete. Maybe we need a new workspace: filter for that though, so the autocomplete shows the policy name instead of ID.

cc @JmillsExpensify @trjExpensify for your thoughts.

@luacmartins
Copy link
Copy Markdown
Contributor

Do we have some estimate on how long it will take to put a fix on BE side @luacmartins?

@SzymczakJ backend PR is in review

@JmillsExpensify
Copy link
Copy Markdown
Contributor

TBH I'd be ok to show both of these as different recent searches, even though they are the same search at the end of the day. My argument is that the user explicitly typed both of those, so they'd probably expect to see both in the recent search area.

I agree with Carlos on this comment.

@JmillsExpensify
Copy link
Copy Markdown
Contributor

I think we should introduce policyID autocomplete. Maybe we need a new workspace: filter for that though, so the autocomplete shows the policy name instead of ID.

For this one, we should be careful as I'm imagining that we'd support the ability to search on multiple policies at once right? If so, then we need to introduce a way for the front-end to do the same in the workspace switcher.

@luacmartins
Copy link
Copy Markdown
Contributor

For this one, we should be careful as I'm imagining that we'd support the ability to search on multiple policies at once right? If so, then we need to introduce a way for the front-end to do the same in the workspace switcher.

Yes. The syntax already supports this, so technically if users typed policyID:<id1>,<id2> the search would work. You're right that the workspace switcher would not work as intended though.

@luacmartins luacmartins self-requested a review October 28, 2024 20:31
Copy link
Copy Markdown
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

@SzymczakJ so let's update the hash to be on the input query so we always show whatever users type, regardless of it being the same query as a previous one (if the only difference is the order of filters)

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

SzymczakJ commented Oct 29, 2024

But using inputQuery as a hash input will not fix this bug #51044!
For example when user types in two queries differing in only sortOrder like category:Advertising sortOrder:asc and category:Advertising sortOrder:desc in SearchRouter then we will get recentSearches list with two queries that look the same, because we don't show sortOrder there. Honestly I'm starting to think there's no good solution for this case, everything has it's pros and cons 😭

@luacmartins
Copy link
Copy Markdown
Contributor

Yea, that's a good point, but I think it would solve the bug unless users manually type sortBy or sortOrder, no? If that's the case, I think we can live with that edge case for now since I think most users wouldn't manually type those. We could explore a future solution where we only save what users actually type.

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

it would solve the bug unless users manually type sortBy or sortOrder, no?

Thats actually the main root cause of the bug, what's more there will be also a bug when user changes sortOrder on search results page, which is highly probable.

I would actually go with the current solution where:

  • we don't have a bug that happens when user manually types sortBy or sortOrder
  • we don't have bug when user changes sortOrder on search results page

Like you said later we could split this into two cases:

  1. use current solution for recentSearches that are derived from using advanced filters page
  2. save what users actually types into search router and in that case compute recentSearchesHash on users input, so the user could see exact queries that he typed, like category:X sortOrder:A

@luacmartins
Copy link
Copy Markdown
Contributor

I'm ok using the current logic as a stepping stone, but I think ultimately we're aiming for the behavior below, so we'll need to work on a follow up for that.

save what users actually types into search router and in that case compute recentSearchesHash on users input, so the user could see exact queries that he typed, like category:X sortOrder:A

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

I agree. So we need to store on BE what user typed into the search router and return it in recentSearches exactly as it was, but only in case, when it was made by SearchRouter

@luacmartins
Copy link
Copy Markdown
Contributor

luacmartins commented Oct 30, 2024

Correct. We currently store the inputQuery param, I'm not sure if we'd want to reuse that param or create a new one for it. The intent behind inputQuery was to be exactly what the user typed, but that doesn't seem to be the case anymore.

@luacmartins
Copy link
Copy Markdown
Contributor

@rayane-djouah let's resume reviews on this PR

luacmartins
luacmartins previously approved these changes Oct 30, 2024
Copy link
Copy Markdown
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

FYI I'll OOO on Friday and Monday.

@rayane-d
Copy link
Copy Markdown
Contributor

rayane-d commented Oct 31, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Screen.Recording.2024-11-02.at.11.29.37.PM.mov
Android: mWeb Chrome
Screen.Recording.2024-11-02.at.11.26.38.PM.mov
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-11-02.at.23.25.08.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-11-02.at.23.22.50.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-11-02.at.11.13.05.PM.mov
MacOS: Desktop
Screen.Recording.2024-11-02.at.11.02.30.PM.mov

@rayane-d
Copy link
Copy Markdown
Contributor

Let's add these QA Steps:

  1. Navigate to the Search page.
  2. Click on the search bar icon to open the search field.
  3. Enter any search query and press the Enter key to submit the query.
  4. On the search results page, change the "Sort By" column contextual filter.
  5. On the search results page, change the "Sort Order" contextual filter.
  6. On the search results page, use the workspace switcher to select a workspace.
  7. Click on the search bar icon again to open the search router.
  8. Verify that the search query (entered in step 3) will only appear once in the recent searches section (no duplicate queries)

Copy link
Copy Markdown
Contributor

@rayane-d rayane-d left a comment

Choose a reason for hiding this comment

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

BUG: I'm still seeing duplicate recent searches that differ only by sortOrder, the recentSearchHash is changing when you change the sorting order:

Screenshot 2024-10-31 at 10 38 15 PM

Screenshot 2024-10-31 at 10 38 05 PM

Screen.Recording.2024-10-31.at.10.36.55.PM.mov

}
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${query.type}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${query.status}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${query.sortBy}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${query.sortBy}`;

we're incorrectly including sortBy and sortOrder in orderedQuery here for recentSearchHash and then adding them again at the end of orderedQuery for primaryHash

Screenshot 2024-10-31 at 10 54 06 PM Screenshot 2024-10-31 at 10 54 25 PM

we need to remove these two lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whoops, that's probably my mistake when merging main 🙇

@rayane-d
Copy link
Copy Markdown
Contributor

@289Adam289 Could you please address the above comment, as @SzymczakJ will be OOO according to this comment? Thank you!

@289Adam289
Copy link
Copy Markdown
Contributor

Hi! I was also OOO on Friday. @SzymczakJ will be back tomorrow and I think it would be best to leave addressing comments to him.

@SzymczakJ
Copy link
Copy Markdown
Contributor Author

I've added the tests steps and fixed bug you mentioned @rayane-djouah

Copy link
Copy Markdown
Contributor

@rayane-d rayane-d 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 tests well 👍

@melvin-bot melvin-bot bot requested a review from luacmartins November 5, 2024 10:34
Copy link
Copy Markdown
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM

@luacmartins luacmartins merged commit 74994dc into Expensify:main Nov 5, 2024
@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Nov 5, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 6, 2024

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.0.58-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 success ✅
🍎🔄 iOS HybridApp 🍎🔄 success ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 7, 2024

🚀 Deployed to production by https://github.com/Julesssss in version: 9.0.58-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 skipped 🚫
🍎🔄 iOS HybridApp 🍎🔄 skipped 🚫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants