1
- import { type EditableManagedCollectionField , framer , type ManagedCollection } from "framer-plugin"
1
+ import { type ManagedCollectionFieldInput , framer , type ManagedCollection } from "framer-plugin"
2
2
import { useEffect , useState } from "react"
3
3
import { type DataSource , dataSourceOptions , mergeFieldsWithExistingFields , syncCollection } from "./data"
4
4
5
5
interface FieldMappingRowProps {
6
- field : EditableManagedCollectionField
6
+ field : ManagedCollectionFieldInput
7
7
originalFieldName : string | undefined
8
- disabled : boolean
8
+ isIgnored : boolean
9
9
onToggleDisabled : ( fieldId : string ) => void
10
10
onNameChange : ( fieldId : string , name : string ) => void
11
11
}
12
12
13
- function FieldMappingRow ( { field, originalFieldName, disabled, onToggleDisabled, onNameChange } : FieldMappingRowProps ) {
13
+ function FieldMappingRow ( {
14
+ field,
15
+ originalFieldName,
16
+ isIgnored,
17
+ onToggleDisabled,
18
+ onNameChange,
19
+ } : FieldMappingRowProps ) {
14
20
return (
15
21
< >
16
22
< button
17
23
type = "button"
18
- className = "source-field"
19
- aria-disabled = { disabled }
24
+ className = { `source-field ${ isIgnored ? "ignored" : "" } ` }
20
25
onClick = { ( ) => onToggleDisabled ( field . id ) }
21
- tabIndex = { 0 }
22
26
>
23
- < input type = "checkbox" checked = { ! disabled } tabIndex = { - 1 } readOnly />
27
+ < input type = "checkbox" checked = { ! isIgnored } tabIndex = { - 1 } readOnly />
24
28
< span > { originalFieldName ?? field . id } </ span >
25
29
</ button >
26
30
< svg xmlns = "http://www.w3.org/2000/svg" width = "8" height = "8" fill = "none" >
@@ -35,8 +39,7 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
35
39
</ svg >
36
40
< input
37
41
type = "text"
38
- style = { { width : "100%" , opacity : disabled ? 0.5 : 1 } }
39
- disabled = { disabled }
42
+ disabled = { isIgnored }
40
43
placeholder = { field . id }
41
44
value = { field . name }
42
45
onChange = { event => onNameChange ( field . id , event . target . value ) }
@@ -50,7 +53,7 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
50
53
)
51
54
}
52
55
53
- const initialManagedCollectionFields : EditableManagedCollectionField [ ] = [ ]
56
+ const initialManagedCollectionFields : ManagedCollectionFieldInput [ ] = [ ]
54
57
const initialFieldIds : ReadonlySet < string > = new Set ( )
55
58
56
59
interface FieldMappingProps {
@@ -68,7 +71,7 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
68
71
69
72
const [ possibleSlugFields ] = useState ( ( ) => dataSource . fields . filter ( field => field . type === "string" ) )
70
73
71
- const [ selectedSlugField , setSelectedSlugField ] = useState < EditableManagedCollectionField | null > (
74
+ const [ selectedSlugField , setSelectedSlugField ] = useState < ManagedCollectionFieldInput | null > (
72
75
possibleSlugFields . find ( field => field . id === initialSlugFieldId ) ?? possibleSlugFields [ 0 ] ?? null
73
76
)
74
77
@@ -204,23 +207,17 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
204
207
key = { `field-${ field . id } ` }
205
208
field = { field }
206
209
originalFieldName = { dataSource . fields . find ( sourceField => sourceField . id === field . id ) ?. name }
207
- disabled = { ignoredFieldIds . has ( field . id ) }
210
+ isIgnored = { ignoredFieldIds . has ( field . id ) }
208
211
onToggleDisabled = { toggleFieldDisabledState }
209
212
onNameChange = { changeFieldName }
210
213
/>
211
214
) ) }
212
215
</ div >
213
216
214
217
< footer >
215
- < hr className = "sticky-top" />
216
- < button disabled = { isSyncing } tabIndex = { 0 } >
217
- { isSyncing ? (
218
- < div className = "framer-spinner" />
219
- ) : (
220
- < span >
221
- Import < span style = { { textTransform : "capitalize" } } > { dataSourceName } </ span >
222
- </ span >
223
- ) }
218
+ < hr />
219
+ < button disabled = { isSyncing } >
220
+ { isSyncing ? < div className = "framer-spinner" /> : `Import ${ dataSourceName } ` }
224
221
</ button >
225
222
</ footer >
226
223
</ form >
0 commit comments