Skip to content

migrate CopyTextToClipboard to functional component#20107

Merged
PauloGasparSv merged 8 commits into
Expensify:mainfrom
nhminhduc:16132-migrate-CopyTextToClipboard
Jun 7, 2023
Merged

migrate CopyTextToClipboard to functional component#20107
PauloGasparSv merged 8 commits into
Expensify:mainfrom
nhminhduc:16132-migrate-CopyTextToClipboard

Conversation

@nhminhduc

@nhminhduc nhminhduc commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Details

Fixed Issues

$ #16132
PROPOSAL: #16132 (comment)

Tests

  1. Log in
  2. Click to own avatar -> Go to profile in setting nav -> Contact method
  3. The copy icon next to "receipts@expensify.com" use this component
  4. Click to the copy icon
  5. Paste message and check if message is in clipboard

Offline tests

Same as online

QA Steps

  • 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 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 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
web.mp4
Mobile Web - Chrome
chrome.mp4
Mobile Web - Safari
safari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mov

@nhminhduc nhminhduc requested a review from a team as a code owner June 2, 2023 22:43
@melvin-bot melvin-bot Bot requested review from PauloGasparSv and mollfpr and removed request for a team June 2, 2023 22:43
@melvin-bot

melvin-bot Bot commented Jun 2, 2023

Copy link
Copy Markdown

@PauloGasparSv @mollfpr One of you needs to 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]

@github-actions

github-actions Bot commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

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

@nhminhduc

Copy link
Copy Markdown
Contributor Author

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

@nhminhduc nhminhduc closed this Jun 2, 2023
@PauloGasparSv PauloGasparSv reopened this Jun 2, 2023
@PauloGasparSv

Copy link
Copy Markdown
Contributor

Re-opening this, I think it was closed by mistake : )

@nhminhduc

Copy link
Copy Markdown
Contributor Author

@PauloGasparSv Tried to close+open to see if the check will go through :D

@mollfpr

mollfpr commented Jun 5, 2023

Copy link
Copy Markdown
Contributor

@nhminhduc Could you resolve the lint issues? Thanks!

@mollfpr mollfpr left a comment

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.

Need to resolve the lint issue and other style problem. @nhminhduc If you using vscode, you can try the command "Format Document With..." > "Prettier - Code formatter".

Comment thread src/components/CopyTextToClipboard.js Outdated
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import withDelayToggleButtonState, {withDelayToggleButtonStatePropTypes} from './withDelayToggleButtonState';
import withLocalize, { withLocalizePropTypes } from './withLocalize';
import withDelayToggleButtonState, { withDelayToggleButtonStatePropTypes } from './withDelayToggleButtonState';

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.

@nhminhduc I think we don't add spaces between brackets.

Suggested change
import withDelayToggleButtonState, { withDelayToggleButtonStatePropTypes } from './withDelayToggleButtonState';
import withDelayToggleButtonState, {withDelayToggleButtonStatePropTypes} from './withDelayToggleButtonState';

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.

Done

Comment thread src/components/CopyTextToClipboard.js Outdated
<Text style={textStyles}>{`${text} `}</Text>
<Tooltip text={translate(`reportActionContextMenu.${isDelayButtonStateComplete ? 'copied' : 'copyToClipboard'}`)}>
<Pressable onPress={copyToClipboard}>
{({ hovered, pressed }) => (

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.

No spaces before/after bracket.

Suggested change
{({ hovered, pressed }) => (
{({hovered, pressed}) => (

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.

Done


/** Styles to apply to the text */
// eslint-disable-next-line react/forbid-prop-types
textStyles: PropTypes.arrayOf(PropTypes.object),

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.

@nhminhduc Any reason to remove the lint disable?

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.

Not really, it doesn't alert on my pc. But I added it again just in case.

Comment thread src/components/CopyTextToClipboard.js Outdated

copyToClipboard() {
if (this.props.isDelayButtonStateComplete) {
const CopyTextToClipboard = ({ text, textStyles, translate, isDelayButtonStateComplete, toggleDelayButtonState }) => {

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.

Don't destructure props or state. It makes the source of a given variable unclear. This guideline helps us quickly know which variables are from props, state, or from some other scope.

@nhminhduc Could you update these destruct props?

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.

Fixed, using props instead.

@mollfpr

mollfpr commented Jun 5, 2023

Copy link
Copy Markdown
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 / 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
20107.Web.mov
Mobile Web - Chrome
20107.mWeb.Chrome.mov
Mobile Web - Safari
20107.mWeb.Safari.mp4
Desktop
20107.Desktop.mov
iOS
20107.iOS.mp4
Android
20107.Android.mov

@nhminhduc

Copy link
Copy Markdown
Contributor Author

Updated to keep up with main branch:
Using PressableWithDelayToggle component.

@mollfpr

mollfpr commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

@nhminhduc Could you resolve the lint issue?

Clipboard.setString(this.props.text);
const CopyTextToClipboard = (props) => {
const copyToClipboard = () => {
Clipboard.setString(props.text);

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.

@nhminhduc @PauloGasparSv Do you guys agree if we wrap this with useCallback since it has dependencies of props.text?

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.

Yes I agree

@nhminhduc

Copy link
Copy Markdown
Contributor Author

Added useCallback, displayName and fixed lint.

@mollfpr mollfpr left a comment

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.

giphy (1)

Thanks @nhminhduc 👍

All yours @PauloGasparSv

@nhminhduc

Copy link
Copy Markdown
Contributor Author

giphy (1)

Thanks @nhminhduc 👍

All yours @PauloGasparSv

Thank you for your time 🙇

@PauloGasparSv

PauloGasparSv commented Jun 7, 2023

Copy link
Copy Markdown
Contributor

Hi @nhminhduc, can you please fix the linter errors here? (I think running npx prettier --write . is enough)

Will review here anyways and re-approve once that's done : )

@PauloGasparSv

PauloGasparSv commented Jun 7, 2023

Copy link
Copy Markdown
Contributor

Tested all platforms and LGTM!

I'm double checking Android before approving because the copy icon isn't there, I'm curious if that was also happening on main and if there was an issue about it.

PauloGasparSv
PauloGasparSv previously approved these changes Jun 7, 2023

@PauloGasparSv PauloGasparSv left a comment

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.

LGTM!

Tested main and the copy icon doesn't show in the Contact Methods page there either.

Waiting on the linter fix to merge this

@nhminhduc

Copy link
Copy Markdown
Contributor Author

Run prettier 👍

@nhminhduc

Copy link
Copy Markdown
Contributor Author

I think on android the icon is showing, just the color is quite off. Not sure why.

@PauloGasparSv

Copy link
Copy Markdown
Contributor

I think on android the icon is showing, just the color is quite off. Not sure why.

@nhminhduc do you mind updating the QA steps to use the Copy icon from somewhere else then? I think this will be reported as a problem if we don't explain in the QA section : )

@PauloGasparSv PauloGasparSv merged commit d55f25e into Expensify:main Jun 7, 2023
@nhminhduc

Copy link
Copy Markdown
Contributor Author

I think on android the icon is showing, just the color is quite off. Not sure why.

@nhminhduc do you mind updating the QA steps to use the Copy icon from somewhere else then? I think this will be reported as a problem if we don't explain in the QA section : )

I will update it tomorrow.

@OSBotify

OSBotify commented Jun 7, 2023

Copy link
Copy Markdown
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.

@nhminhduc

Copy link
Copy Markdown
Contributor Author

Screenshot 2023-06-08 at 13 23 34

Screenshot 2023-06-08 at 13 24 02

@PauloGasparSv @mollfpr Hi, the icon in Android is indeed missing and it is a bug. But I do not think it is from this PR.
You can see above image, when I add PressableWithDelayToggle component with icon, it shows correctly in web, but not in android. This CopyTextToClipboard component are using the PressableWithDelayToggle, therefore it inherits this issue.
Should I create a bug ticket?

@PauloGasparSv

Copy link
Copy Markdown
Contributor

Should I create a bug ticket?

I think that would be awesome @nhminhduc! So that's why, thks so much for explaining it too!

@OSBotify

OSBotify commented Jun 8, 2023

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/PauloGasparSv in version: 1.3.26-0 🚀

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

@isagoico

isagoico commented Jun 9, 2023

Copy link
Copy Markdown

This PR QA is blocked on Android because of this issue #17368. Rest of the platforms is a pass.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.3.26-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.

5 participants