Skip to content

Commit

Permalink
Try to fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Oct 26, 2023
1 parent 71e9a2e commit 05018d0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/block-editor/src/components/block-rename/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const emptyString = ( testString ) => testString?.trim()?.length === 0;

export default function BlockRenameModal( { clientId, onClose } ) {
const blockInformation = useBlockDisplayInformation( clientId );
const originalBlockName = blockInformation?.blockName;
const originalBlockName = blockInformation?.title;

const metadata = useSelect(
( select ) => {
Expand All @@ -34,12 +34,10 @@ export default function BlockRenameModal( { clientId, onClose } ) {
[ clientId ]
);
const { updateBlockAttributes } = useDispatch( blockEditorStore );
const blockName = metadata?.name || '';
const [ editedBlockName, setEditedBlockName ] = useState( blockName );

const [ editedBlockName, setEditedBlockName ] = useState(
metadata?.name || ''
);

const nameHasChanged = editedBlockName !== metadata?.name;
const nameHasChanged = editedBlockName !== blockName;
const nameIsOriginal = editedBlockName === originalBlockName;
const nameIsEmpty = emptyString( editedBlockName );

Expand Down Expand Up @@ -72,7 +70,14 @@ export default function BlockRenameModal( { clientId, onClose } ) {
updateBlockAttributes( [ clientId ], {
metadata: {
...metadata,
name: editedBlockName,
name:
// If the new value is the block's original name (e.g. `Group`)
// or it is an empty string then assume the intent is to reset
// the value. Therefore reset the metadata.
editedBlockName === blockInformation?.title ||
emptyString( editedBlockName )
? undefined
: editedBlockName,
},
} );

Expand Down

0 comments on commit 05018d0

Please sign in to comment.