Skip to content

Commit

Permalink
Block Library: Fix incorrect attributes definitions (#36264)
Browse files Browse the repository at this point in the history
* 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`.

* Spesify type as string or boolean

* Add unit test
  • Loading branch information
Petter Walbø Johnsgård authored Nov 10, 2021
1 parent 216df9e commit 2918b80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"type": "array"
},
"templateLock": {
"type": "string",
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", false ]
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"type": "array"
},
"templateLock": {
"type": "string",
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", false ]
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"default": "div"
},
"templateLock": {
"type": "string",
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", false ]
}
},
Expand Down
16 changes: 16 additions & 0 deletions packages/blocks/src/api/parser/test/get-block-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2918b80

Please sign in to comment.