App icon indicating copy to clipboard operation
App copied to clipboard

[$500] Web - FAB - "New Workspace" option is disabled after deleting Workspace in offline mode

Open kbecciv opened this issue 2 years ago β€’ 22 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Open URL https://staging.new.expensify.com/
  2. Login with any account
  3. Go to Settings->Workspace
  4. Kill the internet connection
  5. Delete the workspace
  6. Turn on the internet connection
  7. Click on FAB button and check for a "New workspace" option

Expected Result:

"New Workspace" option should be available

Actual Result:

"New Workspace" option is disabled. "New Workspace" option becomes available only after re-login

Workaround:

Unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.2.14.0

Reproducible in staging?: Yes

Reproducible in production?: Yes

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

https://user-images.githubusercontent.com/93399543/195712579-88b42f99-83ea-4a33-ad42-7506c1d36476.mp4

Expensify/Expensify Issue URL:

Issue reported by: Applause - Internal Team

Slack conversation:

View all open jobs on GitHub

kbecciv avatar Oct 13 '22 21:10 kbecciv

Triggered auto assignment to @Julesssss (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

melvin-bot[bot] avatar Oct 13 '22 21:10 melvin-bot[bot]

Nice spot. Confirmed that we'll need to re-show the FAB New Workspace option.

Julesssss avatar Oct 14 '22 09:10 Julesssss

@Julesssss Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Oct 18 '22 06:10 melvin-bot[bot]

Triggered auto assignment to @alexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

melvin-bot[bot] avatar Oct 19 '22 09:10 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @Santhosh-Sellavel (External)

melvin-bot[bot] avatar Oct 19 '22 09:10 melvin-bot[bot]

Current assignee @Julesssss is eligible for the External assigner, not assigning anyone new.

melvin-bot[bot] avatar Oct 19 '22 09:10 melvin-bot[bot]

Awaiting contributors

Julesssss avatar Oct 19 '22 09:10 Julesssss

Disregard my last comment, I'll work on the job posting later this week.

alexpensify avatar Oct 19 '22 20:10 alexpensify

The job has been created in Upwork:

Internal: https://www.upwork.com/ab/applicants/1583564673241923584/job-details External: https://www.upwork.com/jobs/~017971a3070c51f85a

alexpensify avatar Oct 21 '22 21:10 alexpensify

Price Doubled to $500 https://www.upwork.com/jobs/~017971a3070c51f85a

mallenexpensify avatar Oct 26 '22 15:10 mallenexpensify

As per my understanding you guys using Redux in your project and after making API request of delete workspace you are calling Redux action to update the UI state and Redux store. The main problem is your tooltip UI popup which is appearing after clicking on "Plus" button is not updating successfully. I will debug the whole code and will read Popup component's code as well for getting information is you code successfully updating (re-rendering) or not.

ahsan-K avatar Oct 26 '22 17:10 ahsan-K

@ahsan-K Seems you are new here.

Get started by checking out our contributing guidelines first and don't forget to check out readme.

Santhosh-Sellavel avatar Oct 26 '22 17:10 Santhosh-Sellavel

@Santhosh-Sellavel I have read and posted the proposal on Upwork as well.

ahsan-K avatar Oct 26 '22 17:10 ahsan-K

I'm afraid you skipped the whole thing, take time to read through and understand our process.

Checkout how to Propose a solution for the job

Santhosh-Sellavel avatar Oct 26 '22 17:10 Santhosh-Sellavel

"Proposal" Hello Sir, I'm am senior software engineer with over 5+ years of experience on ReactJS. I have strong grip on javascript. I have read the description and saw the video of that issue which is on Github. I will be more then happy to solve your issue. I have understand that why "New Workspace" button is not showing after deleting the Work Space.

How i will solve this problem? As per my understanding you guys using Redux in your project and after making API request of delete workspace you are calling Redux action to update the UI state and Redux store. The main problem is your tooltip UI popup which is appearing after clicking on "Plus" button is not updating successfully. I will debug the whole code and will read Popup component's code as well for getting information is you code successfully updating (re-rendering) or not.

Let's jump on an initial call/meeting so that we can discuss more about it.

Best Regards, Ahsan Ali

ahsan-K avatar Oct 26 '22 18:10 ahsan-K

@kbecciv I am not able to reproduce the issue in staging and local environment.

https://user-images.githubusercontent.com/5945400/198107169-1a0dc728-a662-4f09-8043-cc8e10827286.mov

My hypothesis was that the App.reconnectApp shall first fetch the policy that is deleted in client from the server post reconnection and then the Pusher based deletion of policy happens which must be updating the UI again. As both actions are synchronous, we must be seeing such a behavior for a moment till Onyx is updated because of server load or network slow connection.

componentDidMount() {
       NetworkConnection.listenForReconnect();
       NetworkConnection.onReconnect(() => App.reconnectApp());
       PusherConnectionManager.init();
       ...
       ...
   }

However i can't reproduce this issue. It shall help immensely if you check once. All the time my UI in local and staging are updated with 'Create new workspace' the moment is network is back.

smrutiparida avatar Oct 26 '22 18:10 smrutiparida

Hi @ahsan-K. @Santhosh-Sellavel was directing you to the readme as we do not use Redux, and it explains our process for hiring external contributors.

Julesssss avatar Oct 27 '22 08:10 Julesssss

Proposal

This issue occurs because in the FAB menu we check if the user is admin of a policy with the type FREE in order to determine whether to add the New workspace button.

https://github.com/Expensify/App/blob/a341945917aa39adcc9ecad8e6a6d74d6a95f2c4/src/libs/actions/Policy.js#L177-L181

When this policy is deleted in an offline state it is only given the pendingAction CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE so the New workspace button is still added to the FAB menu as it never checks for any pending delete action, as it does in the InitialSettingsPage.

To resolve this we can create a new function in Policy.js :

This firstly checks that the user has any free policies, then checks if the user has any free policies without pending actions (in which case the FAB menu shouldn't be displayed). It then checks if any new free policies have been added while offline (in which case FAB should not be displayed) and finally checks whether the remaining policy has been deleted while offline (in which case the FAB menu should be displayed).

+   /**
+    * Check if the user has any active free policies (aka workspaces)
+    *
+    * @param {Array} policies
+    * @returns {Boolean}
+    */
+   function hasActiveFreePolicy(policies) {
+       const adminFreePolicies = _.filter(policies, policy => policy
+           && policy.type === CONST.POLICY.TYPE.FREE
+           && policy.role === CONST.POLICY.ROLE.ADMIN);
+   
+       if (adminFreePolicies.length === 0) {
+           return false;
+       }
+   
+       if (_.some(adminFreePolicies, policy => !policy.pendingAction)) {
+           return true;
+       }
+   
+       if (_.some(adminFreePolicies, policy => policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD)) {
+           return true;
+       }
+   
+       if (_.some(adminFreePolicies, policy => policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)) {
+           return false;
+       }
+   
+       return true;
+   }

This function can be used in BaseSideBarScreen when creating the FAB menu: https://github.com/Expensify/App/blob/a341945917aa39adcc9ecad8e6a6d74d6a95f2c4/src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js#L172-L175

-...(!Policy.isAdminOfFreePolicy(this.props.allPolicies) ? [ 
+...(!Policy.hasActiveFreePolicy(this.props.allPolicies) ? [

Ollyws avatar Oct 28 '22 09:10 Ollyws

@smrutiparida Issue is not reproduced any more with build 1.2.21.4

https://user-images.githubusercontent.com/93399543/198907265-b1366529-b1f9-4cec-86aa-7b3a8a3df856.mp4

kbecciv avatar Oct 30 '22 23:10 kbecciv

@alexpensify, @Julesssss, @mallenexpensify, @Santhosh-Sellavel Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Oct 31 '22 07:10 melvin-bot[bot]

Only when we go online, the option appears. But should we hide the option until we go online, I believe we should still look for solution @kbecciv ? @Julesssss What do you think?

There is a proposal above looks promising didn't get to test it though. Let me if we wish to proceed will test and update thanks!

Santhosh-Sellavel avatar Oct 31 '22 07:10 Santhosh-Sellavel

Yeah, @Ollyws's proposal sounds good to me. @Santhosh-Sellavel please take a quick review

Julesssss avatar Oct 31 '22 10:10 Julesssss

@Julesssss @Ollyws proposal looks good, test well!

C+ Reviewed πŸŽ€ πŸ‘€ πŸŽ€

Santhosh-Sellavel avatar Oct 31 '22 20:10 Santhosh-Sellavel

πŸ“£ @Ollyws You have been assigned to this job by @Julesssss! Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’» Keep in mind: Code of Conduct | Contributing πŸ“–

melvin-bot[bot] avatar Nov 01 '22 10:11 melvin-bot[bot]

Should have the PR ready within 24 hours.

Ollyws avatar Nov 01 '22 16:11 Ollyws

Thanks for the update!

alexpensify avatar Nov 01 '22 16:11 alexpensify

Cool, looks like we are moving to reviews!

alexpensify avatar Nov 04 '22 23:11 alexpensify

I've checked this GH and see Jule's comment that this one is still under review.

alexpensify avatar Nov 07 '22 23:11 alexpensify

BugZero Checklist: The PR fixing this issue has been merged! The following checklist will need to be completed before the issue can be closed:

  • [ ] A regression test has been added or updated so that the same bug will not reach production again. Link to the updated test here:
  • [ ] The PR that introduced the bug has been identified. Link to the PR:
  • [ ] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [ ] A discussion in #contributor-plus has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [ ] Payment has been made to the issue reporter (if applicable)
  • [ ] Payment has been made to the contributor that fixed the issue (if applicable)
  • [ ] Payment has been made to the contributor+ that helped on the issue (if applicable)

melvin-bot[bot] avatar Nov 08 '22 14:11 melvin-bot[bot]

BugZero Checklist: The PR fixing this issue has been merged! The following checklist will need to be completed before the issue can be closed:

  • [ ] A regression test has been added or updated so that the same bug will not reach production again. Link to the updated test here:
  • [ ] The PR that introduced the bug has been identified. Link to the PR:
  • [ ] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [ ] A discussion in #contributor-plus has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [ ] Payment has been made to the issue reporter (if applicable)
  • [ ] Payment has been made to the contributor that fixed the issue (if applicable)
  • [ ] Payment has been made to the contributor+ that helped on the issue (if applicable)

melvin-bot[bot] avatar Nov 08 '22 14:11 melvin-bot[bot]