Skip to content

Commit

Permalink
Bulk Plugin Management: Allow plugins menu to be contextual (#96175)
Browse files Browse the repository at this point in the history
* include auto updates as a possible filter

* make certain actions contextual based on plugins status on all sites

* Adding support for auto-update enable + disabled

* fix tests

* returns true as default

---------

Co-authored-by: Paulo Trentin <paulo@paulotrentin.com.br>
  • Loading branch information
vykes-mac and paulopmt1 authored Nov 9, 2024
1 parent df9a6e6 commit 61065de
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
17 changes: 13 additions & 4 deletions client/my-sites/plugins/plugins-list/use-actions.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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: <Icon icon={ link } />,
},
Expand All @@ -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: <Icon icon={ linkOff } />,
},
Expand All @@ -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,
},
{
Expand All @@ -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,
},
{
Expand Down
25 changes: 25 additions & 0 deletions client/state/plugins/installed/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 } ];
}, [] );
},
Expand Down
2 changes: 2 additions & 0 deletions client/state/plugins/installed/status/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export const PLUGINS_STATUS = {
ACTIVE: 1,
INACTIVE: 2,
UPDATE: 3,
AUTOUPDATE_ENABLED: 4,
AUTOUPDATE_DISABLED: 5,
};
10 changes: 7 additions & 3 deletions client/state/plugins/installed/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: [],
},
] )
Expand Down

0 comments on commit 61065de

Please sign in to comment.