-
Notifications
You must be signed in to change notification settings - Fork 796
/
index.jsx
145 lines (137 loc) · 5.22 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
/**
* External dependencies
*/
import React from 'react';
import { connect } from 'react-redux';
import FoldableCard from 'components/foldable-card';
import Button from 'components/button';
import Gridicon from 'components/gridicon';
import { translate as __ } from 'i18n-calypso';
import includes from 'lodash/includes';
import analytics from 'lib/analytics';
/**
* Internal dependencies
*/
import {
isModuleActivated as _isModuleActivated,
activateModule,
deactivateModule,
isActivatingModule,
isDeactivatingModule,
getModule as _getModule,
getModules
} from 'state/modules';
import { ModuleToggle } from 'components/module-toggle';
import { AllModuleSettings } from 'components/module-settings/modules-per-tab-page';
import { isUnavailableInDevMode } from 'state/connection';
import { userCanManageModules } from 'state/initial-state';
import Settings from 'components/settings';
export const Page = ( props ) => {
let {
toggleModule,
isModuleActivated,
isTogglingModule,
getModule
} = props,
isAdmin = props.userCanManageModules,
moduleList = Object.keys( props.moduleList );
var cards = [
[ 'tiled-gallery', getModule( 'tiled-gallery' ).name, getModule( 'tiled-gallery' ).description, getModule( 'tiled-gallery' ).learn_more_button ],
[ 'photon', getModule( 'photon' ).name, getModule( 'photon' ).description, getModule( 'photon' ).learn_more_button ],
[ 'carousel', getModule( 'carousel' ).name, getModule( 'carousel' ).description, getModule( 'carousel' ).learn_more_button ],
[ 'widgets', getModule( 'widgets' ).name, getModule( 'widgets' ).description, getModule( 'widgets' ).learn_more_button ],
[ 'widget-visibility', getModule( 'widget-visibility' ).name, getModule( 'widget-visibility' ).description, getModule( 'widget-visibility' ).learn_more_button ],
[ 'custom-css', getModule( 'custom-css' ).name, getModule( 'custom-css' ).description, getModule( 'custom-css' ).learn_more_button ],
[ 'infinite-scroll', getModule( 'infinite-scroll' ).name, getModule( 'infinite-scroll' ).description, getModule( 'infinite-scroll' ).learn_more_button ],
[ 'minileven', getModule( 'minileven' ).name, getModule( 'minileven' ).description, getModule( 'minileven' ).learn_more_button ]
].map( ( element ) => {
if ( ! includes( moduleList, element[0] ) ) {
return null;
}
var unavailableInDevMode = props.isUnavailableInDevMode( element[0] ),
toggle = (
unavailableInDevMode ? __( 'Unavailable in Dev Mode' ) :
<ModuleToggle slug={ element[0] } activated={ isModuleActivated( element[0] ) }
toggling={ isTogglingModule( element[0] ) }
toggleModule={ toggleModule } />
),
customClasses = unavailableInDevMode ? 'devmode-disabled' : '';
return (
<FoldableCard
className={ customClasses }
key={ `module-card_${element[0]}` /* https://fb.me/react-warning-keys */ }
header={ element[1] }
subheader={ element[2] }
summary={ toggle }
expandedSummary={ toggle }
clickableHeaderText={ true }
onOpen={ () => analytics.tracks.recordEvent( 'jetpack_wpa_settings_card_open',
{
card: element[0],
path: props.route.path
}
) }
>
{
isModuleActivated( element[0] ) ?
<AllModuleSettings module={ getModule( element[0] ) } /> :
// Render the long_description if module is deactivated
<div dangerouslySetInnerHTML={ renderLongDescription( getModule( element[0] ) ) } />
}
<div className="jp-module-settings__read-more">
<Button borderless compact href={ element[3] }><Gridicon icon="help-outline" /><span className="screen-reader-text">{ __( 'Learn More' ) }</span></Button>
</div>
</FoldableCard>
);
} );
return (
<div>
{ cards }
<FoldableCard
header={ __( 'Holiday Snow' ) }
subheader={ __( 'Show falling snow in the holiday period.' ) }
clickableHeaderText={ true }
disabled={ ! isAdmin }
summary={ isAdmin ? <Settings slug="snow" /> : '' }
expandedSummary={ isAdmin ? <Settings slug="snow" /> : '' }
onOpen={ () => analytics.tracks.recordEvent( 'jetpack_wpa_settings_card_open',
{
card: 'holiday_snow',
path: props.route.path
}
) }
>
<span className="jp-form-setting-explanation">
{ __( 'Show falling snow on my blog from Dec 1st until Jan 4th.' ) }
</span>
</FoldableCard>
</div>
);
};
function renderLongDescription( module ) {
// Rationale behind returning an object and not just the string
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
return { __html: module.long_description };
}
export default connect(
( state ) => {
return {
isModuleActivated: ( module_name ) => _isModuleActivated( state, module_name ),
isTogglingModule: ( module_name ) =>
isActivatingModule( state, module_name ) || isDeactivatingModule( state, module_name ),
getModule: ( module_name ) => _getModule( state, module_name ),
isUnavailableInDevMode: ( module_name ) => isUnavailableInDevMode( state, module_name ),
userCanManageModules: userCanManageModules( state ),
moduleList: getModules( state )
};
},
( dispatch ) => {
return {
toggleModule: ( module_name, activated ) => {
return ( activated )
? dispatch( deactivateModule( module_name ) )
: dispatch( activateModule( module_name ) );
}
};
}
)( Page );