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

Default suggested links to pages #54622

Merged
merged 6 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 9 additions & 1 deletion packages/block-library/src/navigation-link/link-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ export function getSuggestionsQuery( type, kind ) {
if ( kind === 'post-type' ) {
return { type: 'post', subtype: type };
}
return {};
return {
// for custom link which has no type
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// for custom link which has no type
// for custom link which has no kind

Is it kind?

Copy link
Contributor Author

@draganescu draganescu Oct 2, 2023

Choose a reason for hiding this comment

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

It's type. The switch is on type and the default is for no type.

// always show pages as initial suggestions
initialSuggestionsOptions: {
type: 'post',
subtype: 'page',
perPage: 20,
draganescu marked this conversation as resolved.
Show resolved Hide resolved
},
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,28 @@ const fetchLinkSuggestions = async (
) => {
const {
isInitialSuggestions = false,
initialSuggestionsOptions = undefined,
draganescu marked this conversation as resolved.
Show resolved Hide resolved
} = searchOptions;

const { disablePostFormats = false } = settings;

let {
type = undefined,
subtype = undefined,
page = undefined,
perPage = isInitialSuggestions ? 3 : 20,
draganescu marked this conversation as resolved.
Show resolved Hide resolved
draganescu marked this conversation as resolved.
Show resolved Hide resolved
} = searchOptions;

const { disablePostFormats = false } = settings;

/** @type {Promise<WPLinkSearchResult>[]} */
const queries = [];

if ( isInitialSuggestions && initialSuggestionsOptions ) {
type = initialSuggestionsOptions.type;
subtype = initialSuggestionsOptions.subtype;
page = initialSuggestionsOptions.page;
perPage = initialSuggestionsOptions.perPage;
draganescu marked this conversation as resolved.
Show resolved Hide resolved
}

if ( ! type || type === 'post' ) {
queries.push(
apiFetch( {
Expand Down
Loading