This repository was archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
P2 694 create schema blocks redux store #1119
Merged
increddibelly
merged 12 commits into
develop
from
P2-694-create-schema-blocks-redux-store
Mar 30, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6f0a38b
move schema blocks store from free to monorepo; add typings
increddibelly 4b367d5
initialize Schema Store
increddibelly f8bae10
apply CR comments
increddibelly 16db6b1
Merge remote-tracking branch 'origin/develop' into P2-694-create-sche…
increddibelly 1eb1c42
make redux commands into functions
increddibelly a01e862
Merge remote-tracking branch 'origin/develop' into P2-694-create-sche…
increddibelly 7e69a3b
fix a merge conflict
increddibelly ac006f7
partially redo removed code
increddibelly e1f8129
Merge branch 'develop' of https://github.com/Yoast/javascript into P2…
johannadevos 8302fe3
Merge remote-tracking branch 'origin/develop' into P2-694-create-sche…
increddibelly 114403e
removed unused import and whitespace.
increddibelly 7053134
Merge branch 'P2-694-create-schema-blocks-redux-store' of https://git…
increddibelly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/schema-blocks/src/functions/redux/SchemaBlocksState.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BlockValidationResult } from "../../core/validation"; | ||
|
||
export interface SchemaBlocksState { | ||
validations: Record<string, BlockValidationResult>; | ||
} | ||
|
||
export const SchemaBlocksDefaultState: SchemaBlocksState = { | ||
validations: {}, | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/schema-blocks/src/functions/redux/actions/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { BlockValidationResult } from "../../../core/validation"; | ||
|
||
import * as schemaBlocksActions from "./schemaBlocks"; | ||
|
||
const PREFIX = "WPSEO_"; | ||
|
||
export const SchemaBlocksStoreActions = { | ||
ADD_BLOCK_VALIDATION: `${ PREFIX }ADD_BLOCK_VALIDATION`, | ||
RESET_BLOCK_VALIDATIONS: `${ PREFIX }CLEAR_BLOCK_VALIDATIONS`, | ||
}; | ||
|
||
export interface SchemaBlocksStoreCommand { | ||
type: string; | ||
validation?: BlockValidationResult; | ||
} | ||
|
||
/** | ||
* Configures a redux command to store a validation result. | ||
* | ||
* @param validation The validation to store. | ||
* @returns The configured AddBlockValidation command. | ||
*/ | ||
export function AddBlockValidationCommand( validation: BlockValidationResult ): SchemaBlocksStoreCommand { | ||
return { | ||
type: SchemaBlocksStoreActions.ADD_BLOCK_VALIDATION, | ||
validation: validation, | ||
}; | ||
} | ||
|
||
/** | ||
* Configures a redux command to reset the current validation results. | ||
* | ||
* @returns Thge configured ResetBlockValidation command | ||
*/ | ||
export function ResetBlockValidationCommand(): SchemaBlocksStoreCommand { | ||
return { | ||
type: SchemaBlocksStoreActions.RESET_BLOCK_VALIDATIONS, | ||
}; | ||
} | ||
|
||
export { schemaBlocksActions }; |
21 changes: 21 additions & 0 deletions
21
packages/schema-blocks/src/functions/redux/actions/schemaBlocks.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { BlockValidationResult } from "../../../core/validation"; | ||
import { SchemaBlocksStoreCommand, AddBlockValidationCommand, ResetBlockValidationCommand } from "./"; | ||
|
||
/** | ||
* Updates whether a block is valid. | ||
* | ||
* @param {blockValidationResult} blockValidationResult The block validation to store. | ||
* | ||
* @returns {SchemaBlocksStoreAction} An action for redux. | ||
*/ | ||
export function addBlockValidation( blockValidationResult: BlockValidationResult ): SchemaBlocksStoreCommand { | ||
return AddBlockValidationCommand( blockValidationResult ); | ||
} | ||
|
||
/** | ||
* Commands the store to reset the block validation store to initial state. | ||
* @returns {SchemaBlocksStoreAction} The command to set the initial state for the block validation store. | ||
*/ | ||
export function resetBlockValidation(): SchemaBlocksStoreCommand { | ||
return ResetBlockValidationCommand(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from "./actions"; | ||
export * from "./reducer"; | ||
export * from "./selectors"; | ||
export * from "./initializeSchemaStore"; | ||
|
||
export const YOAST_SCHEMA_BLOCKS_STORE_NAME = "yoast-seo/schema-blocks"; |
24 changes: 24 additions & 0 deletions
24
packages/schema-blocks/src/functions/redux/initializeSchemaStore.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { registerStore, StoreConfig } from "@wordpress/data"; | ||
import { SchemaBlocksDefaultState, SchemaBlocksState } from "./SchemaBlocksState"; | ||
import { schemaBlocksActions } from "./actions"; | ||
import { schemaBlocksReducer } from "./reducer"; | ||
import * as schemaBlocksSelectors from "./selectors"; | ||
import { YOAST_SCHEMA_BLOCKS_STORE_NAME } from "."; | ||
|
||
/** | ||
* Initializes the Schema Blocks store. | ||
*/ | ||
export function initializeSchemaBlocksStore() { | ||
const storeOptions: StoreConfig<SchemaBlocksState> = { | ||
reducer: schemaBlocksReducer, | ||
selectors: { | ||
...schemaBlocksSelectors, | ||
}, | ||
actions: { | ||
...schemaBlocksActions, | ||
}, | ||
initialState: SchemaBlocksDefaultState, | ||
}; | ||
|
||
registerStore( YOAST_SCHEMA_BLOCKS_STORE_NAME, storeOptions ); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { schemaBlocksReducer } from "./schemaBlocks"; |
30 changes: 30 additions & 0 deletions
30
packages/schema-blocks/src/functions/redux/reducer/schemaBlocks.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SchemaBlocksStoreCommand, SchemaBlocksStoreActions } from "../actions"; | ||
import { SchemaBlocksState, SchemaBlocksDefaultState } from "../SchemaBlocksState"; | ||
|
||
/** | ||
* A reducer for the Schema blocks. | ||
* | ||
* @param {SchemaBlocksState} state The current state of the object. | ||
* @param {SetBlockValidation} command The received command. | ||
* | ||
* @returns {SchemaBlocksState} The state. | ||
*/ | ||
export function schemaBlocksReducer( state: SchemaBlocksState = SchemaBlocksDefaultState, command: SchemaBlocksStoreCommand ): SchemaBlocksState { | ||
switch ( command.type ) { | ||
case SchemaBlocksStoreActions.RESET_BLOCK_VALIDATIONS: { | ||
return SchemaBlocksDefaultState; | ||
} | ||
case SchemaBlocksStoreActions.ADD_BLOCK_VALIDATION: { | ||
const newState = Object.assign( {}, state ); | ||
const validation = command.validation; | ||
|
||
newState.validations = newState.validations || {}; | ||
newState.validations[ validation.clientId ] = validation; | ||
|
||
return newState; | ||
} | ||
default: { | ||
return state; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./schemaBlocks"; |
12 changes: 12 additions & 0 deletions
12
packages/schema-blocks/src/functions/redux/selectors/schemaBlocks.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SchemaBlocksState, SchemaBlocksDefaultState } from "../SchemaBlocksState"; | ||
|
||
/** | ||
* The schema validation results. | ||
* | ||
* @param {object} state The current state. | ||
* | ||
* @returns {Record<string, BlockValidationResult>} The schema blocks validation results. | ||
*/ | ||
export function getSchemaBlocksValidationResults( state: SchemaBlocksState ): object { | ||
return state.validations || SchemaBlocksDefaultState.validations; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.