Skip to content

Conversation

@s3rgiosan
Copy link
Member

@s3rgiosan s3rgiosan commented Mar 18, 2025

Warning

This PR is based on #97

Description of the Change

This PR introduces Content Connect relationship support for the Query Loop block, allowing posts to be filtered based on relationships.

Closes #83

How to test the Change

Changelog Entry

Added - Query Loop block integration with Content Connect relationships.

Credits

Props @s3rgiosan

Checklist:

@s3rgiosan s3rgiosan changed the base branch from feature/data-api-backbone to feature/classic-editor-support March 18, 2025 01:03
@s3rgiosan s3rgiosan self-assigned this Mar 18, 2025
@s3rgiosan
Copy link
Member Author

I've created a try/block-editor-ui all-in-one branch to make it easier to test the features in both the block and classic editors, as well as the Query Loop integration.

@jeffpaul jeffpaul added this to the 1.7.0 milestone Mar 21, 2025
@jeffpaul jeffpaul moved this to Code Review in Open Source Practice Mar 21, 2025
@jeffpaul
Copy link
Member

@rickalee @fabiankaegy bumping this for your review

@s3rgiosan s3rgiosan changed the title Featured: Query Loop Block Support Feature: Query Loop Block Support May 16, 2025
@benlk
Copy link

benlk commented May 22, 2025

Note that we'll also need a button to clear search query parameters: either just this integration's parameters, or all query parameters currently in use.

s3rgiosan added 2 commits May 26, 2025 15:32
…-support

# Conflicts:
#	includes/API/V2/Post/Field/Relationships.php
#	package-lock.json
#	package.json
@s3rgiosan
Copy link
Member Author

s3rgiosan commented May 26, 2025

Note that we'll also need a button to clear search query parameters: either just this integration's parameters, or all query parameters currently in use.

@benlk Clearing all query parameters is tricky. The Query block’s core filters don’t offer direct integration, and plugins like Advanced Query Loop can extend or alter them. That makes it hard to identify which filters are active or what the default state should be. I’ve switched from PanelBody to ToolPanel in the UI, which makes it easier to reset custom parameters tied to this integration.

Screenshot 2025-05-26 at 18 16 41

Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

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

This is working very well! I added a few minor comments that should all be easy to address :)

Comment on lines +210 to +219
{hasRelationships && (
<SelectControl
options={relationshipsOptions}
value={relationshipKey}
label={relationshipsControlLabel}
onChange={onRelationshipChange}
help={relationshipsControlHelp}
__nextHasNoMarginBottom
/>
)}
Copy link
Member

Choose a reason for hiding this comment

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

We should only show this select control if there is more than one relationship available. I got it in an example where it only had one option

label={relationshipsControlLabel}
onChange={onRelationshipChange}
help={relationshipsControlHelp}
__nextHasNoMarginBottom
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
__nextHasNoMarginBottom
__nextHasNoMarginBottom
__next40pxDefaultSize

If we need this control we should make sure it has the new default size to make it look better :)

Comment on lines +185 to +201
<ToolsPanelItem
hasValue={() => !!sourcePost}
label={__('Source post', 'tenup-content-connect')}
onDeselect={() => setAttributes({ sourcePost: undefined })}
isShownByDefault
>
<BaseControl help={sourcePostControlHelp}>
<ContentPicker
onPickChange={onSourcePostChange}
mode="post"
content={sourcePost}
contentTypes={postTypesSlugs}
maxContentItems={1}
singlePickedLabel={__('Selected post:', 'tenup-content-connect')}
/>
</BaseControl>
</ToolsPanelItem>
Copy link
Member

Choose a reason for hiding this comment

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

The way this currently works is odd. By default it already has the current post selected. I am not sure if this is how it should be 🤔

I think instead of that we should hide the ContentPicker entirely behind the ToolsPanel dropdown and just not have any value selected.

That way users that want to select a different post to relate to (which should be a very niche feature) can still do it but it isn't there front and center.

* External dependencies
*/
import { v4 as uuidv4 } from 'uuid';
import { registerBlockExtension, ContentPicker } from '@10up/block-components';
Copy link
Member

Choose a reason for hiding this comment

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

If we update to version 1.21.1 of the block components we can use the new code split import syntax for these also:

Suggested change
import { registerBlockExtension, ContentPicker } from '@10up/block-components';
import { ContentPicker } from '@10up/block-components/components/content-picker';
import { registerBlockExtension } from '@10up/block-components/api/register-block-extension';

which will result in a smaller bundle size :)

"archive": "composer archive --file=$npm_package_name --format=zip"
},
"dependencies": {
"@10up/block-components": "^1.20.1",
Copy link
Member

Choose a reason for hiding this comment

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

Lets update this again to the latest version :)


// Clear dirty entities after successful save
dispatch(STORE_NAME).clearDirtyEntities();
(dispatch(STORE_NAME) as any).clearDirtyEntities();
Copy link
Member

Choose a reason for hiding this comment

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

Instead of typing it here as any we should use the actual store reference here instead of just the string of the name. this will ensure the types come across properly

import React from 'react';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
Copy link
Member

Choose a reason for hiding this comment

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

Nice! We should always use the version from @wordpress/editor

@jeffpaul
Copy link
Member

jeffpaul commented Oct 6, 2025

@s3rgiosan back to you after some code review feedback

@jeffpaul jeffpaul removed their request for review October 6, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Code Review

Development

Successfully merging this pull request may close these issues.

4 participants