neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
⭐
Log in to mark this repository.
Merge branch 'worktree-agent-a03a294519d08e908'
0aa6465 · gmorell · 2026-12-01 22:37
Files changed
added
lib/vigil_web/components/event_components.ex
+1059
−0
@@ -0,0 +1,1059 @@
| 1 | +defmodule VigilWeb.EventComponents do | |
| 2 | + @moduledoc """ | |
| 3 | + An event's interfaces, rendered: exceptions with their stack traces, | |
| 4 | + threads, the message, a CSP report, breadcrumbs, the request, user, | |
| 5 | + contexts, extra, SDK, modules, fingerprint and tags, and the raw JSON. | |
| 6 | + Used by the issue page (`VigilWeb.IssueLive.Show`) and, with `public`, | |
| 7 | + by the share page (`VigilWeb.ShareLive.Issue`), which shows only the | |
| 8 | + exception, stack trace and message: the rest may hold personal data. | |
| 9 | + | |
| 10 | + An event's `data` is what an SDK sent, normalised but not trusted: any | |
| 11 | + key may be missing and any value may be any JSON type. Every component | |
| 12 | + here reads it defensively (`map/1`, `list/1`, `text/1`) and renders what | |
| 13 | + isn't a string as JSON, so odd data shows up oddly instead of crashing | |
| 14 | + the page. | |
| 15 | + | |
| 16 | + Stack traces are stored oldest frame first; they are shown most recent | |
| 17 | + call first, Sentry style. Runs of frames outside the app are folded | |
| 18 | + behind a "Show N more frames" toggle (unless no frame is in the app), and | |
| 19 | + each frame opens (a `<details>`) to its source context and variables. | |
| 20 | + Toggles are client-side (`Phoenix.LiveView.JS`), so they cost no round | |
| 21 | + trip and survive no re-render of the event (which only changes when the | |
| 22 | + page moves to another event). | |
| 23 | + """ | |
| 24 | + use VigilWeb, :html | |
| 25 | + | |
| 26 | + ## The whole event | |
| 27 | + | |
| 28 | + @doc """ | |
| 29 | + An event's body. With `public`, only the exception, stack trace (without | |
| 30 | + frame variables), threads and message. | |
| 31 | + """ | |
| 32 | + attr :event, :map, required: true, doc: "a `Vigil.Issues.IssueEvent` (or a map with `:data`)" | |
| 33 | + attr :id, :string, default: "event" | |
| 34 | + attr :public, :boolean, default: false | |
| 35 | + | |
| 36 | + def event_body(assigns) do | |
| 37 | + data = as_map(Map.get(assigns.event, :data)) | |
| 38 | + | |
| 39 | + assigns = | |
| 40 | + assigns | |
| 41 | + |> assign(:data, data) | |
| 42 | + |> assign(:tags, as_map(Map.get(assigns.event, :tags))) | |
| 43 | + |> assign(:exceptions, exception_values(data)) | |
| 44 | + |> assign(:show_vars, !assigns.public) | |
| 45 | + | |
| 46 | + ~H""" | |
| 47 | + <div id={@id} class="space-y-5"> | |
| 48 | + <.processing_errors :if={!@public} id={"#{@id}-errors"} errors={@data["errors"]} /> | |
| 49 | + <.tag_pills :if={!@public and @tags != %{}} id={"#{@id}-tags"} tags={@tags} /> | |
| 50 | + <.message id={"#{@id}-message"} data={@data} /> | |
| 51 | + <.exceptions | |
| 52 | + :if={@exceptions != []} | |
| 53 | + id={"#{@id}-exceptions"} | |
| 54 | + values={@exceptions} | |
| 55 | + show_vars={@show_vars} | |
| 56 | + /> | |
| 57 | + <.threads | |
| 58 | + :if={show_threads?(@data, @exceptions)} | |
| 59 | + id={"#{@id}-threads"} | |
| 60 | + threads={@data["threads"]} | |
| 61 | + show_vars={@show_vars} | |
| 62 | + /> | |
| 63 | + <.section | |
| 64 | + :if={ | |
| 65 | + @exceptions == [] and !show_threads?(@data, @exceptions) and | |
| 66 | + frames(@data["stacktrace"]) != [] | |
| 67 | + } | |
| 68 | + id={"#{@id}-stacktrace"} | |
| 69 | + title="Stack trace" | |
| 70 | + > | |
| 71 | + <.stacktrace id={"#{@id}-st"} stacktrace={@data["stacktrace"]} show_vars={@show_vars} /> | |
| 72 | + </.section> | |
| 73 | + <.csp_report :if={is_map(@data["csp"])} id={"#{@id}-csp"} csp={@data["csp"]} /> | |
| 74 | + | |
| 75 | + <%= if !@public do %> | |
| 76 | + <.breadcrumbs id={"#{@id}-breadcrumbs"} breadcrumbs={@data["breadcrumbs"]} /> | |
| 77 | + <.request_info | |
| 78 | + :if={is_map(@data["request"])} | |
| 79 | + id={"#{@id}-request"} | |
| 80 | + request={@data["request"]} | |
| 81 | + /> | |
| 82 | + <.kv_section | |
| 83 | + :if={non_empty_map?(@data["user"])} | |
| 84 | + id={"#{@id}-user"} | |
| 85 | + title="User" | |
| 86 | + icon="hero-user-micro" | |
| 87 | + value={@data["user"]} | |
| 88 | + /> | |
| 89 | + <.contexts | |
| 90 | + :if={non_empty_map?(@data["contexts"])} | |
| 91 | + id={"#{@id}-contexts"} | |
| 92 | + contexts={@data["contexts"]} | |
| 93 | + /> | |
| 94 | + <.kv_section | |
| 95 | + :if={non_empty_map?(@data["extra"])} | |
| 96 | + id={"#{@id}-extra"} | |
| 97 | + title="Additional data" | |
| 98 | + icon="hero-plus-circle-micro" | |
| 99 | + value={@data["extra"]} | |
| 100 | + /> | |
| 101 | + <.sdk_info :if={non_empty_map?(@data["sdk"])} id={"#{@id}-sdk"} sdk={@data["sdk"]} /> | |
| 102 | + <.modules | |
| 103 | + :if={non_empty_map?(@data["modules"])} | |
| 104 | + id={"#{@id}-modules"} | |
| 105 | + modules={@data["modules"]} | |
| 106 | + /> | |
| 107 | + <.fingerprint | |
| 108 | + :if={as_list(@data["fingerprint"]) != []} | |
| 109 | + id={"#{@id}-fingerprint"} | |
| 110 | + fingerprint={@data["fingerprint"]} | |
| 111 | + /> | |
| 112 | + <.json_view id={"#{@id}-json"} data={@data} /> | |
| 113 | + <% end %> | |
| 114 | + </div> | |
| 115 | + """ | |
| 116 | + end | |
| 117 | + | |
| 118 | + defp show_threads?(data, exceptions) do | |
| 119 | + threads = thread_values(data["threads"]) | |
| 120 | + | |
| 121 | + Enum.any?(threads, &(frames(&1["stacktrace"]) != [])) and | |
| 122 | + (exceptions == [] or Enum.any?(threads, &(&1["crashed"] == true))) | |
| 123 | + end | |
| 124 | + | |
| 125 | + ## Section shell | |
| 126 | + | |
| 127 | + attr :id, :string, required: true | |
| 128 | + attr :title, :string, required: true | |
| 129 | + attr :icon, :string, default: nil | |
| 130 | + attr :rest, :global | |
| 131 | + slot :inner_block, required: true | |
| 132 | + slot :actions | |
| 133 | + | |
| 134 | + @doc "A titled card, the frame of each interface." | |
| 135 | + def section(assigns) do | |
| 136 | + ~H""" | |
| 137 | + <section id={@id} class="rounded-box border border-base-300 bg-base-100" {@rest}> | |
| 138 | + <header class="flex items-center justify-between gap-2 border-b border-base-300 px-4 py-2.5"> | |
| 139 | + <h3 class="flex items-center gap-1.5 text-sm font-semibold"> | |
| 140 | + <.icon :if={@icon} name={@icon} class="size-4 opacity-60" /> | |
| 141 | + {@title} | |
| 142 | + </h3> | |
| 143 | + <div :if={@actions != []} class="flex items-center gap-1">{render_slot(@actions)}</div> | |
| 144 | + </header> | |
| 145 | + <div class="p-4">{render_slot(@inner_block)}</div> | |
| 146 | + </section> | |
| 147 | + """ | |
| 148 | + end | |
| 149 | + | |
| 150 | + ## Exceptions | |
| 151 | + | |
| 152 | + attr :id, :string, required: true | |
| 153 | + attr :values, :list, required: true, doc: "the chain, oldest first (as stored)" | |
| 154 | + attr :show_vars, :boolean, default: true | |
| 155 | + | |
| 156 | + @doc "An exception chain: the raised exception first, then what caused it." | |
| 157 | + def exceptions(assigns) do | |
| 158 | + assigns = | |
| 159 | + assign(assigns, :chain, assigns.values |> as_list() |> Enum.reverse() |> Enum.with_index()) | |
| 160 | + | |
| 161 | + ~H""" | |
| 162 | + <div id={@id} class="space-y-4"> | |
| 163 | + <.section | |
| 164 | + :for={{exc, i} <- @chain} | |
| 165 | + id={"#{@id}-#{i}"} | |
| 166 | + title={if(i == 0, do: "Exception", else: "Caused by")} | |
| 167 | + icon={if(i == 0, do: "hero-bolt-micro", else: "hero-arrow-uturn-up-micro")} | |
| 168 | + > | |
| 169 | + <:actions> | |
| 170 | + <button | |
| 171 | + :if={frames(exc["raw_stacktrace"]) != []} | |
| 172 | + type="button" | |
| 173 | + id={"#{@id}-#{i}-raw-toggle"} | |
| 174 | + class="btn btn-ghost btn-xs" | |
| 175 | + phx-click={ | |
| 176 | + JS.toggle(to: "##{@id}-#{i}-st") | |
| 177 | + |> JS.toggle(to: "##{@id}-#{i}-raw") | |
| 178 | + |> JS.toggle_class("btn-active") | |
| 179 | + } | |
| 180 | + > | |
| 181 | + Raw | |
| 182 | + </button> | |
| 183 | + </:actions> | |
| 184 | + <div class="mb-3 space-y-1"> | |
| 185 | + <div class="flex flex-wrap items-center gap-2"> | |
| 186 | + <span class="font-mono text-base font-semibold text-error"> | |
| 187 | + {text(exc["type"]) || "Exception"} | |
| 188 | + </span> | |
| 189 | + <.mechanism mechanism={exc["mechanism"]} /> | |
| 190 | + <span :if={text(exc["module"])} class="font-mono text-xs text-base-content/50"> | |
| 191 | + {text(exc["module"])} | |
| 192 | + </span> | |
| 193 | + </div> | |
| 194 | + <p :if={text(exc["value"])} class="whitespace-pre-wrap break-words font-mono text-sm"> | |
| 195 | + {text(exc["value"])} | |
| 196 | + </p> | |
| 197 | + </div> | |
| 198 | + <.stacktrace id={"#{@id}-#{i}-st"} stacktrace={exc["stacktrace"]} show_vars={@show_vars} /> | |
| 199 | + <div :if={frames(exc["raw_stacktrace"]) != []} id={"#{@id}-#{i}-raw"} class="hidden"> | |
| 200 | + <.stacktrace | |
| 201 | + id={"#{@id}-#{i}-rawst"} | |
| 202 | + stacktrace={exc["raw_stacktrace"]} | |
| 203 | + show_vars={@show_vars} | |
| 204 | + /> | |
| 205 | + </div> | |
| 206 | + </.section> | |
| 207 | + </div> | |
| 208 | + """ | |
| 209 | + end | |
| 210 | + | |
| 211 | + attr :mechanism, :any, required: true | |
| 212 | + | |
| 213 | + defp mechanism(assigns) do | |
| 214 | + assigns = assign(assigns, :m, as_map(assigns.mechanism)) | |
| 215 | + | |
| 216 | + ~H""" | |
| 217 | + <span :if={@m["handled"] == false} class="badge badge-error badge-sm">unhandled</span> | |
| 218 | + <span :if={@m["handled"] == true} class="badge badge-ghost badge-sm">handled</span> | |
| 219 | + <span :if={text(@m["type"])} class="badge badge-outline badge-sm font-mono"> | |
| 220 | + {text(@m["type"])} | |
| 221 | + </span> | |
| 222 | + <span :if={@m["synthetic"] == true} class="badge badge-ghost badge-sm">synthetic</span> | |
| 223 | + """ | |
| 224 | + end | |
| 225 | + | |
| 226 | + ## Stack traces | |
| 227 | + | |
| 228 | + attr :id, :string, required: true | |
| 229 | + attr :stacktrace, :any, required: true | |
| 230 | + attr :show_vars, :boolean, default: true | |
| 231 | + | |
| 232 | + @doc """ | |
| 233 | + A stack trace, most recent call first. In-app frames show; runs of other | |
| 234 | + frames fold behind a toggle, unless no frame is in-app. The first shown | |
| 235 | + frame starts open. | |
| 236 | + """ | |
| 237 | + def stacktrace(assigns) do | |
| 238 | + frames = assigns.stacktrace |> frames() |> Enum.reverse() |> Enum.with_index() | |
| 239 | + any_in_app? = Enum.any?(frames, fn {f, _} -> f["in_app"] == true end) | |
| 240 | + | |
| 241 | + groups = | |
| 242 | + if any_in_app? do | |
| 243 | + frames | |
| 244 | + |> Enum.chunk_by(fn {f, _} -> f["in_app"] == true end) | |
| 245 | + |> Enum.map(fn [{f, i} | _] = chunk -> {f["in_app"] == true, i, chunk} end) | |
| 246 | + else | |
| 247 | + [{true, 0, frames}] | |
| 248 | + end | |
| 249 | + | |
| 250 | + open = | |
| 251 | + case Enum.find(frames, fn {f, _} -> !any_in_app? or f["in_app"] == true end) do | |
| 252 | + {_, i} -> i | |
| 253 | + nil -> nil | |
| 254 | + end | |
| 255 | + | |
| 256 | + assigns = assign(assigns, groups: groups, open: open, empty?: frames == []) | |
| 257 | + | |
| 258 | + ~H""" | |
| 259 | + <div id={@id} class="overflow-hidden rounded-box border border-base-300"> | |
| 260 | + <p :if={@empty?} class="p-3 text-sm text-base-content/60">No frames.</p> | |
| 261 | + <%= for {shown?, gi, chunk} <- @groups do %> | |
| 262 | + <%= if shown? do %> | |
| 263 | + <.frame | |
| 264 | + :for={{f, i} <- chunk} | |
| 265 | + id={"#{@id}-f#{i}"} | |
| 266 | + frame={f} | |
| 267 | + open={i == @open} | |
| 268 | + show_vars={@show_vars} | |
| 269 | + /> | |
| 270 | + <% else %> | |
| 271 | + <button | |
| 272 | + type="button" | |
| 273 | + id={"#{@id}-more#{gi}"} | |
| 274 | + class="flex w-full items-center gap-1.5 border-b border-base-300 bg-base-200/50 px-3 py-1.5 text-left text-xs text-base-content/60 transition hover:bg-base-200 hover:text-base-content last:border-b-0" | |
| 275 | + phx-click={ | |
| 276 | + JS.toggle(to: "##{@id}-group#{gi}") | |
| 277 | + |> JS.toggle_class("hidden", to: "##{@id}-more#{gi} .lbl") | |
| 278 | + } | |
| 279 | + > | |
| 280 | + <.icon name="hero-chevron-up-down-micro" class="size-3.5" /> | |
| 281 | + <span class="lbl">Show {length(chunk)} more {plural(length(chunk), "frame")}</span> | |
| 282 | + <span class="lbl hidden">Hide {length(chunk)} {plural(length(chunk), "frame")}</span> | |
| 283 | + </button> | |
| 284 | + <div id={"#{@id}-group#{gi}"} class="hidden"> | |
| 285 | + <.frame | |
| 286 | + :for={{f, i} <- chunk} | |
| 287 | + id={"#{@id}-f#{i}"} | |
| 288 | + frame={f} | |
| 289 | + open={false} | |
| 290 | + show_vars={@show_vars} | |
| 291 | + /> | |
| 292 | + </div> | |
| 293 | + <% end %> | |
| 294 | + <% end %> | |
| 295 | + </div> | |
| 296 | + """ | |
| 297 | + end | |
| 298 | + | |
| 299 | + attr :id, :string, required: true | |
| 300 | + attr :frame, :map, required: true | |
| 301 | + attr :open, :boolean, default: false | |
| 302 | + attr :show_vars, :boolean, default: true | |
| 303 | + | |
| 304 | + @doc "One frame: where, then (opened) its source context and variables." | |
| 305 | + def frame(assigns) do | |
| 306 | + f = as_map(assigns.frame) | |
| 307 | + | |
| 308 | + assigns = | |
| 309 | + assign(assigns, | |
| 310 | + f: f, | |
| 311 | + path: text(f["filename"]) || text(f["abs_path"]) || text(f["module"]), | |
| 312 | + function: text(f["function"]) || text(f["raw_function"]), | |
| 313 | + context: source_context(f), | |
| 314 | + vars: if(assigns.show_vars, do: as_map(f["vars"]), else: %{}), | |
| 315 | + in_app?: f["in_app"] == true | |
| 316 | + ) | |
| 317 | + | |
| 318 | + assigns = assign(assigns, :expandable?, assigns.context != [] or assigns.vars != %{}) | |
| 319 | + | |
| 320 | + ~H""" | |
| 321 | + <details | |
| 322 | + id={@id} | |
| 323 | + open={@open and @expandable?} | |
| 324 | + class="group/frame border-b border-base-300 last:border-b-0" | |
| 325 | + > | |
| 326 | + <summary class={[ | |
| 327 | + "flex cursor-pointer list-none flex-wrap items-baseline gap-x-1.5 gap-y-0.5 px-3 py-2 font-mono text-xs transition-colors hover:bg-base-200/60", | |
| 328 | + @in_app? && "bg-base-100", | |
| 329 | + !@in_app? && "bg-base-200/30 text-base-content/70" | |
| 330 | + ]}> | |
| 331 | + <.icon | |
| 332 | + name="hero-chevron-right-micro" | |
| 333 | + class={[ | |
| 334 | + "size-3.5 self-center opacity-50 transition-transform group-open/frame:rotate-90", | |
| 335 | + !@expandable? && "invisible" | |
| 336 | + ]} | |
| 337 | + /> | |
| 338 | + <span :if={text(@f["package"])} class="text-base-content/50">{text(@f["package"])}</span> | |
| 339 | + <span class={["break-all", @in_app? && "font-semibold"]}>{@path || "?"}</span> | |
| 340 | + <span :if={@function} class="text-base-content/50">in</span> | |
| 341 | + <span :if={@function} class="break-all text-primary">{@function}</span> | |
| 342 | + <span :if={line_col(@f)} class="text-base-content/50">at line {line_col(@f)}</span> | |
| 343 | + <span :if={@in_app?} class="badge badge-primary badge-xs ml-auto self-center">in app</span> | |
| 344 | + </summary> | |
| 345 | + <div :if={@expandable?} class="border-t border-base-300 bg-base-200/40"> | |
| 346 | + <ol :if={@context != []} class="overflow-x-auto py-1 font-mono text-xs leading-5"> | |
| 347 | + <li | |
| 348 | + :for={{n, line, current?} <- @context} | |
| 349 | + class={[ | |
| 350 | + "flex whitespace-pre", | |
| 351 | + current? && "bg-warning/20 font-semibold" | |
| 352 | + ]} | |
| 353 | + > | |
| 354 | + <span class="w-12 shrink-0 select-none pr-3 text-right text-base-content/40">{n}</span> | |
| 355 | + <code>{line}</code> | |
| 356 | + </li> | |
| 357 | + </ol> | |
| 358 | + <div :if={@vars != %{}} class="border-t border-base-300 p-2"> | |
| 359 | + <.kv_table id={"#{@id}-vars"} value={@vars} /> | |
| 360 | + </div> | |
| 361 | + </div> | |
| 362 | + </details> | |
| 363 | + """ | |
| 364 | + end | |
| 365 | + | |
| 366 | + # [{line_number | "", line, context_line?}] | |
| 367 | + defp source_context(f) do | |
| 368 | + pre = f["pre_context"] |> as_list() |> Enum.map(&line_text/1) | |
| 369 | + post = f["post_context"] |> as_list() |> Enum.map(&line_text/1) | |
| 370 | + line = line_text(f["context_line"]) | |
| 371 | + lineno = if is_integer(f["lineno"]), do: f["lineno"], else: nil | |
| 372 | + | |
| 373 | + if is_nil(f["context_line"]) and pre == [] and post == [] do | |
| 374 | + [] | |
| 375 | + else | |
| 376 | + start = if lineno, do: lineno - length(pre), else: nil | |
| 377 | + lines = Enum.map(pre, &{&1, false}) ++ [{line, true}] ++ Enum.map(post, &{&1, false}) | |
| 378 | + | |
| 379 | + lines | |
| 380 | + |> Enum.with_index() | |
| 381 | + |> Enum.map(fn {{l, cur}, i} -> {if(start, do: start + i, else: ""), l, cur} end) | |
| 382 | + end | |
| 383 | + end | |
| 384 | + | |
| 385 | + defp line_text(nil), do: "" | |
| 386 | + defp line_text(v), do: text(v) | |
| 387 | + | |
| 388 | + defp line_col(f) do | |
| 389 | + case {f["lineno"], f["colno"]} do | |
| 390 | + {nil, _} -> nil | |
| 391 | + {l, nil} -> text(l) | |
| 392 | + {l, c} -> "#{text(l)}:#{text(c)}" | |
| 393 | + end | |
| 394 | + end | |
| 395 | + | |
| 396 | + ## Threads | |
| 397 | + | |
| 398 | + attr :id, :string, required: true | |
| 399 | + attr :threads, :any, required: true | |
| 400 | + attr :show_vars, :boolean, default: true | |
| 401 | + | |
| 402 | + @doc "Threads with stack traces, one shown at a time (the crashed one first)." | |
| 403 | + def threads(assigns) do | |
| 404 | + threads = | |
| 405 | + assigns.threads | |
| 406 | + |> thread_values() | |
| 407 | + |> Enum.filter(&(frames(&1["stacktrace"]) != [])) | |
| 408 | + |> Enum.with_index() | |
| 409 | + | |
| 410 | + selected = | |
| 411 | + Enum.find(threads, fn {t, _} -> t["crashed"] == true end) || | |
| 412 | + Enum.find(threads, fn {t, _} -> t["current"] == true end) || | |
| 413 | + List.first(threads) | |
| 414 | + | |
| 415 | + assigns = assign(assigns, threads: threads, selected: selected && elem(selected, 1)) | |
| 416 | + | |
| 417 | + ~H""" | |
| 418 | + <.section id={@id} title="Threads" icon="hero-queue-list-micro"> | |
| 419 | + <div :if={length(@threads) > 1} role="tablist" class="tabs tabs-box tabs-xs mb-3 flex-wrap"> | |
| 420 | + <button | |
| 421 | + :for={{t, i} <- @threads} | |
| 422 | + type="button" | |
| 423 | + role="tab" | |
| 424 | + id={"#{@id}-tab#{i}"} | |
| 425 | + class={["tab thread-tab", i == @selected && "tab-active"]} | |
| 426 | + phx-click={ | |
| 427 | + JS.hide(to: "##{@id} .thread-panel") | |
| 428 | + |> JS.show(to: "##{@id}-t#{i}") | |
| 429 | + |> JS.remove_class("tab-active", to: "##{@id} .thread-tab") | |
| 430 | + |> JS.add_class("tab-active") | |
| 431 | + } | |
| 432 | + > | |
| 433 | + {thread_label(t)} | |
| 434 | + <.icon :if={t["crashed"] == true} name="hero-bolt-micro" class="ml-1 size-3 text-error" /> | |
| 435 | + </button> | |
| 436 | + </div> | |
| 437 | + <div | |
| 438 | + :for={{t, i} <- @threads} | |
| 439 | + id={"#{@id}-t#{i}"} | |
| 440 | + class={["thread-panel", i != @selected && "hidden"]} | |
| 441 | + > | |
| 442 | + <p :if={length(@threads) == 1} class="mb-2 text-xs text-base-content/60"> | |
| 443 | + {thread_label(t)} | |
| 444 | + </p> | |
| 445 | + <.stacktrace id={"#{@id}-t#{i}-st"} stacktrace={t["stacktrace"]} show_vars={@show_vars} /> | |
| 446 | + </div> | |
| 447 | + </.section> | |
| 448 | + """ | |
| 449 | + end | |
| 450 | + | |
| 451 | + defp thread_label(t) do | |
| 452 | + name = text(t["name"]) | |
| 453 | + id = text(t["id"]) | |
| 454 | + | |
| 455 | + cond do | |
| 456 | + name && id -> "#{name} (#{id})" | |
| 457 | + name -> name | |
| 458 | + id -> "Thread #{id}" | |
| 459 | + true -> "Thread" | |
| 460 | + end | |
| 461 | + end | |
| 462 | + | |
| 463 | + ## Message, CSP, processing errors | |
| 464 | + | |
| 465 | + attr :id, :string, required: true | |
| 466 | + attr :data, :map, required: true | |
| 467 | + | |
| 468 | + @doc "The event's log message, if it has one." | |
| 469 | + def message(assigns) do | |
| 470 | + assigns = assign(assigns, :text, message_text(assigns.data)) | |
| 471 | + | |
| 472 | + ~H""" | |
| 473 | + <.section :if={@text} id={@id} title="Message" icon="hero-chat-bubble-bottom-center-text-micro"> | |
| 474 | + <pre class="whitespace-pre-wrap break-words font-mono text-sm">{@text}</pre> | |
| 475 | + </.section> | |
| 476 | + """ | |
| 477 | + end | |
| 478 | + | |
| 479 | + defp message_text(data) do | |
| 480 | + log = data["logentry"] | |
| 481 | + | |
| 482 | + cond do | |
| 483 | + is_map(log) and text(log["formatted"]) -> text(log["formatted"]) | |
| 484 | + is_map(log) and text(log["message"]) -> text(log["message"]) | |
| 485 | + is_binary(log) -> log | |
| 486 | + is_binary(data["message"]) and data["message"] != "" -> data["message"] | |
| 487 | + is_map(data["message"]) -> message_text(%{"logentry" => data["message"]}) | |
| 488 | + true -> nil | |
| 489 | + end | |
| 490 | + end | |
| 491 | + | |
| 492 | + attr :id, :string, required: true | |
| 493 | + attr :csp, :map, required: true | |
| 494 | + | |
| 495 | + @doc "A CSP violation report's fields." | |
| 496 | + def csp_report(assigns) do | |
| 497 | + ~H""" | |
| 498 | + <.section id={@id} title="CSP report" icon="hero-shield-exclamation-micro"> | |
| 499 | + <.kv_table id={"#{@id}-table"} value={@csp} /> | |
| 500 | + </.section> | |
| 501 | + """ | |
| 502 | + end | |
| 503 | + | |
| 504 | + attr :id, :string, required: true | |
| 505 | + attr :errors, :any, required: true | |
| 506 | + | |
| 507 | + @doc "Problems met while processing the event, as a quiet notice." | |
| 508 | + def processing_errors(assigns) do | |
| 509 | + assigns = assign(assigns, :errors, as_list(assigns.errors)) | |
| 510 | + | |
| 511 | + ~H""" | |
| 512 | + <div | |
| 513 | + :if={@errors != []} | |
| 514 | + id={@id} | |
| 515 | + class="flex gap-2 rounded-box border border-warning/30 bg-warning/5 px-4 py-2.5 text-sm" | |
| 516 | + > | |
| 517 | + <.icon name="hero-exclamation-triangle-micro" class="mt-0.5 size-4 shrink-0 text-warning" /> | |
| 518 | + <div> | |
| 519 | + <p class="font-medium"> | |
| 520 | + {length(@errors)} {plural(length(@errors), "problem")} processing this event | |
| 521 | + </p> | |
| 522 | + <ul class="mt-1 space-y-0.5 text-xs text-base-content/70"> | |
| 523 | + <li :for={e <- @errors}> | |
| 524 | + <%= if is_map(e) do %> | |
| 525 | + <span class="font-mono">{text(e["type"]) || "error"}</span> | |
| 526 | + <span :if={text(e["name"])}> | |
| 527 | + · <span class="font-mono">{text(e["name"])}</span> | |
| 528 | + </span> | |
| 529 | + <span :if={text(e["value"])}>· {text(e["value"])}</span> | |
| 530 | + <% else %> | |
| 531 | + {text(e)} | |
| 532 | + <% end %> | |
| 533 | + </li> | |
| 534 | + </ul> | |
| 535 | + </div> | |
| 536 | + </div> | |
| 537 | + """ | |
| 538 | + end | |
| 539 | + | |
| 540 | + ## Breadcrumbs | |
| 541 | + | |
| 542 | + @breadcrumbs_shown 30 | |
| 543 | + | |
| 544 | + attr :id, :string, required: true | |
| 545 | + attr :breadcrumbs, :any, required: true | |
| 546 | + | |
| 547 | + @doc "What happened before, oldest first; the oldest fold away past #{@breadcrumbs_shown}." | |
| 548 | + def breadcrumbs(assigns) do | |
| 549 | + crumbs = | |
| 550 | + case assigns.breadcrumbs do | |
| 551 | + %{"values" => v} -> as_list(v) | |
| 552 | + v -> as_list(v) | |
| 553 | + end | |
| 554 | + |> Enum.filter(&is_map/1) | |
| 555 | + | |
| 556 | + hidden = max(length(crumbs) - @breadcrumbs_shown, 0) | |
| 557 | + {older, recent} = Enum.split(crumbs, hidden) | |
| 558 | + | |
| 559 | + assigns = | |
| 560 | + assign(assigns, older: Enum.with_index(older), recent: Enum.with_index(recent, hidden)) | |
| 561 | + | |
| 562 | + ~H""" | |
| 563 | + <.section | |
| 564 | + :if={@older != [] or @recent != []} | |
| 565 | + id={@id} | |
| 566 | + title="Breadcrumbs" | |
| 567 | + icon="hero-list-bullet-micro" | |
| 568 | + > | |
| 569 | + <button | |
| 570 | + :if={@older != []} | |
| 571 | + type="button" | |
| 572 | + id={"#{@id}-older-toggle"} | |
| 573 | + class="btn btn-ghost btn-xs mb-2" | |
| 574 | + phx-click={JS.toggle(to: "##{@id} .crumb-older") |> JS.hide()} | |
| 575 | + > | |
| 576 | + Show {length(@older)} older | |
| 577 | + </button> | |
| 578 | + <div class="-mx-4 -mb-4 overflow-x-auto"> | |
| 579 | + <table class="table table-xs"> | |
| 580 | + <thead> | |
| 581 | + <tr> | |
| 582 | + <th class="w-28">Time</th> | |
| 583 | + <th class="w-32">Category</th> | |
| 584 | + <th>Message</th> | |
| 585 | + </tr> | |
| 586 | + </thead> | |
| 587 | + <tbody> | |
| 588 | + <.crumb :for={{c, i} <- @older} id={"#{@id}-#{i}"} crumb={c} class="crumb-older hidden" /> | |
| 589 | + <.crumb :for={{c, i} <- @recent} id={"#{@id}-#{i}"} crumb={c} class="" /> | |
| 590 | + </tbody> | |
| 591 | + </table> | |
| 592 | + </div> | |
| 593 | + </.section> | |
| 594 | + """ | |
| 595 | + end | |
| 596 | + | |
| 597 | + attr :id, :string, required: true | |
| 598 | + attr :crumb, :map, required: true | |
| 599 | + attr :class, :string, required: true | |
| 600 | + | |
| 601 | + defp crumb(assigns) do | |
| 602 | + c = assigns.crumb | |
| 603 | + assigns = assign(assigns, c: c, level: text(c["level"]) || "info", data: c["data"]) | |
| 604 | + | |
| 605 | + ~H""" | |
| 606 | + <tr id={@id} class={["align-top hover:bg-base-200/40", @class]}> | |
| 607 | + <td class="whitespace-nowrap font-mono text-base-content/60" title={text(@c["timestamp"])}> | |
| 608 | + <span class="flex items-center gap-1.5"> | |
| 609 | + <span class={["size-2 shrink-0 rounded-full", level_dot(@level)]} title={@level} /> | |
| 610 | + {clock(@c["timestamp"])} | |
| 611 | + </span> | |
| 612 | + </td> | |
| 613 | + <td class="font-mono"> | |
| 614 | + <span>{text(@c["category"]) || text(@c["type"]) || "default"}</span> | |
| 615 | + </td> | |
| 616 | + <td class="min-w-64"> | |
| 617 | + <p :if={text(@c["message"])} class="whitespace-pre-wrap break-words font-mono"> | |
| 618 | + {text(@c["message"])} | |
| 619 | + </p> | |
| 620 | + <pre | |
| 621 | + :if={non_empty?(@data)} | |
| 622 | + class="mt-1 whitespace-pre-wrap break-all font-mono text-[0.7rem] text-base-content/60" | |
| 623 | + >{json(@data)}</pre> | |
| 624 | + </td> | |
| 625 | + </tr> | |
| 626 | + """ | |
| 627 | + end | |
| 628 | + | |
| 629 | + ## Request | |
| 630 | + | |
| 631 | + attr :id, :string, required: true | |
| 632 | + attr :request, :map, required: true | |
| 633 | + | |
| 634 | + @doc "The HTTP request: method and URL, query, headers, body, cookies and env." | |
| 635 | + def request_info(assigns) do | |
| 636 | + r = assigns.request | |
| 637 | + | |
| 638 | + assigns = | |
| 639 | + assign(assigns, | |
| 640 | + r: r, | |
| 641 | + method: text(r["method"]), | |
| 642 | + url: text(r["url"]), | |
| 643 | + query: query_string(r["query_string"]), | |
| 644 | + headers: pairs(r["headers"]), | |
| 645 | + cookies: pairs(r["cookies"]), | |
| 646 | + body: r["data"], | |
| 647 | + env: as_map(r["env"]) | |
| 648 | + ) | |
| 649 | + | |
| 650 | + ~H""" | |
| 651 | + <.section id={@id} title="Request" icon="hero-globe-alt-micro"> | |
| 652 | + <p :if={@method || @url} class="mb-3 break-all font-mono text-sm"> | |
| 653 | + <span :if={@method} class="badge badge-neutral badge-sm mr-1.5 font-bold">{@method}</span> | |
| 654 | + {@url} | |
| 655 | + </p> | |
| 656 | + <div class="space-y-3"> | |
| 657 | + <.kv_block :if={@query} id={"#{@id}-query"} title="Query string"> | |
| 658 | + <pre class="whitespace-pre-wrap break-all font-mono text-xs">{@query}</pre> | |
| 659 | + </.kv_block> | |
| 660 | + <.kv_block :if={non_empty?(@body)} id={"#{@id}-body"} title="Body"> | |
| 661 | + <pre class="max-h-96 overflow-auto whitespace-pre-wrap break-all font-mono text-xs">{if is_binary(@body), do: @body, else: json(@body)}</pre> | |
| 662 | + </.kv_block> | |
| 663 | + <.kv_block :if={@headers != []} id={"#{@id}-headers"} title="Headers"> | |
| 664 | + <.kv_table id={"#{@id}-headers-table"} value={@headers} /> | |
| 665 | + </.kv_block> | |
| 666 | + <.kv_block :if={@cookies != []} id={"#{@id}-cookies"} title="Cookies"> | |
| 667 | + <.kv_table id={"#{@id}-cookies-table"} value={@cookies} /> | |
| 668 | + </.kv_block> | |
| 669 | + <.kv_block :if={@env != %{}} id={"#{@id}-env"} title="Environment"> | |
| 670 | + <.kv_table id={"#{@id}-env-table"} value={@env} /> | |
| 671 | + </.kv_block> | |
| 672 | + </div> | |
| 673 | + </.section> | |
| 674 | + """ | |
| 675 | + end | |
| 676 | + | |
| 677 | + defp query_string(q) when is_binary(q) and q != "", do: q | |
| 678 | + defp query_string(q) when is_list(q) or is_map(q), do: if(non_empty?(q), do: json(q)) | |
| 679 | + defp query_string(_), do: nil | |
| 680 | + | |
| 681 | + attr :id, :string, required: true | |
| 682 | + attr :title, :string, required: true | |
| 683 | + slot :inner_block, required: true | |
| 684 | + | |
| 685 | + defp kv_block(assigns) do | |
| 686 | + ~H""" | |
| 687 | + <div id={@id}> | |
| 688 | + <h4 class="mb-1 text-xs font-semibold uppercase tracking-wide text-base-content/50"> | |
| 689 | + {@title} | |
| 690 | + </h4> | |
| 691 | + {render_slot(@inner_block)} | |
| 692 | + </div> | |
| 693 | + """ | |
| 694 | + end | |
| 695 | + | |
| 696 | + ## Key/value interfaces | |
| 697 | + | |
| 698 | + attr :id, :string, required: true | |
| 699 | + attr :title, :string, required: true | |
| 700 | + attr :icon, :string, default: nil | |
| 701 | + attr :value, :any, required: true | |
| 702 | + | |
| 703 | + @doc "A titled key/value table (user, extra)." | |
| 704 | + def kv_section(assigns) do | |
| 705 | + ~H""" | |
| 706 | + <.section id={@id} title={@title} icon={@icon}> | |
| 707 | + <.kv_table id={"#{@id}-table"} value={@value} /> | |
| 708 | + </.section> | |
| 709 | + """ | |
| 710 | + end | |
| 711 | + | |
| 712 | + attr :id, :string, required: true | |
| 713 | + attr :contexts, :map, required: true | |
| 714 | + | |
| 715 | + @doc "One card per context (browser, os, runtime, device, trace, ...)." | |
| 716 | + def contexts(assigns) do | |
| 717 | + assigns = | |
| 718 | + assign( | |
| 719 | + assigns, | |
| 720 | + :cards, | |
| 721 | + assigns.contexts |> as_map() |> Enum.sort_by(&elem(&1, 0)) |> Enum.with_index() | |
| 722 | + ) | |
| 723 | + | |
| 724 | + ~H""" | |
| 725 | + <.section id={@id} title="Contexts" icon="hero-cpu-chip-micro"> | |
| 726 | + <div class="grid gap-3 sm:grid-cols-2"> | |
| 727 | + <div | |
| 728 | + :for={{{name, ctx}, i} <- @cards} | |
| 729 | + id={"#{@id}-#{i}"} | |
| 730 | + data-context={name} | |
| 731 | + class="rounded-box border border-base-300 bg-base-200/30 p-3" | |
| 732 | + > | |
| 733 | + <h4 class="mb-1.5 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide"> | |
| 734 | + {context_title(name, ctx)} | |
| 735 | + </h4> | |
| 736 | + <.kv_table id={"#{@id}-#{i}-table"} value={context_fields(ctx)} /> | |
| 737 | + </div> | |
| 738 | + </div> | |
| 739 | + </.section> | |
| 740 | + """ | |
| 741 | + end | |
| 742 | + | |
| 743 | + defp context_title(name, ctx) do | |
| 744 | + ctx = as_map(ctx) | |
| 745 | + | |
| 746 | + case {text(ctx["name"]), text(ctx["version"])} do | |
| 747 | + {n, v} when is_binary(n) and is_binary(v) -> "#{name} · #{n} #{v}" | |
| 748 | + _ -> text(name) | |
| 749 | + end | |
| 750 | + end | |
| 751 | + | |
| 752 | + defp context_fields(ctx) when is_map(ctx), do: Map.delete(ctx, "type") | |
| 753 | + defp context_fields(ctx), do: %{"value" => ctx} | |
| 754 | + | |
| 755 | + attr :id, :string, required: true | |
| 756 | + attr :sdk, :map, required: true | |
| 757 | + | |
| 758 | + @doc "The SDK that sent the event." | |
| 759 | + def sdk_info(assigns) do | |
| 760 | + assigns = | |
| 761 | + assign(assigns, | |
| 762 | + name: text(assigns.sdk["name"]), | |
| 763 | + version: text(assigns.sdk["version"]), | |
| 764 | + rest: Map.drop(assigns.sdk, ["name", "version"]) | |
| 765 | + ) | |
| 766 | + | |
| 767 | + ~H""" | |
| 768 | + <.section id={@id} title="SDK" icon="hero-cube-micro"> | |
| 769 | + <p class="font-mono text-sm">{@name || "unknown"} <span :if={@version}>{@version}</span></p> | |
| 770 | + <div :if={@rest != %{}} class="mt-2"> | |
| 771 | + <.kv_table id={"#{@id}-table"} value={@rest} /> | |
| 772 | + </div> | |
| 773 | + </.section> | |
| 774 | + """ | |
| 775 | + end | |
| 776 | + | |
| 777 | + attr :id, :string, required: true | |
| 778 | + attr :modules, :map, required: true | |
| 779 | + | |
| 780 | + @doc "Loaded modules/packages and their versions, folded." | |
| 781 | + def modules(assigns) do | |
| 782 | + ~H""" | |
| 783 | + <details id={@id} class="group rounded-box border border-base-300 bg-base-100"> | |
| 784 | + <summary class="flex cursor-pointer list-none items-center gap-1.5 px-4 py-2.5 text-sm font-semibold"> | |
| 785 | + <.icon | |
| 786 | + name="hero-chevron-right-micro" | |
| 787 | + class="size-4 opacity-60 transition-transform group-open:rotate-90" | |
| 788 | + /> Modules <span class="badge badge-ghost badge-sm">{map_size(@modules)}</span> | |
| 789 | + </summary> | |
| 790 | + <div class="border-t border-base-300 p-4"> | |
| 791 | + <.kv_table id={"#{@id}-table"} value={@modules} /> | |
| 792 | + </div> | |
| 793 | + </details> | |
| 794 | + """ | |
| 795 | + end | |
| 796 | + | |
| 797 | + attr :id, :string, required: true | |
| 798 | + attr :fingerprint, :list, required: true | |
| 799 | + | |
| 800 | + @doc "The grouping fingerprint the event was sent with." | |
| 801 | + def fingerprint(assigns) do | |
| 802 | + ~H""" | |
| 803 | + <.section id={@id} title="Fingerprint" icon="hero-finger-print-micro"> | |
| 804 | + <div class="flex flex-wrap gap-1.5"> | |
| 805 | + <code :for={part <- as_list(@fingerprint)} class="badge badge-ghost badge-sm font-mono"> | |
| 806 | + {text(part)} | |
| 807 | + </code> | |
| 808 | + </div> | |
| 809 | + </.section> | |
| 810 | + """ | |
| 811 | + end | |
| 812 | + | |
| 813 | + attr :id, :string, required: true | |
| 814 | + attr :tags, :map, required: true | |
| 815 | + | |
| 816 | + @doc "An event's own tags, as pills." | |
| 817 | + def tag_pills(assigns) do | |
| 818 | + assigns = assign(assigns, :pairs, assigns.tags |> as_map() |> Enum.sort_by(&elem(&1, 0))) | |
| 819 | + | |
| 820 | + ~H""" | |
| 821 | + <div id={@id} class="flex flex-wrap gap-1.5"> | |
| 822 | + <span | |
| 823 | + :for={{k, v} <- @pairs} | |
| 824 | + class="inline-flex overflow-hidden rounded-full border border-base-300 text-xs transition hover:border-primary/50" | |
| 825 | + data-tag={k} | |
| 826 | + > | |
| 827 | + <span class="bg-base-200 px-2 py-0.5 text-base-content/60">{k}</span> | |
| 828 | + <span class="px-2 py-0.5 font-medium">{text(v)}</span> | |
| 829 | + </span> | |
| 830 | + </div> | |
| 831 | + """ | |
| 832 | + end | |
| 833 | + | |
| 834 | + attr :id, :string, required: true | |
| 835 | + attr :value, :any, required: true, doc: "a map, or a list of `{k, v}` / `[k, v]` pairs" | |
| 836 | + | |
| 837 | + @doc "Keys and values; non-string values as (pretty) JSON." | |
| 838 | + def kv_table(assigns) do | |
| 839 | + assigns = assign(assigns, :rows, pairs(assigns.value)) | |
| 840 | + | |
| 841 | + ~H""" | |
| 842 | + <table id={@id} class="w-full table-fixed text-xs"> | |
| 843 | + <tbody> | |
| 844 | + <tr :for={{k, v} <- @rows} class="border-b border-base-300/60 align-top last:border-b-0"> | |
| 845 | + <th class="w-1/3 break-words py-1 pr-3 text-left font-mono font-normal text-base-content/60"> | |
| 846 | + {k} | |
| 847 | + </th> | |
| 848 | + <td class="py-1"> | |
| 849 | + <%= if is_map(v) or is_list(v) do %> | |
| 850 | + <pre class="whitespace-pre-wrap break-all font-mono">{json(v)}</pre> | |
| 851 | + <% else %> | |
| 852 | + <span class="whitespace-pre-wrap break-all font-mono">{display(v)}</span> | |
| 853 | + <% end %> | |
| 854 | + </td> | |
| 855 | + </tr> | |
| 856 | + </tbody> | |
| 857 | + </table> | |
| 858 | + """ | |
| 859 | + end | |
| 860 | + | |
| 861 | + ## JSON | |
| 862 | + | |
| 863 | + attr :id, :string, required: true | |
| 864 | + attr :data, :any, required: true | |
| 865 | + | |
| 866 | + @doc "The whole event as pretty JSON, behind a toggle." | |
| 867 | + def json_view(assigns) do | |
| 868 | + ~H""" | |
| 869 | + <div id={@id}> | |
| 870 | + <button | |
| 871 | + type="button" | |
| 872 | + id={"#{@id}-toggle"} | |
| 873 | + class="btn btn-ghost btn-sm" | |
| 874 | + phx-click={JS.toggle(to: "##{@id}-pre")} | |
| 875 | + > | |
| 876 | + <.icon name="hero-code-bracket-micro" class="size-4" /> JSON | |
| 877 | + </button> | |
| 878 | + <pre | |
| 879 | + id={"#{@id}-pre"} | |
| 880 | + class="mt-2 hidden max-h-[40rem] overflow-auto rounded-box bg-base-200 p-4 font-mono text-xs leading-relaxed" | |
| 881 | + >{json(@data)}</pre> | |
| 882 | + </div> | |
| 883 | + """ | |
| 884 | + end | |
| 885 | + | |
| 886 | + ## Small shared pieces (also used by the pages) | |
| 887 | + | |
| 888 | + attr :level, :any, required: true | |
| 889 | + attr :class, :any, default: nil | |
| 890 | + | |
| 891 | + @doc "A level badge (fatal, error, warning, info, debug)." | |
| 892 | + def level_badge(assigns) do | |
| 893 | + assigns = assign(assigns, :level, text(assigns.level) || "error") | |
| 894 | + | |
| 895 | + ~H""" | |
| 896 | + <span class={["badge badge-sm gap-1", level_badge_class(@level), @class]}> | |
| 897 | + <span class={["size-1.5 rounded-full", level_dot(@level)]} />{@level} | |
| 898 | + </span> | |
| 899 | + """ | |
| 900 | + end | |
| 901 | + | |
| 902 | + attr :at, :any, required: true | |
| 903 | + attr :id, :string, default: nil | |
| 904 | + | |
| 905 | + @doc "A relative time (\"3h ago\"), with the full time as its title." | |
| 906 | + def time_ago(assigns) do | |
| 907 | + ~H""" | |
| 908 | + <time id={@id} datetime={iso(@at)} title={full_time(@at)}>{relative_time(@at)}</time> | |
| 909 | + """ | |
| 910 | + end | |
| 911 | + | |
| 912 | + @doc "How long ago `dt` was, briefly." | |
| 913 | + def relative_time(nil), do: "—" | |
| 914 | + | |
| 915 | + def relative_time(%DateTime{} = dt) do | |
| 916 | + s = DateTime.diff(DateTime.utc_now(), dt) | |
| 917 | + | |
| 918 | + cond do | |
| 919 | + s < 45 -> "just now" | |
| 920 | + s < 3600 -> "#{div(s + 30, 60)}m ago" | |
| 921 | + s < 86_400 -> "#{div(s, 3600)}h ago" | |
| 922 | + s < 86_400 * 30 -> "#{div(s, 86_400)}d ago" | |
| 923 | + s < 86_400 * 365 -> "#{div(s, 86_400 * 30)}mo ago" | |
| 924 | + true -> "#{div(s, 86_400 * 365)}y ago" | |
| 925 | + end | |
| 926 | + end | |
| 927 | + | |
| 928 | + def relative_time(%NaiveDateTime{} = dt), | |
| 929 | + do: dt |> DateTime.from_naive!("Etc/UTC") |> relative_time() | |
| 930 | + | |
| 931 | + def relative_time(_), do: "—" | |
| 932 | + | |
| 933 | + @doc "A time in full, UTC." | |
| 934 | + def full_time(%DateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M:%S UTC") | |
| 935 | + def full_time(%NaiveDateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d %H:%M:%S UTC") | |
| 936 | + def full_time(_), do: nil | |
| 937 | + | |
| 938 | + defp iso(%DateTime{} = dt), do: DateTime.to_iso8601(dt) | |
| 939 | + defp iso(_), do: nil | |
| 940 | + | |
| 941 | + # A breadcrumb's time of day: from an ISO string or a Unix timestamp. | |
| 942 | + defp clock(ts) do | |
| 943 | + dt = | |
| 944 | + cond do | |
| 945 | + is_binary(ts) -> | |
| 946 | + case DateTime.from_iso8601(ts) do | |
| 947 | + {:ok, dt, _} -> dt | |
| 948 | + _ -> nil | |
| 949 | + end | |
| 950 | + | |
| 951 | + is_number(ts) -> | |
| 952 | + case DateTime.from_unix(trunc(ts * 1000), :millisecond) do | |
| 953 | + {:ok, dt} -> dt | |
| 954 | + _ -> nil | |
| 955 | + end | |
| 956 | + | |
| 957 | + true -> | |
| 958 | + nil | |
| 959 | + end | |
| 960 | + | |
| 961 | + if dt, do: Calendar.strftime(dt, "%H:%M:%S.%3f"), else: text(ts) || "" | |
| 962 | + end | |
| 963 | + | |
| 964 | + @doc "daisyUI badge classes for a level." | |
| 965 | + def level_badge_class(level) do | |
| 966 | + case level do | |
| 967 | + l when l in ["fatal", "error"] -> "badge-error badge-soft" | |
| 968 | + "warning" -> "badge-warning badge-soft" | |
| 969 | + "info" -> "badge-info badge-soft" | |
| 970 | + _ -> "badge-ghost" | |
| 971 | + end | |
| 972 | + end | |
| 973 | + | |
| 974 | + @doc "A background colour class for a level's dot." | |
| 975 | + def level_dot(level) do | |
| 976 | + case level do | |
| 977 | + "fatal" -> "bg-error ring-2 ring-error/30" | |
| 978 | + "error" -> "bg-error" | |
| 979 | + "warning" -> "bg-warning" | |
| 980 | + "info" -> "bg-info" | |
| 981 | + _ -> "bg-base-content/30" | |
| 982 | + end | |
| 983 | + end | |
| 984 | + | |
| 985 | + ## Reading untrusted data | |
| 986 | + | |
| 987 | + @doc "The exception chain of an event's data, oldest first (as stored)." | |
| 988 | + def exception_values(data) do | |
| 989 | + case as_map(data)["exception"] do | |
| 990 | + %{"values" => values} -> as_list(values) | |
| 991 | + values when is_list(values) -> values | |
| 992 | + %{"type" => _} = one -> [one] | |
| 993 | + _ -> [] | |
| 994 | + end | |
| 995 | + |> Enum.filter(&is_map/1) | |
| 996 | + end | |
| 997 | + | |
| 998 | + defp thread_values(%{"values" => v}), do: v |> as_list() |> Enum.filter(&is_map/1) | |
| 999 | + defp thread_values(v) when is_list(v), do: Enum.filter(v, &is_map/1) | |
| 1000 | + defp thread_values(_), do: [] | |
| 1001 | + | |
| 1002 | + defp frames(%{"frames" => frames}) when is_list(frames), do: Enum.filter(frames, &is_map/1) | |
| 1003 | + defp frames(_), do: [] | |
| 1004 | + | |
| 1005 | + defp as_map(v) when is_map(v) and not is_struct(v), do: v | |
| 1006 | + defp as_map(_), do: %{} | |
| 1007 | + | |
| 1008 | + defp as_list(v) when is_list(v), do: v | |
| 1009 | + defp as_list(_), do: [] | |
| 1010 | + | |
| 1011 | + defp non_empty_map?(v), do: is_map(v) and map_size(v) > 0 | |
| 1012 | + | |
| 1013 | + defp non_empty?(nil), do: false | |
| 1014 | + defp non_empty?(""), do: false | |
| 1015 | + defp non_empty?([]), do: false | |
| 1016 | + defp non_empty?(m) when is_map(m), do: map_size(m) > 0 | |
| 1017 | + defp non_empty?(_), do: true | |
| 1018 | + | |
| 1019 | + # Rows of a map or a list of pairs, as {string key, value}. | |
| 1020 | + defp pairs(v) when is_map(v) and not is_struct(v), | |
| 1021 | + do: v |> Enum.map(fn {k, val} -> {display(k), val} end) |> Enum.sort_by(&elem(&1, 0)) | |
| 1022 | + | |
| 1023 | + defp pairs(v) when is_list(v) do | |
| 1024 | + Enum.flat_map(v, fn | |
| 1025 | + [k, val] -> [{display(k), val}] | |
| 1026 | + {k, val} -> [{display(k), val}] | |
| 1027 | + %{} = m -> pairs(m) | |
| 1028 | + other -> [{"", other}] | |
| 1029 | + end) | |
| 1030 | + end | |
| 1031 | + | |
| 1032 | + defp pairs(nil), do: [] | |
| 1033 | + defp pairs(other), do: [{"", other}] | |
| 1034 | + | |
| 1035 | + # A scalar as a string; nil and "" as nil. | |
| 1036 | + defp text(nil), do: nil | |
| 1037 | + defp text(""), do: nil | |
| 1038 | + defp text(v) when is_binary(v), do: v | |
| 1039 | + defp text(v), do: display(v) | |
| 1040 | + | |
| 1041 | + defp display(v) when is_binary(v), do: v | |
| 1042 | + defp display(nil), do: "null" | |
| 1043 | + defp display(v) when is_map(v) or is_list(v), do: json(v) | |
| 1044 | + defp display(v), do: encode(v, false) | |
| 1045 | + | |
| 1046 | + defp json(v), do: encode(v, true) | |
| 1047 | + | |
| 1048 | + defp encode(v, pretty) do | |
| 1049 | + case Jason.encode(v, pretty: pretty) do | |
| 1050 | + {:ok, s} -> s | |
| 1051 | + {:error, _} -> inspect(v) | |
| 1052 | + end | |
| 1053 | + rescue | |
| 1054 | + _ -> inspect(v) | |
| 1055 | + end | |
| 1056 | + | |
| 1057 | + defp plural(1, word), do: word | |
| 1058 | + defp plural(_, word), do: word <> "s" | |
| 1059 | +end |
modified
lib/vigil_web/live/issue_live/show.ex
+862
−4
@@ -1,16 +1,874 @@
| 1 | 1 | defmodule VigilWeb.IssueLive.Show do |
| 2 | − @moduledoc "Placeholder; replaced in slice 3." | |
| 2 | + @moduledoc """ | |
| 3 | + One issue: what it is and how often it happens (header and stats), what | |
| 4 | + can be done about it (resolve, ignore, assign, share, delete), and one of | |
| 5 | + its events at a time, newest by default (`:show`) or a given one | |
| 6 | + (`:event`), paged through with Newest / Older / Newer / Oldest. The event | |
| 7 | + itself is drawn by `VigilWeb.EventComponents`. Beside it: the issue's tag | |
| 8 | + facets, the feedback people left, and comments. | |
| 9 | + | |
| 10 | + The page listens on `issue:<id>`. A new event doesn't replace the one | |
| 11 | + being read; it bumps the stats, facets and pager totals and shows a "N | |
| 12 | + new events" pill that jumps to the newest. Changes by others (status, | |
| 13 | + assignee, sharing) and new comments show as they happen; a deleted issue | |
| 14 | + sends the reader back to the list. | |
| 15 | + | |
| 16 | + Keys (a colocated hook, ignored while typing): `r` resolve, `i` ignore, | |
| 17 | + `u` unresolve, `j` older event, `k` newer event, `c` the comment box. | |
| 18 | + Changes need `event:write`; deleting needs `event:admin`. | |
| 19 | + """ | |
| 3 | 20 | use VigilWeb, :live_view |
| 4 | 21 | |
| 22 | + import VigilWeb.EventComponents | |
| 23 | + | |
| 24 | + alias Vigil.Accounts.Scope | |
| 25 | + alias Vigil.Issues | |
| 26 | + | |
| 27 | + @impl true | |
| 28 | + def mount(%{"short_id" => short_id}, _session, socket) do | |
| 29 | + scope = socket.assigns.current_scope | |
| 30 | + project = socket.assigns.project | |
| 31 | + | |
| 32 | + case Issues.get_by_short_id(project.id, short_id) do | |
| 33 | + nil -> | |
| 34 | + {:ok, | |
| 35 | + socket | |
| 36 | + |> assign(:issue, nil) | |
| 37 | + |> put_flash(:error, "That issue doesn't exist, or was deleted.") | |
| 38 | + |> push_navigate(to: list_path(scope, project))} | |
| 39 | + | |
| 40 | + issue -> | |
| 41 | + if connected?(socket), do: Phoenix.PubSub.subscribe(Vigil.PubSub, "issue:#{issue.id}") | |
| 42 | + | |
| 43 | + {:ok, | |
| 44 | + socket | |
| 45 | + |> assign(:can_write?, Scope.can?(scope, "event:write")) | |
| 46 | + |> assign(:can_admin?, Scope.can?(scope, "event:admin")) | |
| 47 | + |> assign(:can_moderate?, Scope.can?(scope, "project:admin")) | |
| 48 | + |> assign(:assignable, Issues.assignable_users(scope.organization.id)) | |
| 49 | + |> assign(:new_events, 0) | |
| 50 | + |> assign(:event, nil) | |
| 51 | + |> assign(:nav, nil) | |
| 52 | + |> assign(:comment_form, to_form(Issues.change_comment())) | |
| 53 | + |> load_issue(issue) | |
| 54 | + |> load_reports() | |
| 55 | + |> load_comments()} | |
| 56 | + end | |
| 57 | + end | |
| 58 | + | |
| 5 | 59 | @impl true |
| 6 | − def mount(_params, _session, socket), do: {:ok, socket} | |
| 60 | + def handle_params(_params, _url, %{assigns: %{issue: nil}} = socket), do: {:noreply, socket} | |
| 61 | + | |
| 62 | + def handle_params(params, _url, socket) do | |
| 63 | + issue = socket.assigns.issue | |
| 64 | + | |
| 65 | + event = | |
| 66 | + case socket.assigns.live_action do | |
| 67 | + :event -> Issues.get_event(issue, params["event_id"]) | |
| 68 | + _ -> Issues.latest_event(issue) | |
| 69 | + end | |
| 70 | + | |
| 71 | + cond do | |
| 72 | + event -> | |
| 73 | + {:noreply, | |
| 74 | + socket | |
| 75 | + |> assign(:event, event) | |
| 76 | + |> assign(:nav, Issues.event_nav(issue, event)) | |
| 77 | + |> then(&if(&1.assigns.nav.newer, do: &1, else: assign(&1, :new_events, 0)))} | |
| 78 | + | |
| 79 | + socket.assigns.live_action == :event -> | |
| 80 | + {:noreply, | |
| 81 | + socket | |
| 82 | + |> put_flash(:error, "That event isn't one of this issue's.") | |
| 83 | + |> push_navigate(to: list_path(socket.assigns.current_scope, socket.assigns.project))} | |
| 84 | + | |
| 85 | + true -> | |
| 86 | + {:noreply, assign(socket, event: nil, nav: nil)} | |
| 87 | + end | |
| 88 | + end | |
| 89 | + | |
| 90 | + ## Loading | |
| 91 | + | |
| 92 | + defp load_issue(socket, issue) do | |
| 93 | + issue = Issues.preload_detail(issue) | |
| 94 | + me = socket.assigns.current_scope.user | |
| 95 | + | |
| 96 | + socket | |
| 97 | + |> assign(:issue, issue) | |
| 98 | + |> assign(:page_title, "#{short_id(socket.assigns.project, issue)} · #{issue.title}") | |
| 99 | + |> assign(:facets, issue |> Issues.tag_facets() |> Enum.sort_by(&elem(&1, 0))) | |
| 100 | + |> assign(:assign_form, to_form(%{"user_id" => issue.assignee_id || ""}, as: :assign)) | |
| 101 | + |> assign(:assign_options, assign_options(socket.assigns.assignable, me)) | |
| 102 | + |> assign(:share_url, VigilWeb.base_url() <> "/share/issues/#{issue.id}") | |
| 103 | + end | |
| 104 | + | |
| 105 | + defp reload_issue(socket) do | |
| 106 | + case Issues.get_by_short_id(socket.assigns.project.id, socket.assigns.issue.short_id) do | |
| 107 | + nil -> | |
| 108 | + socket | |
| 109 | + |> put_flash(:info, "This issue was deleted.") | |
| 110 | + |> push_navigate(to: list_path(socket.assigns.current_scope, socket.assigns.project)) | |
| 111 | + | |
| 112 | + issue -> | |
| 113 | + socket = load_issue(socket, issue) | |
| 114 | + | |
| 115 | + case socket.assigns.event do | |
| 116 | + nil -> socket | |
| 117 | + event -> assign(socket, :nav, Issues.event_nav(issue, event)) | |
| 118 | + end | |
| 119 | + end | |
| 120 | + end | |
| 121 | + | |
| 122 | + defp load_reports(socket) do | |
| 123 | + reports = Issues.list_user_reports(socket.assigns.issue) | |
| 124 | + | |
| 125 | + socket | |
| 126 | + |> assign(:report_count, length(reports)) | |
| 127 | + |> stream(:reports, reports, reset: true) | |
| 128 | + end | |
| 129 | + | |
| 130 | + defp load_comments(socket) do | |
| 131 | + comments = Issues.list_comments(socket.assigns.issue) | |
| 132 | + | |
| 133 | + socket | |
| 134 | + |> assign(:comment_count, length(comments)) | |
| 135 | + |> stream(:comments, comments, reset: true) | |
| 136 | + end | |
| 137 | + | |
| 138 | + defp assign_options(users, me) do | |
| 139 | + others = for u <- users, u.id != me.id, do: {u.email, u.id} | |
| 140 | + [{"Nobody", ""}, {"Me (#{me.email})", me.id} | others] | |
| 141 | + end | |
| 142 | + | |
| 143 | + ## Paths | |
| 144 | + | |
| 145 | + defp list_path(scope, project), | |
| 146 | + do: ~p"/orgs/#{scope.organization.slug}/projects/#{project.slug}" | |
| 147 | + | |
| 148 | + defp issue_path(scope, project, issue), | |
| 149 | + do: ~p"/orgs/#{scope.organization.slug}/projects/#{project.slug}/issues/#{issue.short_id}" | |
| 150 | + | |
| 151 | + defp event_path(scope, project, issue, event_id), | |
| 152 | + do: | |
| 153 | + ~p"/orgs/#{scope.organization.slug}/projects/#{project.slug}/issues/#{issue.short_id}/events/#{event_id}" | |
| 154 | + | |
| 155 | + defp short_id(project, issue), do: "#{String.upcase(project.slug)}-#{issue.short_id}" | |
| 156 | + | |
| 157 | + ## Render | |
| 7 | 158 | |
| 8 | 159 | @impl true |
| 160 | + def render(%{issue: nil} = assigns) do | |
| 161 | + ~H""" | |
| 162 | + <Layouts.app flash={@flash} current_scope={@current_scope} active={:projects}> | |
| 163 | + <p id="issue-missing" class="text-base-content/60">No such issue.</p> | |
| 164 | + </Layouts.app> | |
| 165 | + """ | |
| 166 | + end | |
| 167 | + | |
| 9 | 168 | def render(assigns) do |
| 10 | 169 | ~H""" |
| 11 | − <Layouts.app flash={@flash} current_scope={@current_scope}> | |
| 12 | − <p id="placeholder">Coming in slice 3.</p> | |
| 170 | + <Layouts.app flash={@flash} current_scope={@current_scope} active={:projects}> | |
| 171 | + <div id="issue-keys" phx-hook=".IssueKeys" data-can-write={to_string(@can_write?)}> | |
| 172 | + <.link | |
| 173 | + navigate={list_path(@current_scope, @project)} | |
| 174 | + id="back-to-issues" | |
| 175 | + class="group inline-flex items-center gap-1 text-sm text-base-content/60 transition hover:text-base-content" | |
| 176 | + > | |
| 177 | + <.icon | |
| 178 | + name="hero-arrow-left-micro" | |
| 179 | + class="size-4 transition-transform group-hover:-translate-x-0.5" | |
| 180 | + /> | |
| 181 | + {@project.name} issues | |
| 182 | + </.link> | |
| 183 | + </div> | |
| 184 | + <script :type={Phoenix.LiveView.ColocatedHook} name=".IssueKeys"> | |
| 185 | + export default { | |
| 186 | + mounted() { | |
| 187 | + this.onKey = (e) => { | |
| 188 | + if (e.metaKey || e.ctrlKey || e.altKey || e.isComposing) return | |
| 189 | + const t = e.target | |
| 190 | + if (t && (t.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(t.tagName))) return | |
| 191 | + if (e.key === "c") { | |
| 192 | + const box = document.getElementById("comment-text") | |
| 193 | + if (box) { e.preventDefault(); box.focus() } | |
| 194 | + return | |
| 195 | + } | |
| 196 | + if (["r", "i", "u", "j", "k"].includes(e.key)) { | |
| 197 | + e.preventDefault() | |
| 198 | + this.pushEvent("key", {key: e.key}) | |
| 199 | + } | |
| 200 | + } | |
| 201 | + window.addEventListener("keydown", this.onKey) | |
| 202 | + }, | |
| 203 | + destroyed() { | |
| 204 | + window.removeEventListener("keydown", this.onKey) | |
| 205 | + } | |
| 206 | + } | |
| 207 | + </script> | |
| 208 | + | |
| 209 | + <.issue_header | |
| 210 | + issue={@issue} | |
| 211 | + project={@project} | |
| 212 | + report_count={@report_count} | |
| 213 | + /> | |
| 214 | + | |
| 215 | + <.issue_actions | |
| 216 | + :if={@can_write?} | |
| 217 | + issue={@issue} | |
| 218 | + can_admin?={@can_admin?} | |
| 219 | + assign_form={@assign_form} | |
| 220 | + assign_options={@assign_options} | |
| 221 | + share_url={@share_url} | |
| 222 | + /> | |
| 223 | + | |
| 224 | + <div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_20rem]"> | |
| 225 | + <div class="min-w-0 space-y-5"> | |
| 226 | + <%= if @event do %> | |
| 227 | + <.event_nav | |
| 228 | + event={@event} | |
| 229 | + nav={@nav} | |
| 230 | + new_events={@new_events} | |
| 231 | + newest_path={issue_path(@current_scope, @project, @issue)} | |
| 232 | + path={&event_path(@current_scope, @project, @issue, &1)} | |
| 233 | + /> | |
| 234 | + <.event_body id={"event-#{@event.id}"} event={@event} /> | |
| 235 | + <% else %> | |
| 236 | + <div | |
| 237 | + id="no-events" | |
| 238 | + class="rounded-box border border-dashed border-base-300 p-8 text-center text-sm text-base-content/60" | |
| 239 | + > | |
| 240 | + This issue's events have aged out of retention. | |
| 241 | + </div> | |
| 242 | + <% end %> | |
| 243 | + </div> | |
| 244 | + | |
| 245 | + <aside class="min-w-0 space-y-5"> | |
| 246 | + <.facets facets={@facets} /> | |
| 247 | + <.reports streams={@streams} count={@report_count} /> | |
| 248 | + <.comments | |
| 249 | + streams={@streams} | |
| 250 | + count={@comment_count} | |
| 251 | + form={@comment_form} | |
| 252 | + can_write?={@can_write?} | |
| 253 | + can_moderate?={@can_moderate?} | |
| 254 | + me={@current_scope.user} | |
| 255 | + /> | |
| 256 | + </aside> | |
| 257 | + </div> | |
| 258 | + | |
| 259 | + <p id="key-hints" class="hidden text-center text-xs text-base-content/50 sm:block"> | |
| 260 | + Keys: <kbd class="kbd kbd-xs">j</kbd>/<kbd class="kbd kbd-xs">k</kbd> | |
| 261 | + older/newer event | |
| 262 | + <span :if={@can_write?}> | |
| 263 | + · <kbd class="kbd kbd-xs">r</kbd> | |
| 264 | + resolve · <kbd class="kbd kbd-xs">i</kbd> | |
| 265 | + ignore · <kbd class="kbd kbd-xs">u</kbd> | |
| 266 | + unresolve · <kbd class="kbd kbd-xs">c</kbd> | |
| 267 | + comment | |
| 268 | + </span> | |
| 269 | + </p> | |
| 13 | 270 | </Layouts.app> |
| 14 | 271 | """ |
| 15 | 272 | end |
| 273 | + | |
| 274 | + ## Header | |
| 275 | + | |
| 276 | + attr :issue, :map, required: true | |
| 277 | + attr :project, :map, required: true | |
| 278 | + attr :report_count, :integer, required: true | |
| 279 | + | |
| 280 | + defp issue_header(assigns) do | |
| 281 | + assigns = assign(assigns, :sid, short_id(assigns.project, assigns.issue)) | |
| 282 | + | |
| 283 | + ~H""" | |
| 284 | + <header id="issue-header" class="space-y-4"> | |
| 285 | + <div class="flex flex-wrap items-center gap-2 text-sm"> | |
| 286 | + <button | |
| 287 | + type="button" | |
| 288 | + id="copy-short-id" | |
| 289 | + data-copy={@sid} | |
| 290 | + title="Copy" | |
| 291 | + class="group inline-flex items-center gap-1 rounded-md bg-base-200 px-2 py-0.5 font-mono text-xs font-semibold transition hover:bg-base-300" | |
| 292 | + phx-click={JS.dispatch("phx:copy") |> JS.transition("scale-95", time: 150)} | |
| 293 | + > | |
| 294 | + {@sid} | |
| 295 | + <.icon | |
| 296 | + name="hero-clipboard-document-micro" | |
| 297 | + class="size-3.5 opacity-50 group-hover:opacity-100" | |
| 298 | + /> | |
| 299 | + </button> | |
| 300 | + <.level_badge level={@issue.level} /> | |
| 301 | + <.status_badge issue={@issue} /> | |
| 302 | + <span :if={@issue.is_public} id="public-badge" class="badge badge-info badge-sm badge-outline"> | |
| 303 | + <.icon name="hero-globe-alt-micro" class="size-3" /> public | |
| 304 | + </span> | |
| 305 | + <span :if={@issue.assignee} id="assignee-badge" class="badge badge-ghost badge-sm"> | |
| 306 | + <.icon name="hero-user-micro" class="size-3" /> {@issue.assignee.email} | |
| 307 | + </span> | |
| 308 | + </div> | |
| 309 | + | |
| 310 | + <div class="flex gap-3"> | |
| 311 | + <span class={["mt-1.5 w-1 shrink-0 self-stretch rounded-full", level_dot(@issue.level)]} /> | |
| 312 | + <div class="min-w-0"> | |
| 313 | + <h1 id="issue-title" class="break-words text-xl font-semibold leading-snug sm:text-2xl"> | |
| 314 | + {@issue.title} | |
| 315 | + </h1> | |
| 316 | + <p | |
| 317 | + :if={@issue.culprit not in [nil, ""]} | |
| 318 | + id="issue-culprit" | |
| 319 | + class="mt-1 break-all font-mono text-sm text-base-content/60" | |
| 320 | + > | |
| 321 | + {@issue.culprit} | |
| 322 | + </p> | |
| 323 | + </div> | |
| 324 | + </div> | |
| 325 | + | |
| 326 | + <dl id="issue-stats" class="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6"> | |
| 327 | + <.stat id="stat-events" label="Events">{@issue.count}</.stat> | |
| 328 | + <.stat id="stat-first-seen" label="First seen"><.time_ago at={@issue.first_seen} /></.stat> | |
| 329 | + <.stat id="stat-last-seen" label="Last seen"><.time_ago at={@issue.last_seen} /></.stat> | |
| 330 | + <.stat id="stat-first-release" label="First release"> | |
| 331 | + <span class="font-mono">{release(@issue.first_release)}</span> | |
| 332 | + </.stat> | |
| 333 | + <.stat id="stat-last-release" label="Last release"> | |
| 334 | + <span class="font-mono">{release(@issue.last_release)}</span> | |
| 335 | + </.stat> | |
| 336 | + <.stat id="stat-feedback" label="Feedback">{@report_count}</.stat> | |
| 337 | + </dl> | |
| 338 | + | |
| 339 | + <p | |
| 340 | + :if={@issue.status == :resolved} | |
| 341 | + id="resolved-note" | |
| 342 | + class="flex items-center gap-1.5 text-sm text-success" | |
| 343 | + > | |
| 344 | + <.icon name="hero-check-circle-micro" class="size-4" /> | |
| 345 | + <%= if @issue.resolved_in_release do %> | |
| 346 | + Resolved in release <span class="font-mono font-semibold">{@issue.resolved_in_release.version}</span>; | |
| 347 | + an event from another release reopens it. | |
| 348 | + <% else %> | |
| 349 | + Resolved <.time_ago at={@issue.resolved_at} />; a new event reopens it. | |
| 350 | + <% end %> | |
| 351 | + </p> | |
| 352 | + </header> | |
| 353 | + """ | |
| 354 | + end | |
| 355 | + | |
| 356 | + attr :id, :string, required: true | |
| 357 | + attr :label, :string, required: true | |
| 358 | + slot :inner_block, required: true | |
| 359 | + | |
| 360 | + defp stat(assigns) do | |
| 361 | + ~H""" | |
| 362 | + <div | |
| 363 | + id={@id} | |
| 364 | + class="rounded-box border border-base-300 bg-base-100 px-3 py-2 transition hover:border-base-content/20" | |
| 365 | + > | |
| 366 | + <dt class="text-xs text-base-content/60">{@label}</dt> | |
| 367 | + <dd class="truncate text-lg font-semibold tabular-nums">{render_slot(@inner_block)}</dd> | |
| 368 | + </div> | |
| 369 | + """ | |
| 370 | + end | |
| 371 | + | |
| 372 | + defp release(nil), do: "—" | |
| 373 | + defp release(r), do: r.version | |
| 374 | + | |
| 375 | + attr :issue, :map, required: true | |
| 376 | + | |
| 377 | + defp status_badge(assigns) do | |
| 378 | + ~H""" | |
| 379 | + <span | |
| 380 | + id="status-badge" | |
| 381 | + class={[ | |
| 382 | + "badge badge-sm", | |
| 383 | + @issue.status == :unresolved && "badge-warning badge-soft", | |
| 384 | + @issue.status == :resolved && "badge-success badge-soft", | |
| 385 | + @issue.status == :ignored && "badge-ghost" | |
| 386 | + ]} | |
| 387 | + > | |
| 388 | + {@issue.status} | |
| 389 | + </span> | |
| 390 | + """ | |
| 391 | + end | |
| 392 | + | |
| 393 | + ## Actions | |
| 394 | + | |
| 395 | + attr :issue, :map, required: true | |
| 396 | + attr :can_admin?, :boolean, required: true | |
| 397 | + attr :assign_form, :any, required: true | |
| 398 | + attr :assign_options, :list, required: true | |
| 399 | + attr :share_url, :string, required: true | |
| 400 | + | |
| 401 | + @doc false | |
| 402 | + def issue_actions(assigns) do | |
| 403 | + ~H""" | |
| 404 | + <div | |
| 405 | + id="issue-actions" | |
| 406 | + class="sticky top-16 z-30 -mx-2 flex flex-wrap items-center gap-2 rounded-box border border-base-300 bg-base-100/90 px-2 py-2 shadow-sm backdrop-blur" | |
| 407 | + > | |
| 408 | + <%= if @issue.status == :unresolved do %> | |
| 409 | + <div class="join"> | |
| 410 | + <button | |
| 411 | + type="button" | |
| 412 | + id="resolve" | |
| 413 | + class="btn btn-success btn-sm join-item" | |
| 414 | + phx-click="resolve" | |
| 415 | + phx-disable-with="Resolving…" | |
| 416 | + > | |
| 417 | + <.icon name="hero-check-micro" class="size-4" /> Resolve | |
| 418 | + </button> | |
| 419 | + <div :if={@issue.last_release_id} class="dropdown dropdown-bottom join-item"> | |
| 420 | + <div | |
| 421 | + tabindex="0" | |
| 422 | + role="button" | |
| 423 | + id="resolve-menu" | |
| 424 | + class="btn btn-success btn-sm join-item px-1.5" | |
| 425 | + aria-label="More ways to resolve" | |
| 426 | + > | |
| 427 | + <.icon name="hero-chevron-down-micro" class="size-4" /> | |
| 428 | + </div> | |
| 429 | + <ul | |
| 430 | + tabindex="0" | |
| 431 | + class="menu dropdown-content z-40 mt-1 w-60 rounded-box border border-base-300 bg-base-100 p-1 shadow-lg" | |
| 432 | + > | |
| 433 | + <li> | |
| 434 | + <button | |
| 435 | + type="button" | |
| 436 | + id="resolve-latest" | |
| 437 | + phx-click="resolve_latest" | |
| 438 | + phx-disable-with="Resolving…" | |
| 439 | + > | |
| 440 | + In the latest release | |
| 441 | + <span :if={@issue.last_release} class="font-mono text-xs opacity-60"> | |
| 442 | + {@issue.last_release.version} | |
| 443 | + </span> | |
| 444 | + </button> | |
| 445 | + </li> | |
| 446 | + </ul> | |
| 447 | + </div> | |
| 448 | + </div> | |
| 449 | + <button | |
| 450 | + type="button" | |
| 451 | + id="ignore" | |
| 452 | + class="btn btn-ghost btn-sm" | |
| 453 | + phx-click="ignore" | |
| 454 | + phx-disable-with="Ignoring…" | |
| 455 | + > | |
| 456 | + <.icon name="hero-bell-slash-micro" class="size-4" /> Ignore | |
| 457 | + </button> | |
| 458 | + <% else %> | |
| 459 | + <button | |
| 460 | + type="button" | |
| 461 | + id="unresolve" | |
| 462 | + class="btn btn-warning btn-soft btn-sm" | |
| 463 | + phx-click="unresolve" | |
| 464 | + phx-disable-with="Reopening…" | |
| 465 | + > | |
| 466 | + <.icon name="hero-arrow-uturn-left-micro" class="size-4" /> Unresolve | |
| 467 | + </button> | |
| 468 | + <% end %> | |
| 469 | + | |
| 470 | + <.form for={@assign_form} id="assign-form" phx-change="assign" class="flex items-center gap-1"> | |
| 471 | + <.icon name="hero-user-circle-micro" class="size-4 opacity-60" /> | |
| 472 | + <.input | |
| 473 | + field={@assign_form[:user_id]} | |
| 474 | + type="select" | |
| 475 | + options={@assign_options} | |
| 476 | + class="select select-sm w-44" | |
| 477 | + aria-label="Assignee" | |
| 478 | + /> | |
| 479 | + </.form> | |
| 480 | + | |
| 481 | + <button | |
| 482 | + type="button" | |
| 483 | + id="share-toggle" | |
| 484 | + class={["btn btn-sm", if(@issue.is_public, do: "btn-info btn-soft", else: "btn-ghost")]} | |
| 485 | + phx-click="toggle_share" | |
| 486 | + phx-disable-with="…" | |
| 487 | + > | |
| 488 | + <.icon | |
| 489 | + name={if(@issue.is_public, do: "hero-globe-alt-micro", else: "hero-share-micro")} | |
| 490 | + class="size-4" | |
| 491 | + /> | |
| 492 | + {if @issue.is_public, do: "Shared", else: "Share"} | |
| 493 | + </button> | |
| 494 | + | |
| 495 | + <button | |
| 496 | + :if={@can_admin?} | |
| 497 | + type="button" | |
| 498 | + id="delete-issue" | |
| 499 | + class="btn btn-ghost btn-sm ml-auto text-error" | |
| 500 | + phx-click="delete" | |
| 501 | + data-confirm="Delete this issue? Its events go too." | |
| 502 | + phx-disable-with="Deleting…" | |
| 503 | + > | |
| 504 | + <.icon name="hero-trash-micro" class="size-4" /> Delete | |
| 505 | + </button> | |
| 506 | + | |
| 507 | + <div :if={@issue.is_public} id="share-url-row" class="join w-full"> | |
| 508 | + <input | |
| 509 | + id="share-url" | |
| 510 | + type="text" | |
| 511 | + readonly | |
| 512 | + value={@share_url} | |
| 513 | + class="input input-sm join-item min-w-0 flex-1 font-mono text-xs" | |
| 514 | + aria-label="Share link" | |
| 515 | + /> | |
| 516 | + <button | |
| 517 | + id="copy-share-url" | |
| 518 | + type="button" | |
| 519 | + class="btn btn-sm btn-info join-item" | |
| 520 | + phx-click={JS.dispatch("phx:copy", to: "#share-url")} | |
| 521 | + > | |
| 522 | + <.icon name="hero-clipboard-document-micro" class="size-4" /> Copy | |
| 523 | + </button> | |
| 524 | + </div> | |
| 525 | + </div> | |
| 526 | + """ | |
| 527 | + end | |
| 528 | + | |
| 529 | + ## Event pager | |
| 530 | + | |
| 531 | + attr :event, :map, required: true | |
| 532 | + attr :nav, :map, required: true | |
| 533 | + attr :new_events, :integer, required: true | |
| 534 | + attr :newest_path, :string, required: true | |
| 535 | + attr :path, :any, required: true | |
| 536 | + | |
| 537 | + defp event_nav(assigns) do | |
| 538 | + ~H""" | |
| 539 | + <div | |
| 540 | + id="event-nav" | |
| 541 | + class="flex flex-wrap items-center justify-between gap-3 rounded-box border border-base-300 bg-base-100 px-4 py-3" | |
| 542 | + > | |
| 543 | + <div class="min-w-0 space-y-0.5"> | |
| 544 | + <p class="flex flex-wrap items-center gap-2 text-sm font-semibold"> | |
| 545 | + <span id="event-position">Event {@nav.index} of {@nav.total}</span> | |
| 546 | + <.link | |
| 547 | + :if={@new_events > 0} | |
| 548 | + patch={@newest_path} | |
| 549 | + id="new-events-pill" | |
| 550 | + class="badge badge-primary badge-sm gap-1 transition hover:scale-105 motion-safe:animate-pulse" | |
| 551 | + > | |
| 552 | + <.icon name="hero-arrow-up-micro" class="size-3" /> | |
| 553 | + {@new_events} new {if @new_events == 1, do: "event", else: "events"} | |
| 554 | + </.link> | |
| 555 | + </p> | |
| 556 | + <p class="flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-base-content/60"> | |
| 557 | + <span id="event-id" class="font-mono" title="Event ID">{@event.event_id}</span> | |
| 558 | + <span><.time_ago at={@event.timestamp} /></span> | |
| 559 | + <span :if={is_binary(@event.data["release"])} class="inline-flex items-center gap-1"> | |
| 560 | + <.icon name="hero-tag-micro" class="size-3" /> | |
| 561 | + <span class="font-mono">{@event.data["release"]}</span> | |
| 562 | + </span> | |
| 563 | + <span :if={@event.environment} class="inline-flex items-center gap-1"> | |
| 564 | + <.icon name="hero-server-micro" class="size-3" />{@event.environment} | |
| 565 | + </span> | |
| 566 | + </p> | |
| 567 | + </div> | |
| 568 | + <div class="join"> | |
| 569 | + <.pager_link | |
| 570 | + id="event-newest" | |
| 571 | + to={@nav.newest != @event.id && @nav.newest} | |
| 572 | + path={@path} | |
| 573 | + title="Newest" | |
| 574 | + > | |
| 575 | + <.icon name="hero-chevron-double-left-micro" class="size-4" /> | |
| 576 | + </.pager_link> | |
| 577 | + <.pager_link id="event-newer" to={@nav.newer} path={@path} title="Newer (k)"> | |
| 578 | + <.icon name="hero-chevron-left-micro" class="size-4" /> Newer | |
| 579 | + </.pager_link> | |
| 580 | + <.pager_link id="event-older" to={@nav.older} path={@path} title="Older (j)"> | |
| 581 | + Older <.icon name="hero-chevron-right-micro" class="size-4" /> | |
| 582 | + </.pager_link> | |
| 583 | + <.pager_link | |
| 584 | + id="event-oldest" | |
| 585 | + to={@nav.oldest != @event.id && @nav.oldest} | |
| 586 | + path={@path} | |
| 587 | + title="Oldest" | |
| 588 | + > | |
| 589 | + <.icon name="hero-chevron-double-right-micro" class="size-4" /> | |
| 590 | + </.pager_link> | |
| 591 | + </div> | |
| 592 | + </div> | |
| 593 | + """ | |
| 594 | + end | |
| 595 | + | |
| 596 | + attr :id, :string, required: true | |
| 597 | + attr :to, :any, required: true | |
| 598 | + attr :path, :any, required: true | |
| 599 | + attr :title, :string, required: true | |
| 600 | + slot :inner_block, required: true | |
| 601 | + | |
| 602 | + defp pager_link(assigns) do | |
| 603 | + ~H""" | |
| 604 | + <%= if @to do %> | |
| 605 | + <.link patch={@path.(@to)} id={@id} title={@title} class="btn btn-sm join-item"> | |
| 606 | + {render_slot(@inner_block)} | |
| 607 | + </.link> | |
| 608 | + <% else %> | |
| 609 | + <span id={@id} title={@title} class="btn btn-sm btn-disabled join-item" aria-disabled="true"> | |
| 610 | + {render_slot(@inner_block)} | |
| 611 | + </span> | |
| 612 | + <% end %> | |
| 613 | + """ | |
| 614 | + end | |
| 615 | + | |
| 616 | + ## Sidebar | |
| 617 | + | |
| 618 | + attr :facets, :list, required: true | |
| 619 | + | |
| 620 | + defp facets(assigns) do | |
| 621 | + ~H""" | |
| 622 | + <section id="tag-facets" class="rounded-box border border-base-300 bg-base-100 p-4"> | |
| 623 | + <h2 class="mb-3 flex items-center gap-1.5 text-sm font-semibold"> | |
| 624 | + <.icon name="hero-tag-micro" class="size-4 opacity-60" /> Tags | |
| 625 | + </h2> | |
| 626 | + <p :if={@facets == []} class="text-sm text-base-content/60">No tags yet.</p> | |
| 627 | + <div class="space-y-4"> | |
| 628 | + <div :for={{{key, values}, i} <- Enum.with_index(@facets)} id={"facet-#{i}"} data-key={key}> | |
| 629 | + <h3 class="mb-1 truncate font-mono text-xs font-semibold text-base-content/70">{key}</h3> | |
| 630 | + <ul class="space-y-1"> | |
| 631 | + <li | |
| 632 | + :for={{value, count} <- values} | |
| 633 | + class="group relative overflow-hidden rounded bg-base-200/50 px-2 py-0.5 text-xs" | |
| 634 | + title={"#{value}: #{count}"} | |
| 635 | + > | |
| 636 | + <span | |
| 637 | + class="absolute inset-y-0 left-0 bg-primary/15 transition-all group-hover:bg-primary/25" | |
| 638 | + style={"width: #{percent(count, values)}%"} | |
| 639 | + /> | |
| 640 | + <span class="relative flex justify-between gap-2"> | |
| 641 | + <span class="truncate font-mono">{value}</span> | |
| 642 | + <span class="shrink-0 tabular-nums text-base-content/60"> | |
| 643 | + {percent(count, values)}% | |
| 644 | + </span> | |
| 645 | + </span> | |
| 646 | + </li> | |
| 647 | + </ul> | |
| 648 | + </div> | |
| 649 | + </div> | |
| 650 | + </section> | |
| 651 | + """ | |
| 652 | + end | |
| 653 | + | |
| 654 | + defp percent(count, values) do | |
| 655 | + total = values |> Enum.map(&elem(&1, 1)) |> Enum.sum() | |
| 656 | + if total > 0, do: round(count * 100 / total), else: 0 | |
| 657 | + end | |
| 658 | + | |
| 659 | + attr :streams, :map, required: true | |
| 660 | + attr :count, :integer, required: true | |
| 661 | + | |
| 662 | + defp reports(assigns) do | |
| 663 | + ~H""" | |
| 664 | + <section class="rounded-box border border-base-300 bg-base-100 p-4"> | |
| 665 | + <h2 class="mb-3 flex items-center gap-1.5 text-sm font-semibold"> | |
| 666 | + <.icon name="hero-megaphone-micro" class="size-4 opacity-60" /> User feedback | |
| 667 | + <span :if={@count > 0} class="badge badge-ghost badge-sm">{@count}</span> | |
| 668 | + </h2> | |
| 669 | + <ul id="user-reports" phx-update="stream" class="space-y-3"> | |
| 670 | + <li id="user-reports-empty" class="hidden text-sm text-base-content/60 only:block"> | |
| 671 | + Nobody has left feedback. | |
| 672 | + </li> | |
| 673 | + <li :for={{dom_id, r} <- @streams.reports} id={dom_id} class="text-sm"> | |
| 674 | + <p class="whitespace-pre-wrap break-words">{r.comments}</p> | |
| 675 | + <p class="mt-0.5 text-xs text-base-content/60"> | |
| 676 | + {r.name || "Anonymous"}<span :if={r.email}> · {r.email}</span> | |
| 677 | + · <.time_ago at={r.inserted_at} /> | |
| 678 | + </p> | |
| 679 | + </li> | |
| 680 | + </ul> | |
| 681 | + </section> | |
| 682 | + """ | |
| 683 | + end | |
| 684 | + | |
| 685 | + attr :streams, :map, required: true | |
| 686 | + attr :count, :integer, required: true | |
| 687 | + attr :form, :any, required: true | |
| 688 | + attr :can_write?, :boolean, required: true | |
| 689 | + attr :can_moderate?, :boolean, required: true | |
| 690 | + attr :me, :map, required: true | |
| 691 | + | |
| 692 | + defp comments(assigns) do | |
| 693 | + ~H""" | |
| 694 | + <section class="rounded-box border border-base-300 bg-base-100 p-4"> | |
| 695 | + <h2 class="mb-3 flex items-center gap-1.5 text-sm font-semibold"> | |
| 696 | + <.icon name="hero-chat-bubble-left-right-micro" class="size-4 opacity-60" /> Comments | |
| 697 | + <span :if={@count > 0} id="comment-count" class="badge badge-ghost badge-sm">{@count}</span> | |
| 698 | + </h2> | |
| 699 | + <ul id="comments" phx-update="stream" class="mb-3 space-y-3"> | |
| 700 | + <li id="comments-empty" class="hidden text-sm text-base-content/60 only:block"> | |
| 701 | + No comments yet. | |
| 702 | + </li> | |
| 703 | + <li :for={{dom_id, c} <- @streams.comments} id={dom_id} class="group text-sm"> | |
| 704 | + <div class="flex items-baseline justify-between gap-2 text-xs text-base-content/60"> | |
| 705 | + <span class="truncate font-medium text-base-content/80">{c.user && c.user.email}</span> | |
| 706 | + <span class="flex shrink-0 items-center gap-1"> | |
| 707 | + <.time_ago at={c.inserted_at} /> | |
| 708 | + <button | |
| 709 | + :if={c.user_id == @me.id or @can_moderate?} | |
| 710 | + type="button" | |
| 711 | + id={"delete-#{dom_id}"} | |
| 712 | + class="btn btn-ghost btn-xs text-error opacity-0 transition group-hover:opacity-100 focus:opacity-100" | |
| 713 | + phx-click="delete_comment" | |
| 714 | + phx-value-id={c.id} | |
| 715 | + data-confirm="Delete this comment?" | |
| 716 | + aria-label="Delete comment" | |
| 717 | + > | |
| 718 | + <.icon name="hero-trash-micro" class="size-3.5" /> | |
| 719 | + </button> | |
| 720 | + </span> | |
| 721 | + </div> | |
| 722 | + <p class="mt-0.5 whitespace-pre-wrap break-words">{c.text}</p> | |
| 723 | + </li> | |
| 724 | + </ul> | |
| 725 | + <.form | |
| 726 | + :if={@can_write?} | |
| 727 | + for={@form} | |
| 728 | + id="comment-form" | |
| 729 | + phx-change="validate_comment" | |
| 730 | + phx-submit="add_comment" | |
| 731 | + > | |
| 732 | + <.input | |
| 733 | + field={@form[:text]} | |
| 734 | + id="comment-text" | |
| 735 | + type="textarea" | |
| 736 | + rows="3" | |
| 737 | + placeholder="Add a comment…" | |
| 738 | + /> | |
| 739 | + <button class="btn btn-primary btn-sm" phx-disable-with="Posting…">Comment</button> | |
| 740 | + </.form> | |
| 741 | + </section> | |
| 742 | + """ | |
| 743 | + end | |
| 744 | + | |
| 745 | + ## Events | |
| 746 | + | |
| 747 | + @impl true | |
| 748 | + def handle_event("resolve", _, socket), | |
| 749 | + do: triage(socket, &Issues.resolve(&1, &2), "Resolved.") | |
| 750 | + | |
| 751 | + def handle_event("resolve_latest", _, socket), | |
| 752 | + do: triage(socket, &Issues.resolve_in_latest_release/2, "Resolved in the latest release.") | |
| 753 | + | |
| 754 | + def handle_event("ignore", _, socket), do: triage(socket, &Issues.ignore/2, "Ignored.") | |
| 755 | + def handle_event("unresolve", _, socket), do: triage(socket, &Issues.unresolve/2, "Reopened.") | |
| 756 | + | |
| 757 | + def handle_event("assign", %{"assign" => %{"user_id" => user_id}}, socket) do | |
| 758 | + user_id = if user_id == "", do: nil, else: user_id | |
| 759 | + triage(socket, &Issues.assign(&1, &2, user_id), nil) | |
| 760 | + end | |
| 761 | + | |
| 762 | + def handle_event("toggle_share", _, socket) do | |
| 763 | + public? = !socket.assigns.issue.is_public | |
| 764 | + | |
| 765 | + triage( | |
| 766 | + socket, | |
| 767 | + &Issues.set_public(&1, &2, public?), | |
| 768 | + if(public?, do: "Anyone with the link can see this issue.", else: "No longer shared.") | |
| 769 | + ) | |
| 770 | + end | |
| 771 | + | |
| 772 | + def handle_event("delete", _, socket) do | |
| 773 | + %{current_scope: scope, project: project, issue: issue} = socket.assigns | |
| 774 | + | |
| 775 | + case Issues.delete(scope, issue) do | |
| 776 | + {:ok, _} -> | |
| 777 | + {:noreply, | |
| 778 | + socket | |
| 779 | + |> put_flash(:info, "Issue deleted.") | |
| 780 | + |> push_navigate(to: list_path(scope, project))} | |
| 781 | + | |
| 782 | + {:error, reason} -> | |
| 783 | + {:noreply, put_flash(socket, :error, error_message(reason))} | |
| 784 | + end | |
| 785 | + end | |
| 786 | + | |
| 787 | + def handle_event("validate_comment", %{"comment" => params}, socket) do | |
| 788 | + form = params |> Issues.change_comment() |> Map.put(:action, :validate) |> to_form() | |
| 789 | + {:noreply, assign(socket, :comment_form, form)} | |
| 790 | + end | |
| 791 | + | |
| 792 | + def handle_event("add_comment", %{"comment" => params}, socket) do | |
| 793 | + %{current_scope: scope, issue: issue} = socket.assigns | |
| 794 | + | |
| 795 | + case Issues.add_comment(scope, issue, params) do | |
| 796 | + {:ok, comment} -> | |
| 797 | + {:noreply, | |
| 798 | + socket | |
| 799 | + |> stream_insert(:comments, %{comment | user: scope.user}) | |
| 800 | + |> update(:comment_count, &(&1 + 1)) | |
| 801 | + |> assign(:comment_form, to_form(Issues.change_comment()))} | |
| 802 | + | |
| 803 | + {:error, %Ecto.Changeset{} = changeset} -> | |
| 804 | + {:noreply, assign(socket, :comment_form, to_form(changeset, action: :insert))} | |
| 805 | + | |
| 806 | + {:error, reason} -> | |
| 807 | + {:noreply, put_flash(socket, :error, error_message(reason))} | |
| 808 | + end | |
| 809 | + end | |
| 810 | + | |
| 811 | + def handle_event("delete_comment", %{"id" => id}, socket) do | |
| 812 | + %{current_scope: scope, issue: issue} = socket.assigns | |
| 813 | + | |
| 814 | + case Issues.delete_comment(scope, issue, id) do | |
| 815 | + {:ok, comment} -> | |
| 816 | + {:noreply, | |
| 817 | + socket | |
| 818 | + |> stream_delete(:comments, comment) | |
| 819 | + |> update(:comment_count, &max(&1 - 1, 0))} | |
| 820 | + | |
| 821 | + {:error, reason} -> | |
| 822 | + {:noreply, put_flash(socket, :error, error_message(reason))} | |
| 823 | + end | |
| 824 | + end | |
| 825 | + | |
| 826 | + def handle_event("key", %{"key" => key}, socket) do | |
| 827 | + case {key, socket.assigns.issue.status} do | |
| 828 | + {"r", :unresolved} -> handle_event("resolve", %{}, socket) | |
| 829 | + {"i", :unresolved} -> handle_event("ignore", %{}, socket) | |
| 830 | + {"u", status} when status != :unresolved -> handle_event("unresolve", %{}, socket) | |
| 831 | + {"j", _} -> go_to(socket, socket.assigns.nav && socket.assigns.nav.older) | |
| 832 | + {"k", _} -> go_to(socket, socket.assigns.nav && socket.assigns.nav.newer) | |
| 833 | + _ -> {:noreply, socket} | |
| 834 | + end | |
| 835 | + end | |
| 836 | + | |
| 837 | + defp go_to(socket, nil), do: {:noreply, socket} | |
| 838 | + | |
| 839 | + defp go_to(socket, event_id) do | |
| 840 | + %{current_scope: scope, project: project, issue: issue} = socket.assigns | |
| 841 | + {:noreply, push_patch(socket, to: event_path(scope, project, issue, event_id))} | |
| 842 | + end | |
| 843 | + | |
| 844 | + defp triage(socket, fun, message) do | |
| 845 | + case fun.(socket.assigns.current_scope, socket.assigns.issue) do | |
| 846 | + {:ok, _issue} -> | |
| 847 | + socket = reload_issue(socket) | |
| 848 | + {:noreply, if(message, do: put_flash(socket, :info, message), else: socket)} | |
| 849 | + | |
| 850 | + {:error, reason} -> | |
| 851 | + {:noreply, put_flash(socket, :error, error_message(reason))} | |
| 852 | + end | |
| 853 | + end | |
| 854 | + | |
| 855 | + defp error_message(:forbidden), do: "You can't do that here." | |
| 856 | + defp error_message(:unauthorized), do: "You can't do that here." | |
| 857 | + defp error_message(:not_a_member), do: "Only members of this organization can be assigned." | |
| 858 | + defp error_message(:not_found), do: "That's gone." | |
| 859 | + defp error_message(_), do: "That didn't work." | |
| 860 | + | |
| 861 | + ## Live updates | |
| 862 | + | |
| 863 | + @impl true | |
| 864 | + def handle_info({:issue_event, _}, socket) do | |
| 865 | + {:noreply, | |
| 866 | + socket | |
| 867 | + |> update(:new_events, &(&1 + 1)) | |
| 868 | + |> reload_issue()} | |
| 869 | + end | |
| 870 | + | |
| 871 | + def handle_info({:issue_updated, _}, socket), do: {:noreply, reload_issue(socket)} | |
| 872 | + def handle_info({:issue_comment, _}, socket), do: {:noreply, load_comments(socket)} | |
| 873 | + def handle_info(_, socket), do: {:noreply, socket} | |
| 16 | 874 | end |
modified
lib/vigil_web/live/share_live/issue.ex
+85
−3
@@ -1,15 +1,97 @@
| 1 | 1 | defmodule VigilWeb.ShareLive.Issue do |
| 2 | − @moduledoc "Placeholder; replaced in slice 3." | |
| 2 | + @moduledoc """ | |
| 3 | + An issue its project's members made public (`Vigil.Issues.set_public/3`), | |
| 4 | + for anyone with the link, signed in or not. Read-only, and deliberately | |
| 5 | + thin: the title, culprit, level, counts and when it was seen, and of the | |
| 6 | + latest event only the exception, stack trace and message | |
| 7 | + (`VigilWeb.EventComponents.event_body/1` with `public`). The request, | |
| 8 | + user, breadcrumbs, contexts, extra, tags and frame variables stay | |
| 9 | + private: they may hold personal data. An issue that isn't public (or | |
| 10 | + doesn't exist) answers the same "not found". | |
| 11 | + """ | |
| 3 | 12 | use VigilWeb, :live_view |
| 4 | 13 | |
| 14 | + import VigilWeb.EventComponents | |
| 15 | + | |
| 16 | + alias Vigil.Issues | |
| 17 | + | |
| 5 | 18 | @impl true |
| 6 | − def mount(_params, _session, socket), do: {:ok, socket} | |
| 19 | + def mount(%{"id" => id}, _session, socket) do | |
| 20 | + case Issues.get_public_issue(id) do | |
| 21 | + nil -> | |
| 22 | + {:ok, socket |> assign(:issue, nil) |> assign(:page_title, "Not found")} | |
| 23 | + | |
| 24 | + issue -> | |
| 25 | + {:ok, | |
| 26 | + socket | |
| 27 | + |> assign(:issue, issue) | |
| 28 | + |> assign(:event, Issues.latest_event(issue)) | |
| 29 | + |> assign(:page_title, issue.title)} | |
| 30 | + end | |
| 31 | + end | |
| 7 | 32 | |
| 8 | 33 | @impl true |
| 9 | 34 | def render(assigns) do |
| 10 | 35 | ~H""" |
| 11 | 36 | <Layouts.app flash={@flash} current_scope={@current_scope}> |
| 12 | − <p id="placeholder">Coming in slice 3.</p> | |
| 37 | + <%= if @issue do %> | |
| 38 | + <header id="share-header" class="space-y-4"> | |
| 39 | + <div class="flex flex-wrap items-center gap-2 text-sm"> | |
| 40 | + <span class="rounded-md bg-base-200 px-2 py-0.5 font-mono text-xs font-semibold"> | |
| 41 | + {String.upcase(@issue.project.slug)}-{@issue.short_id} | |
| 42 | + </span> | |
| 43 | + <.level_badge level={@issue.level} /> | |
| 44 | + <span class="badge badge-ghost badge-sm">{@issue.status}</span> | |
| 45 | + <span class="ml-auto inline-flex items-center gap-1 text-xs text-base-content/50"> | |
| 46 | + <.icon name="hero-globe-alt-micro" class="size-3.5" /> Shared issue | |
| 47 | + </span> | |
| 48 | + </div> | |
| 49 | + <div class="flex gap-3"> | |
| 50 | + <span class={["mt-1.5 w-1 shrink-0 self-stretch rounded-full", level_dot(@issue.level)]} /> | |
| 51 | + <div class="min-w-0"> | |
| 52 | + <h1 id="share-title" class="break-words text-xl font-semibold sm:text-2xl"> | |
| 53 | + {@issue.title} | |
| 54 | + </h1> | |
| 55 | + <p | |
| 56 | + :if={@issue.culprit not in [nil, ""]} | |
| 57 | + class="mt-1 break-all font-mono text-sm text-base-content/60" | |
| 58 | + > | |
| 59 | + {@issue.culprit} | |
| 60 | + </p> | |
| 61 | + </div> | |
| 62 | + </div> | |
| 63 | + <dl id="share-stats" class="grid grid-cols-3 gap-3 sm:max-w-xl"> | |
| 64 | + <div class="rounded-box border border-base-300 bg-base-100 px-3 py-2"> | |
| 65 | + <dt class="text-xs text-base-content/60">Events</dt> | |
| 66 | + <dd class="text-lg font-semibold tabular-nums">{@issue.count}</dd> | |
| 67 | + </div> | |
| 68 | + <div class="rounded-box border border-base-300 bg-base-100 px-3 py-2"> | |
| 69 | + <dt class="text-xs text-base-content/60">First seen</dt> | |
| 70 | + <dd class="text-lg font-semibold"><.time_ago at={@issue.first_seen} /></dd> | |
| 71 | + </div> | |
| 72 | + <div class="rounded-box border border-base-300 bg-base-100 px-3 py-2"> | |
| 73 | + <dt class="text-xs text-base-content/60">Last seen</dt> | |
| 74 | + <dd class="text-lg font-semibold"><.time_ago at={@issue.last_seen} /></dd> | |
| 75 | + </div> | |
| 76 | + </dl> | |
| 77 | + </header> | |
| 78 | + | |
| 79 | + <.event_body :if={@event} id="share-event" event={@event} public /> | |
| 80 | + <p :if={!@event} id="share-no-event" class="text-sm text-base-content/60"> | |
| 81 | + This issue's events have aged out. | |
| 82 | + </p> | |
| 83 | + <% else %> | |
| 84 | + <div | |
| 85 | + id="share-not-found" | |
| 86 | + class="mx-auto max-w-md rounded-box border border-dashed border-base-300 p-10 text-center" | |
| 87 | + > | |
| 88 | + <.icon name="hero-eye-slash" class="mx-auto size-8 text-base-content/40" /> | |
| 89 | + <h1 class="mt-3 font-semibold">Not found, or not public</h1> | |
| 90 | + <p class="mt-1 text-sm text-base-content/60"> | |
| 91 | + This issue doesn't exist, or its project no longer shares it. | |
| 92 | + </p> | |
| 93 | + </div> | |
| 94 | + <% end %> | |
| 13 | 95 | </Layouts.app> |
| 14 | 96 | """ |
| 15 | 97 | end |
added
test/vigil_web/components/event_components_test.exs
+198
−0
@@ -0,0 +1,198 @@
| 1 | +defmodule VigilWeb.EventComponentsTest do | |
| 2 | + use ExUnit.Case, async: true | |
| 3 | + | |
| 4 | + import Phoenix.LiveViewTest, only: [rendered_to_string: 1] | |
| 5 | + import Phoenix.Component, only: [sigil_H: 2] | |
| 6 | + | |
| 7 | + alias VigilWeb.EventComponents | |
| 8 | + | |
| 9 | + defp render_event(data, opts \\ []) do | |
| 10 | + assigns = %{ | |
| 11 | + event: %{data: data, tags: Keyword.get(opts, :tags, %{})}, | |
| 12 | + public: Keyword.get(opts, :public, false) | |
| 13 | + } | |
| 14 | + | |
| 15 | + ~H""" | |
| 16 | + <EventComponents.event_body id="ev" event={@event} public={@public} /> | |
| 17 | + """ | |
| 18 | + |> rendered_to_string() | |
| 19 | + |> LazyHTML.from_fragment() | |
| 20 | + end | |
| 21 | + | |
| 22 | + defp count(doc, selector), do: doc |> LazyHTML.query(selector) |> Enum.count() | |
| 23 | + defp text(doc, selector), do: doc |> LazyHTML.query(selector) |> LazyHTML.text() | |
| 24 | + | |
| 25 | + test "the chain shows the raised exception first, then causes" do | |
| 26 | + doc = | |
| 27 | + render_event(%{ | |
| 28 | + "exception" => %{ | |
| 29 | + "values" => [ | |
| 30 | + %{"type" => "Root", "value" => "first"}, | |
| 31 | + %{"type" => "Top", "value" => "last", "mechanism" => %{"handled" => true}} | |
| 32 | + ] | |
| 33 | + } | |
| 34 | + }) | |
| 35 | + | |
| 36 | + assert text(doc, "#ev-exceptions-0") =~ "Top" | |
| 37 | + assert text(doc, "#ev-exceptions-0") =~ "handled" | |
| 38 | + assert text(doc, "#ev-exceptions-1") =~ "Caused by" | |
| 39 | + assert text(doc, "#ev-exceptions-1") =~ "Root" | |
| 40 | + end | |
| 41 | + | |
| 42 | + test "frames: most recent first; no in-app frame means all are shown" do | |
| 43 | + frames = for n <- 1..3, do: %{"filename" => "lib#{n}.py", "lineno" => n, "in_app" => false} | |
| 44 | + | |
| 45 | + doc = | |
| 46 | + render_event(%{"exception" => [%{"type" => "E", "stacktrace" => %{"frames" => frames}}]}) | |
| 47 | + | |
| 48 | + assert text(doc, "#ev-exceptions-0-st-f0") =~ "lib3.py" | |
| 49 | + assert text(doc, "#ev-exceptions-0-st-f2") =~ "lib1.py" | |
| 50 | + assert count(doc, "[id^='ev-exceptions-0-st-more']") == 0 | |
| 51 | + end | |
| 52 | + | |
| 53 | + test "raw stack trace toggle and source context with line numbers" do | |
| 54 | + frame = %{ | |
| 55 | + "filename" => "app.py", | |
| 56 | + "lineno" => 10, | |
| 57 | + "colno" => 4, | |
| 58 | + "in_app" => true, | |
| 59 | + "pre_context" => ["a", "b"], | |
| 60 | + "context_line" => "boom()", | |
| 61 | + "post_context" => ["c"] | |
| 62 | + } | |
| 63 | + | |
| 64 | + doc = | |
| 65 | + render_event(%{ | |
| 66 | + "exception" => %{ | |
| 67 | + "values" => [ | |
| 68 | + %{ | |
| 69 | + "type" => "E", | |
| 70 | + "stacktrace" => %{"frames" => [frame]}, | |
| 71 | + "raw_stacktrace" => %{"frames" => [%{frame | "filename" => "app.min.js"}]} | |
| 72 | + } | |
| 73 | + ] | |
| 74 | + } | |
| 75 | + }) | |
| 76 | + | |
| 77 | + assert count(doc, "#ev-exceptions-0-raw-toggle") == 1 | |
| 78 | + assert text(doc, "#ev-exceptions-0-raw.hidden") =~ "app.min.js" | |
| 79 | + assert text(doc, "#ev-exceptions-0-st-f0 summary") =~ "10:4" | |
| 80 | + context = text(doc, "#ev-exceptions-0-st-f0 ol") | |
| 81 | + assert context =~ "8" and context =~ "10" and context =~ "boom()" | |
| 82 | + end | |
| 83 | + | |
| 84 | + test "odd and malformed data renders without crashing" do | |
| 85 | + odd = [ | |
| 86 | + %{}, | |
| 87 | + %{"exception" => nil}, | |
| 88 | + %{"exception" => "boom"}, | |
| 89 | + %{"exception" => %{"values" => "nope"}}, | |
| 90 | + %{"exception" => %{"values" => [nil, 3, %{"type" => 5, "value" => %{"a" => 1}}]}}, | |
| 91 | + %{"exception" => [%{"stacktrace" => %{"frames" => [nil, "x", %{"lineno" => "12"}]}}]}, | |
| 92 | + %{ | |
| 93 | + "exception" => [ | |
| 94 | + %{ | |
| 95 | + "stacktrace" => %{ | |
| 96 | + "frames" => [ | |
| 97 | + %{ | |
| 98 | + "in_app" => true, | |
| 99 | + "pre_context" => [nil, 1, %{"x" => 1}], | |
| 100 | + "context_line" => 7, | |
| 101 | + "vars" => %{"n" => nil, "l" => [1, %{"b" => true}], "f" => 1.5} | |
| 102 | + } | |
| 103 | + ] | |
| 104 | + }, | |
| 105 | + "mechanism" => "string" | |
| 106 | + } | |
| 107 | + ] | |
| 108 | + }, | |
| 109 | + %{ | |
| 110 | + "threads" => %{ | |
| 111 | + "values" => [ | |
| 112 | + %{ | |
| 113 | + "id" => 1, | |
| 114 | + "crashed" => true, | |
| 115 | + "stacktrace" => %{"frames" => [%{"function" => "run"}]} | |
| 116 | + }, | |
| 117 | + %{"id" => 2, "stacktrace" => %{"frames" => [%{}]}} | |
| 118 | + ] | |
| 119 | + } | |
| 120 | + }, | |
| 121 | + %{"threads" => [1, 2]}, | |
| 122 | + %{"stacktrace" => %{"frames" => [%{"filename" => "top.c"}]}}, | |
| 123 | + %{"logentry" => %{"message" => "hi %s", "params" => ["x"]}}, | |
| 124 | + %{"logentry" => 42, "message" => %{"formatted" => "nested"}}, | |
| 125 | + %{"breadcrumbs" => [%{"timestamp" => 1_700_000_000.5, "data" => [1, 2]}, nil, "x"]}, | |
| 126 | + %{"breadcrumbs" => %{"values" => [%{"timestamp" => "garbage", "level" => 3}]}}, | |
| 127 | + %{ | |
| 128 | + "request" => %{ | |
| 129 | + "headers" => %{"A" => "b"}, | |
| 130 | + "data" => "raw body", | |
| 131 | + "query_string" => [["a", "1"]] | |
| 132 | + } | |
| 133 | + }, | |
| 134 | + %{ | |
| 135 | + "request" => %{"headers" => [["only-one"], "x", nil], "env" => "nope", "cookies" => "a=b"} | |
| 136 | + }, | |
| 137 | + %{"user" => %{"geo" => %{"city" => "Oslo"}}, "extra" => %{"n" => nil, "t" => true}}, | |
| 138 | + %{"contexts" => %{"os" => "not a map", "gpu" => %{"name" => 1}}}, | |
| 139 | + %{"sdk" => %{"name" => nil, "integrations" => ["a"]}, "modules" => %{"x" => "1.0"}}, | |
| 140 | + %{"fingerprint" => ["{{ default }}", 1, nil]}, | |
| 141 | + %{"csp" => %{"blocked_uri" => "https://evil.test", "effective_directive" => "script-src"}}, | |
| 142 | + %{"errors" => [%{"type" => "invalid_data", "name" => "timestamp"}, "plain", nil]} | |
| 143 | + ] | |
| 144 | + | |
| 145 | + for data <- odd do | |
| 146 | + doc = render_event(data, tags: %{"k" => 1}) | |
| 147 | + assert count(doc, "#ev") == 1, "failed on #{inspect(data)}" | |
| 148 | + assert count(render_event(data, public: true), "#ev") == 1 | |
| 149 | + end | |
| 150 | + end | |
| 151 | + | |
| 152 | + test "threads: the crashed thread is selected" do | |
| 153 | + doc = | |
| 154 | + render_event(%{ | |
| 155 | + "threads" => %{ | |
| 156 | + "values" => [ | |
| 157 | + %{ | |
| 158 | + "id" => 1, | |
| 159 | + "name" => "main", | |
| 160 | + "stacktrace" => %{"frames" => [%{"function" => "idle"}]} | |
| 161 | + }, | |
| 162 | + %{ | |
| 163 | + "id" => 2, | |
| 164 | + "name" => "worker", | |
| 165 | + "crashed" => true, | |
| 166 | + "stacktrace" => %{"frames" => [%{"function" => "crash_here"}]} | |
| 167 | + } | |
| 168 | + ] | |
| 169 | + } | |
| 170 | + }) | |
| 171 | + | |
| 172 | + assert count(doc, "#ev-threads-t0.hidden") == 1 | |
| 173 | + assert text(doc, "#ev-threads-t1") =~ "crash_here" | |
| 174 | + assert count(doc, "#ev-threads-t1.hidden") == 0 | |
| 175 | + end | |
| 176 | + | |
| 177 | + test "CSP reports, processing errors and the message" do | |
| 178 | + doc = | |
| 179 | + render_event(%{ | |
| 180 | + "csp" => %{"blocked_uri" => "https://evil.test"}, | |
| 181 | + "errors" => [%{"type" => "invalid_data", "name" => "timestamp"}], | |
| 182 | + "logentry" => %{"formatted" => "hello there"} | |
| 183 | + }) | |
| 184 | + | |
| 185 | + assert text(doc, "#ev-csp") =~ "https://evil.test" | |
| 186 | + assert text(doc, "#ev-errors") =~ "invalid_data" | |
| 187 | + assert text(doc, "#ev-message") =~ "hello there" | |
| 188 | + end | |
| 189 | + | |
| 190 | + test "relative_time" do | |
| 191 | + now = DateTime.utc_now() | |
| 192 | + assert EventComponents.relative_time(now) == "just now" | |
| 193 | + assert EventComponents.relative_time(DateTime.add(now, -2, :hour)) == "2h ago" | |
| 194 | + assert EventComponents.relative_time(DateTime.add(now, -3, :day)) == "3d ago" | |
| 195 | + assert EventComponents.relative_time(nil) == "—" | |
| 196 | + assert EventComponents.relative_time("x") == "—" | |
| 197 | + end | |
| 198 | +end |
added
test/vigil_web/live/issue_live/show_test.exs
+458
−0
@@ -0,0 +1,458 @@
| 1 | +defmodule VigilWeb.IssueLive.ShowTest do | |
| 2 | + use VigilWeb.ConnCase, async: true | |
| 3 | + | |
| 4 | + import Phoenix.LiveViewTest | |
| 5 | + import Vigil.AccountsFixtures | |
| 6 | + import Vigil.OrganizationsFixtures | |
| 7 | + | |
| 8 | + alias Vigil.Accounts.Scope | |
| 9 | + alias Vigil.Ingest | |
| 10 | + alias Vigil.Ingest.{Drain, Envelope} | |
| 11 | + alias Vigil.Issues | |
| 12 | + | |
| 13 | + setup :register_and_log_in_user | |
| 14 | + | |
| 15 | + setup %{user: user} do | |
| 16 | + org = organization_fixture(user) | |
| 17 | + scope = org_scope(user, org) | |
| 18 | + project = project_fixture(scope, %{"name" => "Shop", "slug" => "shop"}) | |
| 19 | + | |
| 20 | + target = %Vigil.Ingest.Target{ | |
| 21 | + project_id: project.id, | |
| 22 | + dsn_id: project.dsn_id, | |
| 23 | + organization_id: org.id, | |
| 24 | + key_id: Ecto.UUID.generate() | |
| 25 | + } | |
| 26 | + | |
| 27 | + %{org: org, scope: scope, project: project, target: target} | |
| 28 | + end | |
| 29 | + | |
| 30 | + defp send_items(target, items) do | |
| 31 | + items = | |
| 32 | + Enum.map(items, fn {type, payload} -> | |
| 33 | + %Envelope.Item{type: type, headers: %{"type" => type}, payload: Jason.encode!(payload)} | |
| 34 | + end) | |
| 35 | + | |
| 36 | + Ingest.accept(target, %{headers: %{}, items: items}, %{client_ip: "203.0.113.7"}) | |
| 37 | + Drain.drain(target.project_id) | |
| 38 | + end | |
| 39 | + | |
| 40 | + defp event(extra \\ %{}) do | |
| 41 | + Map.merge( | |
| 42 | + %{ | |
| 43 | + "event_id" => Vigil.Schema.uuid7() |> String.replace("-", ""), | |
| 44 | + "platform" => "python", | |
| 45 | + "level" => "error", | |
| 46 | + "environment" => "production", | |
| 47 | + "release" => "shop@1.4.2", | |
| 48 | + "tags" => %{"browser" => "Firefox", "region" => "eu-west"}, | |
| 49 | + "exception" => %{ | |
| 50 | + "values" => [ | |
| 51 | + %{ | |
| 52 | + "type" => "ConnectionError", | |
| 53 | + "value" => "db went away", | |
| 54 | + "stacktrace" => %{"frames" => [frame("db/pool.py", "checkout", 88, false)]} | |
| 55 | + }, | |
| 56 | + %{ | |
| 57 | + "type" => "CheckoutFailed", | |
| 58 | + "value" => "could not take payment for order 42", | |
| 59 | + "mechanism" => %{"type" => "excepthook", "handled" => false}, | |
| 60 | + "stacktrace" => %{ | |
| 61 | + "frames" => [ | |
| 62 | + frame("site-packages/flask/app.py", "dispatch", 1820, false), | |
| 63 | + frame("site-packages/flask/app.py", "full_dispatch", 1799, false), | |
| 64 | + frame("shop/views.py", "checkout", 41, true), | |
| 65 | + frame("shop/payments.py", "charge", 17, true) | |
| 66 | + ] | |
| 67 | + } | |
| 68 | + } | |
| 69 | + ] | |
| 70 | + }, | |
| 71 | + "breadcrumbs" => %{ | |
| 72 | + "values" => [ | |
| 73 | + %{ | |
| 74 | + "timestamp" => "2026-11-30T10:00:00Z", | |
| 75 | + "category" => "http", | |
| 76 | + "level" => "info", | |
| 77 | + "data" => %{"url" => "/cart", "status_code" => 200} | |
| 78 | + }, | |
| 79 | + %{ | |
| 80 | + "timestamp" => "2026-11-30T10:00:01Z", | |
| 81 | + "category" => "query", | |
| 82 | + "level" => "warning", | |
| 83 | + "message" => "SELECT * FROM orders WHERE id = 42" | |
| 84 | + } | |
| 85 | + ] | |
| 86 | + }, | |
| 87 | + "request" => %{ | |
| 88 | + "url" => "https://shop.example/checkout", | |
| 89 | + "method" => "POST", | |
| 90 | + "query_string" => "step=pay", | |
| 91 | + "headers" => [["User-Agent", "Mozilla/5.0"], ["X-Request-Id", "req-7781"]], | |
| 92 | + "data" => %{"order" => 42} | |
| 93 | + }, | |
| 94 | + "user" => %{"id" => "u-99", "email" => "buyer@example.test"}, | |
| 95 | + "contexts" => %{ | |
| 96 | + "runtime" => %{"name" => "CPython", "version" => "3.12.1"}, | |
| 97 | + "os" => %{"name" => "Linux", "version" => "6.8"} | |
| 98 | + }, | |
| 99 | + "extra" => %{"cart_size" => 3} | |
| 100 | + }, | |
| 101 | + extra | |
| 102 | + ) | |
| 103 | + end | |
| 104 | + | |
| 105 | + defp frame(file, function, line, in_app) do | |
| 106 | + %{ | |
| 107 | + "filename" => file, | |
| 108 | + "function" => function, | |
| 109 | + "lineno" => line, | |
| 110 | + "in_app" => in_app, | |
| 111 | + "context_line" => " result = #{function}(order)", | |
| 112 | + "pre_context" => ["def #{function}_wrapper(order):", " log(order)"], | |
| 113 | + "post_context" => [" return result"], | |
| 114 | + "vars" => %{"order" => "<Order 42>", "attempt" => 2} | |
| 115 | + } | |
| 116 | + end | |
| 117 | + | |
| 118 | + defp issue(project), do: hd(Issues.list_issues(project.id, status: :all)) | |
| 119 | + | |
| 120 | + defp issue_path(org, project, issue), | |
| 121 | + do: ~p"/orgs/#{org.slug}/projects/#{project.slug}/issues/#{issue.short_id}" | |
| 122 | + | |
| 123 | + defp open_issue(conn, org, project) do | |
| 124 | + issue = issue(project) | |
| 125 | + {:ok, view, _html} = live(conn, issue_path(org, project, issue)) | |
| 126 | + {view, issue} | |
| 127 | + end | |
| 128 | + | |
| 129 | + describe "rendering" do | |
| 130 | + setup %{target: target} do | |
| 131 | + send_items(target, [{"event", event()}]) | |
| 132 | + :ok | |
| 133 | + end | |
| 134 | + | |
| 135 | + test "header, stats and the event's interfaces", %{ | |
| 136 | + conn: conn, | |
| 137 | + org: org, | |
| 138 | + project: project, | |
| 139 | + target: target | |
| 140 | + } do | |
| 141 | + shown = Issues.latest_event(issue(project)) | |
| 142 | + | |
| 143 | + send_items(target, [ | |
| 144 | + {"user_report", | |
| 145 | + %{ | |
| 146 | + "event_id" => shown.event_id, | |
| 147 | + "name" => "Ann", | |
| 148 | + "email" => "a@x.test", | |
| 149 | + "comments" => "it broke" | |
| 150 | + }} | |
| 151 | + ]) | |
| 152 | + | |
| 153 | + {view, issue} = open_issue(conn, org, project) | |
| 154 | + assert has_element?(view, "#stat-feedback", "1") | |
| 155 | + assert has_element?(view, "#user-reports", "it broke") | |
| 156 | + | |
| 157 | + assert has_element?(view, "#issue-header #copy-short-id", "SHOP-#{issue.short_id}") | |
| 158 | + assert has_element?(view, "#issue-title", "CheckoutFailed") | |
| 159 | + assert has_element?(view, "#stat-events", "1") | |
| 160 | + assert has_element?(view, "#stat-first-release", "shop@1.4.2") | |
| 161 | + assert has_element?(view, "#status-badge", "unresolved") | |
| 162 | + | |
| 163 | + # The raised exception first, then its cause. | |
| 164 | + assert has_element?(view, "[id$='-exceptions-0']", "CheckoutFailed") | |
| 165 | + assert has_element?(view, "[id$='-exceptions-0']", "unhandled") | |
| 166 | + assert has_element?(view, "[id$='-exceptions-1']", "Caused by") | |
| 167 | + assert has_element?(view, "[id$='-exceptions-1']", "ConnectionError") | |
| 168 | + | |
| 169 | + # Most recent in-app frame first and open, with its source and vars. | |
| 170 | + assert has_element?(view, "[id$='-exceptions-0-st-f0'][open]", "shop/payments.py") | |
| 171 | + assert has_element?(view, "[id$='-exceptions-0-st-f0']", "result = charge(order)") | |
| 172 | + assert has_element?(view, "[id$='-exceptions-0-st-f0-vars']", "attempt") | |
| 173 | + # Library frames folded behind a toggle. | |
| 174 | + assert has_element?(view, "[id$='-exceptions-0-st-more2']", "Show 2 more frames") | |
| 175 | + assert has_element?(view, "[id$='-exceptions-0-st-group2'].hidden", "flask/app.py") | |
| 176 | + | |
| 177 | + assert has_element?(view, "[id$='-breadcrumbs']", "SELECT * FROM orders") | |
| 178 | + assert has_element?(view, "[id$='-request']", "https://shop.example/checkout") | |
| 179 | + assert has_element?(view, "[id$='-request-headers-table']", "X-Request-Id") | |
| 180 | + assert has_element?(view, "[id$='-user']", "buyer@example.test") | |
| 181 | + assert has_element?(view, "[id$='-contexts'] [data-context='runtime']", "CPython") | |
| 182 | + assert has_element?(view, "[id$='-extra']", "cart_size") | |
| 183 | + assert has_element?(view, "[id$='-tags'] [data-tag='region']", "eu-west") | |
| 184 | + assert has_element?(view, "[id$='-json-pre']", "ConnectionError") | |
| 185 | + | |
| 186 | + assert has_element?(view, "#tag-facets [data-key='browser']", "Firefox") | |
| 187 | + assert has_element?(view, "#tag-facets [data-key='browser']", "100%") | |
| 188 | + assert has_element?(view, "#event-position", "Event 1 of 1") | |
| 189 | + assert has_element?(view, "#event-nav", "shop@1.4.2") | |
| 190 | + assert has_element?(view, "#event-nav", "production") | |
| 191 | + end | |
| 192 | + | |
| 193 | + test "without event:write the context refuses; without event:admin no delete", %{ | |
| 194 | + project: project, | |
| 195 | + scope: scope | |
| 196 | + } do | |
| 197 | + issue = issue(project) |> Issues.preload_detail() | |
| 198 | + read_only = Scope.with_token(scope, nil, ["event:read"]) | |
| 199 | + refute Scope.can?(read_only, "event:write") | |
| 200 | + | |
| 201 | + # The page renders the actions only with event:write; and the context refuses. | |
| 202 | + assert {:error, :forbidden} = Issues.resolve(read_only, issue) | |
| 203 | + | |
| 204 | + html = | |
| 205 | + render_component(&VigilWeb.IssueLive.Show.issue_actions/1, | |
| 206 | + issue: issue, | |
| 207 | + can_admin?: false, | |
| 208 | + assign_form: Phoenix.Component.to_form(%{"user_id" => ""}, as: :assign), | |
| 209 | + assign_options: [{"Nobody", ""}], | |
| 210 | + share_url: "http://x/share" | |
| 211 | + ) | |
| 212 | + | |
| 213 | + doc = LazyHTML.from_fragment(html) | |
| 214 | + assert LazyHTML.query(doc, "#resolve") |> Enum.count() == 1 | |
| 215 | + assert LazyHTML.query(doc, "#delete-issue") |> Enum.count() == 0 | |
| 216 | + end | |
| 217 | + | |
| 218 | + test "a member (event:admin) can delete", %{ | |
| 219 | + conn: conn, | |
| 220 | + org: org, | |
| 221 | + project: project, | |
| 222 | + scope: scope | |
| 223 | + } do | |
| 224 | + member = user_fixture() | |
| 225 | + member_fixture(org, member, :member) | |
| 226 | + {:ok, _} = Vigil.Organizations.update_organization(scope, org, %{open_membership: true}) | |
| 227 | + | |
| 228 | + conn = log_in_user(conn, member) | |
| 229 | + {view, _issue} = open_issue(conn, org, project) | |
| 230 | + assert has_element?(view, "#resolve") | |
| 231 | + assert has_element?(view, "#delete-issue") | |
| 232 | + end | |
| 233 | + end | |
| 234 | + | |
| 235 | + test "pages through three events", %{conn: conn, org: org, project: project, target: target} do | |
| 236 | + for n <- 1..3, do: send_items(target, [{"event", event(%{"tags" => %{"n" => "#{n}"}})}]) | |
| 237 | + {view, issue} = open_issue(conn, org, project) | |
| 238 | + [newest, middle, oldest] = Issues.list_events(issue) | |
| 239 | + | |
| 240 | + assert has_element?(view, "#event-position", "Event 1 of 3") | |
| 241 | + assert has_element?(view, "#event-newer.btn-disabled") | |
| 242 | + base = issue_path(org, project, issue) | |
| 243 | + | |
| 244 | + view |> element("#event-older") |> render_click() | |
| 245 | + assert_patch(view, "#{base}/events/#{middle.id}") | |
| 246 | + assert has_element?(view, "#event-position", "Event 2 of 3") | |
| 247 | + | |
| 248 | + view |> element("#event-oldest") |> render_click() | |
| 249 | + assert_patch(view, "#{base}/events/#{oldest.id}") | |
| 250 | + assert has_element?(view, "#event-older.btn-disabled") | |
| 251 | + assert has_element?(view, "#event-id", oldest.event_id) | |
| 252 | + | |
| 253 | + view |> element("#event-newer") |> render_click() | |
| 254 | + assert_patch(view, "#{base}/events/#{middle.id}") | |
| 255 | + | |
| 256 | + view |> element("#event-newest") |> render_click() | |
| 257 | + assert_patch(view, "#{base}/events/#{newest.id}") | |
| 258 | + assert has_element?(view, "#event-position", "Event 1 of 3") | |
| 259 | + end | |
| 260 | + | |
| 261 | + test "keyboard: j/k page, r/u/i triage", %{ | |
| 262 | + conn: conn, | |
| 263 | + org: org, | |
| 264 | + project: project, | |
| 265 | + target: target | |
| 266 | + } do | |
| 267 | + for _ <- 1..2, do: send_items(target, [{"event", event()}]) | |
| 268 | + {view, issue} = open_issue(conn, org, project) | |
| 269 | + [_newest, older] = Issues.list_events(issue) | |
| 270 | + base = issue_path(org, project, issue) | |
| 271 | + | |
| 272 | + assert has_element?(view, "#issue-keys") | |
| 273 | + render_hook(view, "key", %{"key" => "j"}) | |
| 274 | + assert_patch(view, "#{base}/events/#{older.id}") | |
| 275 | + render_hook(view, "key", %{"key" => "k"}) | |
| 276 | + assert_patch(view, "#{base}/events/#{hd(Issues.list_events(issue)).id}") | |
| 277 | + | |
| 278 | + render_hook(view, "key", %{"key" => "r"}) | |
| 279 | + assert Issues.get_issue(project.id, issue.id).status == :resolved | |
| 280 | + render_hook(view, "key", %{"key" => "u"}) | |
| 281 | + assert Issues.get_issue(project.id, issue.id).status == :unresolved | |
| 282 | + render_hook(view, "key", %{"key" => "i"}) | |
| 283 | + assert Issues.get_issue(project.id, issue.id).status == :ignored | |
| 284 | + assert has_element?(view, "#status-badge", "ignored") | |
| 285 | + end | |
| 286 | + | |
| 287 | + describe "triage" do | |
| 288 | + setup %{target: target} do | |
| 289 | + send_items(target, [{"event", event()}]) | |
| 290 | + :ok | |
| 291 | + end | |
| 292 | + | |
| 293 | + test "resolve, unresolve, ignore", %{conn: conn, org: org, project: project} do | |
| 294 | + {view, issue} = open_issue(conn, org, project) | |
| 295 | + | |
| 296 | + view |> element("#resolve") |> render_click() | |
| 297 | + assert has_element?(view, "#status-badge", "resolved") | |
| 298 | + assert has_element?(view, "#unresolve") | |
| 299 | + refute has_element?(view, "#resolve") | |
| 300 | + | |
| 301 | + view |> element("#unresolve") |> render_click() | |
| 302 | + assert has_element?(view, "#status-badge", "unresolved") | |
| 303 | + | |
| 304 | + view |> element("#resolve-latest") |> render_click() | |
| 305 | + | |
| 306 | + assert %{status: :resolved, resolved_in_release_id: rid} = | |
| 307 | + Issues.get_issue(project.id, issue.id) | |
| 308 | + | |
| 309 | + assert rid | |
| 310 | + assert has_element?(view, "#resolved-note", "shop@1.4.2") | |
| 311 | + | |
| 312 | + view |> element("#unresolve") |> render_click() | |
| 313 | + view |> element("#ignore") |> render_click() | |
| 314 | + assert Issues.get_issue(project.id, issue.id).status == :ignored | |
| 315 | + end | |
| 316 | + | |
| 317 | + test "assign to a member and to nobody", %{conn: conn, org: org, project: project, user: user} do | |
| 318 | + {view, issue} = open_issue(conn, org, project) | |
| 319 | + pal = member_fixture(org).user | |
| 320 | + | |
| 321 | + # The new member shows up in the select after a re-mount. | |
| 322 | + {:ok, view2, _} = live(conn, issue_path(org, project, issue)) | |
| 323 | + | |
| 324 | + view2 |> form("#assign-form", assign: %{user_id: pal.id}) |> render_change() | |
| 325 | + assert Issues.get_issue(project.id, issue.id).assignee_id == pal.id | |
| 326 | + assert has_element?(view2, "#assignee-badge", pal.email) | |
| 327 | + | |
| 328 | + view |> form("#assign-form", assign: %{user_id: user.id}) |> render_change() | |
| 329 | + assert Issues.get_issue(project.id, issue.id).assignee_id == user.id | |
| 330 | + | |
| 331 | + view |> form("#assign-form", assign: %{user_id: ""}) |> render_change() | |
| 332 | + assert Issues.get_issue(project.id, issue.id).assignee_id == nil | |
| 333 | + refute has_element?(view, "#assignee-badge") | |
| 334 | + end | |
| 335 | + | |
| 336 | + test "share toggle shows the link", %{conn: conn, org: org, project: project} do | |
| 337 | + {view, issue} = open_issue(conn, org, project) | |
| 338 | + refute has_element?(view, "#share-url") | |
| 339 | + | |
| 340 | + view |> element("#share-toggle") |> render_click() | |
| 341 | + assert Issues.get_issue(project.id, issue.id).is_public | |
| 342 | + url = VigilWeb.base_url() <> "/share/issues/#{issue.id}" | |
| 343 | + assert has_element?(view, "#share-url[value='#{url}']") | |
| 344 | + | |
| 345 | + view |> element("#share-toggle") |> render_click() | |
| 346 | + refute Issues.get_issue(project.id, issue.id).is_public | |
| 347 | + refute has_element?(view, "#share-url") | |
| 348 | + end | |
| 349 | + | |
| 350 | + test "delete goes back to the list", %{conn: conn, org: org, project: project} do | |
| 351 | + {view, issue} = open_issue(conn, org, project) | |
| 352 | + view |> element("#delete-issue") |> render_click() | |
| 353 | + assert_redirect(view, ~p"/orgs/#{org.slug}/projects/#{project.slug}") | |
| 354 | + refute Issues.get_issue(project.id, issue.id) | |
| 355 | + end | |
| 356 | + | |
| 357 | + test "comments: add and delete", %{conn: conn, org: org, project: project, user: user} do | |
| 358 | + {view, issue} = open_issue(conn, org, project) | |
| 359 | + | |
| 360 | + view |> form("#comment-form", comment: %{text: ""}) |> render_change() | |
| 361 | + view |> form("#comment-form", comment: %{text: "Looking into it"}) |> render_submit() | |
| 362 | + | |
| 363 | + [comment] = Issues.list_comments(issue) | |
| 364 | + assert has_element?(view, "#comments-#{comment.id}", "Looking into it") | |
| 365 | + assert has_element?(view, "#comments-#{comment.id}", user.email) | |
| 366 | + | |
| 367 | + view |> element("#delete-comments-#{comment.id}") |> render_click() | |
| 368 | + refute has_element?(view, "#comments-#{comment.id}") | |
| 369 | + assert Issues.list_comments(issue) == [] | |
| 370 | + end | |
| 371 | + | |
| 372 | + test "another member's comment can't be deleted by a plain member", %{ | |
| 373 | + conn: conn, | |
| 374 | + org: org, | |
| 375 | + project: project, | |
| 376 | + scope: scope | |
| 377 | + } do | |
| 378 | + issue = issue(project) | |
| 379 | + {:ok, _} = Issues.add_comment(scope, issue, %{"text" => "owner's note"}) | |
| 380 | + member = user_fixture() | |
| 381 | + member_fixture(org, member, :member) | |
| 382 | + {:ok, _} = Vigil.Organizations.update_organization(scope, org, %{open_membership: true}) | |
| 383 | + | |
| 384 | + {view, _} = open_issue(log_in_user(conn, member), org, project) | |
| 385 | + [comment] = Issues.list_comments(issue) | |
| 386 | + assert has_element?(view, "#comments-#{comment.id}", "owner's note") | |
| 387 | + refute has_element?(view, "#delete-comments-#{comment.id}") | |
| 388 | + end | |
| 389 | + end | |
| 390 | + | |
| 391 | + describe "live updates" do | |
| 392 | + setup %{target: target} do | |
| 393 | + send_items(target, [{"event", event()}]) | |
| 394 | + :ok | |
| 395 | + end | |
| 396 | + | |
| 397 | + test "a new event shows the pill and bumps the stats", %{ | |
| 398 | + conn: conn, | |
| 399 | + org: org, | |
| 400 | + project: project, | |
| 401 | + target: target | |
| 402 | + } do | |
| 403 | + {view, issue} = open_issue(conn, org, project) | |
| 404 | + refute has_element?(view, "#new-events-pill") | |
| 405 | + shown = Issues.latest_event(issue) | |
| 406 | + | |
| 407 | + send_items(target, [{"event", event()}]) | |
| 408 | + _ = :sys.get_state(view.pid) | |
| 409 | + _ = render(view) | |
| 410 | + | |
| 411 | + assert has_element?(view, "#new-events-pill", "1 new event") | |
| 412 | + assert has_element?(view, "#stat-events", "2") | |
| 413 | + assert has_element?(view, "#event-id", shown.event_id) | |
| 414 | + assert has_element?(view, "#event-position", "Event 2 of 2") | |
| 415 | + | |
| 416 | + view |> element("#new-events-pill") |> render_click() | |
| 417 | + assert_patch(view, issue_path(org, project, issue)) | |
| 418 | + refute has_element?(view, "#new-events-pill") | |
| 419 | + assert has_element?(view, "#event-position", "Event 1 of 2") | |
| 420 | + end | |
| 421 | + | |
| 422 | + test "comments and status changes by others appear", %{ | |
| 423 | + conn: conn, | |
| 424 | + org: org, | |
| 425 | + project: project, | |
| 426 | + scope: scope | |
| 427 | + } do | |
| 428 | + {view, issue} = open_issue(conn, org, project) | |
| 429 | + {:ok, _} = Issues.add_comment(scope, issue, %{"text" => "from elsewhere"}) | |
| 430 | + {:ok, _} = Issues.ignore(scope, issue) | |
| 431 | + _ = :sys.get_state(view.pid) | |
| 432 | + | |
| 433 | + assert has_element?(view, "#comments", "from elsewhere") | |
| 434 | + assert has_element?(view, "#status-badge", "ignored") | |
| 435 | + end | |
| 436 | + end | |
| 437 | + | |
| 438 | + test "an unknown short id goes back to the list", %{conn: conn, org: org, project: project} do | |
| 439 | + list = ~p"/orgs/#{org.slug}/projects/#{project.slug}" | |
| 440 | + | |
| 441 | + assert {:error, {:live_redirect, %{to: ^list, flash: %{"error" => _}}}} = | |
| 442 | + live(conn, ~p"/orgs/#{org.slug}/projects/#{project.slug}/issues/999") | |
| 443 | + end | |
| 444 | + | |
| 445 | + test "an unknown event id goes back to the list", %{ | |
| 446 | + conn: conn, | |
| 447 | + org: org, | |
| 448 | + project: project, | |
| 449 | + target: target | |
| 450 | + } do | |
| 451 | + send_items(target, [{"event", event()}]) | |
| 452 | + issue = issue(project) | |
| 453 | + list = ~p"/orgs/#{org.slug}/projects/#{project.slug}" | |
| 454 | + | |
| 455 | + assert {:error, {:live_redirect, %{to: ^list}}} = | |
| 456 | + live(conn, issue_path(org, project, issue) <> "/events/#{Ecto.UUID.generate()}") | |
| 457 | + end | |
| 458 | +end |
added
test/vigil_web/live/share_live_test.exs
+99
−0
@@ -0,0 +1,99 @@
| 1 | +defmodule VigilWeb.ShareLiveTest do | |
| 2 | + use VigilWeb.ConnCase, async: true | |
| 3 | + | |
| 4 | + import Phoenix.LiveViewTest | |
| 5 | + import Vigil.AccountsFixtures | |
| 6 | + import Vigil.OrganizationsFixtures | |
| 7 | + | |
| 8 | + alias Vigil.Ingest | |
| 9 | + alias Vigil.Ingest.{Drain, Envelope} | |
| 10 | + alias Vigil.Issues | |
| 11 | + | |
| 12 | + setup do | |
| 13 | + owner = user_fixture() | |
| 14 | + org = organization_fixture(owner) | |
| 15 | + scope = org_scope(owner, org) | |
| 16 | + project = project_fixture(scope) | |
| 17 | + | |
| 18 | + target = %Vigil.Ingest.Target{ | |
| 19 | + project_id: project.id, | |
| 20 | + dsn_id: project.dsn_id, | |
| 21 | + organization_id: org.id, | |
| 22 | + key_id: Ecto.UUID.generate() | |
| 23 | + } | |
| 24 | + | |
| 25 | + event = %{ | |
| 26 | + "event_id" => Vigil.Schema.uuid7() |> String.replace("-", ""), | |
| 27 | + "platform" => "python", | |
| 28 | + "level" => "error", | |
| 29 | + "exception" => %{ | |
| 30 | + "values" => [ | |
| 31 | + %{ | |
| 32 | + "type" => "KeyError", | |
| 33 | + "value" => "'sku'", | |
| 34 | + "stacktrace" => %{ | |
| 35 | + "frames" => [ | |
| 36 | + %{ | |
| 37 | + "filename" => "shop/cart.py", | |
| 38 | + "function" => "add", | |
| 39 | + "lineno" => 12, | |
| 40 | + "in_app" => true, | |
| 41 | + "context_line" => " sku = item['sku']", | |
| 42 | + "vars" => %{"secret_token" => "s3cr3t"} | |
| 43 | + } | |
| 44 | + ] | |
| 45 | + } | |
| 46 | + } | |
| 47 | + ] | |
| 48 | + }, | |
| 49 | + "logentry" => %{"formatted" => "adding to cart failed"}, | |
| 50 | + "request" => %{"url" => "https://shop.example/cart", "headers" => [["Cookie", "sid=abc"]]}, | |
| 51 | + "user" => %{"email" => "buyer@example.test"}, | |
| 52 | + "breadcrumbs" => %{"values" => [%{"message" => "clicked add"}]}, | |
| 53 | + "tags" => %{"customer" => "acme"} | |
| 54 | + } | |
| 55 | + | |
| 56 | + item = %Envelope.Item{type: "event", headers: %{}, payload: Jason.encode!(event)} | |
| 57 | + Ingest.accept(target, %{headers: %{}, items: [item]}, %{}) | |
| 58 | + Drain.drain(project.id) | |
| 59 | + [issue] = Issues.list_issues(project.id) | |
| 60 | + | |
| 61 | + %{scope: scope, issue: issue} | |
| 62 | + end | |
| 63 | + | |
| 64 | + test "a public issue shows its exception, not its personal data", %{ | |
| 65 | + conn: conn, | |
| 66 | + scope: scope, | |
| 67 | + issue: issue | |
| 68 | + } do | |
| 69 | + {:ok, _} = Issues.set_public(scope, issue, true) | |
| 70 | + {:ok, view, html} = live(conn, ~p"/share/issues/#{issue.id}") | |
| 71 | + | |
| 72 | + assert has_element?(view, "#share-title", "KeyError") | |
| 73 | + assert has_element?(view, "#share-stats") | |
| 74 | + assert has_element?(view, "#share-event-exceptions", "'sku'") | |
| 75 | + assert has_element?(view, "#share-event-exceptions", "shop/cart.py") | |
| 76 | + assert has_element?(view, "#share-event-message", "adding to cart failed") | |
| 77 | + | |
| 78 | + refute has_element?(view, "#share-event-request") | |
| 79 | + refute has_element?(view, "#share-event-user") | |
| 80 | + refute has_element?(view, "#share-event-breadcrumbs") | |
| 81 | + refute has_element?(view, "#share-event-tags") | |
| 82 | + refute has_element?(view, "#share-event-json") | |
| 83 | + refute html =~ "buyer@example.test" | |
| 84 | + refute html =~ "s3cr3t" | |
| 85 | + refute html =~ "sid=abc" | |
| 86 | + refute html =~ "acme" | |
| 87 | + end | |
| 88 | + | |
| 89 | + test "a private issue is not found", %{conn: conn, issue: issue} do | |
| 90 | + {:ok, view, _} = live(conn, ~p"/share/issues/#{issue.id}") | |
| 91 | + assert has_element?(view, "#share-not-found") | |
| 92 | + refute has_element?(view, "#share-title") | |
| 93 | + end | |
| 94 | + | |
| 95 | + test "a bad id is not found", %{conn: conn} do | |
| 96 | + {:ok, view, _} = live(conn, ~p"/share/issues/nope") | |
| 97 | + assert has_element?(view, "#share-not-found") | |
| 98 | + end | |
| 99 | +end |