-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve custom field documentation #7923
Comments
Any luck creating your "Select images from media gallery" custom field @elliott-w? I was about to start trying to create such a field... |
@cyruskorn Unfortunately not, I'm going to wait for better custom field documentation. I ended up using a relationship field with // Other fields above...
gallery: relationship({
ref: 'PublicImage',
many: true,
ui: {
displayMode: 'cards',
cardFields: ['image'],
inlineEdit: { fields: ['image'] },
inlineCreate: { fields: ['image'] },
inlineConnect: true,
},
}),
// Other fields below... And then the PublicImage list: import { Lists } from '.keystone/types'
import { list } from '@keystone-6/core'
import { image, text, timestamp } from '@keystone-6/core/fields'
import { FileUpload } from 'graphql-upload'
import vars from '../utils/env-vars'
import { requireImage } from '../utils/require-image'
export const lists: Lists = {
PublicImage: list({
fields: {
name: text({
hooks: {
resolveInput: async ({ inputData, resolvedData }) => {
if (!resolvedData.name && inputData.image) {
const upload = (await inputData.image.upload) as FileUpload
return upload.filename
}
return resolvedData.name
},
},
}),
image: image({
storage: vars.IMAGE_STORAGE_PUBLIC,
hooks: {
validateInput: ({ resolvedData, addValidationError, operation }) => {
requireImage(resolvedData.image, operation, addValidationError)
},
},
}),
createdAt: timestamp({
defaultValue: {
kind: 'now',
},
validation: {
isRequired: true,
},
}),
},
}),
}
export default lists |
I've been trying to create my own "Select images from media gallery" custom field which basically just replicates this document component block extension, but I feel like I'm basically throwing my head against a wall trying to understand what all the different custom field config options actually do. While I do appreciate that everything is typed, reverse engineering from the types alone is very painful.
Here's some things I think would be very helpful if explained in documentation:
graphql
object exported from@keystone-6/core
input
andoutput
properties required by thefieldType()
functioncontroller
object work? How does it hook in to everything else? Maybe some simple diagrams?FieldControllerConfig
FieldController<FormState, FilterValue>
I'm sure there's more that I've missed, but better documentation for custom fields would be a god-send.
The text was updated successfully, but these errors were encountered: