/
index.jsx
188 lines (174 loc) · 5.13 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
/**
* External dependencies
*/
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { translate as __ } from 'i18n-calypso';
import analytics from 'lib/analytics';
import chunk from 'lodash/chunk';
import get from 'lodash/get';
/**
* Internal dependencies
*/
import { ModuleSettingsForm as moduleSettingsForm } from 'components/module-settings/module-settings-form';
import DashSectionHeader from 'components/dash-section-header';
import DashActivity from './activity';
import DashStats from './stats/index.jsx';
import DashProtect from './protect';
import DashMonitor from './monitor';
import DashScan from './scan';
import DashAkismet from './akismet';
import DashBackups from './backups';
import DashPluginUpdates from './plugins';
import DashPhoton from './photon';
import DashSearch from './search';
import DashConnections from './connections';
import QuerySitePlugins from 'components/data/query-site-plugins';
import QuerySite from 'components/data/query-site';
import {
userCanManageModules,
userCanViewStats,
userIsSubscriber
} from 'state/initial-state';
import { isDevMode } from 'state/connection';
import { getModuleOverride } from 'state/modules';
const renderPairs = layout => layout.map( item => (
[
item.header,
chunk( item.cards, 2 ).map( ( [ left, right ] ) => (
<div className="jp-at-a-glance__item-grid">
<div className="jp-at-a-glance__left">{ left }</div>
<div className="jp-at-a-glance__right">{ right }</div>
</div>
) )
]
) );
class AtAGlance extends Component {
trackSecurityClick() {
analytics.tracks.recordJetpackClick( 'aag_manage_security_wpcom' );
}
render() {
const settingsProps = {
updateOptions: this.props.updateOptions,
getOptionValue: this.props.getOptionValue,
isUpdating: this.props.isUpdating
};
const urls = {
siteAdminUrl: this.props.siteAdminUrl,
siteRawUrl: this.props.siteRawUrl
};
const securityHeader = <DashSectionHeader
label={ __( 'Security' ) }
settingsPath={ this.props.userCanManageModules ? '#security' : undefined }
externalLink={ this.props.isDevMode || ! this.props.userCanManageModules
? ''
: __( 'Manage security settings' )
}
externalLinkPath={ this.props.isDevMode
? ''
: '#security'
}
externalLinkClick={ this.trackSecurityClick }
/>;
const connections = (
<div>
<DashSectionHeader label={ __( 'Connections' ) } />
<DashConnections />
</div>
);
const isRewindActive = 'active' === get( this.props.rewindStatus, [ 'state' ], false );
const securityCards = [
<DashScan
{ ...settingsProps }
siteRawUrl={ this.props.siteRawUrl }
isRewindActive={ isRewindActive }
/>,
<DashBackups
{ ...settingsProps }
siteRawUrl={ this.props.siteRawUrl }
isRewindActive={ isRewindActive }
/>,
<DashAkismet { ...urls } />,
<DashPluginUpdates { ...settingsProps } { ...urls } />
];
if ( 'inactive' !== this.props.getModuleOverride( 'protect' ) ) {
securityCards.push( <DashProtect { ...settingsProps } /> );
}
if ( 'inactive' !== this.props.getModuleOverride( 'monitor' ) ) {
securityCards.push( <DashMonitor { ...settingsProps } /> );
}
// Maybe add the rewind card
isRewindActive && securityCards.unshift( <DashActivity { ...settingsProps } siteRawUrl={ this.props.siteRawUrl } /> );
// If user can manage modules, we're in an admin view, otherwise it's a non-admin view.
if ( this.props.userCanManageModules ) {
const pairs = [
{
header: securityHeader,
cards: securityCards
}
];
const performanceCards = [];
if ( 'inactive' !== this.props.getModuleOverride( 'photon' ) ) {
performanceCards.push( <DashPhoton { ...settingsProps } /> );
}
if ( 'inactive' !== this.props.getModuleOverride( 'search' ) ) {
performanceCards.push( <DashSearch { ...settingsProps } /> );
}
if ( performanceCards.length ) {
pairs.push( {
header: <DashSectionHeader label={ __( 'Performance' ) } />,
cards: performanceCards
} );
}
return (
<div className="jp-at-a-glance">
<QuerySitePlugins />
<QuerySite />
<DashStats { ...settingsProps } { ...urls } />
{ renderPairs( pairs ) }
{ connections }
</div>
);
}
/*
* Non-admin zone...
*/
let stats = '';
if ( this.props.userCanViewStats ) {
stats = <DashStats { ...settingsProps } { ...urls } />;
}
let protect = '';
if ( this.props.getOptionValue( 'protect' ) ) {
protect = <DashProtect { ...settingsProps } />;
}
return this.props.userIsSubscriber
? (
<div>
{ stats }
{ connections }
</div>
)
: (
<div>
{ stats }
{
// Site Security
this.props.getOptionValue( 'protect' ) && securityHeader
}
{ protect }
{ connections }
</div>
);
} // render
}
export default connect(
( state ) => {
return {
userCanManageModules: userCanManageModules( state ),
userCanViewStats: userCanViewStats( state ),
userIsSubscriber: userIsSubscriber( state ),
isDevMode: isDevMode( state ),
getModuleOverride: module_name => getModuleOverride( state, module_name ),
};
}
)( moduleSettingsForm( AtAGlance ) );