-
Notifications
You must be signed in to change notification settings - Fork 189
Remove Enable AI header toggle #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wprashed
wants to merge
11
commits into
WordPress:develop
Choose a base branch
from
wprashed:fix/600-remove-enable-ai-header-toggle
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0103fed
Remove Enable AI header toggle
wprashed 62dcac0
Fix JS linter and formatting errors
wprashed ff48299
Merge branch 'develop' into fix/600-remove-enable-ai-header-toggle
wprashed 9635c72
Remove globalEnabled checks and update E2E tests for #600
wprashed f223de0
Default is_globally_enabled to true and persist global enabled in ena…
wprashed 317cb0a
Fix race condition in bulk experiment toggling and update import test…
wprashed c3b4de5
Merge branch 'upstream/develop' into fix/600-remove-enable-ai-header-…
wprashed b9f4c09
Fix E2E test helpers and remove obsolete global AI test
wprashed 41cbb0e
Fix E2E import-export setting name, snackbar viewport, and test isola…
wprashed 6178fa8
Merge branch 'develop' into fix/600-remove-enable-ai-header-toggle
dkotter e3cf1ae
Merge branch 'develop' into fix/600-remove-enable-ai-header-toggle
jeffpaul 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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'; | ||
|
|
@@ -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; | ||
|
|
@@ -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[] | ||
|
|
@@ -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 ] | ||
| ); | ||
|
|
@@ -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( () => { | ||
|
|
@@ -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> | ||
|
|
@@ -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 } | ||
|
|
@@ -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 } | ||
|
|
@@ -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 ); | ||
|
|
@@ -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 ); | ||
|
|
@@ -874,7 +796,6 @@ function AISettingsPage() { | |
| <SectionActions | ||
| { ...props } | ||
| experimentSettings={ experimentSettings } | ||
| globalEnabled={ globalEnabled } | ||
| onBulkChange={ handleChange } | ||
| /> | ||
| ), | ||
|
|
@@ -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 { | ||
|
|
@@ -912,7 +831,7 @@ function AISettingsPage() { | |
| } ); | ||
|
|
||
| return [ ...sectionActionsFields, ...featureFields ]; | ||
| }, [ featureDefinitions, featureGroups, globalEnabled, handleChange ] ); | ||
| }, [ featureDefinitions, featureGroups, handleChange ] ); | ||
|
|
||
| const form = useMemo< Form >( () => { | ||
| const showcaseChildren: string[] = []; | ||
|
|
@@ -1019,19 +938,6 @@ function AISettingsPage() { | |
| ) } | ||
| actions={ | ||
| <> | ||
| <Stack align="center" gap="xs"> | ||
| <ToggleControl | ||
| label={ __( 'Enable AI', 'ai' ) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_enabledmethod and so that method will always return false in that scenario. And with no UI to enable things, theSettings_Registration::GLOBAL_OPTIONvalue 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_OPTIONto true. And probably other approaches as well I'm not thinking of right now