From 1759bac4c8012cc6f05bd642123dec3a79aa7713 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:31:12 +0200 Subject: [PATCH 1/5] Lock editing bindings if meta fields interface is opened --- .../preferences-modal/enable-custom-fields.js | 27 ++++++++++++------- packages/editor/src/bindings/post-meta.js | 6 +++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js index c32e337be58c0..3f72202e9f07b 100644 --- a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js +++ b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js @@ -63,15 +63,24 @@ export function EnableCustomFieldsOption( { label, areCustomFieldsEnabled } ) { const [ isChecked, setIsChecked ] = useState( areCustomFieldsEnabled ); return ( - - { isChecked !== areCustomFieldsEnabled && ( - - ) } - + <> + + { isChecked && ( +

+ { __( + 'Connected attributes cannot be edited in the block editor while this interface is active.' + ) } +

+ ) } + { isChecked !== areCustomFieldsEnabled && ( + + ) } +
+ ); } diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 1ecd6ea50ba27..4de8396d4c13b 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -62,6 +62,12 @@ export default { if ( fieldValue === undefined ) { return false; } + // Check that custom fields metabox is not enabled. + const areCustomFieldsEnabled = + select( editorStore ).getEditorSettings().enableCustomFields; + if ( areCustomFieldsEnabled ) { + return false; + } // Check that the user has the capability to edit post meta. const canUserEdit = select( coreDataStore ).canUser( 'update', { From 7b7788a20838aeaf99f1421524b522221114a340 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:44:31 +0200 Subject: [PATCH 2/5] Update snapshots --- .../test/__snapshots__/enable-custom-fields.js.snap | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap index 567b2bcbf8f88..04ce3028e5831 100644 --- a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap +++ b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap @@ -91,6 +91,11 @@ exports[`EnableCustomFieldsOption renders a checked checkbox and a confirmation +

+ Connected attributes cannot be edited in the block editor while this interface is active. +

@@ -198,6 +203,11 @@ exports[`EnableCustomFieldsOption renders a checked checkbox when custom fields +

+ Connected attributes cannot be edited in the block editor while this interface is active. +

`; From 754a17471a9c3077f374f2280b7108584032f932 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:36:23 +0200 Subject: [PATCH 3/5] Refactor the EnableCustomFieldsOption component to improve code readability and maintainability. --- .../preferences-modal/enable-custom-fields.js | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js index 3f72202e9f07b..87690fbe774bf 100644 --- a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js +++ b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js @@ -63,24 +63,22 @@ export function EnableCustomFieldsOption( { label, areCustomFieldsEnabled } ) { const [ isChecked, setIsChecked ] = useState( areCustomFieldsEnabled ); return ( - <> - - { isChecked && ( -

- { __( - 'Connected attributes cannot be edited in the block editor while this interface is active.' - ) } -

- ) } - { isChecked !== areCustomFieldsEnabled && ( - - ) } -
- + + { isChecked && ( +

+ { __( + 'Custom fields connected to block attributes cannot be edited in the block editor while this interface is active.' + ) } +

+ ) } + { isChecked !== areCustomFieldsEnabled && ( + + ) } +
); } From 3a9ef79c3980fd9e4d6b3512089065e2170550c6 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:45:50 +0200 Subject: [PATCH 4/5] Update snapshots --- .../test/__snapshots__/enable-custom-fields.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap index 04ce3028e5831..db9a713ab8301 100644 --- a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap +++ b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap @@ -94,7 +94,7 @@ exports[`EnableCustomFieldsOption renders a checked checkbox and a confirmation

- Connected attributes cannot be edited in the block editor while this interface is active. + Custom fields connected to block attributes cannot be edited in the block editor while this interface is active.

- Connected attributes cannot be edited in the block editor while this interface is active. + Custom fields connected to block attributes cannot be edited in the block editor while this interface is active.

From cc4009d8b6611b85fbe6c427844c14faa291d8e9 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+cbravobernal@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:49:48 +0200 Subject: [PATCH 5/5] Remove extra text --- .../preferences-modal/enable-custom-fields.js | 7 ------- .../test/__snapshots__/enable-custom-fields.js.snap | 10 ---------- 2 files changed, 17 deletions(-) diff --git a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js index 87690fbe774bf..c32e337be58c0 100644 --- a/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js +++ b/packages/edit-post/src/components/preferences-modal/enable-custom-fields.js @@ -68,13 +68,6 @@ export function EnableCustomFieldsOption( { label, areCustomFieldsEnabled } ) { isChecked={ isChecked } onChange={ setIsChecked } > - { isChecked && ( -

- { __( - 'Custom fields connected to block attributes cannot be edited in the block editor while this interface is active.' - ) } -

- ) } { isChecked !== areCustomFieldsEnabled && ( ) } diff --git a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap index db9a713ab8301..567b2bcbf8f88 100644 --- a/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap +++ b/packages/edit-post/src/components/preferences-modal/test/__snapshots__/enable-custom-fields.js.snap @@ -91,11 +91,6 @@ exports[`EnableCustomFieldsOption renders a checked checkbox and a confirmation -

- Custom fields connected to block attributes cannot be edited in the block editor while this interface is active. -

@@ -203,11 +198,6 @@ exports[`EnableCustomFieldsOption renders a checked checkbox when custom fields -

- Custom fields connected to block attributes cannot be edited in the block editor while this interface is active. -

`;