Skip to content

Commit

Permalink
fix(structure): Don't modify EMPTY_PARAMS object
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusGundersen committed Feb 12, 2025
1 parent 9e5f70b commit dd021d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/src/structure/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export const _DEBUG = false

export const EMPTY_PARAMS = {}
export const EMPTY_PARAMS = Object.freeze({})
export const LOADING_PANE = Symbol('LOADING_PANE')

export const DOCUMENT_PANEL_PORTAL_ELEMENT = 'documentPanelPortalElement'
20 changes: 12 additions & 8 deletions packages/sanity/src/structure/getIntentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export function getIntentState(
const panes = routerState?.panes || []
const activePanes = state.activePanes || []
const editDocumentId = params.id || uuid()
const isTemplate = intent === 'create' && params.template
const isVersion = intent === 'create' && params.version

// Loop through open panes and see if any of them can handle the intent
for (let i = activePanes.length - 1; i >= 0; i--) {
Expand All @@ -47,12 +45,7 @@ export function getIntentState(
pane.schemaTypeName === params.type &&
pane.options.filter === '_type == $type')
) {
const paneParams: {
template?: string
version?: string
} = EMPTY_PARAMS
if (isTemplate) paneParams.template = params.template
if (isVersion) paneParams.version = params.version
const paneParams = getPaneParams(intent, params)

return {
panes: panes
Expand All @@ -64,3 +57,14 @@ export function getIntentState(

return {intent: intent, params, payload}
}

function getPaneParams(
intent: string,
{template, version}: Record<string, string>,
): {template?: string; version?: string} {
if (intent !== 'create') return EMPTY_PARAMS
if (template && version) return {template, version}
if (template) return {template}
if (version) return {version}
return EMPTY_PARAMS
}

0 comments on commit dd021d8

Please sign in to comment.