Skip to content

Commit

Permalink
[FLORA-448] Add description field in package index (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
mau5mat authored Dec 10, 2023
1 parent d79142a commit 70523e2
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

## 1.0.14 -- XXXX-XX-XX
* Colourise in red deprecation markers on the package page ([#438](https://github.com/flora-pm/flora-server/pull/439))
* Added more matches to the the natural language processing catergory ([#440](https://github.com/flora-pm/flora-server/pull/440))
* Added more matches to the natural language processing category ([#440](https://github.com/flora-pm/flora-server/pull/440))
* Allow package imports from multiple repositories ([#444](https://github.com/flora-pm/flora-server/pull/444))
* Add a page on namespaces in the documentation ([#451](https://github.com/flora-pm/flora-server/pull/451))
* Add initial support for hosting package tarballs ([#452](https://github.com/flora-pm/flora-server/pull/452))
* Show depended on components in dependencies page ([#464](https://github.com/flora-pm/flora-server/pull/464))
* Add search bar for reverse dependencies ([#476](https://github.com/flora-pm/flora-server/pull/476))
* Support non Hackage repo URLs ([#479](https://github.com/flora-pm/flora-server/pull/479))
* Add description field in package index ([#486](https://github.com/flora-pm/flora-server/pull/486))

## 1.0.13 -- 2023-09-17
* Exclude deprecated releases from latest versions and search ([#373](https://github.com/flora-pm/flora-server/pull/373))
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ db-reset: db-drop db-setup db-provision ## Reset the dev database
db-provision: ## Create categories and repositories
@cabal run -- flora-cli create-user --username "hackage-user" --email "[email protected]" --password "foobar2000"
@cabal run -- flora-cli provision categories
@cabal run -- flora-cli provision-repository --name "hackage" --url https://hackage.haskell.org
@cabal run -- flora-cli provision-repository --name "cardano" --url https://input-output-hk.github.io/cardano-haskell-packages
@cabal run -- flora-cli provision-repository --name "hackage" --url https://hackage.haskell.org \
--description "Central package repository"
@cabal run -- flora-cli provision-repository --name "cardano" --url https://input-output-hk.github.io/cardano-haskell-packages \
--description "Packages of the Cardano project"

db-provision-test-packages: ## Load development data in the database
@cabal run -- flora-cli provision test-packages
Expand Down
11 changes: 6 additions & 5 deletions app/cli/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data Command
| GenDesignSystemComponents
| ImportPackages FilePath Text
| ImportIndex FilePath Text
| ProvisionRepository Text Text
| ProvisionRepository Text Text Text
| ImportPackageTarball PackageName Version FilePath
deriving stock (Show, Eq)

Expand Down Expand Up @@ -135,6 +135,7 @@ parseProvisionRepository =
ProvisionRepository
<$> option str (long "name" <> metavar "<repository name>" <> help "Name of the repository")
<*> option str (long "url" <> metavar "<repository url>" <> help "Link to the package repository")
<*> option str (long "description" <> metavar "<repository description>" <> help "Description of the package repository" <> value "" <> showDefault)

parseImportPackageTarball :: Parser Command
parseImportPackageTarball =
Expand Down Expand Up @@ -174,12 +175,12 @@ runOptions (Options (CreateUser opts)) = do
runOptions (Options GenDesignSystemComponents) = generateComponents
runOptions (Options (ImportPackages path repository)) = importFolderOfCabalFiles path repository
runOptions (Options (ImportIndex path repository)) = importIndex path repository
runOptions (Options (ProvisionRepository name url)) = provisionRepository name url
runOptions (Options (ProvisionRepository name url description)) = provisionRepository name url description
runOptions (Options (ImportPackageTarball pname version path)) = importPackageTarball pname version path

provisionRepository :: (DB :> es, IOE :> es) => Text -> Text -> Eff es ()
provisionRepository name url = do
Update.createPackageIndex name url Nothing
provisionRepository :: (DB :> es, IOE :> es) => Text -> Text -> Text -> Eff es ()
provisionRepository name url description = do
Update.createPackageIndex name url description Nothing

importFolderOfCabalFiles :: (Reader PoolConfig :> es, DB :> es, IOE :> es) => FilePath -> Text -> Eff es ()
importFolderOfCabalFiles path repository = Log.withStdOutLogger $ \appLogger -> do
Expand Down
2 changes: 1 addition & 1 deletion flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ flag prod

common common-extensions
default-extensions:
NoStarIsType
DataKinds
DeriveAnyClass
DerivingStrategies
DerivingVia
DuplicateRecordFields
LambdaCase
NoStarIsType
OverloadedLabels
OverloadedRecordDot
OverloadedStrings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table package_indexes
add column description text not null;
5 changes: 3 additions & 2 deletions src/core/Flora/Model/PackageIndex/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ data PackageIndex = PackageIndex
, repository :: Text
, timestamp :: Maybe UTCTime
, url :: Text
, description :: Text
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromRow, ToRow, NFData)
deriving
(Entity)
via (GenericEntity '[TableName "package_indexes"] PackageIndex)

mkPackageIndex :: IOE :> es => Text -> Text -> Maybe UTCTime -> Eff es PackageIndex
mkPackageIndex repository url timestamp = do
mkPackageIndex :: IOE :> es => Text -> Text -> Text -> Maybe UTCTime -> Eff es PackageIndex
mkPackageIndex repository url description timestamp = do
packageIndexId <- PackageIndexId <$> liftIO UUID.nextRandom
pure $ PackageIndex{..}

Expand Down
8 changes: 4 additions & 4 deletions src/core/Flora/Model/PackageIndex/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Effectful
import Effectful.PostgreSQL.Transact.Effect (DB, dbtToEff)

import Flora.Model.PackageIndex.Types
( PackageIndex
( PackageIndex (..)
, mkPackageIndex
)

Expand All @@ -29,7 +29,7 @@ updatePackageIndexByName repositoryName newTimestamp = do
([field| repository |], repositoryName)
(Only newTimestamp)

createPackageIndex :: (IOE :> es, DB :> es) => Text -> Text -> Maybe UTCTime -> Eff es ()
createPackageIndex repositoryName url timestamp = do
packageIndex <- mkPackageIndex repositoryName url timestamp
createPackageIndex :: (IOE :> es, DB :> es) => Text -> Text -> Text -> Maybe UTCTime -> Eff es ()
createPackageIndex repositoryName url description timestamp = do
packageIndex <- mkPackageIndex repositoryName url description timestamp
void $ dbtToEff $ insert @PackageIndex packageIndex
2 changes: 1 addition & 1 deletion src/web/FloraWeb/Components/PackageListHeader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ presentationHeader title subtitle numberOfPackages = do
div_ [class_ "page-title"] $ do
h1_ [class_ ""] $ do
span_ [class_ "headline"] $ toHtml title
p_ [class_ "package-count"] $ toHtml $ display numberOfPackages <> " results"
div_ [class_ "synopsis lg:text-xl text-center"] $
p_ [class_ ""] (toHtml subtitle)
p_ [class_ "package-count"] $ toHtml $ display numberOfPackages <> " results"
20 changes: 18 additions & 2 deletions src/web/FloraWeb/Pages/Server/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Flora.Logging
import Flora.Model.BlobIndex.Query qualified as Query
import Flora.Model.Package
import Flora.Model.Package.Query qualified as Query
import Flora.Model.PackageIndex.Query qualified as Query
import Flora.Model.PackageIndex.Types (PackageIndex (..))
import Flora.Model.Release.Query qualified as Query
import Flora.Model.Release.Types
Expand All @@ -44,6 +45,7 @@ import FloraWeb.Pages.Templates.Packages qualified as Package
import FloraWeb.Pages.Templates.Screens.Packages qualified as Packages
import FloraWeb.Pages.Templates.Screens.Search qualified as Search
import FloraWeb.Session
import Network.HTTP.Types (notFound404)

server :: ServerT Routes FloraPage
server =
Expand Down Expand Up @@ -76,8 +78,22 @@ showNamespaceHandler namespace pageParam = do
session <- getSession
templateDefaults <- fromSession session defaultTemplateEnv
(count', results) <- Search.listAllPackagesInNamespace namespace (fromPage pageNumber)
render templateDefaults $
Search.showAllPackagesInNamespace namespace count' pageNumber results
if extractNamespaceText namespace == "haskell"
then
render templateDefaults $
Search.showAllPackagesInNamespace
namespace
"Core Haskell packages"
count'
pageNumber
results
else do
mPackageIndex <- Query.getPackageIndexByName (extractNamespaceText namespace)
case mPackageIndex of
Nothing -> renderError templateDefaults notFound404
Just packageIndex ->
render templateDefaults $
Search.showAllPackagesInNamespace namespace packageIndex.description count' pageNumber results

showPackageHandler :: Namespace -> PackageName -> FloraPage (Html ())
showPackageHandler namespace packageName = showPackageVersion namespace packageName Nothing
Expand Down
6 changes: 3 additions & 3 deletions src/web/FloraWeb/Pages/Templates/Screens/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ showAllPackages count currentPage packagesInfo = do
div_ [class_ ""] $ packageListing Nothing packagesInfo
paginationNav count currentPage ListAllPackages

showAllPackagesInNamespace :: Namespace -> Word -> Positive Word -> Vector PackageInfo -> FloraHTML
showAllPackagesInNamespace namespace count currentPage packagesInfo = do
showAllPackagesInNamespace :: Namespace -> Text -> Word -> Positive Word -> Vector PackageInfo -> FloraHTML
showAllPackagesInNamespace namespace description count currentPage packagesInfo = do
div_ [class_ "container"] $ do
presentationHeader (display namespace) "" count
presentationHeader (display namespace) description count
div_ [class_ ""] $ packageListing Nothing packagesInfo
paginationNav count currentPage (ListAllPackagesInNamespace namespace)

Expand Down
5 changes: 4 additions & 1 deletion test/Flora/ImportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ defaultRepo = "test-namespace"
defaultRepoURL :: Text
defaultRepoURL = "localhost"

defaultDescription :: Text
defaultDescription = "test-description"

testImportIndex :: Fixtures -> TestEff ()
testImportIndex fixture = withStdOutLogger $
\logger -> do
mIndex <- Query.getPackageIndexByName defaultRepo
case mIndex of
Nothing -> Update.createPackageIndex defaultRepo defaultRepoURL Nothing
Nothing -> Update.createPackageIndex defaultRepo defaultRepoURL defaultDescription Nothing
Just _ -> pure ()
importFromIndex
logger
Expand Down
2 changes: 1 addition & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ main = do
. runBlobStorePure
. runFailIO
$ do
Update.createPackageIndex "hackage" "" Nothing
Update.createPackageIndex "hackage" "" "" Nothing
testMigrations
f' <- getFixtures
importAllPackages f'
Expand Down

0 comments on commit 70523e2

Please sign in to comment.