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

Share Code URL implementation based on Environment URL #20843

Closed
wants to merge 0 commits into from

Conversation

rojiphil
Copy link
Contributor

@rojiphil rojiphil commented Jun 15, 2023

@mananjadhav @alex-mechler @kevinksullivan @AndrewGable

Details

The following changes can be done to incorporate the functionality in a common place:
a) Leverage the existing WithEnvironment component and add support for environmentURL. This variable will contain the environment-specific URL from Environment.
b) Use the environmentURL from WithEnvironment to decide on the URL for use with Share code functionality. Also, ensure that a trailing slash is present in the environment url.

Fixed Issues

$ #19464
PROPOSAL: #19464 (comment)

Tests

  1. Android Native

Prerequisite:
Find out the latest production version at https://api.github.com/repos/expensify/app/releases/latest.
Tag_name will represent the latest deployed production version
"tag_name": "1.3.27-7",
Here, the latest deployed production version is 1.3.27-7

i) Staging:
Build an android app that uses a production environment configuration file with package version of 1.3.27-8
"version": "1.3.27-8", (i.e. in package.json)
Follow the steps as below:
a) Verify version in Settings->About
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://staging.new.expensify.com/

ii) Production:
Build an android app that uses production environment configuration file with package version of 1.3.27-7
"version": "1.3.27-7", (i.e. in package.json)
Follow the steps below:
a) Verify version in Settings->About
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

iii) Development:
Follow the steps as below:
a) Verify 'dev' label next to Expensify in header.
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://localhost:8080/

  1. mWeb-Android-Chrome/web:

i) Development Version:
a) Launch the expensify app at http://localhost:8080/
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://localhost:8080/

  1. MacOS-Desktop:

i) Production Version:
a) Launch the electron production App
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

ii) Staging Version:
a) Launch the electron staging App
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://staging.new.expensify.com/

  1. iOS-Native-Simulator:

i) Production Environment:
a) Launch the production iOS Native app
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

  1. Safari-Dev
    i) MacOS/iOS-Safari
    a) Launch the dev version on Safari in MacOS
    b) Copy URL to keyboard in Settings->Share code
    c) Paste it in the compose box of one of the existing chat
    d) Verify that the URL starts with https://localhost:8080/
  • Verify that no errors appear in the JS console

Offline tests

i) Android-Native Production Version:
a) Ensure mobile is offline (Disconnect from WiFi and Mobile Data)
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

QA Steps

Following additional test steps are required:

  1. Web
    i) Staging Deployment:
    a) Launch the expensify app at https://staging.new.expensify.com/
    b) Copy URL to keyboard in Settings->Share code
    c) Paste it in the compose box of one of the existing chat
    d) Verify that the URL starts with https://staging.new.expensify.com/

ii) Production Deployment:
a) Launch the expensify app at https://new.expensify.com/
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

  1. iOS Native App:

i) Staging:
a) Setup TestFlight for iOS and launch app
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://staging.new.expensify.com/

ii) Production:
a) Install production version from iOS App Store and launch app.
b) Copy URL to keyboard in Settings->Share code
c) Paste it in the compose box of one of the existing chat
d) Verify that the URL starts with https://new.expensify.com/

  • 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

Android-Native-Staging (1->i)
new-android-native-staging.mp4
Android-Native-Production (1->ii)
new-android-native-prod.mp4
Android-Native-Development (1->iii)
new-android-native-dev.mp4
mWeb-Chrome-Development Version (2->i)
new-mweb-chrome-dev.mp4
MacOS / Desktop Production
new_dtop_prod.mp4
MacOS / Desktop Staging
new_dtop_stag.mp4
iOS / Native - Simulator - Production
new_iosnative_prod.mp4
MacOS / Safari -Dev
new_macossafari_dev.mp4
Offline - Android Native Prod
new_offline_android_prod.mp4

@rojiphil rojiphil requested a review from a team as a code owner June 15, 2023 17:37
@melvin-bot melvin-bot bot requested review from alex-mechler and mananjadhav and removed request for a team June 15, 2023 17:37
@melvin-bot
Copy link

melvin-bot bot commented Jun 15, 2023

@alex-mechler @mananjadhav 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
Copy link
Contributor

github-actions bot commented Jun 15, 2023

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

@rojiphil
Copy link
Contributor Author

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

Comment on lines 47 to 52
getEnvironment().then((environment) =>
{
// Our approach is to use staging url only for staging environment and use production url for all other environments.
const environmentURL = (environment === CONST.ENVIRONMENT.STAGING) ? Url.addTrailingForwardSlash(CONST.STAGING_NEW_EXPENSIFY_URL) : CONST.NEW_EXPENSIFY_URL;
resolve(environmentURL);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you verified every other instance of this function needs this change and you didn't break anything else? Seems like possibly this is the wrong spot to be doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the details section, 'Copy Link' is the only other place where we use getEnvironmentURL(). There, we need this change as the use case is similar to the share code one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copying a link on this branch seems broken, I see a double slash: https://new.expensify.com//r/65129373/1852577140352880000

I don't on main:
http://localhost:8080/r/65129373/1852577140352880000

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Didn't notice the extra slash. Thanks for pointing it out. Will remove the extra slash here

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above, why not include a slash in the code that uses this function? Ideally we can keep that code the same and make the least amount of code changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I am not mistaken, wouldn't it be easier to not modify this file at all? and use Url.addTrailingForwardSlash in the file where we are actually using the URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, our existing approach is to ensure that the configured URLs have a trailing slash using the helper function Url.addTrailingForwardSlash. If the configured URL already has a trailing slash, it will ignore. Else, it will add the trailing slash. If we want to follow the approach of ensuring that there is no trailing slash in the configured URLs, we will have to implement additional code to remove the trailing slash from configured URLs. Also, the URLs in the environment configuration files have a trailing slash. So, I strongly think that we should not attempt a change of approach here towards handling of trailing slash in URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please also have a look at ACTIVE_EXPENSIFY_URL. So, it would be better to keep the existing approach itself as it would be easier and will have less code changes and associated risks.

Copy link
Contributor Author

@rojiphil rojiphil Jun 16, 2023

Choose a reason for hiding this comment

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

@AndrewGable @mananjadhav Please let me know your comments on my comments above too so that we can decide and take it further

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rojiphil I've commented again. The reason I think we went ahead with environment was it takes care of DEV env too.

@rojiphil
Copy link
Contributor Author

A small request. Can one of you please add the following accounts to high-traffic accounts for testing purposes:
[email protected]
[email protected]

@rojiphil
Copy link
Contributor Author

rojiphil commented Jun 16, 2023

@alex-mechler @mananjadhav @AndrewGable Updated PR with more test case result videos + lint checks compliance.
Regarding double slash matter in copy link, currently, I have removed the extra slash. Based on further review, we can take next steps.
Also, I haven't tested with a high-traffic account yet. I got feedback from slack that someone from the PR review team can add the accounts as high traffic ones. Can someone please add my accounts as mentioned here?

getEnvironment().then((environment) =>
{
// Our approach is to use staging url only for staging environment and use production url for all other environments.
const environmentURL = (environment === CONST.ENVIRONMENT.STAGING) ? Url.addTrailingForwardSlash(CONST.STAGING_NEW_EXPENSIFY_URL) : CONST.NEW_EXPENSIFY_URL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again I am confused was't the staging URL being returned when the environment was STAGING? I mean the ENVIRONMENT_URLS ? I don't see a point of adding this change? @rojiphil

@AndrewGable wdyt?

@@ -206,7 +206,7 @@ export default [
onPress: (closePopover, {reportAction, reportID}) => {
Environment.getEnvironmentURL().then((environmentURL) => {
const reportActionID = parseInt(lodashGet(reportAction, 'reportActionID'), 10);
Clipboard.setString(`${environmentURL}/r/${reportID}/${reportActionID}`);
Clipboard.setString(`${environmentURL}r/${reportID}/${reportActionID}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this change is needed if we rollback the commit for environment URL?

@mananjadhav
Copy link
Collaborator

@rojiphil I've raised the same comment again. I think we're over complicating the PR. The change of adding the new prop is fine, and I think we shouldn't be touching the Environment URL logic. This way you won't need to change Clipboard file too.

@AndrewGable wdyt?

@rojiphil
Copy link
Contributor Author

I've raised the same comment again. I think we're over complicating the PR. The change of adding the new prop is fine, and I think we shouldn't be touching the Environment URL logic. This way you won't need to change Clipboard file too.

@mananjadhav Reason why I think we should add trailing slash to staging url is this:
CONST.STAGING_NEW_EXPENSIFY_URL does not contain trailing slash
CONST.NEW_EXPENSIFY_URL contains trailing slash due to ACTIVE_EXPENSIFY_URL
To ensure that both URLs have similar ending, we are adding trailing slash to STAGING_NEW_EXPENSIFY_URL.
In the earlier code itself, there was a bug as staging url did not have trailing slash whereas production url had trailing slash. Please look here
Does my explanation help? If I am missing something here, please let me know.

@mananjadhav
Copy link
Collaborator

I got what you meant, but instead of updating the code to add slash, isn't it better to actually make the URLs consistent? One way to do that would be to update the CONST. Also if you see the NEW_EXPENSIFY_URL is nothing but ACTIVE_EXPENSIFY_URL, which has the Url logic added.

@mananjadhav
Copy link
Collaborator

But I am going to confirm with @AndrewGable and @alex-mechler if we are okay to use ACTIVE_EXPENSIFY_URL ignoring the DEV URL.

@rojiphil
Copy link
Contributor Author

I got what you meant, but instead of updating the code to add slash, isn't it better to actually make the URLs consistent? One way to do that would be to update the CONST. Also if you see the NEW_EXPENSIFY_URL is nothing but ACTIVE_EXPENSIFY_URL, which has the Url logic added.

@mananjadhav Ok. Another thing to note while making the decision is that these URLs can come from the environment configuration files (i.e. .env.staging, .env.production). And so, I don't think it is just enough to make URLs consistent from within the code. We need to ensure that we adjust to a configured URL that may come with or without slash. I think, the person who implemented this would have recognized this fact and decided to always make sure that there is always a trailing slash. The helper function addTrailingForwardSlash does just that. It will ignore if there is a trailing slash. Else, add one.

Copy link
Contributor Author

@rojiphil rojiphil left a comment

Choose a reason for hiding this comment

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

@mananjadhav @AndrewGable I have integrated your review comments with following changes:
a) Rolled back changes in Environment.js file.
b) Rolled back changes in ContextMenuActions.js
c) Added trailing slash code in ShareCodePage.
You were right. We need to keep it simple. Sorry for overdoing the code.
I have updated the review comments also accordingly. KIndly review

@mananjadhav
Copy link
Collaborator

Thanks for addressing the changes @rojiphil. I did a quick review of the code, looks fine. I'll take a look at this again in 2 hours or so along with the testing.

@rojiphil rojiphil changed the title environment url implementation Share Code URL implementation based on Environment URL Jun 20, 2023
@rojiphil rojiphil closed this Jun 20, 2023
@rojiphil rojiphil force-pushed the rojiphil-19464-env-url-fix branch 2 times, most recently from ce0d562 to e6c2704 Compare June 20, 2023 10:22
@rojiphil
Copy link
Contributor Author

rojiphil commented Jun 20, 2023

Oh!! Very sorry for this. I was merging the conflict. And, I force-pushed. Have created another PR here.

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.

3 participants