Skip to content

Commit

Permalink
feat(core): weight mode param on create intents
Browse files Browse the repository at this point in the history
  • Loading branch information
rdunk committed Feb 15, 2024
1 parent 2f777d8 commit 3ddd7ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/src/core/studio/router/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {isRecord} from '../../util/isRecord'
import {type RouterEvent, type RouterStateEvent} from './types'
import {getOrderedTools} from './util/getOrderedTools'

const WEIGHTED_CREATE_INTENT_PARAMS = ['template']
const WEIGHTED_CREATE_INTENT_PARAMS = ['mode', 'template']
const WEIGHTED_EDIT_INTENT_PARAMS = ['mode']

function resolveUrlStateWithDefaultTool(tools: Tool[], state: Record<string, unknown> | null) {
Expand Down
11 changes: 8 additions & 3 deletions packages/sanity/src/structure/structureTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ function canHandleCreateIntent(params: Record<string, unknown>) {
return false
}

// We can handle any create intent as long as it has a `type` parameter,
// but we also know how to deal with templates, where other tools might not
return 'template' in params ? {template: true} : true
const handle: Record<string, boolean> = {}
// We can handle any create intent as long as it has a `type` parameter
// but we are best at `structure` mode
if ('mode' in params) handle.mode = params.mode === 'structure'
// we also know how to deal with templates, where other tools might not
if ('template' in params) handle.template = true

return Object.keys(handle).length ? handle : true
}

function canHandleEditIntent(params: Record<string, unknown>) {
Expand Down

0 comments on commit 3ddd7ba

Please sign in to comment.