Skip to content

Commit

Permalink
Copy data to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejkorsan committed Mar 19, 2024
1 parent 6aab2c5 commit 7fea2f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
37 changes: 26 additions & 11 deletions ruby_event_store-browser/elm/src/Page/ShowEvent.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Page.ShowEvent exposing (Model, Msg(..), initCmd, initModel, showJsonTree, update, view)
port module Page.ShowEvent exposing (Model, Msg(..), initCmd, initModel, showJsonTree, update, view)

import Api
import BrowserTime
Expand All @@ -12,7 +12,7 @@ import Maybe
import Maybe.Extra exposing (values)
import Pagination
import Route
import Svg exposing (svg, path)
import Svg exposing (path, svg)
import Svg.Attributes as SvgAttr
import Url

Expand Down Expand Up @@ -54,14 +54,23 @@ initModel flags eventId =



-- PORT


port copyToClipboard : String -> Cmd msg



-- UPDATE


type Msg
= ChangeOpenedEventDataTreeState JsonTree.State
| ChangeOpenedEventMetadataTreeState JsonTree.State
| EventFetched (Result Http.Error Api.Event)
| CausedEventsFetched (Result Http.Error (Api.PaginatedList Api.Event))
| CausedStreamFetched (Result Http.Error Api.Stream)
| Copy String


initCmd : Flags -> String -> Cmd Msg
Expand All @@ -88,6 +97,9 @@ update msg model =
_ ->
( model, Cmd.none )

Copy content ->
( model, copyToClipboard content )

EventFetched (Ok result) ->
let
event =
Expand Down Expand Up @@ -201,9 +213,6 @@ view_ model =
]
[ text "Loading..." ]
]




Api.Loaded event ->
showEvent model.flags.rootUrl event model.causedEvents
Expand Down Expand Up @@ -234,18 +243,24 @@ showEvent baseUrl event maybeCausedEvents =
[ class "w-full text-left grid md:grid-cols-3 gap-8 overflow-hidden"
]
[ section [ class "space-y-4" ]
[ header [ class "flex justify-between border-gray-400 border-b text-xs pb-2" ] [
h2 [ class "text-gray-500 uppercase font-bold " ] [ text "Event ID" ],
button [ class "text-red-700 no-underline" ] [ text "Copy" ]
]
[ header [ class "flex justify-between border-gray-400 border-b text-xs pb-2" ]
[ h2 [ class "text-gray-500 uppercase font-bold " ] [ text "Event ID" ]
, button [ class "text-red-700 no-underline", onClick (Copy event.eventId) ] [ text "Copy" ]
]
, div [ class "text-sm font-medium font-mono" ] [ text event.eventId ]
]
, section [ class "space-y-4" ]
[ h2 [ class "border-gray-400 border-b text-gray-500 uppercase font-bold text-xs pb-2" ] [ text "Raw Data" ]
[ header [ class "flex justify-between border-gray-400 border-b text-xs pb-2" ]
[ h2 [ class "text-gray-500 uppercase font-bold" ] [ text "Raw Data" ]
, button [ class "text-red-700 no-underline", onClick (Copy event.rawData) ] [ text "Copy" ]
]
, div [ class "overflow-auto w-full" ] [ showJsonTree event.rawData event.dataTreeState (\s -> ChangeOpenedEventDataTreeState s) ]
]
, section [ class "space-y-4" ]
[ h2 [ class "border-gray-400 border-b text-gray-500 uppercase font-bold text-xs pb-2" ] [ text "Raw Metadata" ]
[ header [ class "flex justify-between border-gray-400 border-b text-xs pb-2" ]
[ h2 [ class "text-gray-500 uppercase font-bold" ] [ text "Raw Metadata" ]
, button [ class "text-red-700 no-underline", onClick (Copy event.rawMetadata) ] [ text "Copy" ]
]
, div [ class "overflow-auto w-full" ] [ showJsonTree event.rawMetadata event.metadataTreeState (\s -> ChangeOpenedEventMetadataTreeState s) ]
]
]
Expand Down
3 changes: 1 addition & 2 deletions ruby_event_store-browser/elm/src/Page/ShowStream.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import Api
import BrowserTime
import Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (class, disabled, href)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, href)
import Http
import Pagination
import Route
Expand Down
6 changes: 5 additions & 1 deletion ruby_event_store-browser/public/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Elm.Main.init({
const app = Elm.Main.init({
flags: JSON.parse(document.querySelector("meta[name='ruby-event-store-browser-settings']").getAttribute("content")),
});

app.ports.copyToClipboard.subscribe(function(message) {
navigator.clipboard.writeText(message);
});

0 comments on commit 7fea2f9

Please sign in to comment.