-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lodash: Remove some _.get()
from editor
#48104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,8 +1,3 @@ | ||||
/** | ||||
* External dependencies | ||||
*/ | ||||
import { get } from 'lodash'; | ||||
|
||||
/** | ||||
* WordPress dependencies | ||||
*/ | ||||
|
@@ -21,11 +16,8 @@ export default function PostAuthorCheck( { children } ) { | |||
const post = select( editorStore ).getCurrentPost(); | ||||
const authors = select( coreStore ).getUsers( AUTHORS_QUERY ); | ||||
return { | ||||
hasAssignAuthorAction: get( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
post, | ||||
[ '_links', 'wp:action-assign-author' ], | ||||
false | ||||
), | ||||
hasAssignAuthorAction: | ||||
post._links?.[ 'wp:action-assign-author' ] ?? false, | ||||
hasAuthors: authors?.length >= 1, | ||||
}; | ||||
}, [] ); | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -153,12 +148,9 @@ export default compose( [ | |
const postType = getPostType( getEditedPostAttribute( 'type' ) ); | ||
|
||
return { | ||
hasPublishAction: get( | ||
getCurrentPost(), | ||
[ '_links', 'wp:action-publish' ], | ||
false | ||
), | ||
isPostTypeViewable: get( postType, [ 'viewable' ], false ), | ||
hasPublishAction: | ||
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false, | ||
isPostTypeViewable: postType?.viewable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
isBeingScheduled: isEditedPostBeingScheduled(), | ||
isDirty: isEditedPostDirty(), | ||
isPublished: isCurrentPostPublished(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
import escapeHtml from 'escape-html'; | ||
|
||
/** | ||
|
@@ -106,24 +105,14 @@ export function FlatTermSelector( { slug } ) { | |
|
||
return { | ||
hasCreateAction: _taxonomy | ||
? get( | ||
post, | ||
[ | ||
'_links', | ||
'wp:action-create-' + _taxonomy.rest_base, | ||
], | ||
false | ||
) | ||
? post._links?.[ | ||
'wp:action-create-' + _taxonomy.rest_base | ||
] ?? false | ||
: false, | ||
hasAssignAction: _taxonomy | ||
? get( | ||
post, | ||
[ | ||
'_links', | ||
'wp:action-assign-' + _taxonomy.rest_base, | ||
], | ||
false | ||
) | ||
? post._links?.[ | ||
'wp:action-assign-' + _taxonomy.rest_base | ||
] ?? false | ||
: false, | ||
taxonomy: _taxonomy, | ||
termIds: _termIds, | ||
|
@@ -239,30 +228,23 @@ export function FlatTermSelector( { slug } ) { | |
} | ||
|
||
const newTermIds = [ ...termIds, newTerm.id ]; | ||
const defaultName = slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ); | ||
const termAddedMessage = sprintf( | ||
/* translators: %s: term name. */ | ||
_x( '%s added', 'term' ), | ||
get( | ||
taxonomy, | ||
[ 'labels', 'singular_name' ], | ||
slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) | ||
) | ||
taxonomy?.labels?.singular_name ?? defaultName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
|
||
speak( termAddedMessage, 'assertive' ); | ||
onUpdateTerms( newTermIds ); | ||
} | ||
|
||
const newTermLabel = get( | ||
taxonomy, | ||
[ 'labels', 'add_new_item' ], | ||
slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' ) | ||
); | ||
const singularName = get( | ||
taxonomy, | ||
[ 'labels', 'singular_name' ], | ||
slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) | ||
); | ||
const newTermLabel = | ||
taxonomy?.labels?.add_new_item ?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
( slug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' ) ); | ||
const singularName = | ||
taxonomy?.labels?.singular_name ?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
( slug === 'post_tag' ? __( 'Tag' ) : __( 'Term' ) ); | ||
const termAddedLabel = sprintf( | ||
/* translators: %s: term name. */ | ||
_x( '%s added', 'term' ), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -180,27 +175,18 @@ export function HierarchicalTermSelector( { slug } ) { | |
const { getTaxonomy, getEntityRecords, isResolving } = | ||
select( coreStore ); | ||
const _taxonomy = getTaxonomy( slug ); | ||
const post = getCurrentPost(); | ||
|
||
return { | ||
hasCreateAction: _taxonomy | ||
? get( | ||
getCurrentPost(), | ||
[ | ||
'_links', | ||
'wp:action-create-' + _taxonomy.rest_base, | ||
], | ||
false | ||
) | ||
? post._links?.[ | ||
'wp:action-create-' + _taxonomy.rest_base | ||
] ?? false | ||
: false, | ||
hasAssignAction: _taxonomy | ||
? get( | ||
getCurrentPost(), | ||
[ | ||
'_links', | ||
'wp:action-assign-' + _taxonomy.rest_base, | ||
], | ||
false | ||
) | ||
? post._links?.[ | ||
'wp:action-assign-' + _taxonomy.rest_base | ||
] ?? false | ||
: false, | ||
terms: _taxonomy | ||
? getEditedPostAttribute( _taxonomy.rest_base ) | ||
|
@@ -308,14 +294,12 @@ export function HierarchicalTermSelector( { slug } ) { | |
parent: formParent ? formParent : undefined, | ||
} ); | ||
|
||
const defaultName = | ||
slug === 'category' ? __( 'Category' ) : __( 'Term' ); | ||
const termAddedMessage = sprintf( | ||
/* translators: %s: taxonomy name */ | ||
_x( '%s added', 'term' ), | ||
get( | ||
taxonomy, | ||
[ 'labels', 'singular_name' ], | ||
slug === 'category' ? __( 'Category' ) : __( 'Term' ) | ||
) | ||
taxonomy?.labels?.singular_name ?? defaultName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
speak( termAddedMessage, 'assertive' ); | ||
setAdding( false ); | ||
|
@@ -383,11 +367,9 @@ export function HierarchicalTermSelector( { slug } ) { | |
fallbackIsCategory, | ||
fallbackIsNotCategory | ||
) => | ||
get( | ||
taxonomy, | ||
[ 'labels', labelProperty ], | ||
slug === 'category' ? fallbackIsCategory : fallbackIsNotCategory | ||
); | ||
taxonomy?.labels?.[ labelProperty ] ?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
( slug === 'category' ? fallbackIsCategory : fallbackIsNotCategory ); | ||
|
||
const newTermButtonLabel = labelWithFallback( | ||
'add_new_item', | ||
__( 'Add new category' ), | ||
|
@@ -405,12 +387,8 @@ export function HierarchicalTermSelector( { slug } ) { | |
); | ||
const noParentOption = `— ${ parentSelectLabel } —`; | ||
const newTermSubmitLabel = newTermButtonLabel; | ||
const filterLabel = get( | ||
taxonomy, | ||
[ 'labels', 'search_items' ], | ||
__( 'Search Terms' ) | ||
); | ||
const groupLabel = get( taxonomy, [ 'name' ], __( 'Terms' ) ); | ||
const filterLabel = taxonomy?.labels?.search_items ?? __( 'Search Terms' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const groupLabel = taxonomy?.name ?? __( 'Terms' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const showFilter = availableTerms.length >= MIN_TERMS_COUNT_FOR_FILTER; | ||
|
||
return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPostType()
could returnundefined
.