-
Notifications
You must be signed in to change notification settings - Fork 800
/
index.jsx
266 lines (245 loc) · 7.56 KB
/
index.jsx
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
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { translate as __ } from 'i18n-calypso';
import Button from 'components/button';
import SimpleNotice from 'components/notice';
import NoticeAction from 'components/notice/notice-action';
import analytics from 'lib/analytics';
import get from 'lodash/get';
/**
* Internal dependencies
*/
import { getSiteRawUrl, getSiteAdminUrl } from 'state/initial-state';
import QuerySitePlugins from 'components/data/query-site-plugins';
import QueryVaultPressData from 'components/data/query-vaultpress-data';
import QueryAkismetKeyCheck from 'components/data/query-akismet-key-check';
import { isDevMode } from 'state/connection';
import {
isFetchingPluginsData,
isPluginActive,
isPluginInstalled
} from 'state/site/plugins';
import {
getVaultPressScanThreatCount,
getVaultPressData,
isFetchingVaultPressData,
getAkismetData
} from 'state/at-a-glance';
import {
getSitePlan,
isFetchingSiteData
} from 'state/site';
import {
isAkismetKeyValid,
isFetchingAkismetData
} from 'state/at-a-glance';
class ProStatus extends React.Component {
static propTypes = {
isCompact: PropTypes.bool,
proFeature: PropTypes.string
};
static defaultProps = {
isCompact: true,
proFeature: ''
};
trackProStatusClick = ( type, feature ) => {
analytics.tracks.recordJetpackClick( {
target: 'pro-status',
type: type,
feature: feature
} );
};
handleClickForTracking = ( type, feature ) => {
return () => this.trackProStatusClick( type, feature );
};
getProActions = ( type, feature ) => {
let status = '',
message = false,
action = false,
actionUrl = '';
switch ( type ) {
case 'threats':
status = 'is-error';
if ( this.props.isCompact ) {
action = __( 'Threats', { context: 'A caption for a small button to fix security issues.' } );
} else {
message = __( 'Threats found!', { context: 'Short warning message about new threats found.' } );
action = __( 'FIX', { context: 'A caption for a small button to fix security issues.' } );
}
actionUrl = 'https://dashboard.vaultpress.com/';
break;
case 'free':
case 'personal':
type = 'upgrade';
status = 'is-warning';
if ( ! this.props.isCompact ) {
message = __( 'No scanning', { context: 'Short warning message about site having no security scan.' } );
}
action = __( 'Upgrade', { context: 'Caption for a button to purchase a paid feature.' } );
actionUrl = 'https://jetpack.com/redirect/?source=upgrade&site=' + this.props.siteRawUrl;
break;
case 'secure':
status = 'is-success';
message = __( 'Secure', { context: 'Short message informing user that the site is secure.' } );
break;
case 'invalid_key':
status = 'is-warning';
action = __( 'Invalid key', { context: 'Short warning message about an invalid key being used for Akismet.' } );
actionUrl = this.props.siteAdminUrl + 'admin.php?page=akismet-key-config';
break;
case 'rewind_connected':
return (
<SimpleNotice showDismiss={ false } status="is-success" isCompact>
{ __( 'Connected' ) }
</SimpleNotice>
);
case 'active':
return <span className="jp-dash-item__active-label">{ __( 'ACTIVE' ) }</span>;
}
return (
<SimpleNotice
showDismiss={ false }
status={ status }
isCompact={ true }
>
{
message
}
{
action && <NoticeAction onClick={ this.handleClickForTracking( type, feature ) } href={ actionUrl }>{ action }</NoticeAction>
}
</SimpleNotice>
);
};
/**
* Return a button to Set Up a feature.
*
* @param {string} feature Slug of the feature to set up.
*
* @return {component} A Button component.
*/
getSetUpButton = feature => {
return (
<Button
onClick={ this.handleClickForTracking( 'set_up', feature ) }
compact={ true }
primary={ true }
href={ `https://wordpress.com/plugins/setup/${ this.props.siteRawUrl }?only=${ feature }` }
>
{ __( 'Set up', { context: 'Caption for a button to set up a feature.' } ) }
</Button>
);
};
render() {
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 hasPersonal = /jetpack_personal*/.test( sitePlan.product_slug ),
hasFree = /jetpack_free*/.test( sitePlan.product_slug ),
hasBackups = get( vpData, [ 'data', 'features', 'backups' ], false ),
hasScan = get( vpData, [ 'data', 'features', 'security' ], false );
const getStatus = ( feature, active, installed ) => {
if ( this.props.isDevMode ) {
return '';
}
if ( 'rewind' === feature ) {
return this.getProActions( 'rewind_connected', 'rewind' );
}
if ( 'backups' === feature ) {
if ( hasFree && ! hasBackups ) {
if ( this.props.isCompact ) {
return this.getProActions( 'free', 'backups' );
}
}
}
if ( 'scan' === feature ) {
if ( this.props.fetchingSiteData || this.props.isFetchingVaultPressData ) {
return '';
}
if ( ( hasFree || hasPersonal ) && ! hasScan ) {
if ( this.props.isCompact ) {
return this.getProActions( 'free', 'scan' );
} else if ( hasPersonal && ! hasBackups ) {
// Personal plans doesn't have scan but it does have backups.
return this.getSetUpButton( 'backups' );
}
return '';
}
if ( 'N/A' !== vpData ) {
if ( ! hasScan ) {
return this.getSetUpButton( 'scan' );
}
const threatsCount = this.props.getScanThreats();
if ( 0 !== threatsCount ) {
return this.getProActions( 'threats', 'scan' );
}
if ( 0 === threatsCount ) {
return this.getProActions( 'secure', 'scan' );
}
}
}
if ( 'akismet' === feature ) {
if ( hasFree && ! ( active && installed ) ) {
if ( this.props.isCompact ) {
return this.getProActions( 'free', 'anti-spam' );
}
return '';
}
if ( ! this.props.isAkismetKeyValid && ! this.props.fetchingAkismetData && active && installed ) {
return this.getProActions( 'invalid_key', 'anti-spam' );
}
}
if ( sitePlan.product_slug && pluginSlug ) {
if ( ! hasFree ) {
if ( active && installed ) {
return this.getProActions( 'active' );
}
return this.getSetUpButton( feature );
}
}
return '';
};
return (
<div>
<QuerySitePlugins />
<QueryAkismetKeyCheck />
<QueryVaultPressData />
{ getStatus(
this.props.proFeature,
this.props.pluginActive( pluginSlug ),
this.props.pluginInstalled( pluginSlug )
) }
</div>
);
}
}
export default connect(
( state ) => {
return {
siteRawUrl: getSiteRawUrl( state ),
siteAdminUrl: getSiteAdminUrl( state ),
getScanThreats: () => getVaultPressScanThreatCount( state ),
getVaultPressData: () => getVaultPressData( state ),
getAkismetData: () => getAkismetData( state ),
isFetchingVaultPressData: isFetchingVaultPressData( state ),
sitePlan: () => getSitePlan( state ),
fetchingPluginsData: isFetchingPluginsData( state ),
pluginActive: ( plugin_slug ) => isPluginActive( state, plugin_slug ),
pluginInstalled: ( plugin_slug ) => isPluginInstalled( state, plugin_slug ),
isDevMode: isDevMode( state ),
fetchingSiteData: isFetchingSiteData( state ),
isAkismetKeyValid: isAkismetKeyValid( state ),
fetchingAkismetData: isFetchingAkismetData( state )
};
}
)( ProStatus );