Introduces highlighting package version differences

This commit is contained in:
Andrei Dziahel 2017-12-20 01:16:44 +03:00
parent 298d1d5b52
commit cfb9ed248f
3 changed files with 42 additions and 7 deletions

View File

@ -4,10 +4,12 @@ module Stackage.Snapshot.Diff
, snapshotDiff
, SnapshotDiff()
, toDiffList
, toVersionedDiffList
, VersionChange(..)
, WithSnapshotNames(..)
) where
import qualified Data.Text as T(commonPrefixes)
import Data.Align
import Data.Aeson
import qualified Data.HashMap.Strict as HashMap
@ -36,6 +38,20 @@ instance ToJSON (WithSnapshotNames SnapshotDiff) where
toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)]
toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff
versionPrefix :: VersionChange -> Maybe (Text,Text,Text)
versionPrefix vc = case unVersionChange vc of
These (Version a) (Version b) -> T.commonPrefixes a b
_ -> Nothing
versionedDiffList :: [(PackageName, VersionChange)] -> [(PackageName, VersionChange, Maybe (Text,Text,Text))]
versionedDiffList = map withPrefixedVersion
where
withPrefixedVersion (packageName, versionChange) = (packageName, versionChange, versionPrefix versionChange)
toVersionedDiffList :: SnapshotDiff -> [(PackageName, VersionChange, Maybe (Text, Text, Text))]
toVersionedDiffList = versionedDiffList . toDiffList
-- | Versions of a package as it occurs in the listings provided to `snapshotDiff`.
--
-- Would be represented with `These v1 v2` if the package is present in both listings,

View File

@ -2,4 +2,13 @@
.table th, .table td {
padding-left: 0;
}
.table span.version-removed {
background-color: red;
text-decoration: line-through;
}
.table span.version-added {
background-color: green;
}
}

View File

@ -33,7 +33,7 @@
$else
<option value=@{StackageDiffR name1 name2'}>#{toPathPiece name2'}
<tbody>
$forall (pkgname, VersionChange verChange) <- toDiffList snapDiff
$forall (pkgname, VersionChange verChange, versionDiff) <- toVersionedDiffList snapDiff
<tr>
$case verChange
$of This oldVersion
@ -47,9 +47,19 @@
<a href=@{packageUrl name2 pkgname newVersion}#changes>
#{pkgname}-#{newVersion}
$of These oldVersion newVersion
<td>
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
#{pkgname}-#{oldVersion}
<td>
<a href=@{packageUrl name2 pkgname newVersion}#changes>
#{pkgname}-#{newVersion}
$maybe (common, old, new) <- versionDiff
<td>
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
#{pkgname}-#{common}#
<span .version-removed>#{old}
<td>
<a href=@{packageUrl name2 pkgname newVersion}#changes>
#{pkgname}-#{common}#
<span .version-added>#{new}
$nothing
<td>
<a href=@{packageUrl name1 pkgname oldVersion}#changes>
#{pkgname}-#{oldVersion}
<td>
<a href=@{packageUrl name2 pkgname newVersion}#changes>
#{pkgname}-#{newVersion}