diff --git a/plugin/src/fieldActions/assistFieldActions.tsx b/plugin/src/fieldActions/assistFieldActions.tsx index 6b6b665..386017e 100644 --- a/plugin/src/fieldActions/assistFieldActions.tsx +++ b/plugin/src/fieldActions/assistFieldActions.tsx @@ -23,6 +23,7 @@ import {PrivateIcon} from './PrivateIcon' import {generateCaptionsActions} from './generateCaptionActions' import {useDocumentPane} from 'sanity/desk' import {useSelectedField, useTypePath} from '../assistInspector/helpers' +import {isSchemaAssistEnabled} from '../helpers/assistSupported' function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) { return node @@ -69,7 +70,10 @@ export const assistFieldActions: DocumentFieldAction = { }) const isSelectable = !!useSelectedField(documentSchemaType, typePath) - const assistSupported = useAssistSupported(props.path, schemaType) && isSelectable + const assistSupported = + useAssistSupported(props.path, schemaType) && + isSelectable && + isSchemaAssistEnabled(documentSchemaType) const fieldAssist = useMemo( () => diff --git a/plugin/src/plugin.tsx b/plugin/src/plugin.tsx index e3c0911..7c7fd30 100644 --- a/plugin/src/plugin.tsx +++ b/plugin/src/plugin.tsx @@ -50,7 +50,10 @@ export const assist = definePlugin((config) => { }, unstable_languageFilter: (prev, {documentId, schema, schemaType}) => { const docSchema = schema.get(schemaType) as ObjectSchemaType - return [...prev, createAssistDocumentPresence(documentId, docSchema)] + if (isSchemaAssistEnabled(docSchema)) { + return [...prev, createAssistDocumentPresence(documentId, docSchema)] + } + return prev }, }, diff --git a/plugin/src/schemas/serialize/serializeSchema.test.ts b/plugin/src/schemas/serialize/serializeSchema.test.ts index 60f9d54..7449dda 100644 --- a/plugin/src/schemas/serialize/serializeSchema.test.ts +++ b/plugin/src/schemas/serialize/serializeSchema.test.ts @@ -23,6 +23,28 @@ const mockStudioTypes = [ ] describe('serializeSchema', () => { + test('should not serialize excluded document schema', () => { + const schema = Schema.compile({ + name: 'test', + types: [ + defineType({ + type: 'document', + name: 'article', + fields: [{type: 'string', name: 'title'}], + options: { + aiWritingAssistance: { + exclude: true, + }, + }, + }), + ], + }) + + const serializedTypes = serializeSchema(schema, {leanFormat: true}) + + expect(serializedTypes).toEqual([]) + }) + test('should serialize simple schema', () => { const schema = Schema.compile({ name: 'test', diff --git a/plugin/src/schemas/serialize/serializeSchema.ts b/plugin/src/schemas/serialize/serializeSchema.ts index 9a97cd6..686accd 100644 --- a/plugin/src/schemas/serialize/serializeSchema.ts +++ b/plugin/src/schemas/serialize/serializeSchema.ts @@ -29,6 +29,7 @@ export function serializeSchema(schema: Schema, options?: Options): SerializedSc .filter((t) => !(hiddenTypes.includes(t) || t.startsWith('sanity.'))) .map((t) => schema.get(t)) .filter((t): t is SchemaType => !!t) + .filter((t) => isAssistSupported(t)) .filter((t) => !t.hidden && !t.readOnly) .map((t) => getSchemaStub(t, schema, options)) .filter((t) => {