diff --git a/packages/edit-post/src/components/device-preview/index.js b/packages/edit-post/src/components/device-preview/index.js index adf1b9608d6a14..2ac65ca587ae0c 100644 --- a/packages/edit-post/src/components/device-preview/index.js +++ b/packages/edit-post/src/components/device-preview/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -35,7 +30,7 @@ export default function DevicePreview() { hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(), isSaving: select( editPostStore ).isSavingMetaBoxes(), isPostSaveable: select( editorStore ).isEditedPostSaveable(), - isViewable: get( postType, [ 'viewable' ], false ), + isViewable: postType?.viewable ?? false, deviceType: select( editPostStore ).__experimentalGetPreviewDeviceType(), }; diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js index be6b355d1c8939..a6445a1982dd2f 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { get } from 'lodash'; import classnames from 'classnames'; /** @@ -99,11 +98,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { post_type: postType.slug, } ) } - label={ get( - postType, - [ 'labels', 'view_items' ], - __( 'Back' ) - ) } + label={ postType?.labels?.view_items ?? __( 'Back' ) } showTooltip={ showTooltip } > { buttonIcon } diff --git a/packages/edit-post/src/components/sidebar/featured-image/index.js b/packages/edit-post/src/components/sidebar/featured-image/index.js index 4463bf8e51404a..42215c5de93805 100644 --- a/packages/edit-post/src/components/sidebar/featured-image/index.js +++ b/packages/edit-post/src/components/sidebar/featured-image/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -35,11 +30,9 @@ function FeaturedImage( { isEnabled, isOpened, postType, onTogglePanel } ) { return ( diff --git a/packages/edit-post/src/components/sidebar/page-attributes/index.js b/packages/edit-post/src/components/sidebar/page-attributes/index.js index 84980e99aa3b99..e34680e42a7b52 100644 --- a/packages/edit-post/src/components/sidebar/page-attributes/index.js +++ b/packages/edit-post/src/components/sidebar/page-attributes/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -52,11 +47,9 @@ export function PageAttributes() { return ( diff --git a/packages/editor/src/components/page-attributes/parent.js b/packages/editor/src/components/page-attributes/parent.js index fbf067943615ea..0aa200b624604b 100644 --- a/packages/editor/src/components/page-attributes/parent.js +++ b/packages/editor/src/components/page-attributes/parent.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { get } from 'lodash'; import removeAccents from 'remove-accents'; /** @@ -44,47 +43,48 @@ export const getItemPriority = ( name, searchValue ) => { export function PageAttributesParent() { const { editPost } = useDispatch( editorStore ); const [ fieldValue, setFieldValue ] = useState( false ); - const { parentPost, parentPostId, items, postType } = useSelect( - ( select ) => { - const { getPostType, getEntityRecords, getEntityRecord } = - select( coreStore ); - const { getCurrentPostId, getEditedPostAttribute } = - select( editorStore ); - const postTypeSlug = getEditedPostAttribute( 'type' ); - const pageId = getEditedPostAttribute( 'parent' ); - const pType = getPostType( postTypeSlug ); - const postId = getCurrentPostId(); - const isHierarchical = get( pType, [ 'hierarchical' ], false ); - const query = { - per_page: 100, - exclude: postId, - parent_exclude: postId, - orderby: 'menu_order', - order: 'asc', - _fields: 'id,title,parent', - }; - - // Perform a search when the field is changed. - if ( !! fieldValue ) { - query.search = fieldValue; - } - - return { - parentPostId: pageId, - parentPost: pageId - ? getEntityRecord( 'postType', postTypeSlug, pageId ) - : null, - items: isHierarchical - ? getEntityRecords( 'postType', postTypeSlug, query ) - : [], - postType: pType, - }; - }, - [ fieldValue ] - ); + const { isHierarchical, parentPost, parentPostId, items, postType } = + useSelect( + ( select ) => { + const { getPostType, getEntityRecords, getEntityRecord } = + select( coreStore ); + const { getCurrentPostId, getEditedPostAttribute } = + select( editorStore ); + const postTypeSlug = getEditedPostAttribute( 'type' ); + const pageId = getEditedPostAttribute( 'parent' ); + const pType = getPostType( postTypeSlug ); + const postId = getCurrentPostId(); + const postIsHierarchical = pType?.hierarchical ?? false; + const query = { + per_page: 100, + exclude: postId, + parent_exclude: postId, + orderby: 'menu_order', + order: 'asc', + _fields: 'id,title,parent', + }; + + // Perform a search when the field is changed. + if ( !! fieldValue ) { + query.search = fieldValue; + } + + return { + isHierarchical: postIsHierarchical, + parentPostId: pageId, + parentPost: pageId + ? getEntityRecord( 'postType', postTypeSlug, pageId ) + : null, + items: postIsHierarchical + ? getEntityRecords( 'postType', postTypeSlug, query ) + : [], + postType: pType, + }; + }, + [ fieldValue ] + ); - const isHierarchical = get( postType, [ 'hierarchical' ], false ); - const parentPageLabel = get( postType, [ 'labels', 'parent_item_colon' ] ); + const parentPageLabel = postType?.labels?.parent_item_colon; const pageItems = items || []; const parentOptions = useMemo( () => { diff --git a/packages/editor/src/components/post-featured-image/index.js b/packages/editor/src/components/post-featured-image/index.js index dd50d9bd588051..b46e77ea6a5726 100644 --- a/packages/editor/src/components/post-featured-image/index.js +++ b/packages/editor/src/components/post-featured-image/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -105,7 +100,6 @@ function PostFeaturedImage( { const mediaUpload = useSelect( ( select ) => { return select( blockEditorStore ).getSettings().mediaUpload; }, [] ); - const postLabel = get( postType, [ 'labels' ], {} ); const { mediaWidth, mediaHeight, mediaSourceUrl } = getMediaDetails( media, currentPostId @@ -159,7 +153,7 @@ function PostFeaturedImage( { } { ! featuredImageId && ! isLoading && - ( postLabel.set_featured_image || + ( postType?.labels + ?.set_featured_image || DEFAULT_SET_FEATURE_IMAGE_LABEL ) } @@ -215,7 +210,7 @@ function PostFeaturedImage( { { media && ( - { postLabel.remove_featured_image || + { postType?.labels?.remove_featured_image || DEFAULT_REMOVE_FEATURE_IMAGE_LABEL } diff --git a/packages/editor/src/components/post-locked-modal/index.js b/packages/editor/src/components/post-locked-modal/index.js index e3af0f1a1f63d4..953fabf9953da7 100644 --- a/packages/editor/src/components/post-locked-modal/index.js +++ b/packages/editor/src/components/post-locked-modal/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -164,7 +159,7 @@ export default function PostLockedModal() { _wpnonce: postLockUtils.nonce, } ); const allPostsUrl = addQueryArgs( 'edit.php', { - post_type: get( postType, [ 'slug' ] ), + post_type: postType?.slug, } ); const allPostsLabel = __( 'Exit editor' ); return ( diff --git a/packages/editor/src/components/post-preview-button/index.js b/packages/editor/src/components/post-preview-button/index.js index 2cdca7d98cfb24..b6500e8fbd37d4 100644 --- a/packages/editor/src/components/post-preview-button/index.js +++ b/packages/editor/src/components/post-preview-button/index.js @@ -1,7 +1,6 @@ /** * External dependencies */ -import { get } from 'lodash'; import classnames from 'classnames'; /** @@ -256,7 +255,7 @@ export default compose( [ forcePreviewLink !== undefined ? forcePreviewLink : previewLink, isSaveable: isEditedPostSaveable(), isAutosaveable: forceIsAutosaveable || isEditedPostAutosaveable(), - isViewable: get( postType, [ 'viewable' ], false ), + isViewable: postType?.viewable ?? false, isDraft: [ 'draft', 'auto-draft' ].indexOf( getEditedPostAttribute( 'status' ) diff --git a/packages/editor/src/components/post-publish-panel/postpublish.js b/packages/editor/src/components/post-publish-panel/postpublish.js index 78b14e6b448e92..178fc2c4954058 100644 --- a/packages/editor/src/components/post-publish-panel/postpublish.js +++ b/packages/editor/src/components/post-publish-panel/postpublish.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * WordPress dependencies */ @@ -90,9 +85,9 @@ class PostPublishPanelPostpublish extends Component { render() { const { children, isScheduled, post, postType } = this.props; - const postLabel = get( postType, [ 'labels', 'singular_name' ] ); - const viewPostLabel = get( postType, [ 'labels', 'view_item' ] ); - const addNewPostLabel = get( postType, [ 'labels', 'add_new_item' ] ); + const postLabel = postType?.labels?.singular_name; + const viewPostLabel = postType?.labels?.view_item; + const addNewPostLabel = postType?.labels?.add_new_item; const link = post.status === 'future' ? getFuturePostUrl( post ) : post.link; const addLink = addQueryArgs( 'post-new.php', { diff --git a/packages/editor/src/store/utils/notice-builder.js b/packages/editor/src/store/utils/notice-builder.js index 4a3f87403d07f8..e7bb29741ffc62 100644 --- a/packages/editor/src/store/utils/notice-builder.js +++ b/packages/editor/src/store/utils/notice-builder.js @@ -8,11 +8,6 @@ import { __ } from '@wordpress/i18n'; */ import { SAVE_POST_NOTICE_ID, TRASH_POST_NOTICE_ID } from '../constants'; -/** - * External dependencies - */ -import { get } from 'lodash'; - /** * Builds the arguments for a success notification dispatch. * @@ -24,7 +19,7 @@ import { get } from 'lodash'; export function getNotificationArgumentsForSaveSuccess( data ) { const { previousPost, post, postType } = data; // Autosaves are neither shown a notice nor redirected. - if ( get( data.options, [ 'isAutosave' ] ) ) { + if ( data.options?.isAutosave ) { return []; } @@ -38,7 +33,7 @@ export function getNotificationArgumentsForSaveSuccess( data ) { const willPublish = publishStatus.includes( post.status ); let noticeMessage; - let shouldShowLink = get( postType, [ 'viewable' ], false ); + let shouldShowLink = postType?.viewable ?? false; let isDraft; // Always should a notice, which will be spoken for accessibility.