-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for Array Fields in component blocks (breaking) #7428
Merged
Conversation
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
dcousens
approved these changes
May 25, 2022
dcousens
force-pushed
the
component-field-type
branch
from
May 25, 2022 06:37
ab205e9
to
efa2c79
Compare
Merged
dcousens
changed the title
Component Block Updates
Add support for Array Fields in component blocks (breaking)
May 30, 2022
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces array fields for component blocks.
Array fields are a new component block field that contain 0 to many of another field type, like an object, conditional, form or child field.
This pull request additionally contains substantial changes to the component blocks API.
The breaking changes are entirely about defining components, no data migration is required.
Additionally, there are some smaller improvements:
onChange
function so that you can update more than one field in a component at a timeschema
property to access the schema for those preview propsThe breaking changes for
@keystone-6/fields-document/component-blocks
are:component
function, renamecomponent
topreview
component
function, renameprops
toschema
.schema
(previously.props
), renameprops.{innerFieldName}
toprops.fields.{innerFieldName}
.props.{innerFieldName}
toprops.{innerFieldName}.element
.For example, use
props.fields.title
instead ofprops.title
.For a nested example, use
props.fields.someObject.fields.title
instead ofprops.someObject.title
.As an example, the changes needed for updating the "Hero" component block as seen on https://keystonejs.com/docs/guides/document-field-demo is shown shown below
fields.array
The new array field for component blocks represents an array of another field type, such as an object, conditional, form or other child field.
When there is a single child field within an array field, the document editor will allow pressing enter at the end of an element to add/delete at the start to delete, this allows creating editing experiences similar to the built-in lists.
See below for an example of a question & answers component block with the new array field:
Similar to the built-in document-editor lists, when an array field has only 1 element, pressing enter adds a new element and pressing delete removes an element.
For example, here's a list of checkboxes:
Finally, some other changes introduced in this release are:
preview
propsfields
(and their inner fields, if any) now have anonChange
function so that you can update more than one field in a component at a timepreview
propsfields
(and their inner fields, if any) now have aschema
property to access their respective schema at that levelSome internal breaking changes that are unlikely to affect users are:
ComponentPropField
type is now namedComponentSchema
FormField
's are now constrained to prevent storingundefined
.They must be a string, number, boolean, null, array of one of these or an object with one of these.
This is required so that they can be represented within a JSON array.
props
object on a component-block node, child fields are now stored asnull
instead ofundefined
.This is required so that they can be represented within a JSON array.
Component-block nodes that previously had
undefined
instead ofnull
for a child field will continue to work though, no data migration is required.ObjectField
type now has inner fields on a property namedfields
instead ofvalue
ConditionalField
type now has two type parameters that look like this: