diff --git a/packages/@sanity/desk-tool/src/tool.js b/packages/@sanity/desk-tool/src/tool.js index 985d5b8cf98..a9f0fdcc85a 100644 --- a/packages/@sanity/desk-tool/src/tool.js +++ b/packages/@sanity/desk-tool/src/tool.js @@ -51,14 +51,18 @@ function getIntentState(intentName, params, currentState, payload) { function getFallbackIntentState({documentId, intentName, params, payload}) { const isTemplateCreate = intentName === 'create' && params.template const template = isTemplateCreate && getTemplateById(params.template) - const parameters = { - id: documentId, - template: params.template, - type: (template && template.schemaType) || params.type + const type = (template && template.schemaType) || params.type + const parameters = {} + if (type) { + parameters.type = type + } + + if (template) { + parameters.template = template } return { - panes: [[{id: '__edit__', params: parameters, payload}]] + panes: [[{id: `__edit__${documentId}`, params: parameters, payload}]] } } diff --git a/packages/@sanity/desk-tool/src/utils/parsePanesSegment.js b/packages/@sanity/desk-tool/src/utils/parsePanesSegment.js index 1caa044e249..9a78501a33f 100644 --- a/packages/@sanity/desk-tool/src/utils/parsePanesSegment.js +++ b/packages/@sanity/desk-tool/src/utils/parsePanesSegment.js @@ -44,7 +44,7 @@ function encodeChunks(pane, i, group) { return pairs } - return [...pairs, `${key}=${params[key]}`] + return params[key] ? [...pairs, `${key}=${params[key]}`] : pairs }, []) return ( diff --git a/packages/@sanity/desk-tool/src/utils/resolvePanes.js b/packages/@sanity/desk-tool/src/utils/resolvePanes.js index 1a4f15ce65a..26f3328e9e4 100644 --- a/packages/@sanity/desk-tool/src/utils/resolvePanes.js +++ b/packages/@sanity/desk-tool/src/utils/resolvePanes.js @@ -80,7 +80,7 @@ function resolveForStructure(structure, paneGroups, prevStructure, fromIndex) { const siblings = paneSegments[index] for (let i = splitIndex; i < siblings.length; i++) { const {id} = siblings[i] - const isFallbackEditor = index === 1 && id === '__edit__' + const isFallbackEditor = index === 1 && id.startsWith('__edit__') const child = isFallbackEditor ? resolveFallbackEditor : parent.child const resolverArgs = getResolverArgumentsForSibling(siblings[i], context, isFallbackEditor) subscribeForUpdates(child, index, i, context, resolverArgs) @@ -177,7 +177,8 @@ function resolveForStructure(structure, paneGroups, prevStructure, fromIndex) { } function resolveFallbackEditor(nodeId, context, {params, payload}) { - const {id, template, type} = params + const id = nodeId.replace(/^__edit__/, '') + const {template, type} = params return { id: 'editor', diff --git a/packages/@sanity/structure/src/util/validateId.ts b/packages/@sanity/structure/src/util/validateId.ts index b1fda1b3128..30e84df40d3 100644 --- a/packages/@sanity/structure/src/util/validateId.ts +++ b/packages/@sanity/structure/src/util/validateId.ts @@ -1,7 +1,6 @@ import {SerializeError} from '../SerializeError' import {SerializePath} from '../StructureNodes' -const disallowedIds = ['__edit__'] const disallowedPattern = /([^A-Za-z0-9-_.])/ export function validateId( @@ -26,8 +25,12 @@ export function validateId( ) } - if (disallowedIds.includes(id)) { - throw new SerializeError(`Structure node id cannot be "${id}"`, parentPath, pathSegment) + if (id.startsWith('__edit__')) { + throw new SerializeError( + `Structure node id cannot start with __edit__`, + parentPath, + pathSegment + ) } return id