@@ -3,34 +3,39 @@ module View.Transaction where
3
3
import Prelude hiding (div )
4
4
import Affjax (URL ) -- TODO eliminate
5
5
import Data.Array (mapMaybe )
6
- import Data.Lens (over , preview , _Just , second )
6
+ import Data.String.CodePoints (take )
7
+ import Data.Lens (over , preview , _Just , second , view )
7
8
import Data.Maybe (Maybe , maybe )
9
+ import Data.Newtype (un )
10
+ import Data.Either (either )
8
11
import Data.Either.Nested (type (\/))
12
+ import Data.Tuple.Nested ((/\))
9
13
import Effect.Aff.Class (class MonadAff )
10
14
import Halogen (ComponentHTML )
11
- import Halogen.HTML (HTML , slot , div , table , tr , td , a , text , p , br , pre )
12
- import Halogen.HTML.Properties (href )
15
+ import Halogen.HTML (HTML , slot , div , table , tr , th , td , a , text , p , br , pre )
16
+ import Halogen.HTML.Core (ClassName (..))
17
+ import Halogen.HTML.Properties (classes , href )
13
18
14
19
import View.Studio.Model (Action (..))
15
20
import View.Studio.Model.Route (WiringFiringInfo , ExecutionTrace )
16
21
import Statebox.Client (txUrl )
17
- import Statebox.Core.Lenses (_firingTx , _firing , _firingPath )
18
- import Statebox.Core.Transaction (HashStr , TxSum , FiringTx , WiringTx , isExecution )
22
+ import Statebox.Core.Lenses (_firingTx , _firing , _firingPath , _GluedTransitionId )
23
+ import Statebox.Core.Transaction (HashStr , TxSum , FiringTx , TxId , WiringTx , evalTxSum , isExecution )
19
24
import Statebox.Core.Types (TID , GluedTransitionId (..))
20
25
21
26
22
27
firingTxView :: ∀ s m . MonadAff m => WiringFiringInfo -> FiringTx -> String \/ ExecutionTrace -> ComponentHTML Action s m
23
- firingTxView wfi tx executionTrace =
28
+ firingTxView wfi tx executionTraceE =
24
29
div []
25
30
[ p [] [ text $ if isExecution tx.firing then " Execution" else " Firing" ]
26
31
, table [] $ txWrapperRows wfi tx <>
27
32
firingTxBodyRows wfi tx <>
28
- [ row " trace" $ text $ show $ firedTransitions ] <>
29
- [ row " trace raw " $ text (show executionTrace) ]
33
+ [ row " trace" $ text $ either (const " no " ) ( show <<< map (un GluedTransitionId )) firedTransitionsE ] <>
34
+ [ row " history " $ either (const $ text " no execution trace " ) (firingTxHistoryTable wfi.hash) executionTraceE ]
30
35
]
31
36
where
32
- firedTransitions :: String \/ Array GluedTransitionId
33
- firedTransitions = map (mapMaybe (preview (second <<< _Just <<< _firingTx <<< _firing <<< _firingPath))) executionTrace
37
+ firedTransitionsE :: String \/ Array GluedTransitionId
38
+ firedTransitionsE = map (mapMaybe (preview (second <<< _Just <<< _firingTx <<< _firing <<< _firingPath))) executionTraceE
34
39
35
40
wiringTxView :: ∀ s m . MonadAff m => WiringFiringInfo -> WiringTx -> ComponentHTML Action s m
36
41
wiringTxView wfi tx =
@@ -57,6 +62,30 @@ txWrapperRows wfi tx =
57
62
58
63
-- ------------------------------------------------------------------------------
59
64
65
+ firingTxHistoryTable :: ∀ s m . MonadAff m => TxId -> ExecutionTrace -> ComponentHTML Action s m
66
+ firingTxHistoryTable currentHash et =
67
+ div [] (headerRows <> (historyRow <$> et))
68
+ where
69
+ headerRows = [ tr [] [ th [] [ text " hash" ], th [] [ text " transition" ], th [] [ text " message" ] ] ]
70
+
71
+ historyRow (hash /\ txMaybe) =
72
+ tr [ classes $ if hash == currentHash then [ ClassName " css-tx-current" ] else [] ] $
73
+ maybe [ td [] [ text $ shortHash hash ], td [] [] , td [] [ text $ " transaction not loaded." ] ]
74
+ (evalTxSum (\x -> [ td [] [ text $ shortHash hash ], td [] [] , td [] [ text $ " unexpected non-firing transaction" ] ])
75
+ (\x -> [ td [] [ text $ shortHash hash ], td [] [] , td [] [ text $ " unexpected non-firing transaction" ] ])
76
+ (\x -> [ td [] [ text $ shortHash hash ], td [] [] , td [] [ text $ " unexpected non-firing transaction" ] ])
77
+ (\firingTx -> [ td [] [ text $ shortHash hash ]
78
+ , td [] [ text $ show $ view (_GluedTransitionId >>> _firingPath >>> _firing) firingTx ]
79
+ , td [] [ maybe (text " no message" )
80
+ (\msg -> pre [] [ text $ " \" " <> msg <> " \" " ])
81
+ firingTx.firing.message
82
+ ]
83
+ ])
84
+ )
85
+ txMaybe
86
+
87
+ -- ------------------------------------------------------------------------------
88
+
60
89
wiringTxBodyRows :: ∀ s m . MonadAff m => WiringFiringInfo -> WiringTx -> Array (ComponentHTML Action s m )
61
90
wiringTxBodyRows wfi tx =
62
91
[ row " diagrams" $ text $ show (tx.wiring.diagrams <#> _.name)
@@ -78,3 +107,7 @@ row caption content =
78
107
tr [] [ td [] [ text caption ]
79
108
, td [] [ content ]
80
109
]
110
+
111
+ -- TODO dedupe
112
+ shortHash :: HashStr -> String
113
+ shortHash = take 8
0 commit comments