-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 on 16 June] Make permissions checking asynchronous by creating a withBetas HOC #3194
Comments
This comment has been minimized.
This comment has been minimized.
Yeah, I think this is a good move. I'd like to see those moved to an HOC or at the very least be made asynchronous. Without them being asynchronous, we are limited by the amount of checks we can do. For example, we can't use While this is not currently a problem, I'd like to change this code so that when new betas are added, they do not follow this old sync pattern anymore. |
Gonna try to rephrase this problem solution to make sure I understand... Problem
Solution Make the Permissions methods async + create an HOC to delay rendering the wrapped component until after the async things are finished so we can check the betas via props? Or was the HOC supposed to work differently...? |
What do you mean by delay rendering? As in other HOCs, I think we would not delay it, right? If the betas data is not present, it would render the same as if you were not in any beta and when the data is available, it would re-render. |
Delaying came to mind since I'd assume we would not want to initialize a view with all beta features disabled by default and then flash in the beta features as the various data becomes available. But if we don't care about that then maybe another idea is to just subscribe directly to the betas key via let isOnDev;
function updateBetas(betas = []) {
if (isOnDev) {
Onyx.set(ONYXKEYS.BETAS, CONST.BETAS.ALL);
return;
}
Onyx.merge(ONYXKEYS.BETAS, betas);
}
getEnvironment()
.then((environment) => {
isOnDev = environment === CONST.ENVIRONMENT.DEV;
updateBetas();
}); Now any component that is connected to render() {
if (canUseChronos(this.props.betas)) {
return (...)
};
}
export default withOnyx({
betas: {key: ONYXKEYS.BETAS}
})(SomeComponent); |
I'm out of office today so removing my assignment and adding the AutoAssigner label back in for triaging. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think the delayed re-rendering might be a pre-optimization. I'm not sure that there is really a problem with that yet. However, I do kinda like the idea of just using |
I kind of liked the HOC as it will abstract a common repeating pattern, but I am fine with subscribing to Onyx directly too. |
I prefer Onyx solution, a pretty straightforward thing and no need of HOC overhead. |
@laurenreidexpensify updated the OP, we are ready to move this forward, can you post it to upwork? |
Triggered auto assignment to @timszot ( |
Upwork posting here https://www.upwork.com/jobs/~01f29f2d2fa738d842 |
Proposal
then updating the call as to One of the location for change is https://github.com/Expensify/Expensify.cash/blob/f1cfb9eb102259a8f7f8662c86a432a09c23eb8e/src/pages/home/report/ReportActionCompose.js#L400 Solution for this particular case.
which will be used at https://github.com/Expensify/Expensify.cash/blob/71c58ee8b17fce1503a8c9cabfcdc630b6fc5d2f/src/libs/OptionsListUtils.js#L336
|
@timszot these remain |
@parasharrajat I think that sounds like a good proposal, but please take a look at this usage: https://github.com/Expensify/Expensify.cash/blob/71c58ee8b17fce1503a8c9cabfcdc630b6fc5d2f/src/libs/OptionsListUtils.js#L336 It is going to be the most difficult one since the betas will have to be passed down through several layers. Can you please update your proposal to include this? Thanks! |
@tgolen
which will be used at https://github.com/Expensify/Expensify.cash/blob/71c58ee8b17fce1503a8c9cabfcdc630b6fc5d2f/src/libs/OptionsListUtils.js#L336
|
Yep, I think that's the approach we need to take with this! It's a good
proposal now. Let's go with it. Green light!
…On Tue, Jun 1, 2021 at 10:08 AM Rajat Parashar ***@***.***> wrote:
Better approach would be use the Onyx.connect method to pass the betas to
getOptions but that goes against the desired behavior. We want to wait
until betas is ready on Onyx so subscribing at component level helps but
Onyx.connect will not.
So we can do the following:
1. Subscribe to ONYXKEYS.BETAS at page level(SearchPage).
2. Modify the getOptions to accept betas as optional Config Param
function getOptions(reports, personalDetails, draftComments, activeReportID, {
betas = [],
....
which will be used at
https://github.com/Expensify/Expensify.cash/blob/71c58ee8b17fce1503a8c9cabfcdc630b6fc5d2f/src/libs/OptionsListUtils.js#L336
1. Modify getSearchOptions to take another parameter betas.
https://github.com/Expensify/Expensify.cash/blob/71c58ee8b17fce1503a8c9cabfcdc630b6fc5d2f/src/libs/OptionsListUtils.js#L365
2. pass down the betas from getSearchOptions to getOptions config key
betas
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3194 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJMAB5ATBG4XM3USEGGXJDTQUAWFANCNFSM45VGQQ4Q>
.
|
@parasharrajat have hired you in Upwork 👍🏽 |
Payment has been issued in Upwork @parasharrajat 😃 |
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Problem
The methods in permissions.js file should be asynchronous. They kind of already are if you look at the code, since data is coming from Onyx, but the methods themselves as synchronous, which does not align with how the data is loaded, so there are possible race conditions.
Solution
Change all places where permissions is used to instead subscribe to the
ONYXKEYS.BETAS
onyx key and call permissions methods passing the betas it got from onyx (see this comment)Upwork posting - https://www.upwork.com/jobs/~01f29f2d2fa738d842
/cc @tgolen @marcaaron
The text was updated successfully, but these errors were encountered: