diff --git a/client/my-sites/plugins/plugins-list/use-actions.tsx b/client/my-sites/plugins/plugins-list/use-actions.tsx index ce82e1a8f00f2..481ae409fa19a 100644 --- a/client/my-sites/plugins/plugins-list/use-actions.tsx +++ b/client/my-sites/plugins/plugins-list/use-actions.tsx @@ -1,6 +1,7 @@ import { Icon, link, linkOff, trash } from '@wordpress/icons'; import { translate } from 'i18n-calypso'; import { navigate } from 'calypso/lib/navigate'; +import { PLUGINS_STATUS } from 'calypso/state/plugins/installed/status/constants'; import { Plugin } from 'calypso/state/plugins/installed/types'; import { PluginActions } from '../hooks/types'; @@ -27,7 +28,9 @@ export function useActions( }, label: translate( 'Activate' ), isExternalLink: true, - isEnabled: true, + isEligible( plugin: Plugin ) { + return plugin.status?.includes( PLUGINS_STATUS.INACTIVE ) ?? true; + }, supportsBulk: true, icon: , }, @@ -39,7 +42,9 @@ export function useActions( }, label: translate( 'Deactivate' ), isExternalLink: true, - isEnabled: true, + isEligible( plugin: Plugin ) { + return plugin.status?.includes( PLUGINS_STATUS.ACTIVE ) ?? true; + }, supportsBulk: true, icon: , }, @@ -51,7 +56,9 @@ export function useActions( }, label: translate( 'Enable auto-updates' ), isExternalLink: true, - isEnabled: true, + isEligible( plugin: Plugin ) { + return plugin.status?.includes( PLUGINS_STATUS.AUTOUPDATE_DISABLED ) ?? true; + }, supportsBulk: true, }, { @@ -62,7 +69,9 @@ export function useActions( }, label: translate( 'Disable auto-updates' ), isExternalLink: true, - isEnabled: true, + isEligible( plugin: Plugin ) { + return plugin.status?.includes( PLUGINS_STATUS.AUTOUPDATE_ENABLED ) ?? true; + }, supportsBulk: true, }, { diff --git a/client/state/plugins/installed/selectors.js b/client/state/plugins/installed/selectors.js index a4dc4bc5b64da..addb4fb2c07d5 100644 --- a/client/state/plugins/installed/selectors.js +++ b/client/state/plugins/installed/selectors.js @@ -40,6 +40,20 @@ const _filters = { } ) || plugin.statusRecentlyChanged ); }, + autoupdates: function ( plugin ) { + return ( + some( plugin.sites, function ( site ) { + return site.autoupdate; + } ) || plugin.statusRecentlyChanged + ); + }, + autoupdates_disabled: function ( plugin ) { + return ( + some( plugin.sites, function ( site ) { + return ! site.autoupdate; + } ) || plugin.statusRecentlyChanged + ); + }, isEqual: function ( pluginSlug, plugin ) { return plugin.slug === pluginSlug; }, @@ -125,6 +139,8 @@ export const getPluginsWithUpdateStatuses = createSelector( const active = filter( allPlugins, _filters.active ); const inactive = filter( allPlugins, _filters.inactive ); const withUpdate = filter( allPlugins, _filters.updates ); + const withAutoUpdate = filter( allPlugins, _filters.autoupdates ); + const withAutoUpdateDisabled = filter( allPlugins, _filters.autoupdates_disabled ); return allPlugins.reduce( ( memo, plugin ) => { const status = []; @@ -153,6 +169,15 @@ export const getPluginsWithUpdateStatuses = createSelector( if ( find( active, { slug: plugin.slug } ) ) { status.push( PLUGINS_STATUS.ACTIVE ); } + + if ( find( withAutoUpdate, { slug: plugin.slug } ) ) { + status.push( PLUGINS_STATUS.AUTOUPDATE_ENABLED ); + } + + if ( find( withAutoUpdateDisabled, { slug: plugin.slug } ) ) { + status.push( PLUGINS_STATUS.AUTOUPDATE_DISABLED ); + } + return [ ...memo, { ...plugin, status } ]; }, [] ); }, diff --git a/client/state/plugins/installed/status/constants.ts b/client/state/plugins/installed/status/constants.ts index 200fe138d81b2..8282cd4a6c0ba 100644 --- a/client/state/plugins/installed/status/constants.ts +++ b/client/state/plugins/installed/status/constants.ts @@ -11,4 +11,6 @@ export const PLUGINS_STATUS = { ACTIVE: 1, INACTIVE: 2, UPDATE: 3, + AUTOUPDATE_ENABLED: 4, + AUTOUPDATE_DISABLED: 5, }; diff --git a/client/state/plugins/installed/test/selectors.js b/client/state/plugins/installed/test/selectors.js index c82eb435378ff..fb7a8b46e3075 100644 --- a/client/state/plugins/installed/test/selectors.js +++ b/client/state/plugins/installed/test/selectors.js @@ -496,7 +496,11 @@ describe( 'Installed plugin selectors', () => { version: '1.0', }, }, - status: [ PLUGINS_STATUS.UPDATE, PLUGINS_STATUS.ACTIVE ], + status: [ + PLUGINS_STATUS.UPDATE, + PLUGINS_STATUS.ACTIVE, + PLUGINS_STATUS.AUTOUPDATE_ENABLED, + ], allStatuses: [ { action: 'DEACTIVATE_PLUGIN', @@ -516,14 +520,14 @@ describe( 'Installed plugin selectors', () => { id: 'hello-dolly/hello-dolly', slug: 'hello-dolly/hello-dolly', sites: { 'site.one': { active: true } }, - status: [ PLUGINS_STATUS.ACTIVE ], + status: [ PLUGINS_STATUS.ACTIVE, PLUGINS_STATUS.AUTOUPDATE_DISABLED ], allStatuses: [], }, { id: 'vaultpress/vaultpress', slug: 'vaultpress/vaultpress', sites: { 'site.one': { active: false } }, - status: [ PLUGINS_STATUS.INACTIVE ], + status: [ PLUGINS_STATUS.INACTIVE, PLUGINS_STATUS.AUTOUPDATE_DISABLED ], allStatuses: [], }, ] )