File size: 6,699 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 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 |
import { isEnabled } from '@automattic/calypso-config';
import page from '@automattic/calypso-router';
import { __ } from '@wordpress/i18n';
import { useSelector } from 'react-redux';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { fetchSiteFeatures } from 'calypso/state/sites/features/actions';
import { isSimpleSite } from 'calypso/state/sites/selectors';
import { getSelectedSite, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { getRouteFromContext } from 'calypso/utils';
import { SidebarItem, Sidebar, PanelWithSidebar } from '../components/panel-sidebar';
import { useBreadcrumbs } from '../hooks/breadcrumbs/use-breadcrumbs';
import {
areAdvancedHostingFeaturesSupported,
areHostingFeaturesSupported,
useAreAdvancedHostingFeaturesSupported,
useAreHostingFeaturesSupported,
} from '../hosting/features';
import DashboardBackportSiteSettingsRenderer from '../v2/site-settings';
import DeleteSite from './administration/tools/delete-site';
import ResetSite from './administration/tools/reset-site';
import TransferSite from './administration/tools/transfer-site';
import DatabaseSettings from './database';
import PerformanceSettings from './performance';
import ServerSettings from './server';
import SftpSshSettings from './sftp-ssh';
import useSftpSshSettingTitle from './sftp-ssh/hooks/use-sftp-ssh-setting-title';
import SiteSettings from './site';
import type { Context as PageJSContext } from '@automattic/calypso-router';
export function SettingsSidebar() {
const slug = useSelector( getSelectedSiteSlug );
const isSimple = useSelector( isSimpleSite );
const sftpSshTitle = useSftpSshSettingTitle();
const areHostingFeaturesSupported = useAreHostingFeaturesSupported();
const areAdvancedHostingFeaturesSupported = useAreAdvancedHostingFeaturesSupported();
const { shouldShowBreadcrumbs } = useBreadcrumbs();
if ( isSimple || shouldShowBreadcrumbs ) {
return null;
}
return (
<Sidebar>
<SidebarItem href={ `/sites/settings/site/${ slug }` }>{ __( 'General' ) }</SidebarItem>
{ areAdvancedHostingFeaturesSupported && [
<SidebarItem key="server" href={ `/sites/settings/server/${ slug }` }>
{ __( 'Server' ) }
</SidebarItem>,
<SidebarItem key="sftp-ssh" href={ `/sites/settings/sftp-ssh/${ slug }` }>
{ sftpSshTitle }
</SidebarItem>,
<SidebarItem key="database" href={ `/sites/settings/database/${ slug }` }>
{ __( 'Database' ) }
</SidebarItem>,
] }
{ areHostingFeaturesSupported && (
<SidebarItem href={ `/sites/settings/performance/${ slug }` }>
{ __( 'Performance' ) }
</SidebarItem>
) }
</Sidebar>
);
}
export function redirectToSiteSettingsIfHostingFeaturesNotSupported(
context: PageJSContext,
next: () => void
) {
const state = context.store.getState();
const site = getSelectedSite( state );
if ( ! areHostingFeaturesSupported( site ) ) {
return page.redirect( `/sites/settings/site/${ site?.slug }` );
}
next();
}
export function redirectToSiteSettingsIfAdvancedHostingFeaturesNotSupported(
context: PageJSContext,
next: () => void
) {
const state = context.store.getState();
const site = getSelectedSite( state );
const dispatch = context.store.dispatch;
if ( ! site?.ID ) {
return next();
}
dispatch( fetchSiteFeatures( site?.ID ) ).then( () => {
const isSupported = areAdvancedHostingFeaturesSupported( context.store.getState() );
if ( isSupported === false ) {
return page.redirect( `/sites/settings/site/${ site?.slug }` );
}
next();
} );
}
export function siteSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker title="Sites > Settings > General" path={ getRouteFromContext( context ) } />
<SettingsSidebar />
<SiteSettings />
</PanelWithSidebar>
);
next();
}
export function administrationToolResetSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Reset site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<ResetSite />
</PanelWithSidebar>
);
next();
}
export function administrationToolTransferSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Transfer site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<TransferSite />
</PanelWithSidebar>
);
next();
}
export function administrationToolDeleteSite( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Delete site"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<DeleteSite />
</PanelWithSidebar>
);
next();
}
export function serverSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker title="Sites > Settings > Server" path={ getRouteFromContext( context ) } />
<SettingsSidebar />
<ServerSettings />
</PanelWithSidebar>
);
next();
}
export function sftpSshSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > SFTP/SSH"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<SftpSshSettings />
</PanelWithSidebar>
);
next();
}
export function databaseSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Database"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<DatabaseSettings />
</PanelWithSidebar>
);
next();
}
export function performanceSettings( context: PageJSContext, next: () => void ) {
context.primary = (
<PanelWithSidebar>
<PageViewTracker
title="Sites > Settings > Performance"
path={ getRouteFromContext( context ) }
/>
<SettingsSidebar />
<PerformanceSettings />
</PanelWithSidebar>
);
next();
}
/**
* Backport Hosting Dashboard Site Settings page to the current one.
*/
export async function dashboardBackportSiteSettings( context: PageJSContext, next: () => void ) {
const { site: siteSlug, feature } = context.params;
if ( ! isEnabled( 'dashboard/v2/backport/site-settings' ) ) {
return page.redirect( `/sites/settings/site/${ siteSlug }` );
}
// Route doesn't require a <PageViewTracker /> because the dashboard
// fires its own page view events.
context.primary = (
<DashboardBackportSiteSettingsRenderer
store={ context.store }
siteSlug={ siteSlug }
feature={ feature }
/>
);
next();
}
|