Skip to content

Commit

Permalink
Merge pull request #765 from fel-mazo/development
Browse files Browse the repository at this point in the history
URL uniformisation for namespaces prefix (/@ vs /&40) (#601)
  • Loading branch information
mergify[bot] authored Nov 8, 2024
2 parents d252de2 + 9a65ae1 commit 54fd56b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/web/FloraWeb/Components/PaginationNav.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ mkURL :: SearchAction -> Positive Word -> Text
mkURL ListAllPackages pageNumber =

Check warning on line 45 in src/web/FloraWeb/Components/PaginationNav.hs

View workflow job for this annotation

GitHub Actions / Backend_tests (9.6.6, ubuntu-latest)

Pattern match(es) are non-exhaustive
"/" <> toUrlPiece (Links.packageIndexLink pageNumber)
mkURL (ListAllPackagesInNamespace namespace) pageNumber =
"/" <> toUrlPiece (Links.namespaceLink namespace pageNumber)
Links.namespacePage namespace pageNumber
mkURL (SearchPackages searchTerm) pageNumber =
"/" <> toUrlPiece (Links.packageSearchLink searchTerm pageNumber)
mkURL (DependentsOf namespace packageName mbSearchString) pageNumber =
"/" <> toUrlPiece (Links.packageDependents namespace packageName pageNumber mbSearchString)
Links.dependentsPage namespace packageName pageNumber <> "q=" <> toUrlPiece mbSearchString
mkURL (SearchExecutable searchString) pageNumber =
"/" <> toUrlPiece (Links.packageWithExecutable pageNumber searchString)

Expand Down
29 changes: 29 additions & 0 deletions src/web/FloraWeb/Links.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module FloraWeb.Links where

import Data.Positive
import Data.Text (Text)
import Data.Text.Display (display)
import Distribution.Orphans ()
import Distribution.Version (Version)
import Flora.Model.Package (Namespace (..), PackageName (..))
Expand Down Expand Up @@ -115,3 +116,31 @@ packageWithExecutable pageNumber search =
// Search.displaySearch
/: Just search
/: Just pageNumber

namespacePage :: Namespace -> Positive Word -> Text
namespacePage namespace pageNumber =
"/packages/" <> display namespace <> "?page=" <> toUrlPiece pageNumber

packageResource :: Namespace -> PackageName -> Text
packageResource namespace name = "/packages/" <> display namespace <> "/" <> display name

versionResource :: Namespace -> PackageName -> Version -> Text
versionResource namespace name version =
packageResource namespace name
<> "/"
<> display version

dependentsPage :: Namespace -> PackageName -> Positive Word -> Text
dependentsPage namespace packageName pageNum =
packageResource namespace packageName
<> "/dependents?page="
<> toUrlPiece pageNum

dependenciesPage :: Namespace -> PackageName -> Version -> Text
dependenciesPage namespace packageName version =
versionResource namespace packageName version
<> "/dependencies"

versionsPage :: Namespace -> PackageName -> Text
versionsPage namespace packageName =
packageResource namespace packageName <> "/versions"
22 changes: 10 additions & 12 deletions src/web/FloraWeb/Pages/Templates/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ displayNamespace namespace =
a_
[ class_ "breadcrumb-segment"
, href_
("/" <> toUrlPiece (Links.namespaceLink namespace 1))
("/packages/" <> display namespace <> "?page=1")
]
(toHtml $ display namespace)

Expand Down Expand Up @@ -324,7 +324,7 @@ displayVersions namespace packageName versions numberOfReleases =
let versionClass = "release-version" <> if Just True == release.deprecated then " release-deprecated" else ""
let dataText = ([dataText_ "This release is deprecated, pick another one" | Just True == release.deprecated])
a_
([class_ versionClass, href_ ("/" <> toUrlPiece (Links.packageVersionLink namespace packageName release.version))] <> dataText)
([class_ versionClass, href_ $ Links.versionResource namespace packageName release.version] <> dataText)
(toHtml $ display release.version)
" "
case release.uploadedAt of
Expand Down Expand Up @@ -361,10 +361,10 @@ displayDependencies (namespace, packageName, version) numberOfDependencies depen
showAll :: Target -> Maybe Version -> Namespace -> PackageName -> FloraHTML
showAll target mVersion namespace packageName = do
let resource = case target of
Dependents -> Links.packageDependents namespace packageName (PositiveUnsafe 1) Nothing
Dependencies -> Links.packageDependencies namespace packageName (fromJust mVersion)
Versions -> Links.packageVersions namespace packageName
a_ [class_ "dependency", href_ ("/" <> toUrlPiece resource)] "Show all…"
Dependents -> Links.dependentsPage namespace packageName (PositiveUnsafe 1)
Dependencies -> Links.dependenciesPage namespace packageName (fromJust mVersion)
Versions -> Links.versionsPage namespace packageName
a_ [class_ "dependency", href_ resource] "Show all…"

displayInstructions :: Namespace -> PackageName -> Release -> FloraHTML
displayInstructions namespace packageName latestRelease =
Expand Down Expand Up @@ -404,7 +404,7 @@ displayPackageDeprecation (PackageAlternatives inFavourOf) =
\PackageAlternative{namespace, package} ->
li_ [] $
a_
[href_ ("/packages/" <> display namespace <> "/" <> display package)]
[href_ $ Links.packageResource namespace package]
(text $ display namespace <> "/" <> display package)

displayReleaseDeprecation :: Maybe (Namespace, PackageName, Version) -> FloraHTML
Expand All @@ -416,7 +416,7 @@ displayReleaseDeprecation mLatestViableRelease =
Just (namespace, package, version) -> do
label_ [for_ "install-string", class_ "font-light"] (text "This release has been deprecated in favour of: ")
a_
[href_ ("/packages/" <> display namespace <> "/" <> display package <> "/" <> display version)]
[href_ $ Links.versionResource namespace package version]
(text $ display namespace <> "/" <> display package <> "-" <> display version)

displayTestedWith :: Vector Version -> FloraHTML
Expand Down Expand Up @@ -456,15 +456,13 @@ displayDependents (namespace, packageName) numberOfDependents dependents =
renderDependent :: Package -> FloraHTML
renderDependent Package{name, namespace} = do
let qualifiedName = toHtml $ display namespace <> "/" <> display name
let resource = "/packages/" <> display namespace <> "/" <> display name

a_ [class_ "dependent", href_ resource] qualifiedName
a_ [class_ "dependent", href_ $ Links.packageResource namespace name] qualifiedName

renderDependency :: (Namespace, PackageName, Text) -> FloraHTML
renderDependency (namespace, name, version) = do
let resource = "/packages/" <> display namespace <> "/" <> display name
li_ [class_ "dependency"] $ do
a_ [href_ resource] (toHtml name)
a_ [href_ $ Links.packageResource namespace name] (toHtml name)
toHtmlRaw @Text "&nbsp;"
if version == ">=0"
then ""
Expand Down

0 comments on commit 54fd56b

Please sign in to comment.