@@ -6,7 +6,7 @@ import { Button } from "../components/Button"
66import { CheckboxTextfield } from "../components/CheckboxTextField"
77import { IconChevron } from "../components/Icons"
88import type { CellValue , CollectionFieldType , HeaderRow , PluginContext , Row , SyncMutationOptions } from "../sheets"
9- import { assert , generateUniqueNames , syncMethods } from "../utils"
9+ import { generateUniqueNames , isDefined , syncMethods } from "../utils"
1010
1111interface FieldTypeOption {
1212 type : CollectionFieldType
@@ -104,16 +104,18 @@ const createFieldConfig = (
104104 context : PluginContext ,
105105 row ?: Row
106106) : ManagedCollectionFieldInput [ ] => {
107- return headerRow . map ( ( _ , columnIndex ) => {
108- const sanitizedName = uniqueColumnNames [ columnIndex ]
109- assert ( sanitizedName , "Sanitized name is undefined" )
110-
111- return {
112- id : sanitizedName ,
113- name : sanitizedName ,
114- type : getFieldType ( context , sanitizedName , row ?. [ columnIndex ] ) ,
115- } as ManagedCollectionFieldInput
116- } )
107+ return headerRow
108+ . map ( ( _ , columnIndex ) => {
109+ const sanitizedName = uniqueColumnNames [ columnIndex ]
110+ if ( ! sanitizedName ) return null
111+
112+ return {
113+ id : sanitizedName ,
114+ name : sanitizedName ,
115+ type : getFieldType ( context , sanitizedName , row ?. [ columnIndex ] ) ,
116+ } as ManagedCollectionFieldInput
117+ } )
118+ . filter ( isDefined )
117119}
118120
119121const getFieldNameOverrides = ( context : PluginContext ) : Record < string , string > => {
@@ -159,10 +161,7 @@ export function MapSheetFieldsPage({
159161 const [ disabledColumns , setDisabledColumns ] = useState (
160162 ( ) => new Set < string > ( pluginContext . type === "update" ? pluginContext . ignoredColumns : [ ] )
161163 )
162- const slugFields = useMemo (
163- ( ) => getPossibleSlugFields ( fieldConfig ) . filter ( fieldConfig => ! disabledColumns . has ( fieldConfig . id ) ) ,
164- [ fieldConfig , disabledColumns ]
165- )
164+ const slugFields = useMemo ( ( ) => getPossibleSlugFields ( fieldConfig ) , [ fieldConfig ] )
166165 const [ slugColumn , setSlugColumn ] = useState < string > ( ( ) => getInitialSlugColumn ( pluginContext , slugFields ) )
167166 const [ fieldNameOverrides , setFieldNameOverrides ] = useState < Record < string , string > > ( ( ) =>
168167 getFieldNameOverrides ( pluginContext )
@@ -173,29 +172,8 @@ export function MapSheetFieldsPage({
173172 const nextSet = new Set ( current )
174173 if ( nextSet . has ( id ) ) {
175174 nextSet . delete ( id )
176-
177- // If we're re-enabling a string field and there's currently no valid slug column,
178- // set this field as the slug column
179- const field = fieldConfig . find ( config => config . id === id )
180- if ( field ?. type === "string" ) {
181- const currentSlugField = fieldConfig . find ( config => config . id === slugColumn )
182- if ( ! currentSlugField || nextSet . has ( slugColumn ) ) {
183- setSlugColumn ( id )
184- }
185- }
186175 } else {
187176 nextSet . add ( id )
188-
189- // If the disabled column is the slug column, we need to update it to the next
190- // possible slug field
191- if ( id === slugColumn ) {
192- const nextSlugField = getPossibleSlugFields ( fieldConfig ) . find (
193- field => field . id !== id && ! nextSet . has ( field . id )
194- )
195- if ( nextSlugField ) {
196- setSlugColumn ( nextSlugField . id )
197- }
198- }
199177 }
200178 return nextSet
201179 } )
0 commit comments