Skip to content

Commit 33618f8

Browse files
authored
Hosting Dashboard: Add Settings Database (#103663)
1 parent a82a129 commit 33618f8

File tree

6 files changed

+140
-0
lines changed

6 files changed

+140
-0
lines changed

client/dashboard/app/router.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ const siteSettingsSubscriptionGiftingRoute = createRoute( {
152152
)
153153
);
154154

155+
const siteSettingsDatabaseRoute = createRoute( {
156+
getParentRoute: () => siteRoute,
157+
path: 'settings/database',
158+
} ).lazy( () =>
159+
import( '../sites/settings-database' ).then( ( d ) =>
160+
createLazyRoute( 'site-settings-database' )( {
161+
component: () => <d.default siteSlug={ siteRoute.useParams().siteSlug } />,
162+
} )
163+
)
164+
);
165+
155166
const siteSettingsWordPressRoute = createRoute( {
156167
getParentRoute: () => siteRoute,
157168
path: 'settings/wordpress',
@@ -345,6 +356,7 @@ const createRouteTree = ( config: AppConfig ) => {
345356
siteSettingsRoute,
346357
siteSettingsSiteVisibilityRoute,
347358
siteSettingsSubscriptionGiftingRoute,
359+
siteSettingsDatabaseRoute,
348360
siteSettingsWordPressRoute,
349361
siteSettingsTransferSiteRoute,
350362
] )

client/dashboard/data/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
BasicMetricsData,
1515
SiteSettings,
1616
UrlPerformanceInsights,
17+
PhpMyAdminToken,
1718
} from './types';
1819

1920
export const fetchProfile = async (): Promise< Profile > => {
@@ -371,3 +372,10 @@ export const fetchPerformanceInsights = async (
371372
{ url, advance: '1', hash: token }
372373
);
373374
};
375+
376+
export const fetchPhpMyAdminToken = async ( siteIdOrSlug: string ): Promise< PhpMyAdminToken > => {
377+
return wpcom.req.post( {
378+
path: `/sites/${ siteIdOrSlug }/hosting/pma/token`,
379+
apiNamespace: 'wpcom/v2',
380+
} );
381+
};

client/dashboard/data/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,7 @@ export interface UrlPerformanceInsights {
169169
status: string;
170170
};
171171
}
172+
173+
export interface PhpMyAdminToken {
174+
token: string;
175+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { useQuery } from '@tanstack/react-query';
2+
import {
3+
__experimentalHStack as HStack,
4+
__experimentalText as Text,
5+
__experimentalVStack as VStack,
6+
Button,
7+
Card,
8+
CardBody,
9+
Notice,
10+
} from '@wordpress/components';
11+
import { useDispatch } from '@wordpress/data';
12+
import { __ } from '@wordpress/i18n';
13+
import { store as noticesStore } from '@wordpress/notices';
14+
import { useState } from 'react';
15+
import { siteQuery } from '../../app/queries';
16+
import PageLayout from '../../components/page-layout';
17+
import { fetchPhpMyAdminToken } from '../../data';
18+
import SettingsPageHeader from '../settings-page-header';
19+
import type { Site } from '../../data/types';
20+
21+
export function canOpenPhpMyAdmin( site: Site ) {
22+
return site.is_wpcom_atomic;
23+
}
24+
25+
export default function SiteDatabaseSettings( { siteSlug }: { siteSlug: string } ) {
26+
const { data: site } = useQuery( siteQuery( siteSlug ) );
27+
const { createErrorNotice } = useDispatch( noticesStore );
28+
const [ isFetchingToken, setIsFetchingToken ] = useState( false );
29+
30+
if ( ! site || ! canOpenPhpMyAdmin( site ) ) {
31+
return null;
32+
}
33+
34+
const handleOpenPhpMyAdmin = async () => {
35+
setIsFetchingToken( true );
36+
37+
try {
38+
const { token } = await fetchPhpMyAdminToken( siteSlug );
39+
if ( ! token ) {
40+
throw new Error( 'No token found' );
41+
}
42+
43+
window.open( `https://wordpress.com/pma-login?token=${ token }` );
44+
} catch {
45+
createErrorNotice( __( 'Failed to fetch phpMyAdmin token.' ), { type: 'snackbar' } );
46+
}
47+
48+
setIsFetchingToken( false );
49+
};
50+
51+
return (
52+
<PageLayout
53+
size="small"
54+
header={
55+
<SettingsPageHeader
56+
title={ __( 'Database' ) }
57+
description={ __(
58+
'For the tech-savvy, manage your database with phpMyAdmin and run a wide range of operations with MySQL.'
59+
) }
60+
/>
61+
}
62+
>
63+
<Card>
64+
<CardBody>
65+
<VStack spacing={ 4 }>
66+
<VStack spacing={ 2 }>
67+
<Text size="15px" weight={ 500 } lineHeight="20px">
68+
phpMyAdmin
69+
</Text>
70+
<Text variant="muted" lineHeight="20px">
71+
{ __(
72+
'phpMyAdmin is a free open source software tool that allows you to administer your site’s MySQL database over the Web.'
73+
) }
74+
</Text>
75+
</VStack>
76+
<VStack>
77+
<Notice isDismissible={ false }>
78+
{ __(
79+
'Managing a database can be tricky and it’s not necessary for your site to function.'
80+
) }
81+
</Notice>
82+
</VStack>
83+
<HStack justify="flex-start" expanded={ false } as="span">
84+
<Button variant="primary" isBusy={ isFetchingToken } onClick={ handleOpenPhpMyAdmin }>
85+
{ __( 'Open phpMyAdmin ↗' ) }
86+
</Button>
87+
</HStack>
88+
</VStack>
89+
</CardBody>
90+
</Card>
91+
</PageLayout>
92+
);
93+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Icon } from '@wordpress/components';
2+
import { __ } from '@wordpress/i18n';
3+
import { blockTable } from '@wordpress/icons';
4+
import RouterLinkSummaryButton from '../../components/router-link-summary-button';
5+
import { canOpenPhpMyAdmin } from './index';
6+
import type { Site } from '../../data/types';
7+
8+
export default function DatabaseSettingsSummary( { site }: { site: Site } ) {
9+
if ( ! canOpenPhpMyAdmin( site ) ) {
10+
return null;
11+
}
12+
13+
return (
14+
<RouterLinkSummaryButton
15+
to={ `/sites/${ site.slug }/settings/database` }
16+
title={ __( 'Database' ) }
17+
density="medium"
18+
decoration={ <Icon icon={ blockTable } /> }
19+
/>
20+
);
21+
}

client/dashboard/sites/settings/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { __ } from '@wordpress/i18n';
88
import { siteQuery, siteSettingsQuery } from '../../app/queries';
99
import { PageHeader } from '../../components/page-header';
1010
import PageLayout from '../../components/page-layout';
11+
import DatabaseSettingsSummary from '../settings-database/summary';
1112
import SiteVisibilitySettingsSummary from '../settings-site-visibility/summary';
1213
import SubscriptionGiftingSettingsSummary from '../settings-subscription-gifting/summary';
1314
import WordPressSettingsSummary from '../settings-wordpress/summary';
@@ -34,6 +35,7 @@ export default function SiteSettings( { siteSlug }: { siteSlug: string } ) {
3435
<Heading>{ __( 'Server' ) }</Heading>
3536
<Card>
3637
<VStack>
38+
<DatabaseSettingsSummary site={ site } />
3739
<WordPressSettingsSummary site={ site } />
3840
</VStack>
3941
</Card>

0 commit comments

Comments
 (0)