Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions assets/js/components/relationship-manager.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* global contentConnect */
import React from 'react';
import { ContentPicker } from '@10up/block-components';
import { useSelect, useDispatch } from '@wordpress/data';
import { addQueryArgs } from '@wordpress/url';
import { decodeEntities } from '@wordpress/html-entities';
import { __experimentalText as Text } from '@wordpress/components';
import { store } from '../store';
import { ContentConnectRelationship } from '../store/types';

Expand All @@ -10,6 +13,39 @@ type RelationshipManagerProps = {
relationship: ContentConnectRelationship;
};

type PickedRelationshipType = {
id: number;
type: string;
uuid: string;
title: string;
url: string;
};

/**
* Component to render a preview of a picked relationship.
*
* @component
* @param {object} props - The component props.
* @param {PickedRelationshipType} props.item - The picked relationship to display.
* @returns {*} React JSX
*/
const PickedRelationshipPreview: React.FC<{ item: PickedRelationshipType }> = ({ item }) => {
const { title } = item;
const decodedTitle = decodeEntities(title);

const {
pickedItem: {
truncate = true,
ellipsizeMode = 'auto',
numberOfLines = 1
}
} = contentConnect;

return (
<Text truncate={truncate} ellipsizeMode={ellipsizeMode} numberOfLines={numberOfLines} title={decodedTitle} aria-label={decodedTitle}>{decodedTitle}</Text>
);
};

export function RelationshipManager({ postId, relationship }: RelationshipManagerProps) {
const { updateRelatedEntities } = useDispatch(store);

Expand Down Expand Up @@ -45,6 +81,7 @@ export function RelationshipManager({ postId, relationship }: RelationshipManage
}
return query;
}}
PickedItemPreviewComponent={PickedRelationshipPreview}
/>
);
}
15 changes: 15 additions & 0 deletions includes/UI/BlockEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ public function enqueue_block_editor_assets() {
);

wp_enqueue_script( 'wp-content-connect' );

wp_localize_script(
'wp-content-connect',
'contentConnect',
apply_filters(
'tenup_content_connect_ui_settings',
[
'pickedItem' => [
'truncate' => true,
'ellipsizeMode' => 'auto',
'numberOfLines' => 1,
],
]
)
);
}
}
}