Skip to content

Commit 179150d

Browse files
committed
Use a loose CLI config schema and render runtime copy as components
1 parent 6f34ea1 commit 179150d

6 files changed

Lines changed: 64 additions & 50 deletions

File tree

‎apps/cli/lib/cli-config/core.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const updateCheckSchema = z.object( {
3636
latestVersion: z.string(),
3737
} );
3838

39-
const cliConfigSchema = z.object( {
39+
const cliConfigSchema = z.looseObject( {
4040
version: z.literal( CLI_CONFIG_VERSION ),
4141
sites: z.array( siteSchema ).default( () => [] ),
4242
snapshots: z.array( snapshotSchema ).default( () => [] ),

‎apps/studio/src/components/content-tab-settings.tsx‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { useDeleteSite } from 'src/hooks/use-delete-site';
2222
import { useGetWpVersion } from 'src/hooks/use-get-wp-version';
2323
import { useSiteDetails } from 'src/hooks/use-site-details';
2424
import { getIpcApi } from 'src/lib/get-ipc-api';
25-
import { getFileAccessDescription, getRuntimeDescription } from 'src/lib/site-runtime-copy';
25+
import { FileAccessDescription, RuntimeDescription } from 'src/lib/site-runtime-copy';
2626
import EditSiteDetails from 'src/modules/site-settings/edit-site-details';
2727
import { useAppDispatch } from 'src/stores';
2828
import {
@@ -50,12 +50,6 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
5050
const { __ } = useI18n();
5151
const { data: isCertificateTrusted } = useCheckCertificateTrustQuery();
5252
const isNativePhpRuntime = getSiteRuntime( selectedSite ) === SITE_RUNTIME_NATIVE_PHP;
53-
const runtimeDescription = getRuntimeDescription( __, getSiteRuntime( selectedSite ) );
54-
const fileAccessDescription = getFileAccessDescription(
55-
__,
56-
getSiteRuntime( selectedSite ),
57-
getSiteFileAccess( selectedSite )
58-
);
5953
const username = selectedSite.adminUsername || 'admin';
6054
// Empty strings account for legacy sites lacking a stored password.
6155
const storedPassword = decodePassword( selectedSite.adminPassword ?? '' );
@@ -213,7 +207,10 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
213207
<div className="inline-flex items-center gap-2">
214208
{ /* translators: value for the PHP runtime setting on the site settings screen */ }
215209
<span>{ isNativePhpRuntime ? __( 'Native' ) : __( 'Sandbox' ) }</span>
216-
<Tooltip text={ runtimeDescription } placement="top-start">
210+
<Tooltip
211+
text={ <RuntimeDescription runtime={ getSiteRuntime( selectedSite ) } /> }
212+
placement="top-start"
213+
>
217214
<span
218215
role="img"
219216
aria-label={ __( 'About the PHP runtime setting' ) }
@@ -233,7 +230,15 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
233230
? __( 'All files' )
234231
: __( 'Site directory' ) }
235232
</span>
236-
<Tooltip text={ fileAccessDescription } placement="top-start">
233+
<Tooltip
234+
text={
235+
<FileAccessDescription
236+
runtime={ getSiteRuntime( selectedSite ) }
237+
fileAccess={ getSiteFileAccess( selectedSite ) }
238+
/>
239+
}
240+
placement="top-start"
241+
>
237242
<span
238243
role="img"
239244
aria-label={ __( 'About the file access setting' ) }

‎apps/studio/src/lib/site-runtime-copy.ts‎

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
SITE_FILE_ACCESS_ALL_FILES,
3+
type SiteFileAccess,
4+
} from '@studio/common/lib/site-file-access';
5+
import { SITE_RUNTIME_PLAYGROUND, type SiteRuntime } from '@studio/common/lib/site-runtime';
6+
import { useI18n } from '@wordpress/react-i18n';
7+
8+
// Explainer copy shown under the PHP runtime control in the create/edit site
9+
// forms and in the read-only site settings.
10+
export function RuntimeDescription( { runtime }: { runtime: SiteRuntime } ) {
11+
const { __ } = useI18n();
12+
return (
13+
<>
14+
{ runtime === SITE_RUNTIME_PLAYGROUND
15+
? __( 'Runs the site in an isolated WordPress Playground sandbox.' )
16+
: __( 'Runs the site with native PHP for the best performance.' ) }
17+
</>
18+
);
19+
}
20+
21+
// Explainer copy shown under the File access control in the create/edit site
22+
// forms and in the read-only site settings.
23+
export function FileAccessDescription( {
24+
runtime,
25+
fileAccess,
26+
}: {
27+
runtime: SiteRuntime;
28+
fileAccess: SiteFileAccess;
29+
} ) {
30+
const { __ } = useI18n();
31+
if ( runtime === SITE_RUNTIME_PLAYGROUND ) {
32+
return <>{ __( 'The sandbox can only access the site directory.' ) }</>;
33+
}
34+
if ( fileAccess === SITE_FILE_ACCESS_ALL_FILES ) {
35+
return <>{ __( 'PHP can access any file on your system.' ) }</>;
36+
}
37+
return <>{ __( "Restricts the site's file access to the site directory." ) }</>;
38+
}

‎apps/studio/src/modules/add-site/components/create-site-form.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { SiteFormError } from 'src/components/site-form-error';
3737
import TextControlComponent from 'src/components/text-control';
3838
import { WPVersionSelector } from 'src/components/wp-version-selector';
3939
import { cx } from 'src/lib/cx';
40-
import { getFileAccessDescription } from 'src/lib/site-runtime-copy';
40+
import { FileAccessDescription } from 'src/lib/site-runtime-copy';
4141
import { useCheckCertificateTrustQuery } from 'src/stores/certificate-trust-api';
4242
import type { BlueprintPreferredVersions } from '@studio/common/lib/blueprint-validation';
4343
import type { CreateSiteFormValues, PathValidationResult } from 'src/hooks/use-add-site';
@@ -112,7 +112,6 @@ export const CreateSiteForm = ( {
112112
selectedRuntime === SITE_RUNTIME_PLAYGROUND
113113
? SITE_FILE_ACCESS_SITE_DIRECTORY
114114
: selectedFileAccess;
115-
const fileAccessDescription = getFileAccessDescription( __, selectedRuntime, usedFileAccess );
116115
const [ useCustomDomain, setUseCustomDomain ] = useState( false );
117116
const [ customDomain, setCustomDomain ] = useState< string | null >( null );
118117
const [ enableHttps, setEnableHttps ] = useState( false );
@@ -570,7 +569,10 @@ export const CreateSiteForm = ( {
570569
__nextHasNoMarginBottom
571570
/>
572571
<span className="text-frame-text-secondary text-xs">
573-
{ fileAccessDescription }
572+
<FileAccessDescription
573+
runtime={ selectedRuntime }
574+
fileAccess={ usedFileAccess }
575+
/>
574576
</span>
575577
</div>
576578
</div>

‎apps/studio/src/modules/site-settings/edit-site-details.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { WPVersionSelector } from 'src/components/wp-version-selector';
4646
import { useSiteDetails } from 'src/hooks/use-site-details';
4747
import { cx } from 'src/lib/cx';
4848
import { getIpcApi } from 'src/lib/get-ipc-api';
49-
import { getFileAccessDescription, getRuntimeDescription } from 'src/lib/site-runtime-copy';
49+
import { FileAccessDescription, RuntimeDescription } from 'src/lib/site-runtime-copy';
5050
import { useCheckCertificateTrustQuery } from 'src/stores/certificate-trust-api';
5151

5252
type EditSiteDetailsProps = {
@@ -99,7 +99,6 @@ const EditSiteDetails = ( { currentWpVersion, onSave }: EditSiteDetailsProps ) =
9999
selectedRuntime === SITE_RUNTIME_PLAYGROUND
100100
? SITE_FILE_ACCESS_SITE_DIRECTORY
101101
: selectedFileAccess;
102-
const fileAccessDescription = getFileAccessDescription( __, selectedRuntime, usedFileAccess );
103102
const selectedSitePhpVersion = selectedSite?.phpVersion;
104103
const resolvedSitePhpVersion = resolvePhpVersion( selectedSitePhpVersion );
105104
const phpVersionWarning =
@@ -480,7 +479,7 @@ const EditSiteDetails = ( { currentWpVersion, onSave }: EditSiteDetailsProps ) =
480479
__nextHasNoMarginBottom
481480
/>
482481
<span className="text-frame-text-secondary text-xs">
483-
{ getRuntimeDescription( __, selectedRuntime ) }
482+
<RuntimeDescription runtime={ selectedRuntime } />
484483
</span>
485484
</label>
486485

@@ -507,7 +506,10 @@ const EditSiteDetails = ( { currentWpVersion, onSave }: EditSiteDetailsProps ) =
507506
__nextHasNoMarginBottom
508507
/>
509508
<span className="text-frame-text-secondary text-xs">
510-
{ fileAccessDescription }
509+
<FileAccessDescription
510+
runtime={ selectedRuntime }
511+
fileAccess={ usedFileAccess }
512+
/>
511513
</span>
512514
</label>
513515
</div>

0 commit comments

Comments
 (0)