Skip to content
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

Add editor preference for default state of Link UI settings drawer #52321

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useRef, useState, useEffect } from '@wordpress/element';
import { focus } from '@wordpress/dom';
import { ENTER } from '@wordpress/keycodes';
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
import { store as preferencesStore } from '@wordpress/preferences';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -133,14 +135,33 @@ function LinkControl( {
withCreateSuggestion = true;
}

const { settingsDrawerStatePreference } = useSelect( ( select ) => {
const prefsStore = select( preferencesStore );

const postEditorEnabled =
prefsStore.get( 'core/edit-post', 'linkControlSettingsDrawer' ) ??
false;

const siteEditorEnabled =
prefsStore.get( 'core/edit-site', 'linkControlSettingsDrawer' ) ??
false;

return {
settingsDrawerStatePreference:
postEditorEnabled || siteEditorEnabled,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The return value should be determined based on which editor we are currently within. Else. setting from post editro will apply in Site Editor (and vice versa).

Any ideas or prior art on this. Maybe @talldan will know as he was the architect of the prefs store? 🙏

}, [] );

const isMounting = useRef( true );
const wrapperNode = useRef();
const textInputRef = useRef();
const isEndingEditWithFocus = useRef( false );

const settingsKeys = settings.map( ( { id } ) => id );

const [ settingsOpen, setSettingsOpen ] = useState( false );
const [ settingsOpen, setSettingsOpen ] = useState(
settingsDrawerStatePreference
);

const [
internalControlValue,
Expand Down
22 changes: 18 additions & 4 deletions packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { useMemo, useCallback } from '@wordpress/element';
import {
PostTaxonomies,
PostExcerptCheck,
Expand Down Expand Up @@ -69,12 +69,17 @@ export default function EditPostPreferencesModal() {

const { set: setPreference } = useDispatch( preferencesStore );

const toggleDistractionFree = () => {
const toggleDistractionFree = useCallback( () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
};
}, [
closeGeneralSidebar,
setIsInserterOpened,
setIsListViewOpened,
setPreference,
] );

const sections = useMemo(
() => [
Expand Down Expand Up @@ -152,6 +157,15 @@ export default function EditPostPreferencesModal() {
label={ __( 'Display block breadcrumbs' ) }
/>
) }
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggle's default open/closed state of the link creation interface's settings drawer.`
) }
getdave marked this conversation as resolved.
Show resolved Hide resolved
getdave marked this conversation as resolved.
Show resolved Hide resolved
label={ __(
'Always open Link UI Settings Drawer'
) }
getdave marked this conversation as resolved.
Show resolved Hide resolved
/>
</PreferencesModalSection>
</>
),
Expand Down Expand Up @@ -252,7 +266,7 @@ export default function EditPostPreferencesModal() {
),
},
],
[ isLargeViewport, showBlockBreadcrumbsOption ]
[ isLargeViewport, showBlockBreadcrumbsOption, toggleDistractionFree ]
);

if ( ! isModalActive ) {
Expand Down
13 changes: 10 additions & 3 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PreferencesModalSection,
store as interfaceStore,
} from '@wordpress/interface';
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -41,7 +40,7 @@ export default function EditSitePreferencesModal() {
} );
};

const sections = useMemo( () => [
const sections = [
{
name: 'general',
tabLabel: __( 'General' ),
Expand Down Expand Up @@ -86,6 +85,13 @@ export default function EditSitePreferencesModal() {
) }
label={ __( 'Display block breadcrumbs' ) }
/>
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggle's default open/closed state of the link creation interface's settings drawer.`
) }
label={ __( 'Always open Link UI Settings Drawer' ) }
/>
</PreferencesModalSection>
),
},
Expand All @@ -109,7 +115,8 @@ export default function EditSitePreferencesModal() {
</PreferencesModalSection>
),
},
] );
];

if ( ! isModalActive ) {
return null;
}
Expand Down