-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Editor: Make the AddTerm Component more reusable (#8588)"
A user noticed "Can not read hierarchical of null" error when loading the editor This reverts commit 7d6f7a0.
- Loading branch information
1 parent
7d6f7a0
commit 9f169a5
Showing
8 changed files
with
281 additions
and
170 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
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,49 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isNumber, toArray } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TERMS_RECEIVE } from 'state/action-types'; | ||
import { getEditedPost } from 'state/posts/selectors'; | ||
import { editPost } from 'state/posts/actions'; | ||
|
||
/** | ||
* Dispatches editPost when a new term has been added | ||
* that also has a postId on the action | ||
* | ||
* @param {Function} dispatch Dispatch method | ||
* @param {Object} state Global state tree | ||
* @param {Object} action Action object | ||
*/ | ||
export function onTermsReceive( dispatch, state, action ) { | ||
const { postId, taxonomy, terms, siteId } = action; | ||
const post = getEditedPost( state, siteId, postId ); | ||
const newTerm = terms[ 0 ]; | ||
|
||
// if there is no post, no term, or term is temporary, bail | ||
if ( ! post || ! newTerm || ! isNumber( newTerm.ID ) ) { | ||
return; | ||
} | ||
|
||
const postTerms = post.terms || {}; | ||
|
||
// ensure we have an array since API returns an object | ||
const taxonomyTerms = toArray( postTerms[ taxonomy ] ); | ||
taxonomyTerms.push( newTerm ); | ||
|
||
dispatch( editPost( siteId, postId, { | ||
terms: { | ||
[ taxonomy ]: taxonomyTerms | ||
} | ||
} ) ); | ||
} | ||
|
||
export default ( { dispatch, getState } ) => ( next ) => ( action ) => { | ||
if ( TERMS_RECEIVE === action.type && action.hasOwnProperty( 'postId' ) ) { | ||
onTermsReceive( dispatch, getState(), action ); | ||
} | ||
return next( action ); | ||
}; |
Oops, something went wrong.