-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the post title selection state to the store and update PostTitle (…
…#16704) * Move the post title selection state to the store and update PostTitle * Fix jsdoc type returned for postTitle reducer * Update native version of VisualEditor to use the store to know if the post title is selected * Update doc * Remove unused clearSelectedBlock props in PostTitle web and bring back focus in native version * Fork core/editor store for native instead of modifying it * Move tests to native * Update docs * Revert changes to web PostTitle * Fix post title blur on block selection * Update the isPostTitleSelected state if any other block is selected
- Loading branch information
Showing
8 changed files
with
220 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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,16 @@ | ||
|
||
export * from './actions.js'; | ||
|
||
/** | ||
* Returns an action object that enables or disables post title selection. | ||
* | ||
* @param {boolean} [isSelected=true] Whether post title is currently selected. | ||
* @return {Object} Action object. | ||
*/ | ||
export function togglePostTitleSelection( isSelected = true ) { | ||
return { | ||
type: 'TOGGLE_POST_TITLE_SELECTION', | ||
isSelected, | ||
}; | ||
} |
This file contains 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,64 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import optimist from 'redux-optimist'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { combineReducers } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
editor, | ||
initialEdits, | ||
currentPost, | ||
preferences, | ||
saving, | ||
postLock, | ||
reusableBlocks, | ||
template, | ||
previewLink, | ||
postSavingLock, | ||
isReady, | ||
editorSettings, | ||
} from './reducer.js'; | ||
|
||
export * from './reducer.js'; | ||
|
||
/** | ||
* Reducer returning the post title state. | ||
* | ||
* @param {PostTitleState} state Current state. | ||
* @param {Object} action Dispatched action. | ||
* | ||
* @return {Object} Updated state. | ||
*/ | ||
export const postTitle = combineReducers( { | ||
isSelected( state = false, action ) { | ||
switch ( action.type ) { | ||
case 'TOGGLE_POST_TITLE_SELECTION': | ||
return action.isSelected; | ||
} | ||
|
||
return state; | ||
}, | ||
} ); | ||
|
||
export default optimist( combineReducers( { | ||
editor, | ||
initialEdits, | ||
currentPost, | ||
preferences, | ||
saving, | ||
postLock, | ||
reusableBlocks, | ||
template, | ||
previewLink, | ||
postSavingLock, | ||
isReady, | ||
editorSettings, | ||
postTitle, | ||
} ) ); |
This file contains 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,13 @@ | ||
|
||
export * from './selectors.js'; | ||
|
||
/** | ||
* Returns true if post title is selected. | ||
* | ||
* @param {Object} state Global application state. | ||
* | ||
* @return {boolean} Whether current post title is selected. | ||
*/ | ||
export function isPostTitleSelected( state ) { | ||
return state.postTitle.isSelected; | ||
} |
This file contains 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,17 @@ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { togglePostTitleSelection } from '../actions'; | ||
|
||
describe( 'Editor actions', () => { | ||
describe( 'togglePostTitleSelection', () => { | ||
it( 'should return the TOGGLE_POST_TITLE_SELECTION action', () => { | ||
const result = togglePostTitleSelection( true ); | ||
expect( result ).toEqual( { | ||
type: 'TOGGLE_POST_TITLE_SELECTION', | ||
isSelected: true, | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
This file contains 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,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
postTitle, | ||
} from '../reducer'; | ||
|
||
describe( 'state native', () => { | ||
describe( 'postTitle', () => { | ||
describe( 'isSelected()', () => { | ||
it( 'should not be selected by default', () => { | ||
expect( postTitle( undefined, {} ).isSelected ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return false if not selecting the post title', () => { | ||
const action = { | ||
type: 'TOGGLE_POST_TITLE_SELECTION', | ||
isSelected: false, | ||
}; | ||
|
||
expect( postTitle( { isSelected: true }, action ).isSelected ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return true if selecting the post title', () => { | ||
const action = { | ||
type: 'TOGGLE_POST_TITLE_SELECTION', | ||
isSelected: true, | ||
}; | ||
|
||
expect( postTitle( { isSelected: false }, action ).isSelected ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
This file contains 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,28 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isPostTitleSelected } from '../selectors'; | ||
|
||
describe( 'selectors native', () => { | ||
describe( 'isPostTitleSelected', () => { | ||
it( 'should return true if the post title is selected', () => { | ||
const state = { | ||
postTitle: { | ||
isSelected: true, | ||
}, | ||
}; | ||
|
||
expect( isPostTitleSelected( state ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return false if the post title is not selected', () => { | ||
const state = { | ||
postTitle: { | ||
isSelected: false, | ||
}, | ||
}; | ||
|
||
expect( isPostTitleSelected( state ) ).toBe( false ); | ||
} ); | ||
} ); | ||
} ); |