From 2726500debb18d611df6371c9f6d721ed45a965c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Fri, 5 Nov 2021 17:04:32 +0100 Subject: [PATCH 1/3] Revert "Block Library: Fix incorrect attributes definitions #36140" The `templateLock` attribute is mixed between boolean and string. Setting the type as string introduces an regression that will remove `false` on save. The original PR (#36140) tried to fix a validation issue reported in #35902 The schema error is incorrect. The attribute definition is required to have either a `type` or an `enum`. --- packages/block-library/src/column/block.json | 1 - packages/block-library/src/cover/block.json | 1 - packages/block-library/src/group/block.json | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json index 826b916811cadc..1a1513ad2e66c3 100644 --- a/packages/block-library/src/column/block.json +++ b/packages/block-library/src/column/block.json @@ -17,7 +17,6 @@ "type": "array" }, "templateLock": { - "type": "string", "enum": [ "all", "insert", false ] } }, diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json index cac312ec13386c..ecb8227079c158 100644 --- a/packages/block-library/src/cover/block.json +++ b/packages/block-library/src/cover/block.json @@ -67,7 +67,6 @@ "type": "array" }, "templateLock": { - "type": "string", "enum": [ "all", "insert", false ] } }, diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index c10790d28c427c..5e182cd0e9cba9 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -12,7 +12,6 @@ "default": "div" }, "templateLock": { - "type": "string", "enum": [ "all", "insert", false ] } }, From 276a63881a88a096b79cc33032accdefa4881ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Sun, 7 Nov 2021 22:52:12 +0100 Subject: [PATCH 2/3] Spesify type as string or boolean --- packages/block-library/src/column/block.json | 1 + packages/block-library/src/cover/block.json | 1 + packages/block-library/src/group/block.json | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json index 1a1513ad2e66c3..44ef3438b2344a 100644 --- a/packages/block-library/src/column/block.json +++ b/packages/block-library/src/column/block.json @@ -17,6 +17,7 @@ "type": "array" }, "templateLock": { + "type": [ "string", "boolean" ], "enum": [ "all", "insert", false ] } }, diff --git a/packages/block-library/src/cover/block.json b/packages/block-library/src/cover/block.json index ecb8227079c158..aa00d403411f8b 100644 --- a/packages/block-library/src/cover/block.json +++ b/packages/block-library/src/cover/block.json @@ -67,6 +67,7 @@ "type": "array" }, "templateLock": { + "type": [ "string", "boolean" ], "enum": [ "all", "insert", false ] } }, diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index 5e182cd0e9cba9..d34729441d09e8 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -12,6 +12,7 @@ "default": "div" }, "templateLock": { + "type": [ "string", "boolean" ], "enum": [ "all", "insert", false ] } }, From dfafc5e5e4e4a1836404b715fe35301269632300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petter=20Walb=C3=B8=20Johnsg=C3=A5rd?= Date: Mon, 8 Nov 2021 10:19:29 +0100 Subject: [PATCH 3/3] Add unit test --- .../src/api/parser/test/get-block-attributes.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/blocks/src/api/parser/test/get-block-attributes.js b/packages/blocks/src/api/parser/test/get-block-attributes.js index 727f052a54c803..7b48db67fdb940 100644 --- a/packages/blocks/src/api/parser/test/get-block-attributes.js +++ b/packages/blocks/src/api/parser/test/get-block-attributes.js @@ -222,6 +222,22 @@ describe( 'attributes parsing', () => { expect( value ).toBe( 10 ); } ); + it( 'should return the comment attribute value when using multiple types', () => { + const value = getBlockAttribute( + 'templateLock', + { + type: [ 'string', 'boolean' ], + enum: [ 'all', 'insert', false ], + }, + '', + { + templateLock: false, + } + ); + + expect( value ).toBe( false ); + } ); + it( 'should reject type-invalid value, with default', () => { const value = getBlockAttribute( 'number',