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 and noisysocks committed Nov 10, 2021
1 parent c29a259 commit 627acd3
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 @@ -17,7 +17,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 @@ -67,7 +67,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 @@ -12,7 +12,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 627acd3

Please sign in to comment.