From b76a88aa81a852e5cbd660496ad0a8869eeb63cd Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 12 Nov 2020 17:03:25 -0800 Subject: [PATCH] web: fix --forecast breakage since 1.18 (fix #1390) Replaces the partial HashMap.! with List.elemIndex. (Although the HashMap is more algorithmically efficient, its API changed recently, possibly complicating building, and efficiency is just not going to be an issue here.) --- hledger-web/Hledger/Web/Widget/Common.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hledger-web/Hledger/Web/Widget/Common.hs b/hledger-web/Hledger/Web/Widget/Common.hs index 4b75d3c36..34ecff747 100644 --- a/hledger-web/Hledger/Web/Widget/Common.hs +++ b/hledger-web/Hledger/Web/Widget/Common.hs @@ -21,12 +21,12 @@ module Hledger.Web.Widget.Common import Data.Default (def) import Data.Foldable (find, for_) +import Data.List (elemIndex) #if !(MIN_VERSION_base(4,13,0)) import Data.Semigroup ((<>)) #endif import Data.Text (Text) import qualified Data.Text as T -import qualified Data.HashMap.Strict as HashMap import System.FilePath (takeFileName) import Text.Blaze ((!), textValue) import qualified Text.Blaze.Html5 as H @@ -110,12 +110,15 @@ mixedAmountAsHtml b _ = Just True -> "negative amount" _ -> "positive amount" +-- Make a slug to uniquely identify this transaction +-- in hyperlinks (as far as possible). transactionFragment :: Journal -> Transaction -> String -transactionFragment j = - let hm = HashMap.fromList $ zip (map fst $ jfiles j) [(1::Integer) ..] - in \t -> - printf "transaction-%d-%d" - (hm HashMap.! sourceFilePath (tsourcepos t)) (tindex t) +transactionFragment j Transaction{tindex, tsourcepos} = + printf "transaction-%d-%d" tfileindex tindex + where + -- the numeric index of this txn's file within all the journal files, + -- or 0 if this txn has no known file (eg a forecasted txn) + tfileindex = maybe 0 (+1) $ elemIndex (sourceFilePath tsourcepos) (journalFilePaths j) removeInacct :: Text -> [Text] removeInacct =