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

add display name replacement and make search page router editable #49838

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

289Adam289
Copy link
Contributor

@289Adam289 289Adam289 commented Sep 27, 2024

Details

follow up from #49462 (comment)
makes search page input editable
allows for using filters to and from with emails taxRate with names and cardID with bank name

Fixed Issues

$#49121
PROPOSAL:

Tests

  • Open Search Router on any page
  • Insert query with filters from, to, taxRate e.g. from:name.name@email.com
  • Verify that search works correctly

On wide screen:

  • Use search page input

  • Verify that it is editable and that search works

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Open Search Router on any page
  • Insert query with filters from, to, taxRate e.g. from:name.name@email.com
  • Verify that search works correctly

On wide screen:

  • Use search page input

  • Verify that it is editable and that search works

  • 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
Android: mWeb Chrome
iOS: Native
Screen.Recording.2024-10-04.at.10.33.33.mp4
iOS: mWeb Safari
Screen.Recording.2024-10-04.at.10.37.13.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-10-04.at.10.26.37.mp4
MacOS: Desktop
Screen.Recording.2024-10-04.at.10.40.58.mp4

@289Adam289
Copy link
Contributor Author

While working on this issue, I've stumbled upon two problems with the current Search implementation of filters: from, to, in, cardID, taxRate:

  1. Search Router Input: We can replace emails, names, and bank names only with IDs that are stored in Onyx, hence the user is currently unable to search for expenses and messages that are not in Onyx. (At present, the API only supports IDs)

  2. Saved Search: When a user saves a complex query and opens the app on another device, Onyx may not have all the necessary data to replace IDs with display names, leaving blank spaces in the SearchHeader.

Changing the API to support more than just IDs may be unavoidable, especially considering the first problem. It would also simplify frontend logic substantially by removing functions that replace IDs with names and vice-versa.
cc @Kicu @luacmartins

@luacmartins
Copy link
Contributor

Agreed. I created an issue for it here and I'll work on it next week.

@289Adam289
Copy link
Contributor Author

@luacmartins The current implementations of advanced filters from, to, taxRate, cardID, and in all rely on IDs which enable the creation of more precise queries. Because of this, I doubt we can substitute them with names or emails. Consequently, the replacement of names in user-written queries becomes a necessity. Is that approach correct or should I look for solutions that are not using IDs?

How should we handle the case of the in filter? For instance, the #announce room is often repeated across different workspaces. Should we swap room names with IDs based on the currently selected workspace?

Moreover, how do we approach the situation where no workspace is selected through the workspace switcher?

@luacmartins
Copy link
Contributor

I think this issue will be solved with autocomplete. I was working on the backend PR to allow emails/names but I ran into the same issue you described. I think allowing from/to to use emails is fine because those are unique. taxRate would also be ok because we'd just search for anything with for example 5% rate, but cardID and in are trickier because as you said, those are not unique, so I think we need to rely on autocomplete for those.

I think for now, we'll update from, to and taxRate to take in emails/value and leave cardID and in as is, until autocomplete is available.

@Kicu
Copy link
Contributor

Kicu commented Oct 3, 2024

I think implementing from, to and taxRate first is a good idea 👍

@luacmartins can you expand a bit how would autocomplete help the rest of the cases? I understand that we can save the specific id somewhere in memory when a user picks it from autocomplete, but I don't think that solves everything.

Would we not allow user to type in just a string like in:#wave by hand? will we block it if he/she doesnt choose if there are multiple #wave rooms?

  • what about saved searches? we would have to save id in the search and not the text (like: #admins, #wave)
  • what about deeplinks that people might send to each other? it means we have to store id in the search query in URL

I think we should start thinking about these, because not having a single unique identifier (that is not id) for these fields is a bigger problem.


One interesting thing we found out yesterday while testing app.

You can only type in room mentions in the Composer if you are in a specific workspace (either selected by ws switcher or a workspace report). If you're in "All" room and normal chat - room mentions don't work.
I have no idea how related this might be to our case, but it's worth investigating a bit at least. Perhaps one can only search for a room in the context of policyID?

rec-room-mention.mp4

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.

Left some generic comments, I think you could spent a bit of time to simplify the component a bit, since Search is growing quite fast 😅

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
@289Adam289 289Adam289 marked this pull request as ready for review October 4, 2024 08:47
@289Adam289 289Adam289 requested a review from a team as a code owner October 4, 2024 08:47
@melvin-bot melvin-bot bot requested review from rayane-djouah and removed request for a team October 4, 2024 08:47
Copy link

melvin-bot bot commented Oct 4, 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]

@luacmartins luacmartins self-requested a review October 4, 2024 14:26
@luacmartins
Copy link
Contributor

@rayane-djouah let's prioritize this PR next since I think we should have this functionality in place before we enable the feature to all users.

@rayane-djouah
Copy link
Contributor

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 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
    • 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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

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.

BUG: when changing status the header is updated with the search query

  1. Perform a custom search
  2. Change the status
  3. Note that the header changes away from the Search bar and shows the query instead

Expected behavior: keep the search bar with the new status

Screen.Recording.2024-10-04.at.9.53.16.AM.mov

@luacmartins
Copy link
Contributor

luacmartins commented Oct 4, 2024

Also, I'm not sure about this one, but we're changing the user input to either add things like type:expense status:all or rearrange the order of filters, in my example below test amount>200 to amount>200 test. It feels unexpected. I think we should keep user input as is and just normalize the query under the hood

Screen.Recording.2024-10-04.at.9.59.39.AM.mov

@289Adam289
Copy link
Contributor Author

When user enters the query we navigate to SearchPage with a different root. Then new input is generated using url making it the only source of truth. This is the reason why user input changes after submit. I can make following changes:

  1. Remove `type:{type} status:{status}" from input.
  2. I can try to keep the order of filters but it may require changing the grammar e.g. currently all keywords are filtered from the query and an extra tree with OR operators is created

@luacmartins
Copy link
Contributor

luacmartins commented Oct 4, 2024

@289Adam289 I don't think we need to tackle that in this PR. I realize that it'd involve bigger changes and we need to align on the expected behavior. Let's not block this PR on that or make changes now.

@289Adam289
Copy link
Contributor Author

289Adam289 commented Oct 4, 2024

Ok I will fix the first bug. Should I leave the type and status in the input?

@luacmartins
Copy link
Contributor

Yea, I think we can do that for now as we think of a more holistic approach to not change the user input

@289Adam289
Copy link
Contributor Author

289Adam289 commented Oct 4, 2024

@luacmartins Currently on main when user changes status via status Bar Search Page resets to canned Query. Is it an expected behavior or do we leave the custom query and replace status with status selected from statusBar?

src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
src/components/Search/SearchPageHeader.tsx Outdated Show resolved Hide resolved
src/libs/SearchUtils.ts Outdated Show resolved Hide resolved
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.

BUG: App crashes when searching for a non-existent type and then clicking on the "Filters" button

  1. Perform a custom search with a non-existent type, for example, type:exp status:all date>2024-10-01
  2. Click on the "Filters" button.
  3. Notice that the app crashes.
Screen.Recording.2024-10-07.at.12.33.47.AM.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.

BUG: App crashes when searching for a non-existent expense type and then selecting an expense type from the filters page

  1. Perform a custom search with a non-existent expense type, for example, type:expense status:all expenseType:abcd
  2. Click on the "Filters" button.
  3. Click on the expense type menu
  4. Notice that the app crashes.
Screen.Recording.2024-10-07.at.12.55.26.AM.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.

Problem: The app does not validate search filters before saving them in Onyx. When certain malformed or incorrect filter values are used (e.g., type:expense status:all date<abcd date>abcd amount>abcd amount<abcd expenseType:abc,abcd currency:abcd from:abc,abcd to:abc,abcd category:abc,abcd tag:abc,abcdd taxRate:abc,abc), it leads to inconsistent behavior:

  1. Date Filter: Entering invalid dates results in NaN values displayed in the calendar and console warnings.
Screenshot 2024-10-07 at 1 05 01 AM
  1. Currency Filter: Invalid currencies are shown in the filter page title but not included as selected options on the actual currency filter page
Screen.Recording.2024-10-07.at.1.07.11.AM.mov
  1. Total filter: Total input fields are populated with the string NaN when invalid data is entered.
Screen.Recording.2024-10-07.at.1.09.02.AM.mov
  1. Category and Tag Filters: Non-existent categories and tags are shown in the filter page title and are included as selected options in their respective filter pages. (I think that this is a correct behaviour)
Screen.Recording.2024-10-07.at.1.10.42.AM.mov
  1. From and To filters: Non-existent From and To login values are displayed as empty strings, separated by commas
Screen.Recording.2024-10-07.at.1.12.31.AM.mov
  1. Tax Rate Filter: Tax rate names that do not exist are ignored
Screen.Recording.2024-10-07.at.1.14.10.AM.mov

@rayane-djouah
Copy link
Contributor

In Filter: When entering the input value type:chat status:all in:aaabbbccc with an invalid in filter value, the in value is cleared automatically, and an empty option appears on the in filter page.

Screen.Recording.2024-10-07.at.1.35.01.AM.mov

@289Adam289
Copy link
Contributor Author

I think correct behavior would be to ignore incorrect values in advanced filters. It maybe confusing for a user to see an option and to be unable to select it later. Also in case of from, to and in filters we don't have display name and icon to show. Similar behavior can be observed on github and slack. cc @luacmartins for thoughts

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.

BUG: The status bar incorrectly displays a loading skeleton every time the input query is modified and the enter key is pressed, even if the type has not been changed

  1. Perform a custom search, for example, type:expense status:all test
  2. Modify the search input without changing the type, for example, change to type:expense status:all test2
  3. Observe that the status bar displays a loading skeleton.

Expected behavior: The status bar should only display a loading skeleton if the type in the query is changed

Screen.Recording.2024-10-07.at.2.18.58.PM.mov

@rayane-djouah
Copy link
Contributor

BUG: A parsing error occurs when special characters, such as ä, are used.

Screenshot 2024-10-07 at 2 25 50 PM Screenshot 2024-10-07 at 1 33 59 AM

Comment on lines 74 to 81
<SearchRouterInput
value={text}
setValue={() => {}}
value={value}
setValue={setValue}
onSubmit={onSubmit}
updateSearch={() => {}}
disabled
isFullWidth
wrapperStyle={[styles.searchRouterInputResults, styles.br2]}
wrapperFocusedStyle={styles.searchRouterInputResultsFocused}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to disable autoFocus for the TextInput within the SearchRouterInput when it is used in the SearchPageHeader

Screen.Recording.2024-10-07.at.2.38.40.PM.mov

@289Adam289
Copy link
Contributor Author

289Adam289 commented Oct 7, 2024

I think to allow for parsing special characters like in #49838 (comment) fundamental changes to grammar are inevitable. In previous problems with special character we could just wrap user input in quotation marks. Right now it is impossible without initial parsing. Maybe we should handle it as a follow up.

@rayane-djouah
Copy link
Contributor

Addressing #49838 (comment) in a follow up sounds good to me 👍
cc @luacmartins

@289Adam289
Copy link
Contributor Author

I added last search type to SearchContext so that search bar skeleton visibility depends on last type and not on ref in Search that resets on every navigation. @rayane-djouah could you take a look?
I will fix remaining filters tomorrow.

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.

4 participants