Skip to content

Commit

Permalink
Improve community select for templates ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Feb 13, 2024
1 parent ec1dcd3 commit 996accc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
25 changes: 16 additions & 9 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,27 @@ module Protocol =
type CommunityFilter =
| All
| OnlyCurated
| OnlyCommunity
| OnlyCommunities
| Community of string

member this.ToStringRdb() =
match this with
| All -> "All"
| OnlyCurated -> "Curated"
| OnlyCommunity -> "Community"
| All -> "All"
| OnlyCurated -> "DataPLANT official"
| OnlyCommunities -> "All Communities"
| Community name -> name

static member fromString(str:string) =
match str.ToLower() with
| "all" -> All
| "curated" -> OnlyCurated
| "community" -> OnlyCommunity
| anyElse -> printfn "Unable to parse %s to CommunityFilter. Default to 'All'." anyElse; All
match str with
| "All" -> All
| "All Curated" -> OnlyCurated
| "All Community" -> OnlyCommunities
| anyElse -> Community anyElse

static member CommunityFromOrganisation(org:ARCtrl.Template.Organisation) =
match org with
| ARCtrl.Template.Organisation.DataPLANT -> None
| ARCtrl.Template.Other name -> Some <| Community name

/// This model is used for both protocol insert and protocol search
type Model = {
Expand Down
28 changes: 18 additions & 10 deletions src/Client/Pages/ProtocolTemplates/ProtocolSearchViewComponent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,19 @@ module ComponentAux =

open Fable.Core.JsInterop

let communitySelectField (model) (state: ProtocolViewState) setState =
let options = [
Model.Protocol.CommunityFilter.All
Model.Protocol.CommunityFilter.OnlyCurated
Model.Protocol.CommunityFilter.OnlyCommunity
]
let communitySelectField (model: Messages.Model) (state: ProtocolViewState) setState =
let communityNames =
model.ProtocolState.Templates
|> Array.choose (fun t -> Model.Protocol.CommunityFilter.CommunityFromOrganisation t.Organisation)
|> Array.distinct |> List.ofArray
let options =
[
Model.Protocol.CommunityFilter.All
Model.Protocol.CommunityFilter.OnlyCurated
Model.Protocol.CommunityFilter.OnlyCommunities
]@communityNames
Html.div [
Bulma.label "Search for tags"
Bulma.label "Select community"
Bulma.control.div [
Bulma.control.isExpanded
prop.children [
Expand Down Expand Up @@ -493,10 +498,13 @@ type Search =
else
templates
let filterTableByCommunityFilter communityfilter (protocol:ARCtrl.Template.Template []) =
log communityfilter
match communityfilter with
| Protocol.CommunityFilter.All -> protocol
| Protocol.CommunityFilter.OnlyCurated -> protocol |> Array.filter (fun x -> List.contains (x.Organisation.ToString().ToLower()) curatedOrganisationNames)
| Protocol.CommunityFilter.OnlyCommunity -> protocol |> Array.filter (fun x -> List.contains (x.Organisation.ToString().ToLower()) curatedOrganisationNames |> not)
| Protocol.CommunityFilter.All -> protocol
| Protocol.CommunityFilter.OnlyCurated -> protocol |> Array.filter (fun x -> log (x.Organisation.ToString().ToLower()) ; List.contains (x.Organisation.ToString().ToLower()) curatedOrganisationNames)
| Protocol.CommunityFilter.OnlyCommunities -> protocol |> Array.filter (fun x -> List.contains (x.Organisation.ToString().ToLower()) curatedOrganisationNames |> not)
| Protocol.CommunityFilter.Community name -> protocol |> Array.filter (fun x -> x.Organisation.ToString() = name)


let state, setState = React.useState(ProtocolViewState.init)
let propagateOutside = fun () ->
Expand Down

0 comments on commit 996accc

Please sign in to comment.