I have a block in PageBuilder that calls a content source to fetch a group of stories based on parameters set within the block's configuration panel in PageBuilder. I want to be able to send a parameter that tells the content source how to sort the fetched stories.
I'm using 'PropTypes.contentConfig()' to define the custom field in my React component as documented here, but it doesn't seem extendible to allow additional custom field options to the content config that's parsed from the content source schema I pass it.
StoryCardFeed.propTypes = {
customFields: PropTypes.shape({
// ... other custom fields
contentConfig: PropTypes.contentConfig('content-feed').tag({
group: 'Data Configuration',
name: 'Content Source',
}),
}),
};
According to the docs for creating Content Sources, the only allowable values for the 'type' param are 'text', 'number' and 'site'. I can set the type to 'text' and enter a string like 'first_publish_date:desc' in PageBuilder, but I want to be able to control the values that are being entered in the field so my colleagues who aren't developers can't enter invalid values.
Ideally I'd like to be able to have an array of options for the field that would be rendered as a select menu.
For example:
export default {
fetch: fetchContentFeed,
schemaName: 'content-feed',
filter: ContentFeed,
params: [
{ name: 'size', displayName: 'Size', type: 'number', },
{ name: 'offset', displayName: 'Offset', type: 'number', },
{
name: 'sortBy',
displayName: 'Sort By',
type: 'text', // maintains allowable values of 'text', 'number' and 'site'
// I'd love to have the following options appear as a select menu in the data config section in PageBuilder
options: [
'first_publish_date:desc',
'first_publish_date:asc',
'canonical_url:asc',
'canonical_url:desc'
],
},
],
ttl: 120,
};
I am able to add another custom field for the sort order and define the options there, but then I have no control over its position among the other content source param custom fields. I can either have it above or below all the other fields, not in the middle. The value provided in PageBuilder also isn't passed to the content source and is only available client-side. Since I'm trying to add an option to sort the fetched content, it would make more sense to have that calculation happen server-side.
Thanks for your time and consideration!
Hi Keegan,
Thanks for submitting this idea. It makes sense to add dropdown field type. Since it's already supported on "feature" custom fields, it makes sense to add same support for content source custom fields too.
We'll put this idea in Future Consideration and we'll update the status when we can slot it in our roadmap as an improvement.