Skip to content

Commit

Permalink
fix(core): support serverDocumentActions flag in plugins (#8247)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin authored Jan 13, 2025
1 parent b3cce81 commit 78318f3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const sharedSettings = definePlugin({
],
})

const defaultWorkspace = {
const defaultWorkspace = defineConfig({
name: 'default',
title: 'Test Studio',
projectId: 'ppsg7ml5',
Expand All @@ -179,7 +179,7 @@ const defaultWorkspace = {
tasks: {
enabled: true,
},
}
})

export default defineConfig([
defaultWorkspace,
Expand Down
23 changes: 23 additions & 0 deletions packages/sanity/src/core/config/configPropertyReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,29 @@ export const internalTasksReducer = (opts: {
return result
}

export const serverDocumentActionsReducer = (opts: {
config: PluginOptions
initialValue: boolean | undefined
}): boolean | undefined => {
const {config, initialValue} = opts
const flattenedConfig = flattenConfig(config, [])

const result = flattenedConfig.reduce((acc: boolean | undefined, {config: innerConfig}) => {
const enabled = innerConfig.__internal_serverDocumentActions?.enabled

if (typeof enabled === 'undefined') return acc
if (typeof enabled === 'boolean') return enabled

throw new Error(
`Expected \`__internal_serverDocumentActions\` to be a boolean, but received ${getPrintableType(
enabled,
)}`,
)
}, initialValue)

return result
}

export const partialIndexingEnabledReducer = (opts: {
config: PluginOptions
initialValue: boolean
Expand Down
7 changes: 5 additions & 2 deletions packages/sanity/src/core/config/prepareConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
resolveProductionUrlReducer,
schemaTemplatesReducer,
searchStrategyReducer,
serverDocumentActionsReducer,
startInCreateEnabledReducer,
toolsReducer,
} from './configPropertyReducers'
Expand Down Expand Up @@ -209,8 +210,6 @@ export function prepareConfig(
__internal: {
sources: resolvedSources,
},
// eslint-disable-next-line camelcase
__internal_serverDocumentActions: rawWorkspace.__internal_serverDocumentActions,
...defaultPluginsOptions,
}
preparedWorkspaces.set(rawWorkspace, workspaceSummary)
Expand Down Expand Up @@ -655,6 +654,10 @@ function resolveSource({
fallbackStudioOrigin: createFallbackOriginReducer(config),
},
},
// eslint-disable-next-line camelcase
__internal_serverDocumentActions: {
enabled: serverDocumentActionsReducer({config, initialValue: undefined}),
},

announcements: {
enabled: announcementsEnabledReducer({config, initialValue: true}),
Expand Down
4 changes: 3 additions & 1 deletion packages/sanity/src/core/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ export interface PluginOptions {
enableLegacySearch?: boolean
}

/** @internal */
__internal_serverDocumentActions?: WorkspaceOptions['__internal_serverDocumentActions']

/** Configuration for studio beta features.
* @internal
*/
Expand Down Expand Up @@ -862,7 +865,6 @@ export interface WorkspaceSummary extends DefaultPluginsWorkspaceOptions {
source: Observable<Source>
}>
}
__internal_serverDocumentActions: WorkspaceOptions['__internal_serverDocumentActions']
}

/**
Expand Down

0 comments on commit 78318f3

Please sign in to comment.