@@ -32,6 +32,32 @@ import { AllowedTypesEditor } from "./AllowedTypesEditor";
3232
3333const SLUG_INVALID_CHARS_REGEX = / [ ^ a - z 0 - 9 ] + / g;
3434const SLUG_LEADING_TRAILING_REGEX = / ^ _ | _ $ / g;
35+ const SEARCHABLE_FIELD_TYPES = new Set < FieldType > ( [
36+ "string" ,
37+ "text" ,
38+ "portableText" ,
39+ "slug" ,
40+ "url" ,
41+ ] ) ;
42+ const INDEXABLE_FIELD_TYPES = new Set < FieldType > ( [
43+ "string" ,
44+ "url" ,
45+ "number" ,
46+ "integer" ,
47+ "boolean" ,
48+ "datetime" ,
49+ "select" ,
50+ "reference" ,
51+ "slug" ,
52+ ] ) ;
53+
54+ function isSearchableFieldType ( type : FieldType | null ) : type is FieldType {
55+ return type !== null && SEARCHABLE_FIELD_TYPES . has ( type ) ;
56+ }
57+
58+ function isIndexableFieldType ( type : FieldType | null ) : type is FieldType {
59+ return type !== null && INDEXABLE_FIELD_TYPES . has ( type ) ;
60+ }
3561
3662// ============================================================================
3763// Types
@@ -67,6 +93,7 @@ interface FieldFormState {
6793 required : boolean ;
6894 unique : boolean ;
6995 searchable : boolean ;
96+ indexed : boolean ;
7097 minLength : string ;
7198 maxLength : string ;
7299 min : string ;
@@ -89,6 +116,7 @@ function getInitialFormState(field?: SchemaField): FieldFormState {
89116 required : field . required ,
90117 unique : field . unique ,
91118 searchable : field . searchable ,
119+ indexed : field . indexed ?? false ,
92120 minLength : field . validation ?. minLength ?. toString ( ) ?? "" ,
93121 maxLength : field . validation ?. maxLength ?. toString ( ) ?? "" ,
94122 min : field . validation ?. min ?. toString ( ) ?? "" ,
@@ -111,6 +139,7 @@ function getInitialFormState(field?: SchemaField): FieldFormState {
111139 required : false ,
112140 unique : false ,
113141 searchable : false ,
142+ indexed : false ,
114143 minLength : "" ,
115144 maxLength : "" ,
116145 min : "" ,
@@ -138,7 +167,7 @@ export function FieldEditor({ open, onOpenChange, field, onSave, isSaving }: Fie
138167 }
139168 } , [ open , field ] ) ;
140169
141- const { step, selectedType, slug, label, required, unique, searchable } = formState ;
170+ const { step, selectedType, slug, label, required, unique, searchable, indexed } = formState ;
142171 const { minLength, maxLength, min, max, pattern, options } = formState ;
143172 const setField = < K extends keyof FieldFormState > ( key : K , value : FieldFormState [ K ] ) =>
144173 setFormState ( ( prev ) => ( { ...prev , [ key ] : value } ) ) ;
@@ -312,12 +341,8 @@ export function FieldEditor({ open, onOpenChange, field, onSave, isSaving }: Fie
312341 }
313342
314343 // Only include searchable for text-based fields
315- const isSearchableType =
316- selectedType === "string" ||
317- selectedType === "text" ||
318- selectedType === "portableText" ||
319- selectedType === "slug" ||
320- selectedType === "url" ;
344+ const isSearchableType = isSearchableFieldType ( selectedType ) ;
345+ const isIndexableType = isIndexableFieldType ( selectedType ) ;
321346
322347 const input : CreateFieldInput = {
323348 slug,
@@ -326,6 +351,7 @@ export function FieldEditor({ open, onOpenChange, field, onSave, isSaving }: Fie
326351 required,
327352 unique,
328353 searchable : isSearchableType ? searchable : undefined ,
354+ indexed : isIndexableType ? indexed : undefined ,
329355 validation : Object . keys ( validation ) . length > 0 ? validation : null ,
330356 } ;
331357
@@ -441,17 +467,20 @@ export function FieldEditor({ open, onOpenChange, field, onSave, isSaving }: Fie
441467 onCheckedChange = { ( checked ) => setField ( "unique" , checked ) }
442468 label = { < span className = "text-sm" > { t `Unique` } </ span > }
443469 />
444- { ( selectedType === "string" ||
445- selectedType === "text" ||
446- selectedType === "portableText" ||
447- selectedType === "slug" ||
448- selectedType === "url" ) && (
470+ { isSearchableFieldType ( selectedType ) && (
449471 < Switch
450472 checked = { searchable }
451473 onCheckedChange = { ( checked ) => setField ( "searchable" , checked ) }
452474 label = { < span className = "text-sm" > { t `Searchable` } </ span > }
453475 />
454476 ) }
477+ { isIndexableFieldType ( selectedType ) && (
478+ < Switch
479+ checked = { indexed }
480+ onCheckedChange = { ( checked ) => setField ( "indexed" , checked ) }
481+ label = { < span className = "text-sm" > { t `Indexed` } </ span > }
482+ />
483+ ) }
455484 </ div >
456485
457486 { /* Type-specific validation */ }
0 commit comments