feat(@sanity/presets): add map methods for overriding any preset-created property#788
feat(@sanity/presets): add map methods for overriding any preset-created property#788
Conversation
🦋 Changeset detectedLatest commit: ed28232 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
6631734 to
3309d26
Compare
3309d26 to
7741ce6
Compare
7741ce6 to
ffe2875
Compare
|
Thinking about the API shape overall - the layered approach (direct props, rest spread, map) makes sense as progressive disclosure, and the type machinery around LockedProperties is nice. One thing I keep coming back to: Would it be worth letting That way the simple case stays simple (pass an array, it appends), but the common "I need to control position" case doesn't require reaching for Minor naming thought: |
jordanl17
left a comment
There was a problem hiding this comment.
Nice! Do you think the tests would be doable as a fast follow PR after this is merged? Just consious we don't want to proceed too far ahead of our test coverage as we might end up missing it.
@jordanl17 yes, we absolutely can, and will. My goal was to first quickly iterate on the API and see whether it felt right. |
@jordanl17 I worry the types and usage start to get a bit murky here if we make special exceptions for specific options. My original plan was actually to make any option accept a function in addition to its native type, but the problem with that approach is that some native types are functions (e.g. Maybe this is a sign we haven't gotten the API quite right. Let's talk more about this.
Studio does have some precedence for this naming convention: when duplicating a document, it supports a |
ffe2875 to
345673b
Compare
345673b to
4a4c60b
Compare
4a4c60b to
4fd172b
Compare
4fd172b to
11b3480
Compare
11b3480 to
ed28232
Compare
Description
This branch adds capabilities for extending presets.
fieldsandgroupsconfig. These properties shadow the config users would typically pass to thedefineTypehelpers. When a user provides afieldsorgroupsarray, the values are appended to the values created by the preset.typeconfig.LockedPropertiestype parameter of thedefinePresetTypefunction. Users will not longer be permitted to set this property.defineTypecall.mapconfig. This is an object that provides callbacks that can override any config property set by the preset. This is an escape hatch for users who need to modify a config property created by the preset.Example: append a field to a page using
fieldsExample: prepend a field to a page using
map.fieldsWhat to review
Extending and modifying presets: do these new APIs feel right?
Testing
Not added extensive tests yet as aiming to quickly prove out the API.