@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
52 lines (49 loc) • 1.67 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PostAuthorCheck;
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _postTypeSupportCheck = _interopRequireDefault(require("../post-type-support-check"));
var _store = require("../../store");
var _constants = require("./constants");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Wrapper component that renders its children only if the post type supports the author.
*
* @param {Object} props The component props.
* @param {React.ReactNode} props.children Children to be rendered.
*
* @return {React.ReactNode} The component to be rendered. Return `null` if the post type doesn't
* supports the author or if there are no authors available.
*/function PostAuthorCheck({
children
}) {
const {
hasAssignAuthorAction,
hasAuthors
} = (0, _data.useSelect)(select => {
const post = select(_store.store).getCurrentPost();
const canAssignAuthor = post?._links?.['wp:action-assign-author'] ? true : false;
return {
hasAssignAuthorAction: canAssignAuthor,
hasAuthors: canAssignAuthor ? select(_coreData.store).getUsers(_constants.AUTHORS_QUERY)?.length >= 1 : false
};
}, []);
if (!hasAssignAuthorAction || !hasAuthors) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_postTypeSupportCheck.default, {
supportKeys: "author",
children: children
});
}
//# sourceMappingURL=check.js.map