Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/Abstracts/Abstract_Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function get_category(): string {
* {@inheritDoc}
*/
final public function is_globally_enabled(): bool {
return (bool) get_option( Settings_Registration::GLOBAL_OPTION, false );
return (bool) get_option( Settings_Registration::GLOBAL_OPTION, true );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I've not tested things yet so I may be wrong but if someone currently has things set to be globally disabled, it seems like after this update there will be no way for them to actually enable things, since we're removing the UI.

So for new installs and existing installs that were already enabled, those should be fine. But existing installs that purposely disabled things, I think they'll be permanently stuck in that disabled state.

We use the result of this method in the is_enabled method and so that method will always return false in that scenario. And with no UI to enable things, the Settings_Registration::GLOBAL_OPTION value will never be updated.

Honestly not sure on the best approach here. We could change this method to always return true. We could remove this method all together. We could have an upgrade routine to set Settings_Registration::GLOBAL_OPTION to true. And probably other approaches as well I'm not thinking of right now

}

/**
Expand Down
108 changes: 7 additions & 101 deletions routes/ai-home/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
* WordPress dependencies
*/
import { Page } from '@wordpress/admin-ui';
import {
Button,
Card,
Icon,
Link,
Notice,
Popover,
Stack,
VisuallyHidden,
} from '@wordpress/ui';
import { Button, Card, Link, Notice, Stack } from '@wordpress/ui';
import {
DropdownMenu,
MenuGroup,
Expand All @@ -32,7 +23,6 @@ import { __, _n, sprintf } from '@wordpress/i18n';
import {
check as checkIcon,
download as downloadIcon,
info as infoIcon,
tool as toolIcon,
upload as uploadIcon,
} from '@wordpress/icons';
Expand Down Expand Up @@ -96,8 +86,6 @@ interface PageData {
}

const FEATURE_SETTING_PATTERN = /^wpai_feature_(.+)_enabled$/;
const GLOBAL_FIELD_ID = 'wpai_features_enabled';
const noop = () => {};

function isRecord( value: unknown ): value is Record< string, unknown > {
return typeof value === 'object' && value !== null;
Expand Down Expand Up @@ -270,40 +258,6 @@ const STABLE_FEATURE_DEFINITIONS: FeatureData[] = ( () => {
return unique;
} )();

interface InfoTipProps {
content: string;
}

function InfoTip( { content }: InfoTipProps ) {
const title = __( 'More information', 'ai' );

return (
<Popover.Root>
<Popover.Trigger
openOnHover
delay={ 200 }
closeDelay={ 200 }
aria-label={ title }
className="ai-settings-page__infotip-trigger"
>
<Icon icon={ infoIcon } size={ 20 } />
</Popover.Trigger>
<Popover.Popup
positioner={ <Popover.Positioner side="bottom" align="end" /> }
className="ai-settings-page__infotip-popover"
>
<Popover.Arrow />
<VisuallyHidden render={ <Popover.Title /> }>
{ title }
</VisuallyHidden>
<Popover.Description className="ai-settings-page__infotip-description">
{ content }
</Popover.Description>
</Popover.Popup>
</Popover.Root>
);
}

function buildToggleMessage(
edits: Record< string, unknown >,
featureDefinitions: FeatureData[]
Expand Down Expand Up @@ -362,11 +316,6 @@ function buildToggleMessage(
return __( 'Settings saved.', 'ai' );
}

if ( entry[ 0 ] === GLOBAL_FIELD_ID ) {
return entry[ 1 ]
? __( 'AI enabled.', 'ai' )
: __( 'AI disabled.', 'ai' );
}
const feature = featureDefinitions.find(
( f ) => f.settingName === entry[ 0 ]
);
Expand All @@ -378,29 +327,14 @@ function buildToggleMessage(
sprintf( __( '%s disabled.', 'ai' ), label );
}

function DisabledToggle( { field, data }: DataFormControlProps< AISettings > ) {
return (
<ToggleControl
label={ field.label }
help={ field.description }
checked={ !! field.getValue( { item: data } ) }
// No-op handler required to satisfy React's controlled-component warning; the toggle is disabled.
onChange={ noop }
disabled
/>
);
}

interface SectionActionsProps extends DataFormControlProps< AISettings > {
experimentSettings: string[];
globalEnabled: boolean;
onBulkChange: ( edits: Record< string, boolean > ) => void;
}

function SectionActions( {
experimentSettings,
data,
globalEnabled,
onBulkChange,
}: SectionActionsProps ) {
const allEnabled = useMemo( () => {
Expand Down Expand Up @@ -453,15 +387,15 @@ function SectionActions( {
variant="outline"
size="compact"
onClick={ handleEnableAll }
disabled={ ! globalEnabled || allEnabled }
disabled={ allEnabled }
>
{ __( 'Enable all', 'ai' ) }
</Button>
<Button
variant="outline"
size="compact"
onClick={ handleDisableAll }
disabled={ ! globalEnabled || allDisabled }
disabled={ allDisabled }
>
{ __( 'Disable all', 'ai' ) }
</Button>
Expand Down Expand Up @@ -661,16 +595,11 @@ function VisualCardToggle( {
onChange,
}: DataFormControlProps< AISettings > ) {
const feature = VISUAL_CARD_FEATURES.get( field.id );
const globalEnabled = !! data[ GLOBAL_FIELD_ID ];
const checked = !! field.getValue( { item: data } );
const isDeveloperMode = useDeveloperModeContext();

return (
<Card.Root
className={ `${
! globalEnabled ? ' ai-showcase-card--disabled' : ''
}` }
>
<Card.Root className="ai-showcase-card">
{ feature?.image && (
<img
alt={ feature.label }
Expand All @@ -685,10 +614,9 @@ function VisualCardToggle( {
onChange={ ( value ) =>
onChange( { [ field.id ]: value } )
}
disabled={ ! globalEnabled }
help={ field.description }
/>
{ globalEnabled && checked && isDeveloperMode && feature && (
{ checked && isDeveloperMode && feature && (
<DeveloperSettings
featureId={ feature.id }
capability={ feature.capability }
Expand Down Expand Up @@ -780,7 +708,7 @@ function AISettingsPage() {
);

const aiSettingKeys = useMemo( () => {
const settingKeys = new Set< string >( [ GLOBAL_FIELD_ID ] );
const settingKeys = new Set< string >();

for ( const feature of featureDefinitions ) {
settingKeys.add( feature.settingName );
Expand All @@ -797,12 +725,6 @@ function AISettingsPage() {
return aiSettings;
}, [ aiSettingKeys, editedRecord ] );

const globalEnabled = Boolean( data[ GLOBAL_FIELD_ID ] );
const globalToggleDescription = __(
'Control whether AI is enabled for your site. When disabled, all features and experiments will be inactive regardless of their individual settings.',
'ai'
);

const handleChange = useCallback(
async ( edits: Record< string, unknown > ) => {
const keys = Object.keys( edits );
Expand Down Expand Up @@ -874,7 +796,6 @@ function AISettingsPage() {
<SectionActions
{ ...props }
experimentSettings={ experimentSettings }
globalEnabled={ globalEnabled }
onBulkChange={ handleChange }
/>
),
Expand All @@ -892,8 +813,6 @@ function AISettingsPage() {

if ( VISUAL_CARD_FEATURES.has( feature.settingName ) ) {
baseField.Edit = VisualCardToggle;
} else if ( ! globalEnabled ) {
baseField.Edit = DisabledToggle;
} else if ( feature.settingsFields.length > 0 ) {
baseField.Edit = FeatureToggleWithSettings;
} else {
Expand All @@ -912,7 +831,7 @@ function AISettingsPage() {
} );

return [ ...sectionActionsFields, ...featureFields ];
}, [ featureDefinitions, featureGroups, globalEnabled, handleChange ] );
}, [ featureDefinitions, featureGroups, handleChange ] );

const form = useMemo< Form >( () => {
const showcaseChildren: string[] = [];
Expand Down Expand Up @@ -1019,19 +938,6 @@ function AISettingsPage() {
) }
actions={
<>
<Stack align="center" gap="xs">
<ToggleControl
label={ __( 'Enable AI', 'ai' ) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So we remove the display of the setting here but we don't actually remove the registration of the setting in includes/Settings/Settings_Registration.php. Should we?

checked={ globalEnabled }
onChange={ ( checked ) => {
void handleChange( {
[ GLOBAL_FIELD_ID ]: checked,
} );
} }
disabled={ isLoading }
/>
<InfoTip content={ globalToggleDescription } />
</Stack>
<Link
href="https://github.com/WordPress/ai/tree/develop/docs"
openInNewTab
Expand Down
4 changes: 0 additions & 4 deletions routes/ai-home/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ body:has(.ai-settings-page) .components-popover {
padding-top: var(--wpds-dimension-padding-sm);
}

.ai-showcase-card--disabled {
opacity: 0.6;
}

.ai-settings-page__loading {
flex-grow: 1;
min-height: calc(50vh); // Leave space for the page header.
Expand Down
27 changes: 13 additions & 14 deletions tests/e2e/specs/admin/import-export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
* Internal dependencies
*/
const {
disableExperiments,
enableExperiments,
disableExperiment,
visitSettingsPage,
} = require( '../../utils/helpers' );

Expand Down Expand Up @@ -174,11 +173,11 @@ test.describe( 'Settings import/export', () => {
admin,
page,
} ) => {
// Start with AI disabled so we can confirm cancelling leaves it untouched.
await disableExperiments( admin, page );
// Ensure Title Generation is disabled so we can confirm cancelling leaves it untouched.
await disableExperiment( admin, page, 'Title Generation' );

const filePath = writeTempExportFile( {
wpai_features_enabled: true,
'wpai_feature_title-generation_enabled': true,
} );
tempFiles.push( filePath );

Expand All @@ -194,20 +193,20 @@ test.describe( 'Settings import/export', () => {
await dialog.getByRole( 'button', { name: 'Cancel' } ).click();
await expect( dialog ).not.toBeVisible();

// Global AI toggle must remain disabled since the import was cancelled.
await expect( page.getByLabel( 'Enable AI' ) ).not.toBeChecked();
// Title Generation toggle must remain disabled since the import was cancelled.
await expect( page.getByLabel( 'Title Generation' ) ).not.toBeChecked();
} );

test( 'Confirming the import applies settings without a page reload', async ( {
admin,
page,
} ) => {
// Start with AI disabled so the imported value is a visible change.
await disableExperiments( admin, page );
await expect( page.getByLabel( 'Enable AI' ) ).not.toBeChecked();
// Ensure Title Generation is disabled so the imported value is a visible change.
await disableExperiment( admin, page, 'Title Generation' );
await expect( page.getByLabel( 'Title Generation' ) ).not.toBeChecked();

const filePath = writeTempExportFile( {
wpai_features_enabled: true,
'wpai_feature_title-generation_enabled': true,
} );
tempFiles.push( filePath );

Expand All @@ -234,12 +233,12 @@ test.describe( 'Settings import/export', () => {
// The toggle should reflect the imported value immediately, with no
// manual page reload required (regression guard for the stale
// core-data cache/infinite-spinner issue).
await expect( page.getByLabel( 'Enable AI' ) ).toBeChecked( {
await expect( page.getByLabel( 'Title Generation' ) ).toBeChecked( {
timeout: 10000,
} );

// Cleanup.
await enableExperiments( admin, page );
// Cleanup: restore Title Generation to disabled.
await disableExperiment( admin, page, 'Title Generation' );
} );

test( 'Rejects an invalid file and shows an error notice', async ( {
Expand Down
Loading
Loading