Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

P2 807 variation picker validation #1142

Merged
merged 23 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a453363
first steps
increddibelly Mar 30, 2021
bc19f27
added comment
increddibelly Mar 30, 2021
a91b104
make the VariationPicker validation verify that a block is selected
increddibelly Apr 2, 2021
5ad724e
removed unused imports
increddibelly Apr 2, 2021
6b3f96a
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
increddibelly Apr 6, 2021
f947f2e
simplified parent / child relation in validation
increddibelly Apr 6, 2021
6b9e27c
Updated tests for BlockInstruction.
hansjovis Apr 8, 2021
539a51b
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
hansjovis Apr 8, 2021
7b17aeb
cleanup unit test
increddibelly Apr 8, 2021
14cfa8e
fixed variationpicker validation naming
increddibelly Apr 9, 2021
5b27fa9
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
increddibelly Apr 9, 2021
adf1c54
Don't pass the default value of an optional parameter
johannadevos Apr 12, 2021
c916123
Improve CS
johannadevos Apr 12, 2021
1ad79e6
allow variationpickers to be recommended blocks
increddibelly Apr 9, 2021
b067b89
Expand documentation
increddibelly Apr 12, 2021
ffd6e9e
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
increddibelly Apr 12, 2021
b4fe30c
simplified validation by passing the presence parameter
increddibelly Apr 12, 2021
4ffbe6e
remove unused import
increddibelly Apr 13, 2021
6e08cd3
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
increddibelly Apr 13, 2021
bdd1360
updated validation to explicitly mention unpicked variations
increddibelly Apr 13, 2021
4634389
fix typo
increddibelly Apr 13, 2021
e0501ad
Merge remote-tracking branch 'origin/develop' into P2-807-VariationPi…
hansjovis Apr 13, 2021
a76a4f6
Used backticks instead of quotation marks in test.
hansjovis Apr 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand documentation
  • Loading branch information
increddibelly committed Apr 12, 2021
commit b067b89edc68209032d61968050272033fd25624
4 changes: 3 additions & 1 deletion packages/schema-blocks/src/core/blocks/BlockInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ export default abstract class BlockInstruction extends Instruction {
issues.push( new BlockValidationResult( blockInstance.clientId, this.constructor.name, BlockValidation.Invalid, BlockPresence.Unknown ) );
}

// No issues found? That means the block is valid.
if ( issues.length < 1 ) {
increddibelly marked this conversation as resolved.
Show resolved Hide resolved
return BlockValidationResult.Valid( blockInstance, this.constructor.name );
}

// This is overkill for now but future proof.
// Make sure to report the worst case scenario as the final validation result.
const worstCase: BlockValidationResult = maxBy( issues, issue => issue.result );

const validation = new BlockValidationResult( blockInstance.clientId, this.constructor.name, worstCase.result, worstCase.blockPresence );
validation.issues = issues;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class InnerBlocks extends BlockInstruction {
}

/**
* Checks if the instruction block is valid.
* Checks if the InnerBlock and it's schildren are valid.
*
* @param blockInstance The block instance being validated.
*
Expand All @@ -162,10 +162,12 @@ export default class InnerBlocks extends BlockInstruction {
validate( blockInstance: BlockInstance ): BlockValidationResult {
const issues = validateInnerBlocks( blockInstance, this.options.requiredBlocks, this.options.recommendedBlocks );

// If no issues are found in any of the innerblocks, the Innerblock is valid too.
if ( ! issues || issues.length < 1 ) {
increddibelly marked this conversation as resolved.
Show resolved Hide resolved
return BlockValidationResult.Valid( blockInstance, this.constructor.name );
}

// Make sure to report the worst problem we've found.
const worstCase: BlockValidationResult = maxBy( issues, issue => issue.result );
const validation = new BlockValidationResult( blockInstance.clientId, this.constructor.name, worstCase.result, worstCase.blockPresence );
validation.issues = issues;
Expand Down