1
- import { type EditableManagedCollectionField , framer , type ManagedCollection , useIsAllowedTo } from "framer-plugin"
1
+ import { type ManagedCollectionFieldInput , framer , type ManagedCollection , useIsAllowedTo } from "framer-plugin"
2
2
import { useEffect , useState } from "react"
3
3
import { type DataSource , dataSourceOptions , mergeFieldsWithExistingFields , syncCollection , syncMethods } 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
+ disabled : boolean
11
12
}
12
13
13
- function FieldMappingRow ( { field, originalFieldName, disabled, onToggleDisabled, onNameChange } : FieldMappingRowProps ) {
14
+ function FieldMappingRow ( {
15
+ field,
16
+ originalFieldName,
17
+ isIgnored,
18
+ onToggleDisabled,
19
+ onNameChange,
20
+ disabled,
21
+ } : FieldMappingRowProps ) {
14
22
return (
15
23
< >
16
24
< button
17
25
type = "button"
18
26
className = "source-field"
19
- aria-disabled = { disabled }
27
+ aria-disabled = { isIgnored }
20
28
onClick = { ( ) => onToggleDisabled ( field . id ) }
21
29
tabIndex = { 0 }
30
+ disabled = { disabled }
22
31
>
23
- < input type = "checkbox" checked = { ! disabled } tabIndex = { - 1 } readOnly />
32
+ < input type = "checkbox" checked = { ! isIgnored } tabIndex = { - 1 } readOnly />
24
33
< span > { originalFieldName ?? field . id } </ span >
25
34
</ button >
26
35
< svg xmlns = "http://www.w3.org/2000/svg" width = "8" height = "8" fill = "none" >
@@ -35,8 +44,8 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
35
44
</ svg >
36
45
< input
37
46
type = "text"
38
- style = { { width : "100%" , opacity : disabled ? 0.5 : 1 } }
39
- disabled = { disabled }
47
+ style = { { width : "100%" , opacity : isIgnored || disabled ? 0.5 : 1 } }
48
+ disabled = { isIgnored || disabled }
40
49
placeholder = { field . id }
41
50
value = { field . name }
42
51
onChange = { event => onNameChange ( field . id , event . target . value ) }
@@ -50,7 +59,7 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
50
59
)
51
60
}
52
61
53
- const initialManagedCollectionFields : EditableManagedCollectionField [ ] = [ ]
62
+ const initialManagedCollectionFields : ManagedCollectionFieldInput [ ] = [ ]
54
63
const initialFieldIds : ReadonlySet < string > = new Set ( )
55
64
56
65
interface FieldMappingProps {
@@ -68,7 +77,7 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
68
77
69
78
const [ possibleSlugFields ] = useState ( ( ) => dataSource . fields . filter ( field => field . type === "string" ) )
70
79
71
- const [ selectedSlugField , setSelectedSlugField ] = useState < EditableManagedCollectionField | null > (
80
+ const [ selectedSlugField , setSelectedSlugField ] = useState < ManagedCollectionFieldInput | null > (
72
81
possibleSlugFields . find ( field => field . id === initialSlugFieldId ) ?? possibleSlugFields [ 0 ] ?? null
73
82
)
74
83
@@ -137,12 +146,6 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
137
146
const handleSubmit = async ( event : React . FormEvent < HTMLFormElement > ) => {
138
147
event . preventDefault ( )
139
148
140
- if ( ! isAllowedToManage ) {
141
- console . error ( "Insufficient permissions for management" )
142
- framer . notify ( "Insufficient permissions for management" , { variant : "error" } )
143
- return
144
- }
145
-
146
149
if ( ! selectedSlugField ) {
147
150
// This can't happen because the form will not submit if no slug field is selected
148
151
// but TypeScript can't infer that.
@@ -196,6 +199,8 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
196
199
if ( ! selectedField ) return
197
200
setSelectedSlugField ( selectedField )
198
201
} }
202
+ disabled = { ! isAllowedToManage }
203
+ style = { { opacity : isAllowedToManage ? 1 : 0.5 } }
199
204
>
200
205
{ possibleSlugFields . map ( possibleSlugField => {
201
206
return (
@@ -215,24 +220,27 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
215
220
key = { `field-${ field . id } ` }
216
221
field = { field }
217
222
originalFieldName = { dataSource . fields . find ( sourceField => sourceField . id === field . id ) ?. name }
218
- disabled = { ignoredFieldIds . has ( field . id ) }
223
+ isIgnored = { ignoredFieldIds . has ( field . id ) }
219
224
onToggleDisabled = { toggleFieldDisabledState }
220
225
onNameChange = { changeFieldName }
226
+ disabled = { ! isAllowedToManage }
221
227
/>
222
228
) ) }
223
229
</ div >
224
230
225
231
< footer >
226
232
< hr />
227
- < button disabled = { isSyncing || ! isAllowedToManage } tabIndex = { 0 } >
233
+ < button
234
+ disabled = { isSyncing || ! isAllowedToManage }
235
+ tabIndex = { 0 }
236
+ title = { isAllowedToManage ? undefined : "Insufficient permissions" }
237
+ >
228
238
{ isSyncing ? (
229
239
< div className = "framer-spinner" />
230
- ) : isAllowedToManage ? (
240
+ ) : (
231
241
< span >
232
242
Import < span style = { { textTransform : "capitalize" } } > { dataSourceName } </ span >
233
243
</ span >
234
- ) : (
235
- "Insufficient permissions"
236
244
) }
237
245
</ button >
238
246
</ footer >
0 commit comments