Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store applied filters in onyx #48312

Conversation

289Adam289
Copy link
Contributor

@289Adam289 289Adam289 commented Aug 30, 2024

Details

Fixed Issues

$ #48156
$ #48407
PROPOSAL:

Tests

  1. Open the app
  2. Go to Search
  3. From the available options, select both a Type (Expense, Invoice, Trip, or Chat) and a Status (from the status bar).
  4. Click "Filters" button
  5. Verify that the available filters are relevant to the selected type
  6. Apply filters as needed
  7. Close the filters page
  8. Click "Filters" button
  9. Verify that the previous filters values are selected
  10. Click on "View results"
  11. Verify that the displayed results match the previously selected Type and Status
  12. Click "Filters" button
  13. Verify that the previously used filters are selected
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Open the app
  2. Go to Search
  3. From the available options, select both a Type (Expense, Invoice, Trip, or Chat) and a Status (from the status bar).
  4. Click "Filters" button
  5. Verify that the available filters are relevant to the selected type
  6. Apply filters as needed
  7. Close the filters page
  8. Click "Filters" button
  9. Verify that the previous filters values are selected
  10. Click on "View results"
  11. Verify that the displayed results match the previously selected Type and Status
  12. Click "Filters" button
  13. Verify that the previously used filters are selected
  • Verify that no errors appear in the JS console

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.
  • 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.

Screenshots/Videos

Android: Native
Screen.Recording.2024-09-03.at.10.58.07.mov
Android: mWeb Chrome
Screen.Recording.2024-09-03.at.09.28.39.mp4
iOS: Native
Screen.Recording.2024-09-02.at.15.06.02.mp4
iOS: mWeb Safari
Screen.Recording.2024-09-02.at.15.06.02.mov
MacOS: Chrome / Safari
Screen.Recording.2024-09-02.at.14.04.41.mov
MacOS: Desktop

Copy link
Contributor

@Guccio163 Guccio163 left a comment

Choose a reason for hiding this comment

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

LGTM when it comes to strictly this PR, but I found bug in Category filter and it's probably linked to parser, maybe you can take a look at it @289Adam289 :

  • If you create Category with &amp; written inside, select this category in Filters, save and display results, the whole page crashed:
Screen.Recording.2024-08-30.at.15.42.57.mov

Additionally, it doesn't happen if I create tag with & alone in it, which encoded version in &amp;

Copy link
Contributor

@Kicu Kicu left a comment

Choose a reason for hiding this comment

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

In general code looks good, I have left mostly minor comments about naming, and 1 comment to simplify code.
Good job 👍

src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/components/Search/SearchPageHeader.tsx Outdated Show resolved Hide resolved
src/components/Search/SearchPageHeader.tsx Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/pages/Search/SearchTypeMenuNarrow.tsx Outdated Show resolved Hide resolved
@289Adam289 289Adam289 marked this pull request as ready for review September 3, 2024 09:13
@289Adam289 289Adam289 requested a review from a team as a code owner September 3, 2024 09:13
@melvin-bot melvin-bot bot requested review from rayane-djouah and removed request for a team September 3, 2024 09:13
Copy link

melvin-bot bot commented Sep 3, 2024

@rayane-djouah 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]

@289Adam289
Copy link
Contributor Author

@luacmartins ready for review

Copy link
Contributor

@Kicu Kicu left a comment

Choose a reason for hiding this comment

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

LGTM, left some more small comments

src/pages/Search/AdvancedSearchFilters.tsx Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/components/Search/types.ts Show resolved Hide resolved
@luacmartins luacmartins self-requested a review September 4, 2024 17:16
Copy link
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.

Looks great. Left a small comment.

src/components/Search/SearchPageHeader.tsx Outdated Show resolved Hide resolved
src/pages/Search/SearchTypeMenuNarrow.tsx Outdated Show resolved Hide resolved
if (keyInCorrectForm) {
return `${CONST.SEARCH.SYNTAX_FILTER_KEYS[keyInCorrectForm]}:${filterValue as string}`;
}
return `${filterValue as string}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to sanitize the string for the keyword filter?

Copy link
Contributor Author

@289Adam289 289Adam289 Sep 5, 2024

Choose a reason for hiding this comment

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

At first I didn't think it was necessary but after some thought if we add operator symbols to sanitizeString function and sanitize every word of an input it should prevent some bugs.

Copy link
Contributor Author

@289Adam289 289Adam289 Sep 5, 2024

Choose a reason for hiding this comment

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

While working on keyword filter sanitization i came across another problem. Quotation marks are hard to parse. For example category with a single quote mark breaks the parser and even sanitizing it wont help. I suggest we discuss this problem in another issue cause it may need some fundamental changes in grammar itself. cc @luacmartins @Kicu

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it'd require changes to the grammar and we can handle that as a separate issue.

src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Show resolved Hide resolved
Comment on lines 534 to 543
if (
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add In and Has filters keys

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also consider defining a MULTIPLE_VALUES_FILTER_KEYS const and then check for Object.values(MULTIPLE_VALUES_FILTER_KEYS).includes(filterKey) instead. This will simplify the condition if we need it in multiple places

@rayane-djouah
Copy link
Contributor

I've noticed that we're not excluding duplicate keyword filter values

@289Adam289
Copy link
Contributor Author

I don't think duplicate keyword filter values are a problem. If a user chooses to enter "test test" then I think we should leave it as it is.

@luacmartins
Copy link
Contributor

I don't think duplicate keyword filter values are a problem. If a user chooses to enter "test test" then I think we should leave it as it is.

I agree this is not a problem. We're also updating the grammar here that will combine them into a single node

luacmartins
luacmartins previously approved these changes Sep 5, 2024
Copy link
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 previously approved these changes Sep 9, 2024
Copy link
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
Copy link
Contributor

I'm gonna merge this PR as is and then work on a follow up to address this comment

@luacmartins
Copy link
Contributor

@289Adam289 if you'd like you can remove the Has and Is filter from the advanced filters page, so we can move this PR forward. I'll work on adding them to the status bar, since that requires some backend changes.

@289Adam289
Copy link
Contributor Author

I can do that

@rayane-djouah
Copy link
Contributor

rayane-djouah commented Sep 10, 2024

@289Adam289 I've found a bug:

  1. Open the expense type search.
  2. Open filters and select values.
  3. Navigate back from the filters page; note that the filter values remain saved.
  4. Change the search type to "chat."
  5. Re-open the filters page.
  6. Observe that the previously saved filter values are still being applied for the common filters between expense and chat types.
  7. Click "view results."

Expected Results: Only filters relevant to the "chat" type, from the previously saved filter values, should be applied.
Or, filters values should be cleared when we change the type.

Actual Results: Filters related to both the "chat" and the original "expense" type from the saved filter values are incorrectly applied together.

Screen.Recording.2024-09-10.at.1.08.42.PM.mov

@rayane-djouah
Copy link
Contributor

Regarding the QA steps, steps 9 and 10 should be before "clicking view results button" because we clear the selected values when we click on the button, Could you please update the steps to:

  1. Open the app
  2. Go to Search
  3. From the available options, select both a Type (Expense, Invoice, Trip, or Chat) and a Status (from the status bar).
  4. Click "Filters" button
  5. Verify that the available filters are relevant to the selected type
  6. Apply filters as needed
  7. Close the filters page
  8. Click "Filters" button
  9. Verify that the previous filters values are selected
  10. Click on "View results"
  11. Verify that the displayed results match the previously selected Type and Status
  12. Click "Filters" button
  13. Verify that the filters values are empty (cleared)

@289Adam289
Copy link
Contributor Author

I don't think last step is correct. Filter values should be the same as before clicking "ViewResults"

@rayane-djouah
Copy link
Contributor

rayane-djouah commented Sep 10, 2024

I don't think last step is correct. Filter values should be the same as before clicking "ViewResults"

@289Adam289 We're currently clearing the filters here when we click on "View Results" :

SearchActions.clearAdvancedFilters();

Do we need to change it?

@rayane-djouah
Copy link
Contributor

@289Adam289 We've encountered another bug:

The "Reset filters" button is visible on the filters page even when no values have been selected. When accessing the filters page from a different type (e.g., "Chat") and clicking the "Reset filters" button, the filters displayed switch to those related to the "Expense" type instead of remaining consistent with the currently selected type.

Screen.Recording.2024-09-10.at.1.54.55.PM.mov

@289Adam289
Copy link
Contributor Author

We're currently clearing the filters here when we click on "View Results" :

Onyx is cleared to prevent bugs and make url the only source of truth. So we shouldn't change it.
The goal od this PR is to get filters from url and set values in Onyx upon clicking filter button

@luacmartins
Copy link
Contributor

It seems like we have a couple of minor bugs left. Let's squash them and get this one merged 😄

@Kicu
Copy link
Contributor

Kicu commented Sep 11, 2024

To clarify about filter values in onyx.
Storing them in onyx was added only for the Advanced Filters Form to work.
In some of the filters we are using FromProvider which expects to get an onyx key with the form state - won't work otherwise. So it made the most sense to make the whole form use onyx as storage, both for single value filters and multi-picker filters.

However we store the values in onyx only when the form page (search/filters) is open. When you're on other Search pages we store nothing in onyx - URL (or params in navigation state) are the single source of truth.

@289Adam289
Copy link
Contributor Author

Now Onyx is cleared when changing type. Reset button is only visible when filters are set and it clears only advanced filters.

@rayane-djouah
Copy link
Contributor

Screenshots/Videos

Android: Native
Screen.Recording.2024-09-11.at.11.40.56.AM.mov
Android: mWeb Chrome
Screen.Recording.2024-09-11.at.11.33.02.AM.mov
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-09-11.at.11.29.47.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-09-11.at.11.25.31.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-09-11.at.10.57.34.AM.mov
MacOS: Desktop
Screen.Recording.2024-09-11.at.11.22.55.AM.mov

@rayane-djouah
Copy link
Contributor

rayane-djouah commented Sep 11, 2024

@289Adam289, on both the Android native app and mobile Chrome web version, the filter values sometimes do not clear when changing the type. Could you please try to reproduce this issue on your end?

Android: Native
Screen.Recording.2024-09-11.at.11.40.56.AM.mov
Android: mWeb Chrome
Screen.Recording.2024-09-11.at.11.33.02.AM.mov

@rayane-djouah
Copy link
Contributor

Fixed! thanks!

Screen.Recording.2024-09-11.at.1.14.00.PM.mov

Copy link
Contributor

@rayane-djouah rayane-djouah 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 September 11, 2024 12:19
@rayane-djouah
Copy link
Contributor

@luacmartins all yours!

Copy link
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 3e3388d into Expensify:main Sep 11, 2024
16 checks passed
@OSBotify
Copy link
Contributor

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.0.33-4 🚀

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

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