Skip to content

Instantly share code, notes, and snippets.

@stefanoverna
Created March 28, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanoverna/183f2e28e8f9fc55c81b0cddb8a867d3 to your computer and use it in GitHub Desktop.
Save stefanoverna/183f2e28e8f9fc55c81b0cddb8a867d3 to your computer and use it in GitHub Desktop.
Example of usage of new hooks
import { connect } from 'datocms-plugin-sdk';
connect({
buildItemPresentationInfo(item, ctx) {
// we only want to customize the presentation for records of a specific
// model
if (item.relationships.item_type.data.id !== '810975') {
return undefined;
}
const title =
typeof item.attributes.title === 'string' ? item.attributes.title : 'N/A';
return {
title: title.toUpperCase(),
imageUrl: `https://loremflickr.com/150/150/${title
.toLowerCase()
.replace(/\s+/g, ',')}`,
};
},
initialLocationQueryForItemSelector(openerField, itemType, ctx) {
// we only want to customize the location for a specific field, when
// opening the selector a specific model
if (openerField.id !== '7292330' || itemType.id !== '168664') {
return undefined;
}
return {
locationQuery: {
filter: {
fields: {
name: {
matches: {
pattern: 'michael',
case_sensitive: false,
regexp: false,
},
},
},
},
},
};
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment