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

Patterns: Remove reusable text from menu once rename hint has been dismissed #52664

Merged
merged 11 commits into from
Jul 17, 2023
4 changes: 4 additions & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ _Parameters_
- _props_ `Object`: Optional. Props to pass to the element. Must contain the ref if one is defined.
- _options_ `Object`: Optional. Inner blocks options.

### useReusableBlocksRenameHint

Undocumented declaration.
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

### useSetting

Hook that retrieves the given setting for the block instance in use.
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@ export { default as useSetting } from './use-setting';
/*
* The following rename hint component can be removed in 6.4.
*/
export { default as ReusableBlocksRenameHint } from './inserter/reusable-block-rename-hint';
export {
default as ReusableBlocksRenameHint,
useReusableBlocksRenameHint,
} from './inserter/reusable-block-rename-hint';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import { store as preferencesStore } from '@wordpress/preferences';

const PREFERENCE_NAME = 'isResuableBlocksrRenameHintVisible';

export function useReusableBlocksRenameHint() {
return useSelect(
( select ) =>
select( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true,
[]
);
}

export default function ReusableBlocksRenameHint() {
const isReusableBlocksRenameHint = useSelect(
( select ) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BlockSettingsMenuControls,
store as blockEditorStore,
ReusableBlocksRenameHint,
useReusableBlocksRenameHint,
} from '@wordpress/block-editor';
import { useCallback, useState } from '@wordpress/element';
import {
Expand Down Expand Up @@ -40,7 +41,8 @@ export default function ReusableBlockConvertButton( {
clientIds,
rootClientId,
} ) {
const [ syncType, setSyncType ] = useState( 'unsynced' );
const showRenameHint = useReusableBlocksRenameHint();
const [ syncType, setSyncType ] = useState( undefined );
const [ isModalOpen, setIsModalOpen ] = useState( false );
const [ title, setTitle ] = useState( '' );
const canConvert = useSelect(
Expand Down Expand Up @@ -97,7 +99,7 @@ export default function ReusableBlockConvertButton( {
syncType
);
createSuccessNotice(
syncType === 'fully'
! syncType
? sprintf(
// translators: %s: the name the user has given to the pattern.
__( 'Synced Pattern created: %s' ),
Expand Down Expand Up @@ -141,7 +143,9 @@ export default function ReusableBlockConvertButton( {
icon={ symbol }
onClick={ () => setIsModalOpen( true ) }
>
{ __( 'Create pattern/reusable block' ) }
{ showRenameHint
? __( 'Create pattern/reusable block' )
: __( 'Create pattern' ) }
</MenuItem>
{ isModalOpen && (
<Modal
Expand Down Expand Up @@ -176,12 +180,12 @@ export default function ReusableBlockConvertButton( {
help={ __(
'Editing the pattern will update it anywhere it is used.'
) }
checked={ syncType === 'fully' }
checked={ ! syncType }
onChange={ () => {
setSyncType(
syncType === 'fully'
! syncType
? 'unsynced'
: 'fully'
: undefined
);
} }
/>
Expand Down