From ff112d76363fb3a89c8ab4e3c6fcfa52c37bd3ff Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:46:47 +0200 Subject: [PATCH] Block Bindings: Remove key fallback in bindings get values and rely on source label (#65517) * Always fall back to source label * Adapt e2e tests Co-authored-by: SantosGuillamot Co-authored-by: gziolo --- .../src/hooks/use-bindings-attributes.js | 5 ++-- .../editor/various/block-bindings.spec.js | 26 +------------------ 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/packages/block-editor/src/hooks/use-bindings-attributes.js b/packages/block-editor/src/hooks/use-bindings-attributes.js index e1ebf5fda6b8e..ac045004cc654 100644 --- a/packages/block-editor/src/hooks/use-bindings-attributes.js +++ b/packages/block-editor/src/hooks/use-bindings-attributes.js @@ -162,9 +162,8 @@ export const withBlockBindingSupport = createHigherOrderComponent( let values = {}; if ( ! source.getValues ) { Object.keys( bindings ).forEach( ( attr ) => { - // Default to the `key` or the source label when `getValues` doesn't exist - values[ attr ] = - bindings[ attr ].args?.key || source.label; + // Default to the the source label when `getValues` doesn't exist. + values[ attr ] = source.label; } ); } else { values = source.getValues( { diff --git a/test/e2e/specs/editor/various/block-bindings.spec.js b/test/e2e/specs/editor/various/block-bindings.spec.js index c556c469698eb..90a5d2b1da9f1 100644 --- a/test/e2e/specs/editor/various/block-bindings.spec.js +++ b/test/e2e/specs/editor/various/block-bindings.spec.js @@ -66,7 +66,7 @@ test.describe( 'Block bindings', () => { ); } ); - test( 'should show the key of the custom field in server sources with key', async ( { + test( 'should always show the source label in server-only sources', async ( { editor, } ) => { await editor.insertBlock( { @@ -86,30 +86,6 @@ test.describe( 'Block bindings', () => { const paragraphBlock = editor.canvas.getByRole( 'document', { name: 'Block: Paragraph', } ); - await expect( paragraphBlock ).toHaveText( - 'text_custom_field' - ); - } ); - - test( 'should show the source label in server sources without key', async ( { - editor, - } ) => { - await editor.insertBlock( { - name: 'core/paragraph', - attributes: { - content: 'paragraph default content', - metadata: { - bindings: { - content: { - source: 'core/server-source', - }, - }, - }, - }, - } ); - const paragraphBlock = editor.canvas.getByRole( 'document', { - name: 'Block: Paragraph', - } ); await expect( paragraphBlock ).toHaveText( 'Server Source' ); } );