-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from RailsEventStore/rl/browser-tree
Make Browser display data and metadata in collapsable trees
- Loading branch information
Showing
9 changed files
with
340 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module OpenedEventUI exposing (..) | ||
|
||
import JsonTree | ||
import Html exposing (..) | ||
import Html.Attributes exposing (placeholder, disabled, href, class) | ||
|
||
|
||
type alias Event = | ||
{ eventType : String | ||
, eventId : String | ||
, createdAt : String | ||
, rawData : String | ||
, rawMetadata : String | ||
} | ||
|
||
|
||
type alias Model = | ||
{ event : Event | ||
, dataTreeState : JsonTree.State | ||
, metadataTreeState : JsonTree.State | ||
} | ||
|
||
|
||
type Msg | ||
= ChangeOpenedEventDataTreeState JsonTree.State | ||
| ChangeOpenedEventMetadataTreeState JsonTree.State | ||
|
||
|
||
initModel : Event -> Model | ||
initModel e = | ||
{ event = e | ||
, dataTreeState = JsonTree.defaultState | ||
, metadataTreeState = JsonTree.defaultState | ||
} | ||
|
||
|
||
update : Msg -> Model -> ( Model, Cmd Msg ) | ||
update msg model = | ||
case msg of | ||
ChangeOpenedEventDataTreeState newState -> | ||
( { model | dataTreeState = newState }, Cmd.none ) | ||
|
||
ChangeOpenedEventMetadataTreeState newState -> | ||
( { model | metadataTreeState = newState }, Cmd.none ) | ||
|
||
|
||
showEvent : Model -> Html Msg | ||
showEvent model = | ||
div [ class "event" ] | ||
[ h1 [ class "event__title" ] [ text model.event.eventType ] | ||
, div [ class "event__body" ] | ||
[ table [] | ||
[ thead [] | ||
[ tr [] | ||
[ th [] [ text "Event id" ] | ||
, th [] [ text "Raw Data" ] | ||
, th [] [ text "Raw Metadata" ] | ||
] | ||
] | ||
, tbody [] | ||
[ tr [] | ||
[ td [] [ text model.event.eventId ] | ||
, td [] [ showJsonTree model.event.rawData model.dataTreeState (\s -> (ChangeOpenedEventDataTreeState s)) ] | ||
, td [] [ showJsonTree model.event.rawMetadata model.metadataTreeState (\s -> (ChangeOpenedEventMetadataTreeState s)) ] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
|
||
|
||
showJsonTree : String -> JsonTree.State -> (JsonTree.State -> msg) -> Html msg | ||
showJsonTree rawJson treeState changeState = | ||
JsonTree.parseString rawJson | ||
|> Result.map (\tree -> JsonTree.view tree ({ onSelect = Nothing, toMsg = changeState }) treeState) | ||
|> Result.withDefault (pre [] [ text rawJson ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.