Skip to content
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
10c412e
fix update node version to 20
fabiankaegy Feb 17, 2025
2cf7e95
replace view app with modern toolkit based build process
fabiankaegy Feb 17, 2025
2272b0d
update installed packages
fabiankaegy Feb 17, 2025
01f6dc2
add initial scaffolding for store
fabiankaegy Feb 17, 2025
2b5b721
fix comment out enqueued scripts from MetaBox
fabiankaegy Feb 17, 2025
f1c3071
add initial working version of the store
fabiankaegy Feb 17, 2025
388fb66
clean up store
fabiankaegy Feb 18, 2025
c622ead
add hooks for interfacing with data store
fabiankaegy Feb 18, 2025
4bda6c3
harden types
fabiankaegy Feb 18, 2025
5a08969
fix how data is passed to server
fabiankaegy Feb 18, 2025
44333e2
handle undefined post ID’s
fabiankaegy Feb 18, 2025
21c278b
install additional dependencies
fabiankaegy Feb 18, 2025
621e135
add initial version of UI
fabiankaegy Feb 18, 2025
5b8055a
Move PluginDocumentSettingsPanel to RelationshipManager component for…
s3rgiosan Mar 14, 2025
c9a4748
Replace FormTokenField with 10up Content Picker
s3rgiosan Mar 14, 2025
ed27efb
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 14, 2025
416656c
Remove console.log
s3rgiosan Mar 14, 2025
c448f18
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 14, 2025
1827028
Rename RelatedPosts to RelatedEntities to support post-to-user relati…
s3rgiosan Mar 14, 2025
cf65bb2
Rename file
s3rgiosan Mar 14, 2025
052f5fa
Pass undefined on contentTypes for post-to-user relationships
s3rgiosan Mar 14, 2025
643a666
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 14, 2025
960e5b9
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 14, 2025
810c18c
Remove test code 🤦‍♂️
s3rgiosan Mar 14, 2025
bd25262
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 14, 2025
97a2b87
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 18, 2025
927705c
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan Mar 18, 2025
03a4ef2
Respect "enable_ui" flag when rendering the relationship panel
s3rgiosan Apr 4, 2025
32402d0
Add await for updateRelatedEntities
s3rgiosan Apr 4, 2025
b7edacf
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan May 6, 2025
fb2d409
Use id and remove ID
s3rgiosan May 6, 2025
d35c0fd
Update internal state while syncing to the server in the background
s3rgiosan May 6, 2025
ba82f14
Add docblocks
s3rgiosan May 6, 2025
5b2770c
Extract key generation logic
s3rgiosan May 6, 2025
0f8170b
Remove redundant state update call
s3rgiosan May 6, 2025
d7e6258
Memoize selector
s3rgiosan May 6, 2025
cca2536
Fix adding new relationships
s3rgiosan May 6, 2025
7884213
Update useRelatedEntities hook
s3rgiosan May 6, 2025
bbb2003
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan May 8, 2025
d88aa0a
Improve ContentPicker query filtering for relationship context
s3rgiosan May 8, 2025
53ad11d
Update MetaBox.php
s3rgiosan May 9, 2025
0308424
Fix typo
barryceelen May 21, 2025
b5350e9
Add support for max_items
barryceelen May 21, 2025
95bdda1
Merge pull request #112 from 10up/feature/max-items
s3rgiosan May 22, 2025
dbd3cfb
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan May 22, 2025
c2640e8
Update to 100
s3rgiosan May 22, 2025
fead1ae
Update 10up Block components
s3rgiosan May 22, 2025
3f6915f
Add npm scripts
s3rgiosan May 26, 2025
462b7d2
Merge branch 'feature/helpers' into feature/data-api-backbone
s3rgiosan May 26, 2025
cf79b34
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan May 26, 2025
ee94e60
Merge branch 'feature/rest-api-endpoint' into feature/data-api-backbone
s3rgiosan May 26, 2025
e031119
Only reflect relationship changes after post being saved
s3rgiosan Jun 16, 2025
fc7263a
Address PR comments
s3rgiosan Jun 17, 2025
0a0b4a7
Update dependencies
s3rgiosan Jun 17, 2025
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ sassdoc
scss-lint-report.xml
config.codekit

/assets/js/content-connect.js
/assets/js/content-connect.min.js
/dist/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
43 changes: 43 additions & 0 deletions assets/js/components/relationship-manager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { ContentPicker } from '@10up/block-components';
import { useSelect, useDispatch } from '@wordpress/data';
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[]) => {
const newIds = newEntities.map(entity => entity.id);

await updateRelatedEntities(
postId,
relationship.rel_key,
relationship.rel_type,
newIds
);
};

return (
<ContentPicker
onPickChange={handleChange}
mode={relationship?.object_type ?? 'post'}
content={relatedEntities}
contentTypes={relationship?.post_type}
maxContentItems={relationship?.max_items ?? 100}
isOrderable={relationship?.sortable ?? false}
/>
);
}
46 changes: 46 additions & 0 deletions assets/js/components/relationships-panel.tsx
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>
))}
</>
);
}
15,260 changes: 0 additions & 15,260 deletions assets/js/content-connect.js

This file was deleted.

2 changes: 2 additions & 0 deletions assets/js/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './use-relationships';
import './use-related-entities';
30 changes: 30 additions & 0 deletions assets/js/hooks/use-related-entities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { store } from '../store';
import { useSelect, useDispatch } from '@wordpress/data';
import { useCallback } from 'react';
import { GetRelatedEntitiesOptions } from '../store/api';

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((relatedIds: number[]) => {
updateRelatedEntities(postId, options.rel_key, options.rel_type, relatedIds);
}, [postId, options, updateRelatedEntities]);

return [hasResolved, relatedEntities, _updateRelatedEntities] as const;
}
26 changes: 26 additions & 0 deletions assets/js/hooks/use-relationships.ts
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;
}
9 changes: 9 additions & 0 deletions assets/js/index.ts
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,
});
Loading