Skip to content

Commit

Permalink
fix: autocomplete now with proper label
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Mar 9, 2024
1 parent 88170e3 commit 3bee916
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 223 deletions.
151 changes: 3 additions & 148 deletions src/Client/Components/Autocomplete.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Autocomplete =


[<JSX.Component>]
let Indications (props :
let View (props :
{|
label : string
selected : string option
Expand All @@ -35,156 +35,11 @@ module Autocomplete =
| s when s |> String.IsNullOrWhiteSpace ||
s = "undefined" -> None
| s -> s |> Some
|> fun x -> Logging.log "value is none: " x.IsNone; x
|> props.updateSelected

let renderInput pars =
JSX.jsx """
<TextField {...pars} label="Indicaties" />
"""

JSX.jsx
$"""
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import FormControl from '@mui/material/FormControl';
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
renderInput={renderInput}
>
</Autocomplete>
"""



[<JSX.Component>]
let Medication (props :
{|
label : string
selected : string option
values : string []
updateSelected : string option -> unit
isLoading : bool
|}
) =

let handleChange =
fun ev ->
ev?target?innerText
|> string
|> function
| s when s |> String.IsNullOrWhiteSpace ||
s = "undefined" -> None
| s -> s |> Some
|> fun x -> Logging.log "value is none: " x.IsNone; x
|> props.updateSelected

let renderInput pars =
JSX.jsx """
<TextField {...pars} label="Medicatie" />
"""

JSX.jsx
$"""
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import FormControl from '@mui/material/FormControl';
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
renderInput={renderInput}
>
</Autocomplete>
"""



[<JSX.Component>]
let Routes (props :
{|
label : string
selected : string option
values : string []
updateSelected : string option -> unit
isLoading : bool
|}
) =

let handleChange =
fun ev ->
ev?target?innerText
|> string
|> function
| s when s |> String.IsNullOrWhiteSpace ||
s = "undefined" -> None
| s -> s |> Some
|> fun x -> Logging.log "value is none: " x.IsNone; x
|> props.updateSelected

let renderInput pars =
JSX.jsx """
<TextField {...pars} label="Routes" />
"""

JSX.jsx
$"""
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import FormControl from '@mui/material/FormControl';
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
renderInput={renderInput}
>
</Autocomplete>
"""



[<JSX.Component>]
let DoseTypes (props :
{|
label : string
selected : string option
values : string []
updateSelected : string option -> unit
isLoading : bool
|}
) =

let handleChange =
fun ev ->
ev?target?innerText
|> string
|> function
| s when s |> String.IsNullOrWhiteSpace ||
s = "undefined" -> None
| s -> s |> Some
|> fun x -> Logging.log "value is none: " x.IsNone; x
|> props.updateSelected

let renderInput pars =
JSX.jsx """
<TextField {...pars} label="Doseer types" />
JSX.jsx $"""
<TextField {{...pars}} label={props.label} />
"""

JSX.jsx
Expand Down
47 changes: 16 additions & 31 deletions src/Client/Views/Formulary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,13 @@ module Formulary =


let autoComplete isLoading lbl selected dispatch xs =
match lbl with
| _ when lbl = "ind" ->
Components.Autocomplete.Indications({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ when lbl = "med" ->
Components.Autocomplete.Medication({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ ->
Components.Autocomplete.Routes({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
Components.Autocomplete.View({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})


let progress =
Expand Down Expand Up @@ -223,40 +205,43 @@ module Formulary =
| Resolved form -> false, form.Indication, form.Indications
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Formulary Indications`` |> getTerm "Indicaties")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Formulary Indications`` |> getTerm "Indicaties") state.Indication (IndicationChange >> dispatch)
|> select isLoading lbl state.Indication (IndicationChange >> dispatch)
else
items
|> autoComplete isLoading "ind" sel (IndicationChange >> dispatch)
|> autoComplete isLoading lbl sel (IndicationChange >> dispatch)
}
{
match props.formulary with
| Resolved form -> false, form.Generic, form.Generics
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Formulary Medications`` |> getTerm "Medicatie")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Formulary Medications`` |> getTerm "Medicatie") state.Generic (GenericChange >> dispatch)
|> select isLoading lbl state.Generic (GenericChange >> dispatch)
else
items
|> autoComplete isLoading "med" sel (GenericChange >> dispatch)
|> autoComplete isLoading lbl sel (GenericChange >> dispatch)
}
{
match props.formulary with
| Resolved form -> false, form.Route, form.Routes
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Formulary Routes`` |> getTerm "Routes")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Formulary Routes`` |> getTerm "Routes") state.Route (RouteChange >> dispatch)
|> select isLoading lbl state.Route (RouteChange >> dispatch)
else
items
|> autoComplete isLoading "rts" sel (RouteChange >> dispatch)
|> autoComplete isLoading lbl sel (RouteChange >> dispatch)
}
</Stack>
Expand Down
63 changes: 19 additions & 44 deletions src/Client/Views/Prescribe.fs
Original file line number Diff line number Diff line change
Expand Up @@ -221,42 +221,13 @@ module Prescribe =
|})

let autoComplete isLoading lbl selected dispatch xs =
match lbl with
| _ when lbl = "ind" ->
Components.Autocomplete.Indications({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ when lbl = "med" ->
Components.Autocomplete.Medication({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ when lbl = "rts" ->
Components.Autocomplete.Routes({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ when lbl = "dts" ->
Components.Autocomplete.DoseTypes({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ ->
$"cannot create autocomplete from {lbl}"
|> failwith
Components.Autocomplete.View({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})

let progress =
match props.scenarios with
Expand Down Expand Up @@ -411,41 +382,44 @@ module Prescribe =
| Resolved scrs -> false, scrs.Indication, scrs.Indications
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Prescribe Indications`` |> getTerm "Indicaties")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Prescribe Indications`` |> getTerm "Indicaties") sel (IndicationChange >> dispatch)
|> select isLoading lbl sel (IndicationChange >> dispatch)
else
items
|> autoComplete isLoading "ind" sel (IndicationChange >> dispatch)
|> autoComplete isLoading lbl sel (IndicationChange >> dispatch)
}
<Stack direction={stackDirection} spacing={3} >
{
match props.scenarios with
| Resolved scrs -> false, scrs.Medication, scrs.Medications
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Prescribe Medications`` |> getTerm "Medicatie")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Prescribe Medications`` |> getTerm "Medicatie") sel (MedicationChange >> dispatch)
|> select isLoading lbl sel (MedicationChange >> dispatch)
else
items
|> autoComplete isLoading "med" sel (MedicationChange >> dispatch)
|> autoComplete isLoading lbl sel (MedicationChange >> dispatch)
}
{
match props.scenarios with
| Resolved scrs -> false, scrs.Route, scrs.Routes
| _ -> true, None, [||]
|> fun (isLoading, sel, items) ->
let lbl = (Terms.``Prescribe Routes`` |> getTerm "Routes")
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading (Terms.``Prescribe Routes`` |> getTerm "Routes") sel (RouteChange >> dispatch)
|> select isLoading lbl sel (RouteChange >> dispatch)
else
items
|> autoComplete isLoading "rts" sel (RouteChange >> dispatch)
|> autoComplete isLoading lbl sel (RouteChange >> dispatch)
}
{
Expand All @@ -455,13 +429,14 @@ module Prescribe =
scrs.Route.IsSome ->
(false, scrs.DoseType, scrs.DoseTypes)
|> fun (isLoading, sel, items) ->
let lbl = "Doseer types"
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading "Doseer types" sel (DoseTypeChange >> dispatch)
|> select isLoading lbl sel (DoseTypeChange >> dispatch)
else
items
|> autoComplete isLoading "dts" sel (DoseTypeChange >> dispatch)
|> autoComplete isLoading lbl sel (DoseTypeChange >> dispatch)
| _ -> JSX.jsx $"<></>"
}
Expand Down

0 comments on commit 3bee916

Please sign in to comment.