allways display default value for fields in result details (#155)

fixes #154
This commit is contained in:
Rok Garbas 2020-08-24 12:11:53 +02:00 committed by GitHub
parent e4fec33f2b
commit 0ef75fa71d
Failed to generate hash of commit
2 changed files with 95 additions and 94 deletions

View file

@ -13,6 +13,7 @@ import Html
exposing exposing
( Html ( Html
, a , a
, code
, dd , dd
, div , div
, dl , dl
@ -205,9 +206,12 @@ viewResultItemDetails channel item =
Err _ -> Err _ ->
[] []
asCode value = asPre value =
pre [] [ text value ] pre [] [ text value ]
asCode value =
code [] [ text value ]
githubUrlPrefix branch = githubUrlPrefix branch =
"https://github.com/NixOS/nixpkgs-channels/blob/" ++ branch ++ "/" "https://github.com/NixOS/nixpkgs-channels/blob/" ++ branch ++ "/"
@ -235,43 +239,31 @@ viewResultItemDetails channel item =
_ -> _ ->
wrapWith value wrapWith value
withEmpty wrapWith maybe =
case maybe of
Nothing ->
asPre default
Just "" ->
asPre default
Just value ->
wrapWith value
in in
dl [ class "dl-horizontal" ] dl [ class "dl-horizontal" ]
[ dt [] [ text "Name" ] [ dt [] [ text "Name" ]
, dd [] , dd [] [ withEmpty asText (Just item.source.name) ]
[ item.source.name
|> asText
]
, dt [] [ text "Description" ] , dt [] [ text "Description" ]
, dd [] , dd [] [ withEmpty asText item.source.description ]
[ item.source.description
|> Maybe.withDefault default
|> asText
]
, dt [] [ text "Default value" ] , dt [] [ text "Default value" ]
, dd [] , dd [] [ withEmpty asCode item.source.default ]
[ item.source.default
|> Maybe.withDefault default
|> wrapped asCode
]
, dt [] [ text "Type" ] , dt [] [ text "Type" ]
, dd [] , dd [] [ withEmpty asPre item.source.type_ ]
[ item.source.type_
|> Maybe.withDefault default
|> asCode
]
, dt [] [ text "Example value" ] , dt [] [ text "Example value" ]
, dd [] , dd [] [ withEmpty (wrapped asCode) item.source.example ]
[ item.source.example
|> Maybe.withDefault default
|> wrapped asCode
]
, dt [] [ text "Declared in" ] , dt [] [ text "Declared in" ]
, dd [] , dd [] [ withEmpty asGithubLink item.source.source ]
[ item.source.source
|> Maybe.withDefault default
|> asGithubLink
]
] ]

View file

@ -19,6 +19,7 @@ import Html
, dl , dl
, dt , dt
, li , li
, pre
, table , table
, tbody , tbody
, td , td
@ -265,17 +266,6 @@ viewResultItemDetails channel item =
Nothing -> Nothing ->
text <| cleanPosition value text <| cleanPosition value
withDefault wrapWith maybe =
case maybe of
Nothing ->
text default
Just "" ->
text default
Just value ->
wrapWith value
mainPlatforms platform = mainPlatforms platform =
List.member platform List.member platform
[ "x86_64-linux" [ "x86_64-linux"
@ -299,8 +289,7 @@ viewResultItemDetails channel item =
|> List.map (showPlatform hydra) |> List.map (showPlatform hydra)
showPlatform hydra platform = showPlatform hydra platform =
li [] case
[ case
( getHydraDetailsForPlatform hydra platform ( getHydraDetailsForPlatform hydra platform
, Search.channelDetailsFromId channel , Search.channelDetailsFromId channel
) )
@ -321,11 +310,9 @@ viewResultItemDetails channel item =
( _, _ ) -> ( _, _ ) ->
text platform text platform
]
showLicence license = showLicence license =
li [] case ( license.fullName, license.url ) of
[ case ( license.fullName, license.url ) of
( Nothing, Nothing ) -> ( Nothing, Nothing ) ->
text default text default
@ -337,11 +324,9 @@ viewResultItemDetails channel item =
( Just fullName, Just url ) -> ( Just fullName, Just url ) ->
a [ href url ] [ text fullName ] a [ href url ] [ text fullName ]
]
showMaintainer maintainer = showMaintainer maintainer =
li [] a
[ a
[ href <| [ href <|
case maintainer.github of case maintainer.github of
Just github -> Just github ->
@ -351,29 +336,53 @@ viewResultItemDetails channel item =
"#" "#"
] ]
[ text <| maintainer.name ++ " <" ++ maintainer.email ++ ">" ] [ text <| maintainer.name ++ " <" ++ maintainer.email ++ ">" ]
]
asPre value =
pre [] [ text value ]
asCode value =
code [] [ text value ]
asList list =
case list of
[] ->
asPre default
_ ->
ul [ class "inline" ] <| List.map (\i -> li [] [ i ]) list
withEmpty wrapWith maybe =
case maybe of
Nothing ->
asPre default
Just "" ->
asPre default
Just value ->
wrapWith value
in in
dl [ class "dl-horizontal" ] dl [ class "dl-horizontal" ]
[ dt [] [ text "Attribute Name" ] [ dt [] [ text "Attribute Name" ]
, dd [] [ asText item.source.attr_name ] , dd [] [ withEmpty asText (Just item.source.attr_name) ]
, dt [] [ text "Name" ] , dt [] [ text "Name" ]
, dd [] [ asText item.source.pname ] , dd [] [ withEmpty asText (Just item.source.pname) ]
, dt [] [ text "Install command" ] , dt [] [ text "Install command" ]
, dd [] [ code [] [ text <| "nix-env -iA nixos." ++ item.source.attr_name ] ] , dd [] [ withEmpty asCode (Just ("nix-env -iA nixos." ++ item.source.attr_name)) ]
, dt [] [ text <| "Nix expression" ] , dt [] [ text "Nix expression" ]
, dd [] [ withDefault asGithubLink item.source.position ] , dd [] [ withEmpty asGithubLink item.source.position ]
, dt [] [ text "Platforms" ] , dt [] [ text "Platforms" ]
, dd [] [ ul [ class "inline" ] <| showPlatforms item.source.hydra item.source.platforms ] , dd [] [ asList (showPlatforms item.source.hydra item.source.platforms) ]
, dt [] [ text "Homepage" ] , dt [] [ text "Homepage" ]
, dd [] [ withDefault asLink item.source.homepage ] , dd [] [ withEmpty asLink item.source.homepage ]
, dt [] [ text "Licenses" ] , dt [] [ text "Licenses" ]
, dd [] [ ul [ class "inline" ] <| List.map showLicence item.source.licenses ] , dd [] [ asList (List.map showLicence item.source.licenses) ]
, dt [] [ text "Maintainers" ] , dt [] [ text "Maintainers" ]
, dd [] [ ul [ class "inline" ] <| List.map showMaintainer item.source.maintainers ] , dd [] [ asList (List.map showMaintainer item.source.maintainers) ]
, dt [] [ text "Description" ] , dt [] [ text "Description" ]
, dd [] [ withDefault asText item.source.description ] , dd [] [ withEmpty asText item.source.description ]
, dt [] [ text "Long description" ] , dt [] [ text "Long description" ]
, dd [] [ withDefault asText item.source.longDescription ] , dd [] [ withEmpty asText item.source.longDescription ]
] ]