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

View file

@ -19,6 +19,7 @@ import Html
, dl
, dt
, li
, pre
, table
, tbody
, td
@ -265,17 +266,6 @@ viewResultItemDetails channel item =
Nothing ->
text <| cleanPosition value
withDefault wrapWith maybe =
case maybe of
Nothing ->
text default
Just "" ->
text default
Just value ->
wrapWith value
mainPlatforms platform =
List.member platform
[ "x86_64-linux"
@ -299,81 +289,100 @@ viewResultItemDetails channel item =
|> List.map (showPlatform hydra)
showPlatform hydra platform =
li []
[ case
( getHydraDetailsForPlatform hydra platform
, Search.channelDetailsFromId channel
)
of
( Just hydraDetails, _ ) ->
a
[ href <| "https://hydra.nixos.org/build/" ++ String.fromInt hydraDetails.build_id
]
[ text platform
]
case
( getHydraDetailsForPlatform hydra platform
, Search.channelDetailsFromId channel
)
of
( Just hydraDetails, _ ) ->
a
[ href <| "https://hydra.nixos.org/build/" ++ String.fromInt hydraDetails.build_id
]
[ text platform
]
( Nothing, Just channelDetails ) ->
a
[ href <| "https://hydra.nixos.org/job/" ++ channelDetails.jobset ++ "/nixpkgs." ++ item.source.attr_name ++ "." ++ platform
]
[ text platform
]
( Nothing, Just channelDetails ) ->
a
[ href <| "https://hydra.nixos.org/job/" ++ channelDetails.jobset ++ "/nixpkgs." ++ item.source.attr_name ++ "." ++ platform
]
[ text platform
]
( _, _ ) ->
text platform
]
( _, _ ) ->
text platform
showLicence license =
li []
[ case ( license.fullName, license.url ) of
( Nothing, Nothing ) ->
text default
case ( license.fullName, license.url ) of
( Nothing, Nothing ) ->
text default
( Just fullName, Nothing ) ->
text fullName
( Just fullName, Nothing ) ->
text fullName
( Nothing, Just url ) ->
a [ href url ] [ text default ]
( Nothing, Just url ) ->
a [ href url ] [ text default ]
( Just fullName, Just url ) ->
a [ href url ] [ text fullName ]
]
( Just fullName, Just url ) ->
a [ href url ] [ text fullName ]
showMaintainer maintainer =
li []
[ a
[ href <|
case maintainer.github of
Just github ->
"https://github.com/" ++ github
a
[ href <|
case maintainer.github of
Just github ->
"https://github.com/" ++ github
Nothing ->
"#"
]
[ text <| maintainer.name ++ " <" ++ maintainer.email ++ ">" ]
Nothing ->
"#"
]
[ 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
dl [ class "dl-horizontal" ]
[ dt [] [ text "Attribute Name" ]
, dd [] [ asText item.source.attr_name ]
, dd [] [ withEmpty asText (Just item.source.attr_name) ]
, dt [] [ text "Name" ]
, dd [] [ asText item.source.pname ]
, dd [] [ withEmpty asText (Just item.source.pname) ]
, dt [] [ text "Install command" ]
, dd [] [ code [] [ text <| "nix-env -iA nixos." ++ item.source.attr_name ] ]
, dt [] [ text <| "Nix expression" ]
, dd [] [ withDefault asGithubLink item.source.position ]
, dd [] [ withEmpty asCode (Just ("nix-env -iA nixos." ++ item.source.attr_name)) ]
, dt [] [ text "Nix expression" ]
, dd [] [ withEmpty asGithubLink item.source.position ]
, 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" ]
, dd [] [ withDefault asLink item.source.homepage ]
, dd [] [ withEmpty asLink item.source.homepage ]
, dt [] [ text "Licenses" ]
, dd [] [ ul [ class "inline" ] <| List.map showLicence item.source.licenses ]
, dd [] [ asList (List.map showLicence item.source.licenses) ]
, dt [] [ text "Maintainers" ]
, dd [] [ ul [ class "inline" ] <| List.map showMaintainer item.source.maintainers ]
, dd [] [ asList (List.map showMaintainer item.source.maintainers) ]
, dt [] [ text "Description" ]
, dd [] [ withDefault asText item.source.description ]
, dd [] [ withEmpty asText item.source.description ]
, dt [] [ text "Long description" ]
, dd [] [ withDefault asText item.source.longDescription ]
, dd [] [ withEmpty asText item.source.longDescription ]
]