UNPKG

@wordpress/editor

Version:
58 lines (55 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = PostTrashCheck; var _data = require("@wordpress/data"); var _coreData = require("@wordpress/core-data"); var _store = require("../../store"); var _constants = require("../../store/constants"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Wrapper component that renders its children only if the post can trashed. * * @param {Object} props - The component props. * @param {Element} props.children - The child components to render. * * @return {Component|null} The rendered child components or null if the post can not trashed. */ function PostTrashCheck({ children }) { const { canTrashPost } = (0, _data.useSelect)(select => { const { isEditedPostNew, getCurrentPostId, getCurrentPostType } = select(_store.store); const { canUser } = select(_coreData.store); const postType = getCurrentPostType(); const postId = getCurrentPostId(); const isNew = isEditedPostNew(); const canUserDelete = !!postId ? canUser('delete', { kind: 'postType', name: postType, id: postId }) : false; return { canTrashPost: (!isNew || postId) && canUserDelete && !_constants.GLOBAL_POST_TYPES.includes(postType) }; }, []); if (!canTrashPost) { return null; } return children; } //# sourceMappingURL=check.js.map