File size: 5,656 Bytes
1e92f2d | 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 | import { localize, getLocaleSlug } from 'i18n-calypso';
import moment from 'moment';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import titlecase from 'to-title-case';
import SitePreview from 'calypso/blocks/site-preview';
import DocumentHead from 'calypso/components/data/document-head';
import InlineSupportLink from 'calypso/components/inline-support-link';
import { JetpackConnectionHealthBanner } from 'calypso/components/jetpack/connection-health';
import Main from 'calypso/components/main';
import NavigationHeader from 'calypso/components/navigation-header';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { Experiment } from 'calypso/lib/explat';
import { mapPostStatus } from 'calypso/lib/route';
import urlSearch from 'calypso/lib/url-search';
import PostTypeFilter from 'calypso/my-sites/post-type-filter';
import { withJetpackConnectionProblem } from 'calypso/state/jetpack-connection-health/selectors/is-jetpack-connection-problem.js';
import { getPostTypeLabel } from 'calypso/state/post-types/selectors';
import { POST_STATUSES } from 'calypso/state/posts/constants';
import isJetpackSite from 'calypso/state/sites/selectors/is-jetpack-site';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import PageList from './page-list';
import './style.scss';
class PagesMain extends Component {
static displayName = 'Pages';
static propTypes = {
status: PropTypes.string,
search: PropTypes.string,
};
getAnalyticsPath() {
const { status, siteId } = this.props;
const basePath = '/pages';
if ( siteId && status ) {
return `${ basePath }/${ status }/:site`;
}
if ( status ) {
return `${ basePath }/${ status }`;
}
if ( siteId ) {
return `${ basePath }/:site`;
}
return basePath;
}
getAnalyticsTitle() {
const { status } = this.props;
if ( status && status.length ) {
return `Pages > ${ titlecase( status ) }`;
}
return 'Pages > Published';
}
render() {
const {
isJetpack,
isPossibleJetpackConnectionProblem,
siteId,
search,
status,
translate,
queryType,
author,
} = this.props;
const postStatus = mapPostStatus( status );
/* Check if All Sites Mode */
const isAllSites = siteId ? 1 : 0;
const query = {
// all-sites mode, i.e the /me/posts endpoint, only supports up to 20 results at a time
// however, /sites/$site/posts/ endpoint used for single site supports up to 100,
// let's utilize that to load hierarchical view by default for most of the sites
number: siteId ? 50 : 20,
search,
site_visibility: ! siteId ? 'visible' : undefined,
author,
// When searching, search across all statuses so the user can
// always find what they are looking for, regardless of what tab
// the search was initiated from. Use POST_STATUSES rather than
// "any" to do this, since the latter excludes trashed posts.
status: search ? POST_STATUSES.join( ',' ) : postStatus,
type: queryType,
};
const listKey = [ siteId, status, search ].join( '-' );
return (
<Main wideLayout classname="pages">
<PageViewTracker path={ this.getAnalyticsPath() } title={ this.getAnalyticsTitle() } />
{ isJetpack && isPossibleJetpackConnectionProblem && (
<JetpackConnectionHealthBanner siteId={ siteId } />
) }
<DocumentHead title={ translate( 'Pages' ) } />
<SitePreview />
<NavigationHeader
screenOptionsTab="edit.php?post_type=page"
navigationItems={ [] }
title={ translate( 'Pages' ) }
subtitle={ translate(
'Create, edit, and manage the pages on your site. {{learnMoreLink}}Learn more{{/learnMoreLink}}.',
'Create, edit, and manage the pages on your sites. {{learnMoreLink}}Learn more{{/learnMoreLink}}.',
{
count: isAllSites,
components: {
learnMoreLink: <InlineSupportLink supportContext="pages" showIcon={ false } />,
},
}
) }
/>
<PostTypeFilter query={ query } siteId={ siteId } statusSlug={ status } />
<PageList
key={ listKey }
siteId={ siteId }
status={ status }
search={ search }
query={ query }
/>
{ /* ExPlat's Evergreen A/A Test Experiment:
*
* This continually starts a new experiment every week that doesn't render anything and
* shouldn't send any extra requests, just to help us ensure our experimentation system is
* working smoothly.
*
* This particular spot isn't special, it just needs somewhere to live.
*
* We use iso-week and iso-week-year in order to consistently change the experiment name every week.
* Assumes users have a somewhat working clock but shouldn't be a problem if they don't.
*/ }
<Experiment
name={ `explat_test_aa_weekly_calypso_${ moment.utc().format( 'GGGG' ) }_week_${ moment
.utc()
.format( 'WW' ) }` }
defaultExperience={ null }
treatmentExperience={ null }
loadingExperience={ null }
/>
<Experiment
name="explat_test_aaaaa_2021_08_26_18_59"
defaultExperience={ null }
treatmentExperience={ null }
loadingExperience={ null }
/>
</Main>
);
}
}
const mapState = ( state ) => {
const queryType = 'page';
const siteId = getSelectedSiteId( state );
const searchPagesPlaceholder = getPostTypeLabel(
state,
siteId,
queryType,
'search_items',
getLocaleSlug( state )
);
return {
searchPagesPlaceholder,
queryType,
siteId,
isJetpack: isJetpackSite( state, siteId ),
};
};
export default connect( mapState )(
localize( withJetpackConnectionProblem( urlSearch( PagesMain ) ) )
);
|