Skip to content
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

Query: Ensure create new post link is above block styles #49566

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-c
import AdvancedControls from '../inspector-controls-tabs/advanced-controls-panel';
import PositionControls from '../inspector-controls-tabs/position-controls-panel';
import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSettings';
import CreateNewPostLink from '../create-new-post-link';

function useContentBlocks( blockTypes, block ) {
const contentBlocksObjectAux = useMemo( () => {
Expand Down Expand Up @@ -326,6 +327,9 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
className={ blockInformation.isSynced && 'is-synced' }
/>
<BlockVariationTransforms blockClientId={ clientId } />
{ blockName === 'core/query' && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just add a comment, that this should leave with the first chance we get(either relocation of CreateNewPostLink inside Query or any other way)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I can definitely add a comment before merging this.

Dan and I were discussing our options around creating a private SlotFill. My plan is to explore that a little tomorrow. If it looks like something we can get in soon, then we'll opt for that instead of this PR 🤞

<CreateNewPostLink clientId={ clientId } />
) }
{ showTabs && (
<InspectorControlsTabs
hasBlockStyles={ hasBlockStyles }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';

const CreateNewPostLink = ( { clientId } ) => {
const postType = useSelect(
( select ) => {
const { getBlockAttributes } = select( blockEditorStore );
return getBlockAttributes( clientId )?.query?.postType;
},
[ clientId ]
);

if ( ! postType ) return null;
const newPostUrl = addQueryArgs( 'post-new.php', {
post_type: postType,
} );

return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
__( '<a>Add new post</a>' ),
// eslint-disable-next-line jsx-a11y/anchor-has-content
{ a: <a href={ newPostUrl } /> }
) }
</div>
);
};

export default CreateNewPostLink;
53 changes: 0 additions & 53 deletions packages/block-library/src/query/hooks.js

This file was deleted.

8 changes: 1 addition & 7 deletions packages/block-library/src/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { loop as icon } from '@wordpress/icons';
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
Expand All @@ -13,7 +12,6 @@ import edit from './edit';
import save from './save';
import variations from './variations';
import deprecated from './deprecated';
import queryInspectorControls from './hooks';

const { name } = metadata;
export { metadata, name };
Expand All @@ -26,8 +24,4 @@ export const settings = {
deprecated,
};

export const init = () => {
addFilter( 'editor.BlockEdit', 'core/query', queryInspectorControls );

return initBlock( { name, metadata, settings } );
};
export const init = () => initBlock( { name, metadata, settings } );