-
Notifications
You must be signed in to change notification settings - Fork 22
Feature: Native Block Editor Interface #94
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
fabiankaegy
wants to merge
54
commits into
feature/rest-api-endpoint
Choose a base branch
from
feature/data-api-backbone
base: feature/rest-api-endpoint
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.
+20,491
−21,182
Open
Changes from 40 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
10c412e
fix update node version to 20
fabiankaegy 2cf7e95
replace view app with modern toolkit based build process
fabiankaegy 2272b0d
update installed packages
fabiankaegy 01f6dc2
add initial scaffolding for store
fabiankaegy 2b5b721
fix comment out enqueued scripts from MetaBox
fabiankaegy f1c3071
add initial working version of the store
fabiankaegy 388fb66
clean up store
fabiankaegy c622ead
add hooks for interfacing with data store
fabiankaegy 4bda6c3
harden types
fabiankaegy 5a08969
fix how data is passed to server
fabiankaegy 44333e2
handle undefined post ID’s
fabiankaegy 21c278b
install additional dependencies
fabiankaegy 621e135
add initial version of UI
fabiankaegy 5b8055a
Move PluginDocumentSettingsPanel to RelationshipManager component for…
s3rgiosan c9a4748
Replace FormTokenField with 10up Content Picker
s3rgiosan ed27efb
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 416656c
Remove console.log
s3rgiosan c448f18
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 1827028
Rename RelatedPosts to RelatedEntities to support post-to-user relati…
s3rgiosan cf65bb2
Rename file
s3rgiosan 052f5fa
Pass undefined on contentTypes for post-to-user relationships
s3rgiosan 643a666
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 960e5b9
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 810c18c
Remove test code 🤦♂️
s3rgiosan bd25262
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 97a2b87
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 927705c
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan 03a4ef2
Respect "enable_ui" flag when rendering the relationship panel
s3rgiosan 32402d0
Add await for updateRelatedEntities
s3rgiosan b7edacf
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan fb2d409
Use id and remove ID
s3rgiosan d35c0fd
Update internal state while syncing to the server in the background
s3rgiosan ba82f14
Add docblocks
s3rgiosan 5b2770c
Extract key generation logic
s3rgiosan 0f8170b
Remove redundant state update call
s3rgiosan d7e6258
Memoize selector
s3rgiosan cca2536
Fix adding new relationships
s3rgiosan 7884213
Update useRelatedEntities hook
s3rgiosan bbb2003
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan d88aa0a
Improve ContentPicker query filtering for relationship context
s3rgiosan 53ad11d
Update MetaBox.php
s3rgiosan 0308424
Fix typo
barryceelen b5350e9
Add support for max_items
barryceelen 95bdda1
Merge pull request #112 from 10up/feature/max-items
s3rgiosan dbd3cfb
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan c2640e8
Update to 100
s3rgiosan fead1ae
Update 10up Block components
s3rgiosan 3f6915f
Add npm scripts
s3rgiosan 462b7d2
Merge branch 'feature/helpers' into feature/data-api-backbone
s3rgiosan cf79b34
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan ee94e60
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan e031119
Only reflect relationship changes after post being saved
s3rgiosan fc7263a
Address PR comments
s3rgiosan 0a0b4a7
Update dependencies
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
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 @@ | ||
| 20 |
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,50 @@ | ||
| import React from 'react'; | ||
| import { ContentPicker } from '@10up/block-components'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { addQueryArgs } from '@wordpress/url'; | ||
| import { store } from '../store'; | ||
| import { ContentConnectRelationship } from '../store/types'; | ||
|
|
||
| type RelationshipManagerProps = { | ||
| postId: number | null; | ||
| relationship: ContentConnectRelationship; | ||
| }; | ||
|
|
||
| export function RelationshipManager({ postId, relationship }: RelationshipManagerProps) { | ||
| const { updateRelatedEntities } = useDispatch(store); | ||
|
|
||
| const { relatedEntities } = useSelect((select) => ({ | ||
| relatedEntities: select(store).getRelatedEntities(postId, { | ||
| rel_key: relationship.rel_key, | ||
| rel_type: relationship.rel_type, | ||
| }), | ||
| }), [postId, relationship.rel_key]); | ||
|
|
||
| const handleChange = async (newEntities: any[]) => { | ||
| await updateRelatedEntities( | ||
| postId, | ||
| relationship.rel_key, | ||
| relationship.rel_type, | ||
| newEntities | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <ContentPicker | ||
| onPickChange={handleChange} | ||
| mode={relationship?.object_type ?? 'post'} | ||
| content={relatedEntities} | ||
| contentTypes={relationship?.post_type} | ||
| maxContentItems={relationship?.max_items ?? 100} | ||
| isOrderable={relationship?.sortable ?? false} | ||
| queryFilter={(query) => { | ||
| if (relationship?.rel_key) { | ||
| return addQueryArgs(query, { | ||
| content_connect: relationship.rel_key | ||
| }); | ||
| } | ||
| return 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React from 'react'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { store as editorStore } from '@wordpress/editor'; | ||
| import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; | ||
| import { store } from '../store'; | ||
| import { RelationshipManager } from './relationship-manager'; | ||
|
|
||
| export function RelationshipsPanel() { | ||
| const { postId, relationships } = useSelect((select) => { | ||
| const postId = select(editorStore).getCurrentPostId(); | ||
| const relationships = select(store).getRelationships(postId); | ||
|
|
||
| return { | ||
| postId, | ||
| relationships, | ||
| }; | ||
| }, []); | ||
|
|
||
| if (!relationships || Object.keys(relationships).length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const enabledRelationships = Object.values(relationships).filter( | ||
| (relationship) => relationship.enable_ui === true | ||
| ); | ||
|
|
||
| if (enabledRelationships.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {enabledRelationships.map((relationship) => ( | ||
| <PluginDocumentSettingPanel | ||
| name={`content-connect-relationship-${relationship.rel_key}`} | ||
| title={relationship.labels.name} | ||
| > | ||
| <RelationshipManager | ||
| postId={postId} | ||
| relationship={relationship} | ||
| /> | ||
| </PluginDocumentSettingPanel> | ||
| ))} | ||
| </> | ||
| ); | ||
| } |
This file was deleted.
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import './use-relationships'; | ||
| import './use-related-entities'; |
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,31 @@ | ||
| import { store } from '../store'; | ||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||
| import { useCallback } from 'react'; | ||
| import { GetRelatedEntitiesOptions } from '../store/api'; | ||
| import { ContentConnectRelatedEntities } from '../store/types'; | ||
|
|
||
| export function useRelatedEntities(postId: number, options: GetRelatedEntitiesOptions) { | ||
| const { hasResolved, relatedEntities } = useSelect( | ||
| (select) => { | ||
| const params = [postId, options] as const; | ||
| const relatedEntities = select(store).getRelatedEntities(...params); | ||
| // @ts-expect-error - The hasFinishedResolution method is a meta-method that coming | ||
| // from WordPress. Because of that, it's not typed correctly in our custom store. | ||
| const hasResolved: boolean = select(store).hasFinishedResolution('getRelatedEntities', params); | ||
|
|
||
| return { | ||
| relatedEntities, | ||
| hasResolved, | ||
| }; | ||
| }, | ||
| [postId, options] | ||
| ); | ||
|
|
||
| const { updateRelatedEntities } = useDispatch(store); | ||
|
|
||
| const _updateRelatedEntities = useCallback((entities: ContentConnectRelatedEntities) => { | ||
| updateRelatedEntities(postId, options.rel_key, options.rel_type, entities); | ||
| }, [postId, options, updateRelatedEntities]); | ||
|
|
||
| return [hasResolved, relatedEntities, _updateRelatedEntities] as const; | ||
| } |
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,26 @@ | ||
| import { store } from '../store'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { GetRelationshipsOptions } from '../store/api'; | ||
|
|
||
| export function useRelationships( | ||
| postId: number, | ||
| options?: GetRelationshipsOptions | ||
| ) { | ||
| const { relationships, hasResolved } = useSelect( | ||
| (select) => { | ||
| const params = [postId, options] as const; | ||
| const relationships = select(store).getRelationships(...params); | ||
| // @ts-expect-error - The hasFinishedResolution method is a meta-method that coming | ||
| // from WordPress. Because of that, it's not typed correctly in our custom store. | ||
| const hasResolved: boolean = select(store).hasFinishedResolution('getRelationships', params); | ||
|
|
||
| return { | ||
| relationships, | ||
| hasResolved, | ||
| }; | ||
| }, | ||
| [postId, options] | ||
| ); | ||
|
|
||
| return [hasResolved, relationships] as const; | ||
| } |
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,9 @@ | ||
| import './store'; | ||
| import './hooks'; | ||
|
|
||
| import { registerPlugin } from '@wordpress/plugins'; | ||
| import { RelationshipsPanel } from './components/relationships-panel'; | ||
|
|
||
| registerPlugin('wp-content-connect', { | ||
| render: RelationshipsPanel, | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this search parameter mainly to give context to the editor-side search when it reaches the
rest_post_search_queryhook in PHP. One of my clients uses ElasticPress, and I needed a way to disable EP for these specific queries. This parameter can also be used to filter search results based on client-specific requirements. It might also be worth including the current post ID.