Skip to content

Commit

Permalink
Merge pull request Automattic#13874 from Automattic/fix/wpsc-empty-in…
Browse files Browse the repository at this point in the history
…itial-state

Extensions: WPSC - Handle empty initial state
  • Loading branch information
donnapep authored May 12, 2017
2 parents 953b295 + e4c104b commit 6633f67
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 32 deletions.
3 changes: 1 addition & 2 deletions client/extensions/wp-super-cache/advanced-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const AdvancedTab = ( {
is_cache_enabled,
is_super_cache_enabled,
},
siteUrl,
} ) => {
return (
<div>
Expand All @@ -37,7 +36,7 @@ const AdvancedTab = ( {
<RejectedUserAgents />
<LockDown />
{ is_cache_enabled && is_super_cache_enabled &&
<DirectlyCachedFiles siteUrl={ siteUrl } />
<DirectlyCachedFiles />
}
<FixConfig />
</div>
Expand Down
10 changes: 4 additions & 6 deletions client/extensions/wp-super-cache/cdn-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import React from 'react';
import { pick } from 'lodash';
import { get, pick } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -32,7 +32,7 @@ const CdnTab = ( {
handleSubmitForm,
isRequesting,
isSaving,
siteUrl,
site,
translate,
} ) => {
return (
Expand Down Expand Up @@ -79,7 +79,7 @@ const CdnTab = ( {
{ translate(
'The new URL to be used in place of %(url)s for rewriting. No trailing / please.',
{
args: { url: siteUrl },
args: { url: get( site, 'URL' ) },
}
) }
</FormSettingExplanation>
Expand Down Expand Up @@ -147,9 +147,7 @@ const CdnTab = ( {
'off-site URL above). Use a comma as the delimiter. For pages with a large number of static files, ' +
'this can improve browser performance. CNAMEs may also need to be configured on your CDN.',
{
args: {
url: siteUrl,
},
args: { url: get( site, 'URL' ) },
components: {
a: (
<ExternalLink
Expand Down
15 changes: 13 additions & 2 deletions client/extensions/wp-super-cache/contents-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
successNotice,
} from 'state/notices/actions';
import { generateStats } from './state/stats/actions';
import {
getSiteTitle,
isJetpackSiteMultiSite,
} from 'state/sites/selectors';
import {
getStats,
isGeneratingStats,
Expand All @@ -32,13 +36,16 @@ class ContentsTab extends Component {
handleDeleteCache: PropTypes.func.isRequired,
isDeleting: PropTypes.bool,
isMultisite: PropTypes.bool,
site: PropTypes.object.isRequired,
siteTitle: PropTypes.string,
translate: PropTypes.func.isRequired,
};

static defaultProps = {
fields: {},
isDeleting: false,
isMultisite: false,
siteTitle: '',
};

state = {
Expand All @@ -64,13 +71,13 @@ class ContentsTab extends Component {

const {
isSuccessful,
site,
siteTitle,
translate,
} = this.props;

if ( isSuccessful ) {
this.props.successNotice(
translate( 'Cache stats regenerated on %(site)s.', { args: { site: site && site.title } } ),
translate( 'Cache stats regenerated on %(site)s.', { args: { site: siteTitle } } ),
{ id: 'wpsc-cache-stats' }
);
} else {
Expand Down Expand Up @@ -246,10 +253,14 @@ const connectComponent = connect(
const stats = getStats( state, siteId );
const isGenerating = isGeneratingStats( state, siteId );
const isSuccessful = isStatsGenerationSuccessful( state, siteId );
const isMultisite = isJetpackSiteMultiSite( state, siteId );
const siteTitle = getSiteTitle( state, siteId );

return {
isGenerating,
isMultisite,
isSuccessful,
siteTitle,
stats,
};
},
Expand Down
10 changes: 4 additions & 6 deletions client/extensions/wp-super-cache/directly-cached-files.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ class DirectlyCachedFiles extends Component {
isRequesting,
isSaving,
setFieldArrayValue,
siteUrl,
site,
translate
} = this.props;
const {
cache_direct_pages = [],
cache_path,
} = fields;
const cache_direct_pages = fields.cache_direct_pages || [];
const cache_path = fields.cache_path || '';
const notices = pick( this.props.notices, [
'cache_readonly',
'cache_writable',
Expand Down Expand Up @@ -98,7 +96,7 @@ class DirectlyCachedFiles extends Component {
'For example: to cache {{em}}%(url)s/about/{{/em}}, you would enter %(url)s/about/ or /about/. ' +
'The cached file will be generated the next time an anonymous user visits that page.',
{
args: { url: siteUrl },
args: { url: site && site.URL },
components: { em: <em /> },
}
) }
Expand Down
2 changes: 0 additions & 2 deletions client/extensions/wp-super-cache/easy-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class EasyTab extends Component {
isSaving: PropTypes.bool,
isTesting: PropTypes.bool,
site: PropTypes.object.isRequired,
siteId: PropTypes.number.isRequired,
testCache: PropTypes.func.isRequired,
translate: PropTypes.func.isRequired,
};

Expand Down
8 changes: 4 additions & 4 deletions client/extensions/wp-super-cache/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const WPSuperCache = ( { site, tab } ) => {
const renderTab = () => {
switch ( tab ) {
case Tabs.ADVANCED:
return <AdvancedTab siteUrl={ site.URL } />;
return <AdvancedTab />;
case Tabs.CDN:
return <CdnTab siteUrl={ site.URL } />;
return <CdnTab />;
case Tabs.CONTENTS:
return <ContentsTab isMultisite={ site.is_multisite } />;
return <ContentsTab />;
case Tabs.PRELOAD:
return <PreloadTab />;
default:
return <EasyTab site={ site } />;
return <EasyTab />;
}
};

Expand Down
8 changes: 5 additions & 3 deletions client/extensions/wp-super-cache/navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const Navigation = ( { activeTab, site, translate } ) => {
path = `${ path }/${ tab }`;
}

path += `/${ site.slug }`;
if ( site ) {
path += `/${ site.slug }`;
}

return (
<SectionNavTabItem
Expand All @@ -72,12 +74,12 @@ const Navigation = ( { activeTab, site, translate } ) => {

Navigation.propTypes = {
activeTab: PropTypes.string,
site: React.PropTypes.object.isRequired,
site: PropTypes.object,
translate: PropTypes.func.isRequired,
};

Navigation.defaultProps = {
activeTab: ''
activeTab: '',
};

export default localize( Navigation );
14 changes: 7 additions & 7 deletions client/extensions/wp-super-cache/preload-tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ class PreloadTab extends Component {
onChange={ this.handlePreloadRefreshChange }>
<span>
{ translate(
'Refresh preloaded cache files every {{number /}} minute. ',
'Refresh preloaded cache files every {{number /}} minutes. ',
'Refresh preloaded cache files every {{number /}} minute ',
'Refresh preloaded cache files every {{number /}} minutes ',
{
count: preload_interval,
count: preload_interval || 0,
components: {
number: renderCachePreloadInterval( {
handleChange,
Expand All @@ -166,11 +166,11 @@ class PreloadTab extends Component {
) }

{ translate(
'(minimum %d minute)',
'(minimum %d minutes)',
'(minimum %(minutes)d minute).',
'(minimum %(minutes)d minutes).',
{
args: minimum_preload_interval,
count: minimum_preload_interval,
args: { minutes: minimum_preload_interval || 0 },
count: minimum_preload_interval || 0,
}
) }
</span>
Expand Down

0 comments on commit 6633f67

Please sign in to comment.