Created
March 28, 2023 09:27
-
-
Save stefanoverna/183f2e28e8f9fc55c81b0cddb8a867d3 to your computer and use it in GitHub Desktop.
Example of usage of new hooks
This file contains 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
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