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 generic AutoCompleteSuggestions component #18024

Merged
merged 6 commits into from
May 4, 2023

Conversation

szebniok
Copy link
Contributor

@szebniok szebniok commented Apr 26, 2023

Details

I've created the AutoCompleteSuggestions component and rewritten the EmojiSuggestions to use it. This is a first PR related to #17890—the second one will implement the MentionSuggestions, which will use the AutoCompleteSuggestions.

Fixed Issues

$ #17890

Tests

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

This PR refactors functionality added in #14686, so the tests can be reused here.

  • 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 / Chrome
    • iOS / native
    • iOS / 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 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 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(themeColors.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 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-04-26.at.14.19.08.mov
Mobile Web - Chrome
Screen.Recording.2023-04-26.at.14.23.05.mov
Mobile Web - Safari
Screen.Recording.2023-04-26.at.14.32.14.mov
Desktop
Screen.Recording.2023-04-26.at.14.37.13.mov
iOS
Screen.Recording.2023-04-26.at.14.40.33.mov
Android
Screen.Recording.2023-04-26.at.14.50.12.mov

@github-actions
Copy link
Contributor

github-actions bot commented Apr 26, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@szebniok szebniok force-pushed the rework-emoji-suggestions branch from e0d9635 to 9e23a06 Compare April 26, 2023 12:51
@szebniok
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@szebniok szebniok marked this pull request as ready for review April 26, 2023 13:40
@szebniok szebniok requested a review from a team as a code owner April 26, 2023 13:40
@melvin-bot melvin-bot bot requested review from amyevans and removed request for a team April 26, 2023 13:40
@MelvinBot
Copy link

@amyevans 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]

@szebniok szebniok force-pushed the rework-emoji-suggestions branch from a05be2e to 125db68 Compare April 26, 2023 14:32
@szebniok szebniok force-pushed the rework-emoji-suggestions branch from 125db68 to f798983 Compare April 26, 2023 14:33
Copy link
Contributor

@0xmiros 0xmiros left a comment

Choose a reason for hiding this comment

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

Code overall looks good. Just minor feedback:

Comment on lines 11 to 35
const propTypes = {
/** Array of suggestions */
// eslint-disable-next-line react/forbid-prop-types
suggestions: PropTypes.arrayOf(PropTypes.object).isRequired,

/** Function used to render each suggestion, returned JSX will be enclosed inside a Pressable component */
renderSuggestionMenuItem: PropTypes.func.isRequired,

/** Create unique keys for each suggestion item */
keyExtractor: PropTypes.func.isRequired,

/** The index of the highlighted suggestion */
highlightedSuggestionIndex: PropTypes.number.isRequired,

/** Fired when the user selects a suggestion */
onSelect: PropTypes.func.isRequired,

/** Show that we can use large auto-complete suggestion picker.
* Depending on available space and whether the input is expanded, we can have a small or large mention suggester.
* When this value is false, the suggester will have a height of 2.5 items. When this value is true, the height can be up to 5 items. */
isSuggestionPickerLarge: PropTypes.bool.isRequired,

/** Show that we should include ReportRecipientLocalTime view height */
shouldIncludeReportRecipientLocalTimeHeight: PropTypes.bool.isRequired,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I see all props are required. Can we make some of them optional? i.e. highlightedSuggestionIndex is fine not to be required. Before, the default value was 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering making some of the props optional, but ultimately decided against it (YAGNI).

The way I saw it:
suggestions and renderSuggestionMenuItem - It doesn't make sense to use this component without providing the suggestions and a way of displaying them
keyExtractor - I could consider making it optional, as FlatList is falling back to using item.key, item.id and the item index
highlightedSuggestionIndex - I think that the default value of 0 is problematic—we either care about the highlights and set this value, or we don't keep track of it, but in this case we have an useless piece of data lying around.
onSelect - I initially rejected it, but now I can see a potential need of displaying the suggestions without a way of interacting with them
isSuggestionPickerLarge and shouldIncludeReportRecipientLocalTimeHeight - I would say that these props may be ugly, and are tightly coupling our component to the report composer, but they were necessary in the previous implementation.

The way I see it, I could consider making the keyExtractor and onSelect optional, and set the default value of highlightedSuggestionIndex to undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me 👍🏾

src/styles/styles.js Outdated Show resolved Hide resolved
<Text style={styles.emojiSuggestionsText}>
:
{_.map(styledTextArray, ({text, isColored}, i) => (
<Text key={`${text}+${i}`} style={StyleUtils.getColoredBackgroundStyle(isColored)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

This existed before but not sure why index is used for key. Is there any possibility that texts are duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that is likely scenario, as the item.name is splitted into at most into 3 parts, and item.name contains the : sign at the beginning and at the end.
I could consider setting the key to text, but I could see an argument being made that the current solution is more future-proof.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like index is safer in general as a key.

src/pages/home/report/AutoCompleteSuggestions.js Outdated Show resolved Hide resolved
@stitesExpensify stitesExpensify self-requested a review April 26, 2023 17:37
@0xmiros
Copy link
Contributor

0xmiros commented Apr 26, 2023

@szebniok please fix merge conflict came from #17788

@puneetlath
Copy link
Contributor

@0xmiroslav looks like the comments we have here are minor. Would you be able to do the all-device testing today?

@szebniok you have some conflicts again.

@0xmiros
Copy link
Contributor

0xmiros commented Apr 27, 2023

Sure, will do once main merged into this branch

@szebniok
Copy link
Contributor Author

@0xmiroslav @puneetlath I've merged the main branch and fixed the conflicts.

@puneetlath
Copy link
Contributor

Great. @0xmiroslav can we get this tested today?


export default EmojiSuggestions;
// AutoCompleteSuggestions.defaultProps = defaultProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: we can remove comment

Copy link
Contributor

Choose a reason for hiding this comment

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

+1


AutoCompleteSuggestions.propTypes = propTypes;

// AutoCompleteSuggestions.defaultProps = defaultProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: we can remove comment

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@0xmiros
Copy link
Contributor

0xmiros commented Apr 28, 2023

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 / Chrome
    • iOS / native
    • iOS / 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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(themeColors.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 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

Web
web.mov
Mobile Web - Chrome
mchrome.mov
Mobile Web - Safari
msafari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mov

0xmiros
0xmiros previously approved these changes Apr 28, 2023
Copy link
Contributor

@0xmiros 0xmiros left a comment

Choose a reason for hiding this comment

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

The merge conflict was from #17788 which fixes #16485.
I double checked this PR applies changes from #17788 correctly and thus fixes both #16485 and #17890

I ran QA steps in #14686 and confirmed nothing breaks.

So all good.

amyevans
amyevans previously approved these changes Apr 28, 2023
Copy link
Contributor

@amyevans amyevans left a comment

Choose a reason for hiding this comment

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

Refactor looks good to me, just a few minor suggestions!

src/components/AutoCompleteSuggestions/index.js Outdated Show resolved Hide resolved

export default EmojiSuggestions;
// AutoCompleteSuggestions.defaultProps = defaultProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1


AutoCompleteSuggestions.propTypes = propTypes;

// AutoCompleteSuggestions.defaultProps = defaultProps;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

src/components/EmojiSuggestions.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions.js Outdated Show resolved Hide resolved
src/components/EmojiSuggestions.js Outdated Show resolved Hide resolved
src/styles/styles.js Outdated Show resolved Hide resolved
Comment on lines 11 to 35
const propTypes = {
/** Array of suggestions */
// eslint-disable-next-line react/forbid-prop-types
suggestions: PropTypes.arrayOf(PropTypes.object).isRequired,

/** Function used to render each suggestion, returned JSX will be enclosed inside a Pressable component */
renderSuggestionMenuItem: PropTypes.func.isRequired,

/** Create unique keys for each suggestion item */
keyExtractor: PropTypes.func.isRequired,

/** The index of the highlighted suggestion */
highlightedSuggestionIndex: PropTypes.number.isRequired,

/** Fired when the user selects a suggestion */
onSelect: PropTypes.func.isRequired,

/** Show that we can use large auto-complete suggestion picker.
* Depending on available space and whether the input is expanded, we can have a small or large mention suggester.
* When this value is false, the suggester will have a height of 2.5 items. When this value is true, the height can be up to 5 items. */
isSuggestionPickerLarge: PropTypes.bool.isRequired,

/** Show that we should include ReportRecipientLocalTime view height */
shouldIncludeReportRecipientLocalTimeHeight: PropTypes.bool.isRequired,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me 👍🏾

<Text style={styles.emojiSuggestionsText}>
:
{_.map(styledTextArray, ({text, isColored}, i) => (
<Text key={`${text}+${i}`} style={StyleUtils.getColoredBackgroundStyle(isColored)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like index is safer in general as a key.

@puneetlath puneetlath merged commit d6d84b6 into Expensify:main May 4, 2023
@OSBotify
Copy link
Contributor

OSBotify commented May 4, 2023

✋ 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

OSBotify commented May 4, 2023

🚀 Deployed to staging by https://github.com/puneetlath in version: 1.3.10-0 🚀

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

@mvtglobally
Copy link

Can we check this off since another ticket in prod? #14686 (comment)

@puneetlath
Copy link
Contributor

@mvtglobally I don't follow the question. Mind clarifying?

@mvtglobally
Copy link

@puneetlath i am referring to QA steps image
Do we need to test this PR?

@puneetlath
Copy link
Contributor

Thanks for confirming. Yes we do need to test. We can test using the QA steps from #14686

@mvtglobally
Copy link

Posting so team can reference

QA Steps
Condition: You are in the chat screen and the text input is focused with the keyboard expanded

Mobile:

Enter :s in an empty text input.

Observe that there is no suggestion.

Add 'm' to the text input so it contains :sm.

Verify that the Emoji suggester appears above the text input.

Tap on any of the suggested emojis.

Verify that :sm is replaced with the selected emoji.

Enter some text in the text input.

Add a space or create a new line.

Expand the input

Enter a colon followed by two letters that correspond to the name of the desired emoji (e.g. smile -> :sm, flag -> :fl).

Verify that the Emoji suggester appears above the text input.

Tap on one of the suggested emojis.

Verify that the text (e.g. :sm, :fl, etc.) is replaced with the selected emoji.

WEB/Desktop:

Enter :s in an empty text input.
Observe that there is no suggestion.
Add 'm' to the text input so it contains :sm.
Verify that the Emoji suggester appears above the text input.
Use the arrow keys to switch between suggested emojis.
Select a suggested emoji by either tapping on it or pressing Enter if you are using the arrow keys.
Verify that :sm is replaced with the selected emoji.
Note: The suggestion will only appear if you enter a colon followed by two letters without any spaces in between. Before the colon, there should be either a space, a line break, or the input should be the first word in the text field. (So, the following values would not trigger the suggestion::s, : sm, :s m, sm:sm)
Emoji suggestions could contain up to 5 items. Is a screen small we show a height of 2.5 items and you can scroll this box.

@OSBotify
Copy link
Contributor

OSBotify commented May 9, 2023

🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.12-0 🚀

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.

8 participants