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

fix: deleted workspace with invoices is accessible by url #49509

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

Conversation

gijoe0295
Copy link
Contributor

@gijoe0295 gijoe0295 commented Sep 20, 2024

Details

Fixed Issues

$ #49093
PROPOSAL: #49093 (comment)

Tests

Precondition: User B has no workspace

  1. [User A] Send an invoice to User B
  2. [User B] Pay the invoice using Pay as a business option
  3. [User B] Delete the workspace
  4. [User B] Go to invoice chat
  5. [User B] Click on the "workspace" link in Expensify message
  6. [User B] Verify not found page shows
  • Verify that no errors appear in the JS console

Offline tests

NA

QA Steps

Precondition: User B has no workspace

  1. [User A] Send an invoice to User B
  2. [User B] Pay the invoice using Pay as a business option
  3. [User B] Delete the workspace
  4. [User B] Go to invoice chat
  5. [User B] Click on the "workspace" link in Expensify message
  6. [User B] Verify not found page shows
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-09-20.at.10.12.21.mov
Android: mWeb Chrome
Screen.Recording.2024-09-20.at.10.09.41.mov
iOS: Native
Screen.Recording.2024-09-20.at.10.02.41.mov
iOS: mWeb Safari
Screen.Recording.2024-09-20.at.10.05.46.mov
MacOS: Chrome / Safari
Screen.Recording.2024-09-20.at.09.51.20.mov
MacOS: Desktop
Screen.Recording.2024-09-20.at.10.06.52.mov

@gijoe0295 gijoe0295 marked this pull request as ready for review September 20, 2024 03:11
@gijoe0295 gijoe0295 requested a review from a team as a code owner September 20, 2024 03:11
Copy link

melvin-bot bot commented Sep 20, 2024

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

@melvin-bot melvin-bot bot removed the request for review from a team September 20, 2024 03:11
@ishpaul777
Copy link
Contributor

We have conflicts @gijoe0295

@ishpaul777
Copy link
Contributor

ishpaul777 commented Sep 23, 2024

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

@ishpaul777
Copy link
Contributor

ishpaul777 commented Sep 23, 2024

@gijoe0295 Jest test failing, can you please take a look

@gijoe0295
Copy link
Contributor Author

Seems not related to this PR. Will try to merge main soon to see if it's fixed.

@@ -296,11 +297,11 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
const prevProtectedMenuItems = usePrevious(protectedCollectPolicyMenuItems);
const enabledItem = protectedCollectPolicyMenuItems.find((curItem) => !prevProtectedMenuItems.some((prevItem) => curItem.routeName === prevItem.routeName));

const shouldShowPolicy = useMemo(() => PolicyUtils.shouldShowPolicy(policy, isOffline, currentUserLogin), [policy, isOffline, currentUserLogin]);
const prevShouldShowPolicy = usePrevious(shouldShowPolicy);
Copy link
Contributor

@ishpaul777 ishpaul777 Sep 23, 2024

Choose a reason for hiding this comment

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

why did you do it like this it seems to be not working sometimes and sometime i still see workspacepages we want something like mentioned in this proposal #49093 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking.

Copy link
Contributor

Choose a reason for hiding this comment

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

see in this vid. workspace is deleted but it still navigates to the page

Screen.Recording.2024-09-27.at.12.20.38.AM-1.mov

Copy link
Contributor Author

@gijoe0295 gijoe0295 Sep 27, 2024

Choose a reason for hiding this comment

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

One problem on main: If we navigated to an invalid link with 3-pane layout, we would have duplicated not found pages in LHP and central pane. And I haven't seen it get reported:

Screenshot 2024-09-28 at 01 26 20

cc @kosmydel Can you take a look since you worked on #41665?

Copy link
Contributor

Choose a reason for hiding this comment

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

but for me your solution works only sometimes, mainly on small screens it often does not work @gijoe0295

Copy link
Contributor Author

@gijoe0295 gijoe0295 Sep 27, 2024

Choose a reason for hiding this comment

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

@ishpaul777 Besides the above issue, I pushed the approach mentioned in your linked proposal.

Screen.Recording.2024-09-28.at.01.43.58.mov

Copy link
Contributor

Choose a reason for hiding this comment

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

okay thanks! i'll test again in my morning, off for the day today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @gijoe0295, thanks for reaching out. Unfortunately, I no longer work for Expensify. If you need help with this issue, you can try asking C+, who was responsible for this issue, or someone else who participated in the discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops thank you. Sorry for the inconvenience.

@ishpaul777
Copy link
Contributor

I am having trouble sending invoice to any user, it was working last i tested @gijoe0295 can you please check on your side,

Screen.Recording.2024-09-25.at.11.51.39.PM.mov

@gijoe0295
Copy link
Contributor Author

I am having trouble sending invoice to any user, it was working last i tested @gijoe0295 can you please check on your side,

Worked normally for me after merging latest main.

@ishpaul777
Copy link
Contributor

ishpaul777 commented Sep 30, 2024

Bug: [IOS] Infinite loading when navigating to deleted workspace page

Screen.Recording.2024-10-01.at.1.56.52.AM.mov

@gijoe0295

@ishpaul777
Copy link
Contributor

gentle bump. @gijoe0295 ^

@ishpaul777
Copy link
Contributor

@gijoe0295 Its already 3 days without any response, Are you still interested finishing this PR?

@gijoe0295
Copy link
Contributor Author

Sorry. Still taking a look. Will provide updates in several hours.

@gijoe0295
Copy link
Contributor Author

@ishpaul777 Can you please retry or provide reproduction steps? I retried many times but still couldn't reproduce the infinite loading.

@ishpaul777
Copy link
Contributor

i'll give this a test again on monday this was consistently reproducable for me last i checked. Steps are same as in PR description,only this different, i was not able to navigate using the link in message (it pointing to staging) so i copied dev. link)

@ishpaul777
Copy link
Contributor

ishpaul777 commented Oct 7, 2024

Bug: [IOS] Infinite loading when navigating to deleted workspace page

Screen.Recording.2024-10-01.at.1.56.52.AM.mov
@gijoe0295

still reproducable, steps same as in PR test steps

Untitled.mov

@ishpaul777
Copy link
Contributor

@gijoe0295 ^

@joekaufmanexpensify
Copy link
Contributor

@gijoe0295 Could you please provide an update on this asap? We need to get this done very soon. Ideally, we'd like to fix the additional bug that @ishpaul777 found in this same PR. If we're not able to get a resolution here soon, we'll need to reopen this issue for additional proposals from other contributors.

@gijoe0295
Copy link
Contributor Author

Finally manage to reproduce the issue. Specific steps are:

  1. [User A] Send an invoice to User B whose has no workspace
  2. [User B] Pay the invoice using Pay as a business option
  3. Go to invoice chat
  4. Click on the "workspace" link in Expensify message
  5. Delete the workspace
  6. Back to invoice chat
  7. Click on the "workspace" link in Expensify message
  8. Observe full screen loading

Before this policy metadata is returned by OpenReport, it's null at the time it gets deleted:

Screenshot 2024-09-13 at 01 28 52

And when we navigate back to the invoice chat in step 6, OpenReport is not called. However the root problem is the isLoadingPolicy in WithPolicy is always true in this case:

const [policy, policyResults] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [policyDraft, policyDraftResults] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);
const isLoadingPolicy = isLoadingOnyxValue(policyResults, policyDraftResults);

That's the root cause, I'll investigate more and provide solution in several hours.

@gijoe0295
Copy link
Contributor Author

gijoe0295 commented Oct 11, 2024

Root cause

Same root cause: #48725 (comment).

TL;DR After Onyx.clear (DeleteWorkspace returns Onyx.set(policyID, null)), useOnyx data gets stuck in loading state causing infinite loading. It's Onyx-internal and being resolved in Expensify/react-native-onyx#588.

This issue happens on main as well with same reproducible steps and only on small screens.

Why "only on small screens"?

For small screens, when we go back to invoice chat, OpenReport is not triggered and the policy is still undefined (after being deleted) => isLoadingPolicy in withPolicy gets stuck in loading state => the above Onyx issue.

For large screens, since we manually press the LHN item to open the invoice chat, OpenReport is enforced to be called.

When I tested this PR and added recordings on small screens, I did it the second way (manually open invoice chat from LHN) so I did not spot this bug initially.

Next Steps

  1. Given this issue also happens on main; is Onyx-internal and being worked on in Fix problems related to Onyx.clear and useOnyx react-native-onyx#588. we can put this PR on hold
  2. A workaround is to force calling OpenReport when we go back to invoice chat from workspace list so the policy gets the correct data
  3. Update the BE DeleteWorkspace not to delete the policy completely and keep these metadata because they are used for invoice chats:
Screenshot 2024-09-13 at 01 28 52

@ishpaul777 Which one do you recommend, 1, 2 or 3?

@ishpaul777
Copy link
Contributor

Thanks for your investigation @gijoe0295 I'll validate your RCA and give my thoughts today.

@srikarparsi
Copy link
Contributor

srikarparsi commented Oct 15, 2024

Cool, lets go with 1. Putting this PR on hold for Expensify/react-native-onyx#588 (Internal discussion)

@srikarparsi srikarparsi changed the title fix: deleted workspace with invoices is accessible by url [HOLD https://github.com/Expensify/react-native-onyx/pull/588] fix: deleted workspace with invoices is accessible by url Oct 15, 2024
@ishpaul777
Copy link
Contributor

On HOLD

@ishpaul777
Copy link
Contributor

@gijoe0295 holding PR Expensify/react-native-onyx#588 is merged but we haven't bumped Onyx version in App yet, will you check if the bug is resolved using patch or bumping version locally. Thank you!

@gijoe0295
Copy link
Contributor Author

gijoe0295 commented Nov 7, 2024

@ishpaul777 I manually bumped Onyx version and retested but the infinite loading status was not resolved. I did some investigation and want to consult @fabioh8010.

Hi @fabioh8010, during the implementation of this PR, we spotted a similar issue to Expensify/react-native-onyx#588 and it already happens on main, is not related to but blocks testing this PR:

Racing conditions between an Onyx.clear() execution and useOnyx subscription causes useOnyx to be always in loading state and never fully resolve its first connection.

I manually bumped Onyx version to 2.0.78 but it did not resolve the issue.

Later on, I tried the solution mentioned in Problem 2 to disable reuseConnection in useOnyx and that eventually fixed it.

const [policy, policyResults] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);

My questions are:

  1. Is our issue and Fix problems related to Onyx.clear and useOnyx react-native-onyx#588 the same? (Has the same root cause and SHOULD have been fixed by that PR)
  2. If so, is the reuseConnection: false approach mentioned above appropriate? Is there any side effects of not reuseConnection? Or do you have any idea why Fix problems related to Onyx.clear and useOnyx react-native-onyx#588 did not fix it?

It would be nice if you can help us unblock this PR. Thank you!

@fabioh8010
Copy link
Contributor

Thanks for the report @gijoe0295, I will check this today

@ishpaul777
Copy link
Contributor

Hey guys, I am on limited availability until Friday. will not check GH often if need me for review or anything, ping me on slack

@fabioh8010
Copy link
Contributor

@gijoe0295 @ishpaul777 Sorry for the late here. After some try and error I was able to reproduce this issue, but I don't think my Onyx PR would solve it. My PR solved a infinite loading state issue that happened during logout process, where Onyx.clear() method is really called. You mentioned Onyx.clear in your RCA but Onyx.set(policyID, null) is not the same thing to the clear operation.

I agree we should investigate the issue in Onyx but if we need this PR to get merged faster, maybe it's better to disable the connection reuse (reuseConnection to false) as you mentioned and add a comment linking to the GH issue where we will conduct the investigations separately.

WDYT?

@gijoe0295
Copy link
Contributor Author

gijoe0295 commented Nov 15, 2024

@fabioh8010 Thanks a lot. I'm fine with your suggestion as long as reuseConnection: false had no side effects. Of course I'll test it carefully. Can you please create an issue for the Onyx bug?

cc @ishpaul777

@gijoe0295 gijoe0295 changed the title [HOLD https://github.com/Expensify/react-native-onyx/pull/588] fix: deleted workspace with invoices is accessible by url fix: deleted workspace with invoices is accessible by url Nov 15, 2024
@fabioh8010
Copy link
Contributor

Issue created -> #52640

cc @gijoe0295 @ishpaul777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants