/* eslint-disable jsx-a11y/anchor-is-valid */ /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable jsx-a11y/no-static-element-interactions */ import { ExternalLink } from '@automattic/components'; import { Button } from '@wordpress/components'; import { Icon, trash } from '@wordpress/icons'; import clsx from 'clsx'; import { localize } from 'i18n-calypso'; import { Component } from 'react'; import { connect } from 'react-redux'; import PopoverMenuItem from 'calypso/components/popover-menu/item'; import { gaRecordEvent } from 'calypso/lib/analytics/ga'; import { recordTracksEvent } from 'calypso/lib/analytics/tracks'; import { REMOVE_PLUGIN } from 'calypso/lib/plugins/constants'; import { getSiteFileModDisableReason, isMainNetworkSite } from 'calypso/lib/site/utils'; import PluginAction from 'calypso/my-sites/plugins/plugin-action/plugin-action'; import { removePlugin } from 'calypso/state/plugins/installed/actions'; import { isPluginActionInProgress } from 'calypso/state/plugins/installed/selectors'; import { removePluginStatuses } from 'calypso/state/plugins/installed/status/actions'; import { withShowPluginActionDialog } from '../hooks/use-show-plugin-action-dialog'; import './style.scss'; class PluginRemoveButton extends Component { static displayName = 'PluginRemoveButton'; removeAction = () => { const { plugin, site, showPluginActionDialog } = this.props; showPluginActionDialog( 'remove', [ plugin ], [ site ], this.processRemovalConfirmation ); }; processRemovalConfirmation = ( accepted ) => { if ( accepted ) { this.props.removePluginStatuses( 'completed', 'error', 'up-to-date' ); this.props.removePlugin( this.props.site.ID, this.props.plugin ); if ( this.props.isEmbed ) { gaRecordEvent( 'Plugins', 'Remove plugin with no selected site', 'Plugin Name', this.props.plugin.slug ); recordTracksEvent( 'calypso_plugin_remove_click_from_sites_list', { site: this.props.site.ID, plugin: this.props.plugin.slug, } ); } else { gaRecordEvent( 'Plugins', 'Remove plugin on selected Site', 'Plugin Name', this.props.plugin.slug ); recordTracksEvent( 'calypso_plugin_remove_click_from_plugin_info', { site: this.props.site.ID, plugin: this.props.plugin.slug, } ); } } }; getDisabledInfo = () => { if ( ! this.props.site || ! this.props.site.options ) { // we don't have enough info return null; } if ( this.props.site.options.is_multi_network ) { return this.props.translate( '%(site)s is part of a multi-network installation, which is not currently supported.', { args: { site: this.props.site.title }, } ); } if ( ! isMainNetworkSite( this.props.site ) ) { return this.props.translate( '%(pluginName)s cannot be removed because %(site)s is not the main site of the multi-site installation.', { args: { site: this.props.site.title, pluginName: this.props.plugin.name, }, } ); } if ( ! this.props.site.canUpdateFiles && this.props.site.options.file_mod_disabled ) { const reasons = getSiteFileModDisableReason( this.props.site, 'modifyFiles' ); const html = []; if ( reasons.length > 1 ) { html.push(
{ this.props.translate( '%(pluginName)s cannot be removed:', { args: { pluginName: this.props.plugin.name }, } ) }
); const list = reasons.map( ( reason, i ) => ({ this.props.translate( '%(pluginName)s cannot be removed. %(reason)s', { args: { pluginName: this.props.plugin.name, reason: reasons[ 0 ] }, } ) }
); } html.push(