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-05-08] [Simplified Collect][CLEAN UP][LOW] Standardize on Workspace wrapper #37898

Closed
luacmartins opened this issue Mar 7, 2024 · 31 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2

Comments

@luacmartins
Copy link
Contributor

luacmartins commented Mar 7, 2024

Problem

Coming from here, we have a few wrappers we use in Workspace pages, i.e. WorkspacePageWithSections, AdminPolicyAccessOrNotFoundWrapper and PaidPolicyAccessOrNotFoundWrapper. We should standardize on using a single one for all our pages.

Those wrappers also break the not-found views.

Going to e.g. https://staging.new.expensify.com/workspace/dssaddssdaads/categories` we see duplicated not found (that's what is the scope of the other issue) and after pressing the back button we see another ones...

Why is this important

DRYs code and makes it more maintainable

Solution

Investigate how to combine them and update all usages.

cc @kosmydel

Issue OwnerCurrent Issue Owner: @JmillsExpensify
@luacmartins luacmartins added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Mar 7, 2024
@luacmartins luacmartins self-assigned this Mar 7, 2024
Copy link

melvin-bot bot commented Mar 7, 2024

Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

Copy link

melvin-bot bot commented Mar 12, 2024

@JmillsExpensify, @luacmartins Eep! 4 days overdue now. Issues have feelings too...

@JmillsExpensify
Copy link

Added a weekly here since this is low and in the polish bucket.

@luacmartins
Copy link
Contributor Author

Polish item

@kosmydel
Copy link
Contributor

A new wrapper FeatureEnabledAccessOrNotFoundWrapper.tsx emerged in this PR.

I've consulted it internally, and someone from SWM will take care of this issue.

@melvin-bot melvin-bot bot added the Overdue label Mar 21, 2024
@BrtqKr
Copy link
Contributor

BrtqKr commented Mar 21, 2024

Hey, I'm an engineer from SWM, I'll be taking over this issue 👋

@luacmartins
Copy link
Contributor Author

Nice! Excited for this one! @BrtqKr would you mind sharing the general approach you're thinking of taking before we dive deep into the code?

@BrtqKr
Copy link
Contributor

BrtqKr commented Mar 25, 2024

@luacmartins the code is literally identical in most of those wrappers, so the idea is to:

  1. Merge AdminPolicyAccessOrNotFoundWrapper and PaidPolicyAccessOrNotFoundWrapper into a single AccessOrNotFoundWrapper. AccessOrNotFoundWrapper will receive accessVariants array prop, which will be mapped into a proper function for determining whether the not found page should be displayed, something like this to be more exact:
const POLICY_ACCESS_VARIANTS = {
    PAID: (policy: OnyxEntry<OnyxTypes.Policy>) => !PolicyUtils.isPaidGroupPolicy(policy) || !policy?.isPolicyExpenseChatEnabled,
    ADMIN: (policy: OnyxEntry<OnyxTypes.Policy>) => !PolicyUtils.isPolicyAdmin(policy),
} as const satisfies Record<string, (policy: OnyxTypes.Policy) => boolean>;
  1. Merge the the existing FeatureEnabledAccessOrNotFoundWrapper with the previously mentioned wrappers, based on the optional featureName param - we just check whether the feature is enabled and add it to the other conditions. And the other difference is a fallback page being displayed - for now, that would be NotFoundPage for the standard conditions and FullPageNotFoundView if this is based on a feature flag, but we could make it more configurable in the future.

@luacmartins luacmartins changed the title [LOW] Standardize on Workspace wrapper [Simplified Collect][CLEAN UP][LOW] Standardize on Workspace wrapper Mar 25, 2024
@luacmartins
Copy link
Contributor Author

luacmartins commented Mar 25, 2024

Sounds good. Could we add FeatureEnabledAccessOrNotFoundWrapper as a predicate to the POLICY_ACCESS_VARIANTS as well? Maybe each entry could be an object with a specific fallback page too so it can handle future changes without updating the wrapper itself, something like:

const POLICY_ACCESS_VARIANTS = {
    PAID: {
         predicate: (policy: OnyxEntry<OnyxTypes.Policy>) => !PolicyUtils.isPaidGroupPolicy(policy) || !policy?.isPolicyExpenseChatEnabled,
         fallback: NotFoundPage
    },
    ...
}

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Mar 27, 2024

hello hello 👋

There are some PRs that add another set of new screens that should be limited to admin users.

Depending on when the unified wrapper that is suggested here is ready, we might use that one or create temporary wrappers. I'd appreciate it if you could share the rough ETA for it if you could, @BrtqKr 🙇

@BrtqKr
Copy link
Contributor

BrtqKr commented Mar 28, 2024

@hayata-suenaga, we'll be sending a PR with those changes this evening at the latest

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Mar 28, 2024

@BrtqKr

I forgot to update here, but we're reassessing our approach to protecting routes (i.e., restricting screen access to certain users).

We started developing a pattern where a wrapper screen is created for each protected screen to check if the user has the necessary permissions to access it or not. Based on the user's access level, either the requested screen is displayed or the "not-found" page is displayed.

I understand that this GH ticket is to standardize this pattern and create a unified wrapper component.

However, after internal discussions, our engineers have decided to adjust our strategy. Instead of implementing access logic at the component level, we now prefer to do so in the navigation layer. React Navigation allows for the conditional rendering of screens within a navigator. We will use this feature to implement protected routes. This approach is recommended in the React Navigation documentation.

cc: @roryabraham

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Mar 28, 2024

We plan to test that the conditional rendering approach does indeed work with our current codebase by using this pattern in the newly added accounting-related screens. If the approach is confirmed to be effective, we will replace the currently implemented wrappers with conditional rendering inside navigators.

@BrtqKr
Copy link
Contributor

BrtqKr commented Apr 22, 2024

Sounds good. Could we add FeatureEnabledAccessOrNotFoundWrapper as a predicate to the POLICY_ACCESS_VARIANTS as well? Maybe each entry could be an object with a specific fallback page too so it can handle future changes without updating the wrapper itself, something like:

const POLICY_ACCESS_VARIANTS = {
    PAID: {
         predicate: (policy: OnyxEntry<OnyxTypes.Policy>) => !PolicyUtils.isPaidGroupPolicy(policy) || !policy?.isPolicyExpenseChatEnabled,
         fallback: NotFoundPage
    },
    ...
}

In general, this was unnecessarily increasing complexity, so I ended up treating feature flags as a separate case. Overall, the main problem is the fact that those conditions can happen simultaneously, so we would need to somehow determine which one of them is more important. There might be different cases with a different priority, so I'd just make the feature flag the more important variant since it was able to cover all existing cases and there have been a lot of them.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels May 1, 2024
@melvin-bot melvin-bot bot changed the title [Simplified Collect][CLEAN UP][LOW] Standardize on Workspace wrapper [HOLD for payment 2024-05-08] [Simplified Collect][CLEAN UP][LOW] Standardize on Workspace wrapper May 1, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 1, 2024
Copy link

melvin-bot bot commented May 1, 2024

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

Copy link

melvin-bot bot commented May 1, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.68-3 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-05-08. 🎊

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

  • @BrtqKr does not require payment (Contractor)

Copy link

melvin-bot bot commented May 1, 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:

  • [@luacmartins] The PR that introduced the bug has been identified. Link to the PR:
  • [@luacmartins] 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:
  • [@luacmartins] A discussion in #expensify-bugs 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:
  • [@BrtqKr] Determine if we should create a regression test for this bug.
  • [@BrtqKr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@JmillsExpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

Copy link

melvin-bot bot commented May 8, 2024

Skipping the payment summary for this issue since all the assignees are employees or vendors. If this is incorrect, please manually add the payment summary SO.

@melvin-bot melvin-bot bot added the Overdue label May 10, 2024
Copy link

melvin-bot bot commented May 13, 2024

@JmillsExpensify, @luacmartins, @BrtqKr Huh... This is 4 days overdue. Who can take care of this?

@BrtqKr
Copy link
Contributor

BrtqKr commented May 14, 2024

It was merged some time ago #40598, not sure why Melvin is still mentioning us. Would you mind closing this issue, or is there anything left to do?

@luacmartins
Copy link
Contributor Author

It seems like we need to payout C+ @ahmedGaber93 for the PR review.

@melvin-bot melvin-bot bot added the Overdue label May 16, 2024
Copy link

melvin-bot bot commented May 17, 2024

@JmillsExpensify, @luacmartins, @ahmedGaber93, @BrtqKr Whoops! This issue is 2 days overdue. Let's get this updated quick!

@JmillsExpensify
Copy link

Payment summary: @ahmedGaber93 $500 for pr review and testing.

@melvin-bot melvin-bot bot removed the Overdue label May 19, 2024
@JmillsExpensify
Copy link

Offer sent via Upwork

@JmillsExpensify
Copy link

Offer paid out, so closing out this issue.

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. Daily KSv2
Projects
Archived in project
Development

No branches or pull requests

6 participants