Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: small adjustments
  • Loading branch information
nightnei committed Apr 10, 2025
commit 7fc4e8933268b950e15928d2fe1c93ca0923cc35
1 change: 0 additions & 1 deletion src/components/content-tab-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps )
const storedPassword = decodePassword( selectedSite.adminPassword ?? '' );
const password = storedPassword === '' ? 'password' : storedPassword;
const [ wpVersion, refreshWpVersion ] = useGetWpVersion( selectedSite );

const domain = selectedSite.customDomain
? `${ selectedSite.customDomain }`
: `localhost:${ selectedSite.port }`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const addWpVersionToList = ( newOption: Option, options: Option[] ): Opti

const firstOlderVersionIndex = options.findIndex( ( compareVersion ) => {
const compareVer = semver.coerce( compareVersion.value );

return compareVer && semver.gt( currentVer, compareVer );
} );

Expand Down
7 changes: 2 additions & 5 deletions src/components/wp-version-selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { DEFAULT_WORDPRESS_VERSION } from 'vendor/wp-now/src/constants';
import { addWpVersionToList } from './add-wp-version-to-list';

type WPVersionSelectorProps = {
siteWpVersion?: string;

selectedValue: string;
onChange: ( version: string ) => void;
errorMessage?: string | null;
disabled?: boolean;
// Is used if you want to add a custom option to the list, for example the current version of a site
extraOptions?: { label: string; value: string }[];
/** Fallback options shown when available versions couldn't be fetched */
fallbackOptions: { label: string; value: string }[];
};

Expand All @@ -31,7 +31,6 @@ export const WPVersionSelector = ( {
fallbackOptions,
}: WPVersionSelectorProps ) => {
const { __ } = useI18n();

const isOffline = useOffline();
const offlineMessage = __( 'Changing WordPress version requires an internet connection.' );
const { data: wpVersions = [] } = useGetWordPressVersions();
Expand All @@ -42,10 +41,8 @@ export const WPVersionSelector = ( {
let stableVersions: { label: string; value: string }[] = wpVersions.filter(
( version ) => ! version.isBeta && ! version.isDevelopment && version.value !== 'latest'
);

extraOptions?.forEach( ( extraOption ) => {
const alreadyExists = wpVersions.some( ( version ) => version.value === extraOption.value );

if ( alreadyExists ) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/hooks/use-add-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export function useAddSite() {
if ( useCustomDomain && ! customDomain ) {
usedCustomDomain = generateCustomDomainFromSiteName( siteName ?? '' );
}

await createSite(
path,
siteName ?? '',
Expand Down
17 changes: 7 additions & 10 deletions src/modules/site-settings/edit-site-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
const [ selectedPhpVersion, setSelectedPhpVersion ] = useState< AllowedPHPVersion >(
( selectedSite?.phpVersion as AllowedPHPVersion ) ?? DEFAULT_PHP_VERSION
);

const getAdjustedWpVersion = useCallback(
const getEffectiveWpVersion = useCallback(
() =>
// undefined means that this site was created before the isWpAutoUpdating option was introduced to Studio
[ undefined, true ].includes( selectedSite?.isWpAutoUpdating )
? DEFAULT_WORDPRESS_VERSION
: currentWpVersion,
[ selectedSite, currentWpVersion ]
);

const [ selectedWpVersion, setSelectedWpVersion ] = useState( getAdjustedWpVersion() );

const [ selectedWpVersion, setSelectedWpVersion ] = useState( getEffectiveWpVersion() );
const [ useCustomDomain, setUseCustomDomain ] = useState( Boolean( selectedSite?.customDomain ) );
const [ customDomain, setCustomDomain ] = useState< string | null >(
selectedSite?.customDomain ?? null
Expand Down Expand Up @@ -83,7 +80,7 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
!! selectedSite &&
selectedSite.name === siteName &&
selectedSite.phpVersion === selectedPhpVersion &&
getAdjustedWpVersion() === selectedWpVersion &&
getEffectiveWpVersion() === selectedWpVersion &&
Boolean( selectedSite.customDomain ) === useCustomDomain &&
usedCustomDomain === customDomain &&
!! selectedSite.enableHttps === ( !! usedCustomDomain && enableHttps );
Expand All @@ -96,13 +93,13 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
}
setSiteName( selectedSite.name );
setSelectedPhpVersion( selectedSite.phpVersion as AllowedPHPVersion );
setSelectedWpVersion( getAdjustedWpVersion() );
setSelectedWpVersion( getEffectiveWpVersion() );
setUseCustomDomain( Boolean( selectedSite.customDomain ) );
setCustomDomain( selectedSite.customDomain ?? null );
setCustomDomainError( '' );
setErrorUpdatingWpVersion( null );
setEnableHttps( selectedSite.enableHttps ?? false );
}, [ selectedSite, getAdjustedWpVersion ] );
}, [ selectedSite, getEffectiveWpVersion ] );

const onSiteEdit = async ( event: FormEvent ) => {
event.preventDefault();
Expand All @@ -112,7 +109,7 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
setIsEditingSite( true );
setErrorUpdatingWpVersion( null );

const hasWpVersionChanged = selectedWpVersion !== getAdjustedWpVersion();
const hasWpVersionChanged = selectedWpVersion !== getEffectiveWpVersion();
const hasPhpVersionChanged = selectedPhpVersion !== selectedSite.phpVersion;
const needsRestart = selectedSite.running && ( hasWpVersionChanged || hasPhpVersionChanged );
setNeedsRestart( needsRestart );
Expand Down Expand Up @@ -140,7 +137,7 @@ export default function EditSiteDetails( { currentWpVersion, onSave }: EditSiteD
title: __( 'Error changing WordPress version' ),
message: errorMessage,
} );
setSelectedWpVersion( getAdjustedWpVersion() );
setSelectedWpVersion( getEffectiveWpVersion() );
setIsEditingSite( false );
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/site-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function getAbsoluteUrl( details: SiteDetails ): string {
return `http://localhost:${ details.port }`;
}

// We use SiteDetails for storing it in appdata-v1.json, so this meta was introduced for extra data which is not stored locally
type SiteServerMeta = {
wpVersion?: string;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sejas This is only one point where I am not sure that it's the best approach. I am not very familiar with wpnow etc, so could you please take a look on my approach to say - is it good, or maybe it's better to go another way.

};
Expand Down
1 change: 1 addition & 0 deletions vendor/wp-now/src/execute-wp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function executeWPCli(

//Set the SAPI name to cli before running the script
await php.setSapiName( 'cli' );

await prepareWordPress( php, options );

php.mkdir( '/tmp' );
Expand Down