-
Notifications
You must be signed in to change notification settings - Fork 22
Feature: Query Loop Block Support #98
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
Open
s3rgiosan
wants to merge
70
commits into
develop
Choose a base branch
from
feature/query-loop-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
06a65d0
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan f111a95
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 8124366
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan d86a2c8
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 86a7142
Add QueryLoop integration scaffold
s3rgiosan d747367
Add QueryLoop integration scaffold
s3rgiosan 4cee982
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 3d55313
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan e28388a
Rename class for clarity
s3rgiosan 69149c8
Rename class for clarity
s3rgiosan 525c651
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 278be0b
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 00891ba
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan ff6658f
Merge branch 'feature/rest-api-endpoint' into feature/query-loop-support
s3rgiosan 300cfbe
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan bdca82a
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 62c83a1
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan f593472
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan a766a3e
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan afeae34
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 1392bad
Add query loop block extension
s3rgiosan 31d0285
Add query loop block extension
s3rgiosan 8d1cd49
Update help texts
s3rgiosan 860ac4e
Update help texts
s3rgiosan 7b064d4
Update query block extension
s3rgiosan fad2d96
Update query block extension
s3rgiosan b047bda
Rename extended attributes and add initial support for the relationsh…
s3rgiosan 8c30bcc
Rename extended attributes and add initial support for the relationsh…
s3rgiosan 16109cc
Updates for Query Loop editor and front-end queries
s3rgiosan 150c31e
Updates for Query Loop editor and front-end queries
s3rgiosan f4dff24
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 89ef678
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 82f14ad
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 48977e9
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan c5dd3a8
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan e33921d
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan bc2790e
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 7a7a66d
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 89bb093
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 4260c99
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan ecca653
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 668c8d0
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 7ae79a7
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 0476cd5
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan ee53cee
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 01c68d6
Merge branch 'feature/classic-editor-support' into feature/query-loop…
s3rgiosan 638e2e0
Replace PanelBody with ToolsPanel for better integration with the Que…
s3rgiosan 2793617
Replace PanelBody with ToolsPanel for better integration with the Que…
s3rgiosan b1e4087
Rename label
s3rgiosan cdee5fe
Rename label
s3rgiosan 6f23f18
Rename plugin namespace back to wp-content-connect
s3rgiosan 1466f35
Rename plugin namespace back to wp-content-connect
s3rgiosan 0c11a79
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan ffd56e0
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 2a055a3
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 572eef7
Merge branch 'feature/data-api-backbone' into feature/query-loop-support
s3rgiosan 491c544
Merge branch 'develop' into feature/query-loop-support
s3rgiosan faa084a
Use code-split imports
s3rgiosan 90ae5c8
Use store reference instead of name in persist helper
s3rgiosan 3fb7d48
Addressed code review feedback
s3rgiosan a3c636a
Bump dependencies
s3rgiosan f838b78
Merge branch 'feature/query-loop-support' of github.com:10up/wp-conte…
s3rgiosan bce3647
Drop unused relationships helper import in query block integration
s3rgiosan 8038dea
Make order-by-relationship toggle resettable in query block panel
s3rgiosan d9d3a21
Scope query loop relationship args per block
s3rgiosan 54bdeb7
Add QueryBlockIntegration coverage
s3rgiosan ac2cd38
Add Query Loop relationship e2e spec
s3rgiosan 41e7aba
Simplify Query Loop relationship control
s3rgiosan 5b41804
Update dependencies
s3rgiosan ec78ec0
Merge branch 'develop' into feature/query-loop-support
s3rgiosan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "extends": [ | ||
| "@10up/eslint-config/wordpress" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,263 @@ | ||
| /* eslint-disable @wordpress/no-unsafe-wp-apis */ | ||
| /* eslint-disable import/no-extraneous-dependencies */ | ||
| /* eslint-disable import/extensions */ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { ContentPicker } from '@10up/block-components/components/content-picker'; | ||
| import { registerBlockExtension } from '@10up/block-components/api/register-block-extension'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { | ||
| ToggleControl, | ||
| Notice, | ||
| SelectControl, | ||
| BaseControl, | ||
| __experimentalVStack as VStack, | ||
| __experimentalToolsPanel as ToolsPanel, | ||
| __experimentalToolsPanelItem as ToolsPanelItem, | ||
| } from '@wordpress/components'; | ||
| import { InspectorControls } from '@wordpress/block-editor'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { store as editorStore } from '@wordpress/editor'; | ||
| import { useMemo, useEffect, useRef } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { store } from '../store'; | ||
|
|
||
| const BlockEdit = ({ setAttributes, attributes }) => { | ||
| const { query, showRelated, relationshipKey, sourcePost, orderByRelationship } = attributes; | ||
| const { postType: queriedPostType } = query; | ||
|
|
||
| const { postTypes, relationships, hasRelationships, hasMultipleRelationships, currentPostId } = | ||
| useSelect( | ||
| (select) => { | ||
| const { getPostTypes } = select(coreStore); | ||
| const excludedPostTypes = ['attachment']; | ||
| const filteredPostTypes = getPostTypes({ per_page: -1 })?.filter( | ||
| ({ viewable, slug }) => viewable && !excludedPostTypes.includes(slug), | ||
| ); | ||
|
|
||
| const currentPostId = select(editorStore).getCurrentPostId(); | ||
|
|
||
| const postRelationships = select(store).getRelationships( | ||
| sourcePost?.[0]?.id || currentPostId, | ||
| ); | ||
| const filteredRelationships = Object.values(postRelationships).filter( | ||
| (relationship) => | ||
| Array.isArray(relationship.post_type) && | ||
| relationship.post_type.includes(queriedPostType), | ||
| ); | ||
|
|
||
| return { | ||
| postTypes: filteredPostTypes, | ||
| relationships: filteredRelationships, | ||
| hasRelationships: filteredRelationships.length > 0, | ||
| hasMultipleRelationships: filteredRelationships.length > 1, | ||
| currentPostId, | ||
| }; | ||
| }, | ||
| [queriedPostType, sourcePost?.length], | ||
| ); | ||
|
|
||
| const postTypesSlugs = useMemo(() => (postTypes || []).map(({ slug }) => slug), [postTypes]); | ||
|
|
||
| const relationshipsOptions = useMemo( | ||
| () => | ||
| relationships.map((relationship) => ({ | ||
| value: relationship.rel_key, | ||
| label: relationship.labels.name, | ||
| })), | ||
| [relationships], | ||
| ); | ||
|
|
||
| const selectedRelationshipKey = useMemo( | ||
| () => | ||
| relationshipKey && relationships.some((rel) => rel.rel_key === relationshipKey) | ||
| ? relationshipKey | ||
| : relationships[0]?.rel_key, | ||
| [relationshipKey, relationships], | ||
| ); | ||
|
|
||
| const selectedRelationship = useMemo( | ||
| () => | ||
| relationships.find((relationship) => relationship.rel_key === selectedRelationshipKey), | ||
| [relationships, selectedRelationshipKey], | ||
| ); | ||
|
|
||
| const lastQueryRef = useRef(query); | ||
|
|
||
| const updatedQuery = useMemo(() => { | ||
| if (!showRelated || !selectedRelationship) { | ||
| const { relationshipQuery, orderByRelationship, ...cleanQuery } = query; | ||
| return cleanQuery; | ||
| } | ||
|
|
||
| return { | ||
| ...query, | ||
| orderByRelationship: (orderByRelationship ?? true) && selectedRelationship.sortable, | ||
| relationshipQuery: [ | ||
| { | ||
| name: selectedRelationship.rel_name, | ||
| related_to_post: sourcePost?.[0]?.id || currentPostId, | ||
| }, | ||
| ], | ||
| }; | ||
| }, [query, showRelated, orderByRelationship, selectedRelationship, sourcePost, currentPostId]); | ||
|
|
||
| useEffect(() => { | ||
| if (JSON.stringify(lastQueryRef.current) !== JSON.stringify(updatedQuery)) { | ||
| setAttributes({ query: updatedQuery }); | ||
| lastQueryRef.current = updatedQuery; | ||
| } | ||
| }, [updatedQuery, setAttributes]); | ||
|
|
||
| const relationshipsControlLabel = __('Relationship', 'tenup-content-connect'); | ||
| const relationshipsControlHelp = __( | ||
| 'Select a relationship to determine how related entities are retrieved.', | ||
| 'tenup-content-connect', | ||
| ); | ||
| const sourcePostControlHelp = __( | ||
| 'Choose the post from which related entities will be pulled. Defaults to the current post.', | ||
| 'tenup-content-connect', | ||
| ); | ||
|
|
||
| const resetAll = () => { | ||
| setAttributes({ | ||
| showRelated: false, | ||
| sourcePost: undefined, | ||
| relationshipKey: undefined, | ||
| orderByRelationship: undefined, | ||
| }); | ||
| }; | ||
|
|
||
| const onShowRelatedChange = (value) => { | ||
| if (!value) { | ||
| resetAll(); | ||
| } else { | ||
| setAttributes({ showRelated: value }); | ||
| } | ||
| }; | ||
|
|
||
| const onSourcePostChange = (ids) => { | ||
| setAttributes({ sourcePost: ids.length ? ids : undefined }); | ||
| }; | ||
|
|
||
| const onRelationshipChange = (value) => { | ||
| setAttributes({ relationshipKey: value }); | ||
| }; | ||
|
|
||
| const onOrderByRelationshipChange = (value) => { | ||
| setAttributes({ orderByRelationship: value }); | ||
| }; | ||
|
|
||
| return ( | ||
| <InspectorControls> | ||
| <ToolsPanel label={__('Related', 'tenup-content-connect')} resetAll={resetAll}> | ||
| <ToolsPanelItem | ||
| hasValue={() => !!showRelated} | ||
| label={__('Related entities', 'tenup-content-connect')} | ||
| onDeselect={() => resetAll()} | ||
| isShownByDefault | ||
| > | ||
| <VStack spacing={4}> | ||
| <ToggleControl | ||
| label={__('Only show related entities', 'tenup-content-connect')} | ||
| checked={showRelated} | ||
| onChange={onShowRelatedChange} | ||
| /> | ||
| {showRelated && !hasRelationships && ( | ||
| <Notice spokenMessage={null} status="warning" isDismissible={false}> | ||
| {__( | ||
| 'No relationships exist for the selected post type or post. Try selecting a different post or post type.', | ||
| 'tenup-content-connect', | ||
| )} | ||
| </Notice> | ||
| )} | ||
| </VStack> | ||
| </ToolsPanelItem> | ||
| {showRelated && ( | ||
| <ToolsPanelItem | ||
| hasValue={() => !!sourcePost} | ||
| label={__('Source post', 'tenup-content-connect')} | ||
| onDeselect={() => setAttributes({ sourcePost: undefined })} | ||
| > | ||
| <BaseControl help={sourcePostControlHelp}> | ||
| <ContentPicker | ||
| onPickChange={onSourcePostChange} | ||
| mode="post" | ||
| content={sourcePost} | ||
| contentTypes={postTypesSlugs} | ||
| maxContentItems={1} | ||
| singlePickedLabel={__('Selected post:', 'tenup-content-connect')} | ||
| /> | ||
| </BaseControl> | ||
| </ToolsPanelItem> | ||
| )} | ||
| {showRelated && hasMultipleRelationships && ( | ||
| <ToolsPanelItem | ||
| hasValue={() => !!relationshipKey} | ||
| label={__('Relationship', 'tenup-content-connect')} | ||
| onDeselect={() => setAttributes({ relationshipKey: undefined })} | ||
| isShownByDefault | ||
| > | ||
| <SelectControl | ||
| options={relationshipsOptions} | ||
| value={relationshipKey} | ||
| label={relationshipsControlLabel} | ||
| onChange={onRelationshipChange} | ||
| help={relationshipsControlHelp} | ||
| __nextHasNoMarginBottom | ||
| __next40pxDefaultSize | ||
| /> | ||
| </ToolsPanelItem> | ||
| )} | ||
| {showRelated && selectedRelationship?.sortable && ( | ||
| <ToolsPanelItem | ||
| hasValue={() => orderByRelationship !== undefined} | ||
| label={__('Order by relationship', 'tenup-content-connect')} | ||
| onDeselect={() => setAttributes({ orderByRelationship: undefined })} | ||
| > | ||
| <ToggleControl | ||
| __nextHasNoMarginBottom | ||
| label={__('Order by relationship', 'tenup-content-connect')} | ||
| checked={orderByRelationship ?? true} | ||
| onChange={onOrderByRelationshipChange} | ||
| help={__( | ||
| 'If enabled, the order of the posts will be determined by the selected relationship. This supersedes any other ordering.', | ||
| 'tenup-content-connect', | ||
| )} | ||
| /> | ||
| </ToolsPanelItem> | ||
| )} | ||
| </ToolsPanel> | ||
| </InspectorControls> | ||
| ); | ||
| }; | ||
|
|
||
| registerBlockExtension('core/query', { | ||
| extensionName: 'content-connect', | ||
| attributes: { | ||
| showRelated: { | ||
| type: 'boolean', | ||
| default: false, | ||
| }, | ||
| sourcePost: { | ||
| type: 'array', | ||
| }, | ||
| relationshipKey: { | ||
| type: 'string', | ||
| }, | ||
| orderByRelationship: { | ||
| type: 'boolean', | ||
| }, | ||
| }, | ||
| classNameGenerator: () => '', | ||
| Edit: BlockEdit, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './core-query'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-deprecated', 'wp-dom', 'wp-dom-ready', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => '82ac952edad0ee4ec44c'); | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => '377f6f6490bfd79cc04f'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-deprecated', 'wp-dom', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => '4f272cda04d4a62a55fe'); | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => 'ce1d1d5d9c62f539010a'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.