Refactor Dropdown

This commit is contained in:
Eike Kettner
2021-04-02 15:54:02 +02:00
parent b9c98c6578
commit 8d15d97857
26 changed files with 493 additions and 504 deletions

View File

@ -37,7 +37,7 @@ mkFolderOption flags allFolders idref =
else
""
in
{ value = idref.id, text = idref.name, additional = adds }
{ text = idref.name, additional = adds }
isFolderMember : List FolderItem -> Maybe String -> Bool

View File

@ -0,0 +1,20 @@
module Util.Person exposing (mkPersonOption)
import Api.Model.IdName exposing (IdName)
import Api.Model.Person exposing (Person)
import Comp.Dropdown
import Dict exposing (Dict)
import Util.String
mkPersonOption : IdName -> Dict String Person -> Comp.Dropdown.Option
mkPersonOption idref personDict =
let
org =
Dict.get idref.id personDict
|> Maybe.andThen .organization
|> Maybe.map .name
|> Maybe.map (Util.String.ellipsis 15)
|> Maybe.withDefault ""
in
Comp.Dropdown.Option idref.name org

View File

@ -1,12 +1,14 @@
module Util.Tag exposing
( getCategories
( catSettings
, getCategories
, makeCatDropdownModel
, makeDropdownModel
, makeDropdownModel2
, tagSettings
)
import Api.Model.Tag exposing (Tag)
import Comp.Dropdown
import Data.DropdownStyle as DS
import Data.UiSettings
import Util.List
@ -16,30 +18,19 @@ makeDropdownModel =
Comp.Dropdown.makeModel
{ multiple = True
, searchable = \n -> n > 0
, makeOption = \tag -> { value = tag.id, text = tag.name, additional = "" }
, labelColor =
\tag ->
\settings ->
"basic " ++ Data.UiSettings.tagColorString tag settings
, placeholder = "Choose a tag"
}
makeDropdownModel2 : Comp.Dropdown.Model Tag
makeDropdownModel2 =
Comp.Dropdown.makeModel
{ multiple = True
, searchable = \n -> n > 0
, makeOption = \tag -> { value = tag.id, text = tag.name, additional = "" }
, labelColor =
\tag ->
\settings ->
Data.UiSettings.tagColorString2 tag settings
++ -- legacy colors
" basic "
++ Data.UiSettings.tagColorString tag settings
, placeholder = "Choose a tag"
}
tagSettings : DS.DropdownStyle -> Comp.Dropdown.ViewSettings Tag
tagSettings ds =
{ makeOption = \tag -> { text = tag.name, additional = "" }
, labelColor =
\tag ->
\settings ->
Data.UiSettings.tagColorString2 tag settings
, placeholder = "Choose a tag"
, style = ds
}
makeCatDropdownModel : Comp.Dropdown.Model String
@ -47,12 +38,18 @@ makeCatDropdownModel =
Comp.Dropdown.makeModel
{ multiple = True
, searchable = \n -> n > 0
, makeOption = \cat -> { value = cat, text = cat, additional = "" }
, labelColor = \_ -> \_ -> ""
, placeholder = "Choose a tag category"
}
catSettings : DS.DropdownStyle -> Comp.Dropdown.ViewSettings String
catSettings ds =
{ makeOption = \cat -> { text = cat, additional = "" }
, labelColor = \_ -> \_ -> ""
, placeholder = "Choose a tag category"
, style = ds
}
getCategories : List Tag -> List String
getCategories tags =
List.filterMap .category tags