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

P2 786 only render ok when block is valid #1146

Merged
merged 41 commits into from
May 10, 2021
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4f15ce7
Added a method that checks if the blockValidationResult is considered…
Apr 7, 2021
d976c74
Adds a check to see if the added suggestion is valid
Apr 7, 2021
0e3a803
Updates the tests for the blocksuggestions
Apr 7, 2021
f772213
Improval of the test by mocking the functions directly
Apr 7, 2021
bc2a734
Merge branch 'develop' of https://github.com/Yoast/javascript into P2…
Apr 8, 2021
9eb9930
Process CR
Apr 8, 2021
c467972
Remove typehints in jsdoc
Apr 8, 2021
54dfb3a
Merge branch 'develop' of https://github.com/Yoast/javascript into P2…
Apr 8, 2021
cd2ea53
Check if the block validation is OK
Apr 12, 2021
c67c29a
Merge branch 'develop' of https://github.com/Yoast/javascript into P2…
Apr 12, 2021
ebfa7e5
Merge branch 'develop' of https://github.com/Yoast/javascript into P2…
Apr 14, 2021
8e2debd
Refactored the BlockSuggestionsPresenter a little bit
Apr 15, 2021
7404075
Changes the working of the validation a little bit.
Apr 15, 2021
51d120d
make the SidebarWarningPresenter retrieve validation for a client Id
increddibelly Apr 15, 2021
74d36e4
fix unit tests
increddibelly Apr 16, 2021
c89071d
extract the BlockSuggestionsPresenter logic from the component
increddibelly Apr 16, 2021
e95a228
BlockSuggestionsPresenter allows more detailed control now; validatio…
increddibelly Apr 19, 2021
565f3fe
Merge branch 'develop' into P2-786-only-render-ok-when-block-is-valid
increddibelly Apr 19, 2021
0426ce0
added additional valid results and validation
increddibelly Apr 20, 2021
9c10dcf
Add validation to RichtTextBase
increddibelly Apr 20, 2021
e251ab9
remove unused code
increddibelly Apr 20, 2021
25356ce
added ValidationBlockInstruction to allow blocks to opt-in validation
increddibelly Apr 23, 2021
9872f78
fixing unit tests
increddibelly Apr 23, 2021
cd31dfe
fixed unit tests
increddibelly Apr 29, 2021
94a719f
Bump @wordpress/data to the latest version
johannadevos Apr 29, 2021
87a09ca
prevent an error for missing instructions
increddibelly Apr 29, 2021
f9f5aaf
Merge remote-tracking branch 'origin/release/16.3' into P2-786-only-r…
increddibelly Apr 29, 2021
cad6799
replaced ValidatingBlockInstruction base class with single function
increddibelly Apr 30, 2021
9f8404e
Merge remote-tracking branch 'origin/release/16.3' into P2-786-only-r…
increddibelly Apr 30, 2021
1d0e61d
fine tune variationpicker validation
increddibelly May 3, 2021
a41779b
fix Date validation
increddibelly May 3, 2021
3c14f53
typo
increddibelly May 3, 2021
e28dcb0
Merge remote-tracking branch 'origin/develop' into P2-786-only-render…
increddibelly May 3, 2021
8db91db
fix Date tests.
increddibelly May 4, 2021
318b5a3
Update packages/schema-blocks/src/functions/presenters/BlockSuggestio…
increddibelly May 6, 2021
0f4d7b1
Update packages/schema-blocks/src/functions/presenters/BlockSuggestio…
increddibelly May 6, 2021
94fa03a
processed CR comments
increddibelly May 6, 2021
c93634a
Update packages/schema-blocks/src/core/validation/BlockValidationResu…
increddibelly May 6, 2021
3cfa7f1
fix CS
increddibelly May 6, 2021
a92916b
make method of reading current block content consistent with other Yo…
increddibelly May 6, 2021
0053d33
Removed superfluous isValid check from BlockSuggestionsPresenter.
hansjovis May 6, 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
Changes the working of the validation a little bit.
Might need some additional work
  • Loading branch information
Andy Meerwaldt committed Apr 15, 2021
commit 74040756181ecda268d437fbcdc14c51b96ee9a4
10 changes: 5 additions & 5 deletions packages/schema-blocks/src/core/blocks/BlockInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import BlockLeaf from "./BlockLeaf";
import { RenderEditProps, RenderSaveProps } from "./BlockDefinition";
import { ReactElement } from "@wordpress/element";
import { BlockConfiguration, BlockInstance } from "@wordpress/blocks";
import { BlockValidation, BlockValidationResult } from "../validation";
import { BlockValidation, BlockValidationResult, BlockPresence } from "../validation";
import Instruction, { InstructionOptions } from "../Instruction";
import { attributeExists, attributeNotEmpty } from "../../functions/validators";
import { BlockPresence } from "../validation/BlockValidationResult";
import { maxBy } from "lodash";

export type BlockInstructionClass = {
Expand Down Expand Up @@ -80,8 +79,9 @@ export default abstract class BlockInstruction extends Instruction {
validate( blockInstance: BlockInstance ): BlockValidationResult {
const issues: BlockValidationResult[] = [];

let presence = BlockPresence.Unknown;
if ( this.options ) {
const presence = this.options.required ? BlockPresence.Required : BlockPresence.Recommended;
presence = this.options.required ? BlockPresence.Required : BlockPresence.Recommended;
const attributeValid = attributeExists( blockInstance, this.options.name as string ) &&
attributeNotEmpty( blockInstance, this.options.name as string );
if ( ! attributeValid ) {
Expand All @@ -90,12 +90,12 @@ export default abstract class BlockInstruction extends Instruction {
}

if ( blockInstance.name.startsWith( "core/" ) && ! blockInstance.isValid ) {
issues.push( new BlockValidationResult( blockInstance.clientId, this.constructor.name, BlockValidation.Invalid, BlockPresence.Unknown ) );
issues.push( new BlockValidationResult( blockInstance.clientId, this.constructor.name, BlockValidation.Invalid, presence ) );
}

// No issues found? That means the block is valid.
if ( issues.length < 1 ) {
return BlockValidationResult.Valid( blockInstance, this.constructor.name );
return BlockValidationResult.Valid( blockInstance, this.constructor.name, presence );
}

// Make sure to report the worst case scenario as the final validation result.
Expand Down