-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make eligibility checks more async (#88452)
- Loading branch information
1 parent
4cbccfc
commit ba1e802
Showing
10 changed files
with
56 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 32 additions & 6 deletions
38
client/blocks/plugins-update-manager/hooks/use-is-eligible-for-feature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
import { useContext } from 'react'; | ||
import { PluginUpdateManagerContext } from '../context'; | ||
import { WPCOM_FEATURES_SCHEDULED_UPDATES } from '@automattic/calypso-products'; | ||
import { useSelector } from 'calypso/state'; | ||
import getHasLoadedSiteFeatures from 'calypso/state/selectors/has-loaded-site-features'; | ||
import isSiteWpcomAtomic from 'calypso/state/selectors/is-site-wpcom-atomic'; | ||
import siteHasFeature from 'calypso/state/selectors/site-has-feature'; | ||
import { hasLoadedSitePlansFromServer } from 'calypso/state/sites/plans/selectors'; | ||
import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | ||
|
||
export function useIsEligibleForFeature() { | ||
const { isEligibleForFeature } = useContext( PluginUpdateManagerContext ); | ||
return isEligibleForFeature; | ||
} | ||
export const useIsEligibleForFeature = function () { | ||
const siteId = useSelector( getSelectedSiteId ); | ||
|
||
const isFeaturesLoaded: boolean = useSelector( ( state ) => | ||
getHasLoadedSiteFeatures( state, siteId ) | ||
); | ||
|
||
const isSitePlansLoaded: boolean = useSelector( ( state ) => | ||
hasLoadedSitePlansFromServer( state, siteId ) | ||
); | ||
|
||
const hasScheduledUpdatesFeature = useSelector( ( state ) => | ||
siteHasFeature( state, siteId, WPCOM_FEATURES_SCHEDULED_UPDATES ) | ||
); | ||
const isAtomic = useSelector( ( state ) => isSiteWpcomAtomic( state, siteId as number ) ); | ||
const isEligibleForFeature = hasScheduledUpdatesFeature && isAtomic; | ||
return { | ||
isEligibleForFeature, | ||
isAtomic, | ||
hasScheduledUpdatesFeature, | ||
isFeaturesLoaded, | ||
isSitePlansLoaded, | ||
loading: ! isFeaturesLoaded || ! isSitePlansLoaded, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters