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

[HOLD for payment 2024-10-22] [$250] Workflow - Tapping add approval workflow or tapping back shows diff. behavior in mweb&android #50094

Closed
2 of 6 tasks
lanitochka17 opened this issue Oct 2, 2024 · 40 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Monthly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 2, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.43-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Launch both mweb and Android
  2. Tap profile icon -- workspaces -- new workspace
  3. Tap more features -- enable workflow
  4. Tap workflow -- enable add approvals
  5. Tap add approval workflow
  6. Tap app back button

Expected Result:

While tapping add approval workflow or on tapping app back button "No members to display " page must not be shown

Actual Result:

In Android, tapping add approval workflow " No members to display " shown briefly but in mweb while tapping back button No members to display " page is shown

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6622365_1727889041861.Screenrecorder-2024-10-02-22-26-36-193_compress_1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021841560364430821283
  • Upwork Job ID: 1841560364430821283
  • Last Price Increase: 2024-10-02
  • Automatic offers:
    • Nodebrute | Contributor | 104312293
Issue OwnerCurrent Issue Owner: @s77rt
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 2, 2024
Copy link

melvin-bot bot commented Oct 2, 2024

Triggered auto assignment to @garrettmknight (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

@garrettmknight FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@cretadn22
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

What is the root cause of that problem?

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);

We clear the approval workflow data before closing the modal.

What changes do you think we should make in order to solve the problem?

We should first call Navigation.goBack(); and only clear the data once the transition is complete.

        Navigation.goBack();  // We also can use dismissModal and Modal.close 
        if (isInitialCreationFlow) {
                InteractionManager.runAfterInteractions(() => {
                    Workflow.clearApprovalWorkflow();
                });
        }

@garrettmknight garrettmknight added the External Added to denote the issue can be worked on by a contributor label Oct 2, 2024
Copy link

melvin-bot bot commented Oct 2, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021841560364430821283

@melvin-bot melvin-bot bot changed the title Workflow - Tapping add approval workflow or tapping back shows diff. behavior in mweb&android [$250] Workflow - Tapping add approval workflow or tapping back shows diff. behavior in mweb&android Oct 2, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 2, 2024
Copy link

melvin-bot bot commented Oct 2, 2024

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

@nkdengineer
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Android, tapping add approval workflow " No members to display " shown briefly but in mweb while tapping back button No members to display " page is shown

What is the root cause of that problem?

  1. For mweb, the approval flow is cleared before we complete navigating back to the previous screen then the empty screen appears briefly

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);
const button = useMemo(() => {

  1. For Android, we merge the approval workflow data to Onyx here and then navigate to the approval screen but the data is merged after we navigate to the approval screen. So the empty screen appears briefly based on this condition here

Workflow.setApprovalWorkflow({
...INITIAL_APPROVAL_WORKFLOW,
availableMembers,
usedApproverEmails,
});
Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID));
}, [policy, route.params.policyID, availableMembers, usedApproverEmails]);

What changes do you think we should make in order to solve the problem?

  1. For mweb bug, we should navigate back first and wrap the logic to clear approval workflow in InteractionManager.runAfterInteractions or use Modal.close
const goBack = useCallback(() => {
    Navigation.goBack();
    InteractionManager.runAfterInteractions(() => {
        if (!isInitialCreationFlow) {
            return;
        }
        Workflow.clearApprovalWorkflow();
    });
}, [isInitialCreationFlow]);

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);
const button = useMemo(() => {

  1. For Android bug, we should navigate to the approval screen after the data is merged to Onyx completely.

Workflow.setApprovalWorkflow({
...INITIAL_APPROVAL_WORKFLOW,
availableMembers,
usedApproverEmails,
});
Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID));
}, [policy, route.params.policyID, availableMembers, usedApproverEmails]);

To do that we can use set method here which is faster because I see that we always pass full approval workflow data to this function.

Onyx.merge(ONYXKEYS.APPROVAL_WORKFLOW, approvalWorkflow);

Or we can return the Onyx.merge promise in this function then move the navigate logic to .then of the promise returned by setApprovalWorkflow function.

Workflow.setApprovalWorkflow({
...INITIAL_APPROVAL_WORKFLOW,
availableMembers,
usedApproverEmails,
});
Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID));
}, [policy, route.params.policyID, availableMembers, usedApproverEmails]);

What alternative solutions did you explore? (Optional)

@abzokhattab
Copy link
Contributor

abzokhattab commented Oct 2, 2024

Edited by proposal-police: This proposal was edited at 2024-10-02 20:22:02 UTC.

Proposal

Please restate the problem we are trying to solve in this issue.

Workflow - When tapping "Add Approval Workflow" or navigating back, the message "No members to display" is briefly shown.

What is the root cause of the problem?

When tapping the back button, the approval workflow object is set to null:

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);
const button = useMemo(() => {

function clearApprovalWorkflow() {
Onyx.set(ONYXKEYS.APPROVAL_WORKFLOW, null);
}
This causes the shouldShowListEmptyContent variable to resolve to undefined, not false:
const shouldShowListEmptyContent = approvalWorkflow && approvalWorkflow.availableMembers.length === 0;
Since we display the listEmptyContent if shouldShowListEmptyContent is true, the issue arises when shouldShowListEmptyContent is undefined. In such cases, the BaseSelectionList component uses a default value of true for shouldShowListEmptyContent:
shouldShowListEmptyContent = true,
When an undefined value is passed, the component interprets it as not provided, and defaults to true.

What changes should we make to solve the problem?

We should ensure that the value passed is always a boolean, not undefined.To do this, we can update the code here:

const shouldShowListEmptyContent = approvalWorkflow && approvalWorkflow.availableMembers.length === 0;
as follows:

const shouldShowListEmptyContent = !!(approvalWorkflow && approvalWorkflow.availableMembers.length === 0);

This ensures the empty page is only displayed when appropriate. we can do the same change in other arias that uses the shouldShowListEmptyContent prop in the selectionlist

now, we will have an issue where the members list becomes empty before navigating back. To address this, and the problem where the sections list becomes empty after clearing the members list, we can introduce a ref or state, isNavigatingBack. This state will be set to true if the user is navigating back after clearing the workflow.We will also use a usePrevious ref for approvalWorkflow?.availableMembers, which will be utilized in the section memo when the app is navigating back.
By implementing this solution, we maintain the synchronous behavior of first clearing the data and then performing the back action.

Changes:

  1. Introduce the following:
    const [isNavigatingBack, setIsNavigatingBack] = useState(false);
const previousAvailableMembers = usePrevious(approvalWorkflow?.availableMembers);
  1. add setIsNavigatingBack(true) in the goBack function before clearing the flow
  2. Modify this condition as follows:
if (!approvalWorkflow?.members || isNavigatingBack) {
  1. Use previousAvailableMembers when navigating back instead of this :
        if (approvalWorkflow?.availableMembers ?? isNavigatingBack) {
            const workflowAvailableMembers = (isNavigatingBack ? previousAvailableMembers : approvalWorkflow?.availableMembers) ?? [];
            const availableMembers = workflowAvailableMembers
  1. Add || isNavigatingBack in this line .

What alternative solutions did you explore? (Optional)

@Nodebrute
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Tapping add approval workflow or tapping back shows diff. behavior in mweb&android

What is the root cause of that problem?

First, we only clear the workflow when the user presses Go Back. The workflow will not be cleared if the user clicks on the central pane to navigate the workflow page. The second issue is that we encounter the member's empty state because of this.

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);

What changes do you think we should make to solve the problem?

We should remove this implementation from here. In this component WorkspaceWorkflowsApprovalsExpensesFromPage, we will only go back

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);

  onBackButtonPress={()=>Navigation.goBack()}

And then in WorkspaceWorkflowsPage We will clearApprovalWorkflow before starting a new one here

https://github.com/Expensify/App/blob/main/src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx#L102

      Workflow.clearApprovalWorkflow();
        Workflow.setApprovalWorkflow({
            ...INITIAL_APPROVAL_WORKFLOW,
            availableMembers,
            usedApproverEmails,
        });

We can implement the same solution in other places too where we have this issue

What alternative solutions did you explore? (Optional)

In the alternative solution, we should also remove the clearApprovalWorkflow from WorkspaceWorkflowsApprovalsExpensesFromPage and use only goBack()

and in here we can use set by doing this we'll make sure that every time we are setting value instead of merging

function setApprovalWorkflow(approvalWorkflow: NullishDeep<ApprovalWorkflowOnyx>) {
Onyx.merge(ONYXKEYS.APPROVAL_WORKFLOW, approvalWorkflow);
}

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

An empty state view is shown when opening/closing the approval workflow page.

What is the root cause of that problem?

When we open the page, we will set the approval data first and then navigate to the page.

Workflow.setApprovalWorkflow({
...INITIAL_APPROVAL_WORKFLOW,
availableMembers,
usedApproverEmails,
});
Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID));

However, the onyx data is not immediately available which is noticeable in slower devices like Android.

And when we close the page, we clear the approval data.

const goBack = useCallback(() => {
if (isInitialCreationFlow) {
Workflow.clearApprovalWorkflow();
}
Navigation.goBack();
}, [isInitialCreationFlow]);

What changes do you think we should make in order to solve the problem?

For the first problem, we can use Navigation.setNavigationActionToMicrotaskQueue to delay the navigation.

export default function setNavigationActionToMicrotaskQueue(navigationAction: () => void) {
/**
* The function is used when the app needs to set a navigation action to the microtask queue, it guarantees to execute Onyx.update first, then the navigation action.
* More details - https://github.com/Expensify/App/issues/37785#issuecomment-1989056726.
*/

Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(route.params.policyID)));

For the second problem, we can delay the clearing of data using InteractionManager, just like we did here.

Navigation.dismissModal();
InteractionManager.runAfterInteractions(() => {
// Remove the approval workflow using the initial data as it could be already edited
Workflow.removeApprovalWorkflow(route.params.policyID, initialApprovalWorkflow);
});

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@cretadn22, @nkdengineer, @Nodebrute and @bernhardoj Thank you for the proposals. The RCA makes sense in general but the not found view should only be shown if the approvalWorkflow data is available and we have no members.

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@abzokhattab Thanks for the proposal. The RCA makes sense. I find your solution the easiest to implement even though it will cause blank space to appear on animation instead of the not found view but I don't think thats something that we should optimize for. Overall looks good to me.

🎀 👀 🎀 C+ reviewed (see #50094 (comment))
Link to proposal

Copy link

melvin-bot bot commented Oct 3, 2024

Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@abzokhattab Actually I found that the solution is not enough. We get a weird view after selecting some users and going back

Screen.Recording.2024-10-03.at.7.12.54.PM.mov

@nkdengineer
Copy link
Contributor

@s77rt The selected proposal is not enough because we still need to fix the approval workflow will be cleared briefly before we go back to the workflow page.

@abzokhattab
Copy link
Contributor

Thanks @s77rt for the review, i extended my proposal to cover the other problem where the members list becomes empty when going back

to solve it i used a help state isNavigatingBack that would allow to freeze the members list while clearing the flow.

the important this in my proposal is that it keeps the synchronous nature of clearing the data first then going back, not the other way around.

POC

Screen.Recording.2024-10-03.at.9.15.32.PM.mov

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

Since we need another "complementary" solution, I'm giving this another review:

  • @cretadn22 Proposal is not complete (only handles the mWeb cause)
  • @nkdengineer Let's avoid delays i.e. InteractionManager.runAfterInteractions
  • @Nodebrute Looks good to me
  • @bernhardoj both setNavigationActionToMicrotaskQueue and InteractionManager.runAfterInteractions add delays and should be avoided

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@abzokhattab The new changes making this more complex and it feels like band-aid solution

@abzokhattab
Copy link
Contributor

I see, thanks for the review!

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@Nodebrute's proposal looks good to me

cc @stitesExpensify

@nkdengineer
Copy link
Contributor

To do that we can use set method here which is faster because I see that we always pass full approval workflow data to this function.

@s77rt For the selected proposal, with the main or alternative we also need to use set method in setApprovalWorkflow function which is the key to fixing the Android native bug and I'm the first one who suggested this. For the mweb bug, I think moving clearApprovalWorkflow or delaying the call of this function is fine because we don't call any API.

@s77rt
Copy link
Contributor

s77rt commented Oct 3, 2024

@nkdengineer I believe the key in @Nodebrute's proposal is to not call Workflow.clearApprovalWorkflow on going back. Using Onyx.set is not mandatory.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production labels Oct 15, 2024
@melvin-bot melvin-bot bot changed the title [$250] Workflow - Tapping add approval workflow or tapping back shows diff. behavior in mweb&android [HOLD for payment 2024-10-22] [$250] Workflow - Tapping add approval workflow or tapping back shows diff. behavior in mweb&android Oct 15, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Oct 15, 2024
Copy link

melvin-bot bot commented Oct 15, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Oct 15, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.48-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-10-22. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Oct 15, 2024

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

@s77rt
Copy link
Contributor

s77rt commented Oct 16, 2024

@dylanexpensify dylanexpensify moved this to Hold for Payment in [#whatsnext] #expense Oct 18, 2024
@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Oct 21, 2024
@garrettmknight
Copy link
Contributor

Payment summary:

@melvin-bot melvin-bot bot removed the Overdue label Oct 23, 2024
@garrettmknight
Copy link
Contributor

Paid out in Upwork. @s77rt request when you're ready.

@github-project-automation github-project-automation bot moved this from Hold for Payment to Done in [#whatsnext] #expense Oct 23, 2024
@tgolen
Copy link
Contributor

tgolen commented Oct 23, 2024

Reopening for @s77rt and @garrettmknight to complete the regression checklist.

@tgolen tgolen reopened this Oct 23, 2024
@s77rt
Copy link
Contributor

s77rt commented Oct 23, 2024

@tgolen Completed here #50094 (comment)

@JmillsExpensify
Copy link

$250 approved for @s77rt

@tgolen
Copy link
Contributor

tgolen commented Oct 24, 2024

Thanks @s77rt, and apologies that I missed it. @garrettmknight can you please be sure to copy those answers into the actual checklist and then complete it out?

@s77rt Can you give a little more context behind the regression? Would you say it was caused by one of these?

  • Initial design was incorrect or incomplete
  • Bug introduced during implementation
  • Bug caused by some unrelated change
  • Other (please specify)

@garrettmknight garrettmknight added Weekly KSv2 and removed Daily KSv2 labels Oct 24, 2024
@s77rt
Copy link
Contributor

s77rt commented Oct 24, 2024

I would say it's a bug that is introduced during implementation but it could also be that the design was incorrect if it was specific about the area where the bug occurred (I don't have access to the doc to confirm).

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Nov 18, 2024
Copy link

melvin-bot bot commented Nov 18, 2024

This issue has not been updated in over 15 days. @garrettmknight, @s77rt, @stitesExpensify, @Nodebrute eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Monthly KSv2
Projects
Archived in project
Development

No branches or pull requests