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
, SnapshotDiff() , SnapshotDiff()
, toDiffList , toDiffList
, toVersionedDiffList
, VersionChange(..) , VersionChange(..)
, WithSnapshotNames(..) , WithSnapshotNames(..)
) where ) where
import qualified Data.Text as T(commonPrefixes)
import Data.Align import Data.Align
import Data.Aeson import Data.Aeson
import qualified Data.HashMap.Strict as HashMap import qualified Data.HashMap.Strict as HashMap
@ -36,6 +38,20 @@ instance ToJSON (WithSnapshotNames SnapshotDiff) where
toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)] toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)]
toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff 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`. -- | 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, -- 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 { .table th, .table td {
padding-left: 0; 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 $else
<option value=@{StackageDiffR name1 name2'}>#{toPathPiece name2'} <option value=@{StackageDiffR name1 name2'}>#{toPathPiece name2'}
<tbody> <tbody>
$forall (pkgname, VersionChange verChange) <- toDiffList snapDiff $forall (pkgname, VersionChange verChange, versionDiff) <- toVersionedDiffList snapDiff
<tr> <tr>
$case verChange $case verChange
$of This oldVersion $of This oldVersion
@ -47,9 +47,19 @@
<a href=@{packageUrl name2 pkgname newVersion}#changes> <a href=@{packageUrl name2 pkgname newVersion}#changes>
#{pkgname}-#{newVersion} #{pkgname}-#{newVersion}
$of These oldVersion newVersion $of These oldVersion newVersion
<td> $maybe (common, old, new) <- versionDiff
<a href=@{packageUrl name1 pkgname oldVersion}#changes> <td>
#{pkgname}-#{oldVersion} <a href=@{packageUrl name1 pkgname oldVersion}#changes>
<td> #{pkgname}-#{common}#
<a href=@{packageUrl name2 pkgname newVersion}#changes> <span .version-removed>#{old}
#{pkgname}-#{newVersion} <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}