Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | 9x 9x 9x 9x 9x 9x | import { getRedirectUrl } from '@automattic/jetpack-components';
import { __, _x } from '@wordpress/i18n';
import { Text } from '@wordpress/ui';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import Button from 'components/button';
import QueryAkismetKeyCheck from 'components/data/query-akismet-key-check';
import QuerySitePlugins from 'components/data/query-site-plugins';
import QueryVaultPressData from 'components/data/query-vaultpress-data';
import analytics from 'lib/analytics';
import {
getVaultPressScanThreatCount,
getVaultPressData,
isFetchingVaultPressData,
getAkismetData,
isAkismetKeyValid,
isFetchingAkismetData,
} from 'state/at-a-glance';
import { isOfflineMode } from 'state/connection';
import { getSiteRawUrl, getSiteAdminUrl } from 'state/initial-state';
import { getRewindStatus } from 'state/rewind';
import { getSitePlan, siteHasFeature, isFetchingSiteData } from 'state/site';
import { isFetchingPluginsData, isPluginActive, isPluginInstalled } from 'state/site/plugins';
import styles from './style.module.scss';
/**
* Render a small status indicator with a coloured dot and label.
*
* @param {object} props - Component props.
* @param {string} props.status - Status key.
* @param {React.ReactNode} props.label - Label content.
* @return {import('react').ReactElement} The status indicator.
*/
const StatusIndicator = ( { status, label } ) => (
<Text variant="body-sm" className={ clsx( styles.status, styles[ `is-${ status }` ] ) }>
<span className={ styles.indicator } />
<span>{ label }</span>
</Text>
);
const DEFAULT_LABELS = {
active: __( 'Active', 'jetpack' ),
error: __( 'Error', 'jetpack' ),
action: __( 'Action needed', 'jetpack' ),
inactive: __( 'Inactive', 'jetpack' ),
initializing: __( 'Setting up', 'jetpack' ),
};
/**
* Track click on Pro status badge.
*
* @param {string} type - Status of a certain feature.
* @param {string} feature - Slug of plugin or service.
* @return {undefined}
*/
const trackProStatusClick = ( type, feature ) =>
analytics.tracks.recordJetpackClick( {
target: 'pro-status',
type: type,
feature: feature,
} );
/**
* Build function to pass as onClick property.
*
* @param {string} type - Status of a certain feature.
* @param {string} feature - Slug of plugin or service.
* @return {Function} Function to track a click.
*/
const handleClickForTracking = ( type, feature ) => () => trackProStatusClick( type, feature );
class ProStatus extends Component {
static propTypes = {
isCompact: PropTypes.bool,
proFeature: PropTypes.string,
// Connected
rewindStatus: PropTypes.object.isRequired,
};
static defaultProps = {
isCompact: true,
proFeature: '',
};
getRewindMessage() {
switch ( this.props.rewindStatus.state ) {
case 'provisioning':
return {
status: 'initializing',
text: __( 'Setting up', 'jetpack' ),
};
case 'awaiting_credentials':
return {
status: 'action',
text: __( 'Action needed', 'jetpack' ),
};
case 'active':
return {
status: 'active',
text: __( 'Connected', 'jetpack' ),
};
default:
return { status: '', text: '' };
}
}
getProActions = ( type, feature ) => {
let status = '',
message = false,
action = false,
actionUrl = '';
switch ( type ) {
case 'threats':
status = 'error';
action = _x(
'Threats detected',
'A caption for a small button to fix security issues.',
'jetpack'
);
actionUrl = getRedirectUrl( 'vaultpress-dashboard' );
break;
case 'secure':
status = 'active';
message = _x(
'Secure',
'Short message informing user that the site is secure.',
'jetpack'
);
break;
case 'invalid_key':
return;
case 'rewind_connected': {
const rewindMessage = this.getRewindMessage();
return (
<StatusIndicator
status={ rewindMessage.status }
label={ DEFAULT_LABELS[ rewindMessage.status ] }
/>
);
}
case 'active':
return <StatusIndicator status="active" label={ DEFAULT_LABELS.active } />;
}
const label = (
<>
{ message }
{ action && (
<a onClick={ handleClickForTracking( type, feature ) } href={ actionUrl }>
{ action }
</a>
) }
</>
);
return <StatusIndicator status={ status } label={ label } />;
};
/**
* Return a button to Set Up a feature.
*
* @param {string} feature - Slug of the feature to set up.
* @return {import('react').ReactElement} A Button component.
*/
getSetUpButton = feature => {
return (
<Button
onClick={ handleClickForTracking( 'set_up', feature ) }
compact={ true }
primary={ true }
href={ getRedirectUrl( 'calypso-plugins-setup', {
site: this.props.siteRawUrl,
query: `only=${ feature }`,
} ) }
>
{ _x( 'Set up', 'Caption for a button to set up a feature.', 'jetpack' ) }
</Button>
);
};
render() {
const { purchasedVaultPressBackups, purchasedVaultPressScan } = this.props;
const sitePlan = this.props.sitePlan,
vpData = this.props.getVaultPressData();
let pluginSlug = '';
if (
'scan' === this.props.proFeature ||
'backups' === this.props.proFeature ||
'vaultpress' === this.props.proFeature
) {
pluginSlug = 'vaultpress/vaultpress.php';
}
if ( 'akismet' === this.props.proFeature ) {
pluginSlug = 'akismet/akismet.php';
}
const hasFree = /jetpack_free*/.test( sitePlan.product_slug ),
usingVPBackups = vpData?.data?.features?.backups ?? false,
usingVPScan = vpData?.data?.features?.security ?? false;
const getStatus = ( feature, active, installed ) => {
switch ( feature ) {
case 'rewind':
// This is the newer backup technology powered by Jetpack Backup.
return this.getProActions( 'rewind_connected', 'rewind' );
case 'backups':
// This is the older backup technology powered by VaultPress.
if ( hasFree && ! usingVPBackups && this.props.isCompact ) {
return '';
}
break;
case 'scan':
if ( this.props.fetchingSiteData || this.props.isFetchingVaultPressData ) {
return '';
}
if ( 'N/A' !== vpData ) {
if ( purchasedVaultPressScan ) {
if ( usingVPScan ) {
return this.getProActions(
0 === this.props.getScanThreats() ? 'secure' : 'threats',
'scan'
);
}
return this.getSetUpButton( 'scan' );
} else if ( purchasedVaultPressBackups && ! usingVPBackups && ! this.props.isCompact ) {
return this.getSetUpButton( 'backups' );
}
}
return '';
case 'search':
return '';
case 'akismet':
if ( hasFree && ! ( active && installed ) ) {
return '';
}
if (
! this.props.isAkismetKeyValid &&
! this.props.fetchingAkismetData &&
active &&
installed &&
! hasFree
) {
return this.getSetUpButton( feature );
}
break;
}
// Show set up or active status only for paid features that depend on a plugin, and only under a paid plan
if ( sitePlan.product_slug && pluginSlug && ! hasFree ) {
return active && installed
? this.getProActions( 'active' )
: this.getSetUpButton( feature );
}
return '';
};
return (
<div>
<QuerySitePlugins />
<QueryAkismetKeyCheck />
<QueryVaultPressData />
{ ! this.props.isOfflineMode &&
getStatus(
this.props.proFeature,
this.props.pluginActive( pluginSlug ),
this.props.pluginInstalled( pluginSlug )
) }
</div>
);
}
}
export default connect( state => {
const sitePlan = getSitePlan( state );
return {
siteRawUrl: getSiteRawUrl( state ),
siteAdminUrl: getSiteAdminUrl( state ),
getScanThreats: () => getVaultPressScanThreatCount( state ),
getVaultPressData: () => getVaultPressData( state ),
getAkismetData: () => getAkismetData( state ),
isFetchingVaultPressData: isFetchingVaultPressData( state ),
sitePlan,
fetchingPluginsData: isFetchingPluginsData( state ),
pluginActive: plugin_slug => isPluginActive( state, plugin_slug ),
pluginInstalled: plugin_slug => isPluginInstalled( state, plugin_slug ),
isOfflineMode: isOfflineMode( state ),
fetchingSiteData: isFetchingSiteData( state ),
isAkismetKeyValid: isAkismetKeyValid( state ),
fetchingAkismetData: isFetchingAkismetData( state ),
rewindStatus: getRewindStatus( state ),
purchasedVaultPressBackups: siteHasFeature( state, 'vaultpress-backups' ),
purchasedVaultPressScan: siteHasFeature( state, 'vaultpress-security-scanning' ),
};
} )( ProStatus );
|