File size: 1,357 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { WPCOM_FEATURES_MANAGE_PLUGINS } from '@automattic/calypso-products';
import { createSelector } from '@wordpress/data';
import isSiteAutomatedTransfer from 'calypso/state/selectors/is-site-automated-transfer';
import siteHasFeature from 'calypso/state/selectors/site-has-feature';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import type { PluginComponentProps } from '../types';
import type { SiteDetails } from '@automattic/data-stores';
import type { AppState } from 'calypso/types';

export const getAllowedPluginActions = createSelector(
	( state: AppState, plugin: PluginComponentProps, selectedSite?: SiteDetails ) => {
		const autoManagedPlugins = [ 'jetpack', 'vaultpress', 'akismet' ];
		const siteIsAtomic = selectedSite && isSiteAutomatedTransfer( state, selectedSite?.ID );
		const siteIsJetpack = selectedSite && isJetpackSite( state, selectedSite?.ID );
		const hasManagePlugins =
			selectedSite && siteHasFeature( state, selectedSite?.ID, WPCOM_FEATURES_MANAGE_PLUGINS );
		const isManagedPlugin = siteIsAtomic && autoManagedPlugins.includes( plugin.slug );
		const canManagePlugins =
			! selectedSite || ( siteIsJetpack && ! siteIsAtomic ) || ( siteIsAtomic && hasManagePlugins );

		return {
			autoupdate: ! isManagedPlugin && canManagePlugins,
			activation: ! isManagedPlugin && canManagePlugins,
		};
	}
);