From 7e4b84c75b3bb8bf966ad17869400077ad4f711f Mon Sep 17 00:00:00 2001 From: abmc <> Date: Tue, 16 Dec 2025 06:14:08 +0100 Subject: [PATCH] feat: Allow block discriminator field in view columns Enable displaying the block discriminator field (e.g., _block) in collection view columns by extending getFieldByPath to recognize block fields. When a path like 'content._block' is requested, returns a virtual string field definition so the block type can be displayed in list views. --- lib/schema.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/schema.ts b/lib/schema.ts index 3be8950d5..dbf9c2678 100644 --- a/lib/schema.ts +++ b/lib/schema.ts @@ -307,11 +307,23 @@ function interpolate(input: string, data: Record, prefixFallback?: function getFieldByPath(schema: Field[], path: string): Field | undefined { const [first, ...rest] = path.split('.'); const field = schema.find(f => f.name === first); - - return !field ? undefined - : rest.length === 0 ? field - : field.type === 'object' && field.fields ? getFieldByPath(field.fields, rest.join('.')) - : undefined; + + if (!field) return undefined; + if (rest.length === 0) return field; + + if (field.type === 'object' && field.fields) { + return getFieldByPath(field.fields, rest.join('.')); + } + + // Handle block discriminator field (e.g., "content._block") + if (field.type === 'block' && rest.length === 1) { + const blockKey = field.blockKey || '_block'; + if (rest[0] === blockKey) { + return { name: blockKey, type: 'string', label: field.label || 'Type' } as Field; + } + } + + return undefined; } // Get the primary field for a schema