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

Add new post link to Query #27732

Merged
merged 3 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -20,7 +20,14 @@ import {
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { useEffect, useState, useCallback, useMemo } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import {
useEffect,
useState,
useCallback,
useMemo,
createInterpolateElement,
} from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -143,8 +150,24 @@ export default function QueryInspectorControls( {
onChangeDebounced();
return onChangeDebounced.cancel;
}, [ querySearch, onChangeDebounced ] );

const CreateNewPostLink = ( { type } ) => {
const newPostUrl = addQueryArgs( 'post-new.php', {
post_type: type,
} );
return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
__( '<a>Create a new post</a> for this feed.' ),
// eslint-disable-next-line jsx-a11y/anchor-has-content
{ a: <a href={ newPostUrl } /> }
) }
</div>
);
};
return (
<InspectorControls>
<CreateNewPostLink type={ postType } />
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
<PanelBody title={ __( 'Settings' ) }>
<ToggleControl
label={ __( 'Inherit query from URL' ) }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/query/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.block-library-query-toolbar__popover .components-popover__content {
min-width: 230px;
}

.wp-block-query__create-new-link {
padding: 0 $grid-unit-20 $grid-unit-20 56px;
}