@@ -52,6 +52,18 @@ module Helper =
52
52
?Roles= this.Roles
53
53
)
54
54
55
+ type OntologyAnnotationMutable (? name ,? tsr ,? tan ) =
56
+ member val Name : string option = name with get, set
57
+ member val TSR : string option = tsr with get, set
58
+ member val TAN : string option = tan with get, set
59
+
60
+ static member fromOntologyAnnotation ( oa : OntologyAnnotation ) =
61
+ let name = if oa.NameText = " " then None else Some oa.NameText
62
+ OntologyAnnotationMutable( ?name= name, ?tsr= oa.TermSourceREF, ?tan= oa.TermAccessionNumber)
63
+
64
+ member this.ToOntologyAnnotation () =
65
+ OntologyAnnotation.fromString( ?termName= this.Name,? tsr= this.TSR,? tan= this.TAN)
66
+
55
67
let addButton ( clickEvent : MouseEvent -> unit ) =
56
68
Html.div [
57
69
prop.classes [ " is-flex" ; " is-justify-content-center" ]
@@ -110,31 +122,37 @@ type FormComponents =
110
122
[<ReactComponent>]
111
123
static member OntologyAnnotationInput ( oa : OntologyAnnotation , label : string , setter : OntologyAnnotation -> unit , ? showTextLabels : bool , ? removebutton : MouseEvent -> unit ) =
112
124
let showTextLabels = defaultArg showTextLabels true
125
+ let oa = React.useRef( Helper.OntologyAnnotationMutable.fromOntologyAnnotation oa)
113
126
Bulma.field.div [
114
127
if label <> " " then Bulma.label label
115
128
Html.div [
116
129
prop.classes [ " form-container" ]
117
130
prop.children [
118
131
FormComponents.TextInput(
119
- oa.NameText ,
132
+ Option.defaultValue " " oa.current.Name ,
120
133
( if showTextLabels then $" Term Name" else " " ),
121
- ( fun s -> { oa with Name = AnnotationValue.Text s |> Some } |> setter),
134
+ ( fun s ->
135
+ let s = if s = " " then None else Some s
136
+ oa.current.Name <- s
137
+ oa.current.ToOntologyAnnotation() |> setter),
122
138
fullwidth = true
123
139
)
124
140
FormComponents.TextInput(
125
- oa.TermSourceREFString ,
141
+ Option.defaultValue " " oa.current.TSR ,
126
142
( if showTextLabels then $" TSR" else " " ),
127
143
( fun s ->
128
- let s2 = s |> fun s -> if s = " " then None else Some s
129
- { oa with TermSourceREF = s2 } |> setter),
144
+ let s = if s = " " then None else Some s
145
+ oa.current.TSR <- s
146
+ oa.current.ToOntologyAnnotation() |> setter),
130
147
fullwidth = true
131
148
)
132
149
FormComponents.TextInput(
133
- oa.TermAccessionShort ,
150
+ Option.defaultValue " " oa.current.TAN ,
134
151
( if showTextLabels then $" TAN" else " " ),
135
152
( fun s ->
136
- let s2 = s |> fun s -> if s = " " then None else Some s
137
- { oa with TermAccessionNumber = s2 } |> setter),
153
+ let s = if s = " " then None else Some s
154
+ oa.current.TAN <- s
155
+ oa.current.ToOntologyAnnotation() |> setter),
138
156
fullwidth = true
139
157
)
140
158
if removebutton.IsSome then
@@ -149,13 +167,14 @@ type FormComponents =
149
167
]
150
168
151
169
[<ReactComponent>]
152
- static member PersonInput ( person : Person , setter : Person -> unit , ? deletebutton : MouseEvent -> unit ) =
170
+ static member PersonInput ( person' : Person , setter : Person -> unit , ? deletebutton : MouseEvent -> unit ) =
153
171
let isExtended , setIsExtended = React.useState( false )
154
- let fn = Option.defaultValue " " person.FirstName
155
- let ln = Option.defaultValue " " person.LastName
156
- let mi = Option.defaultValue " " person.MidInitials
157
172
// Must use `React.useRef` do this. Otherwise simultanios updates will overwrite each other
158
- let person = React.useRef( Helper.PersonMutable.fromPerson person)
173
+ let person = React.useRef( Helper.PersonMutable.fromPerson person')
174
+ React.useEffect(( fun _ -> person.current <- Helper.PersonMutable.fromPerson person'), [| box person|])
175
+ let fn = Option.defaultValue " " person.current.FirstName
176
+ let ln = Option.defaultValue " " person.current.LastName
177
+ let mi = Option.defaultValue " " person.current.MidInitials
159
178
let nameStr =
160
179
let x = $" {fn} {mi} {ln}" .Trim()
161
180
if x = " " then " <name>" else x
@@ -263,17 +282,20 @@ type FormComponents =
263
282
setter { person.current.ToPerson() with Roles = Some nextRoles}
264
283
),
265
284
showTextLabels = false ,
266
- removebutton=( fun e ->
267
- let nextRoles = person.current.Roles.Value |> Array.removeAt i
268
- setter { person.current.ToPerson() with Roles = if nextRoles.Length = 0 then None else Some nextRoles}
285
+ removebutton=( fun _ ->
286
+ person.current.Roles <- (
287
+ let a = Array.removeAt i person.current.Roles.Value
288
+ if a = Array.empty then None else Some a
289
+ )
290
+ person.current.ToPerson() |> setter
269
291
))
270
292
]
271
293
)
272
294
]
273
295
Helper.addButton ( fun _ ->
274
296
let roles = Option.defaultValue [||] person.current.Roles
275
- let newRoles = Array.append roles [| OntologyAnnotation.empty|]
276
- setter { person.current.ToPerson() with Roles = Some newRoles }
297
+ person.current.Roles <- Array.append roles [| OntologyAnnotation.empty|] |> Some
298
+ person.current.ToPerson() |> setter
277
299
)
278
300
]
279
301
if deletebutton.IsSome then
0 commit comments