Slice 3: the issue UI

ce059fe · gmorell · 2026-12-01 22:38

12 files +333 -34
Message
{commit_body(@commit)}

Files changed

modified ROADMAP.md
+7 −1
@@ -275,7 +275,7 @@ libraries to the images.
275 275 - Real sentry-python and sentry-elixir events go all the way into issues in `VigilWeb.SdkConformanceTest`.
276 276 - `mix vigil.test ORG PROJECT` sends test events.
277 277
278 −### 3. Issue UI · large
278 +### 3. Issue UI · large · **done**
279 279 - **Project issue list:**
280 280 - Stream-backed with live inserts.
281 281 - Filters for status, level, environment, release, assignee and time range.
@@ -292,6 +292,12 @@ libraries to the images.
292 292 - **Org dashboard:** projects, recent issues across them, and an events-per-hour chart.
293 293 - **Keyboard navigation** (j/k, e/r/i).
294 294 - **Exit:** daily triage is possible without leaving Vigil.
295 +- **As built:**
296 + - Issue list filters live in the URL (`q`, `status`, `env`, `period`, `sort`, `page`); search is Sentry style (`is:`, `level:`, `env:`, `release:`, `assigned:me`, `key:value` tags, free text). Live updates are coalesced to one a second.
297 + - Issue detail has event navigation, stack traces with system frames folded and source context, and the full interfaces. The share page shows the exception and stack only (no request, user, breadcrumbs, contexts or frame vars).
298 + - The org dashboard has an events-per-hour chart (with a table view), 24h counts per project, and the latest unresolved issues.
299 + - Keyboard shortcuts on the list (j/k/o/x/r/i, /) and on the detail page (r/i/u, j/k events, c). Neither has been tried in a browser yet.
300 + - **Permissions to revisit:** GlitchTip gives every role `event:admin`, so members can delete issues. Comment moderation was narrowed to `project:admin`.
295 301
296 302 ### 4. Alerts and notifications · medium
297 303 - **Rules:** per project, "N events in M minutes", "new issue" and "regression". Recipients are email, a generic webhook (Slack-compatible), Discord, ntfy, Teams, Google Chat and Zulip, with GlitchTip's payload shapes.
modified lib/vigil/issues.ex
+6 −1
@@ -528,7 +528,12 @@ defmodule Vigil.Issues do
528 528 with {:ok, id} <- Ecto.UUID.cast(comment_id),
529 529 %Comment{} = comment <- Repo.get_by(Comment, id: id, issue_id: issue.id),
530 530 true <- comment.user_id == scope.user.id or Scope.can?(scope, "project:admin") do
531 − Repo.delete(comment)
531 + comment
532 + |> Repo.delete()
533 + |> tap(fn
534 + {:ok, c} -> broadcast(issue, {:issue_comment, %{issue_id: issue.id, comment_id: c.id}})
535 + _ -> :ok
536 + end)
532 537 else
533 538 false -> {:error, :forbidden}
534 539 _ -> {:error, :not_found}
modified lib/vigil_web/live/org_live/show.ex
+241 −32
@@ -1,24 +1,65 @@
1 1 defmodule VigilWeb.OrgLive.Show do
2 2 @moduledoc """
3 − An organization's front page: the projects the caller may see. Issues
4 − and activity join this page in later slices.
3 + An organization's front page: events per hour over the last day across
4 + the projects the caller may see, those projects with their own 24-hour
5 + counts, and the latest unresolved issues across them. It follows new
6 + events live (PubSub, per project), refreshing at most once a second.
5 7 """
6 8 use VigilWeb, :live_view
7 9
8 10 alias Vigil.Accounts.Scope
9 − alias Vigil.Projects
11 + alias Vigil.{Issues, Projects}
10 12 alias Vigil.Projects.Platforms
11 13
14 + @refresh_ms 1000
15 +
12 16 @impl true
13 17 def mount(_params, _session, socket) do
14 18 scope = socket.assigns.current_scope
15 19 projects = Projects.list_visible(scope)
16 20
21 + if connected?(socket) do
22 + Enum.each(projects, &Phoenix.PubSub.subscribe(Vigil.PubSub, "project:#{&1.id}:issues"))
23 + end
24 +
17 25 {:ok,
18 26 socket
19 27 |> assign(:page_title, scope.organization.name)
20 − |> assign(:empty?, projects == [])
21 − |> stream(:projects, projects)}
28 + |> assign(:project_ids, Enum.map(projects, & &1.id))
29 + |> assign(:refresh_scheduled?, false)
30 + |> stream(:projects, projects)
31 + |> load()}
32 + end
33 +
34 + defp load(socket) do
35 + ids = socket.assigns.project_ids
36 + hourly = Issues.project_hourly(ids)
37 +
38 + socket
39 + |> assign(:hourly, hourly)
40 + |> assign(:total_24h, hourly |> Enum.map(&elem(&1, 1)) |> Enum.sum())
41 + |> assign(:project_counts, Issues.project_counts_24h(ids))
42 + |> stream(:recent, Issues.recent_across(ids), reset: true)
43 + end
44 +
45 + @impl true
46 + def handle_info({:issue_event, _}, socket), do: {:noreply, schedule_refresh(socket)}
47 + def handle_info({:issue_updated, _}, socket), do: {:noreply, schedule_refresh(socket)}
48 + def handle_info({:issue_comment, _}, socket), do: {:noreply, socket}
49 +
50 + def handle_info(:refresh, socket) do
51 + socket = socket |> assign(:refresh_scheduled?, false) |> load()
52 +
53 + # Project counts show inside streamed cards: re-insert them.
54 + projects = Projects.list_visible(socket.assigns.current_scope)
55 + {:noreply, stream(socket, :projects, projects, reset: true)}
56 + end
57 +
58 + defp schedule_refresh(%{assigns: %{refresh_scheduled?: true}} = socket), do: socket
59 +
60 + defp schedule_refresh(socket) do
61 + Process.send_after(self(), :refresh, @refresh_ms)
62 + assign(socket, :refresh_scheduled?, true)
22 63 end
23 64
24 65 @impl true
@@ -26,12 +67,12 @@ defmodule VigilWeb.OrgLive.Show do
26 67 ~H"""
27 68 <Layouts.app flash={@flash} current_scope={@current_scope} active={:projects}>
28 69 <.header>
29 − Projects
70 + {@current_scope.organization.name}
30 71 <:subtitle>
31 72 <%= if Scope.global?(@current_scope) or @current_scope.organization.open_membership do %>
32 − Every project in {@current_scope.organization.name}.
73 + Every project in the organization.
33 74 <% else %>
34 − The projects of your teams in {@current_scope.organization.name}.
75 + The projects of your teams.
35 76 <% end %>
36 77 </:subtitle>
37 78 <:actions>
@@ -46,33 +87,201 @@ defmodule VigilWeb.OrgLive.Show do
46 87 </:actions>
47 88 </.header>
48 89
49 − <ul id="project-list" phx-update="stream" class="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
50 − <li
51 − id="project-list-empty"
52 − class="hidden rounded-box border border-dashed border-base-300 p-8 text-center text-sm text-base-content/60 only:block sm:col-span-2 lg:col-span-3"
90 + <section
91 + id="events-chart"
92 + class="rounded-box border border-base-300 bg-base-100 p-5"
93 + aria-labelledby="events-chart-title"
94 + >
95 + <div class="flex items-baseline justify-between gap-3">
96 + <h2 id="events-chart-title" class="text-sm font-semibold">
97 + Events per hour, last 24 hours
98 + </h2>
99 + <p class="text-sm text-base-content/70">
100 + <span id="events-total" class="text-2xl font-bold tabular-nums text-base-content">
101 + {format_count(@total_24h)}
102 + </span>
103 + events
104 + </p>
105 + </div>
106 + <.hourly_bars hourly={@hourly} />
107 + </section>
108 +
109 + <div class="grid gap-6 lg:grid-cols-[1fr_22rem]">
110 + <section>
111 + <h2 class="mb-3 text-sm font-semibold">Latest unresolved issues</h2>
112 + <ul
113 + id="recent-issues"
114 + phx-update="stream"
115 + class="divide-y divide-base-300 rounded-box border border-base-300 bg-base-100"
116 + >
117 + <li
118 + id="recent-empty"
119 + class="hidden p-6 text-center text-sm text-base-content/60 only:block"
120 + >
121 + Nothing unresolved. Quiet day.
122 + </li>
123 + <li :for={{dom_id, issue} <- @streams.recent} id={dom_id}>
124 + <.link
125 + navigate={
126 + ~p"/orgs/#{@current_scope.organization.slug}/projects/#{issue.project.slug}/issues/#{issue.short_id}"
127 + }
128 + class="group flex items-center gap-3 px-4 py-3 transition hover:bg-base-200/60"
129 + >
130 + <span
131 + class={["h-8 w-1 shrink-0 rounded-full", level_class(issue.level)]}
132 + aria-hidden="true"
133 + />
134 + <div class="min-w-0 flex-1">
135 + <p class="truncate text-sm font-medium group-hover:text-primary">{issue.title}</p>
136 + <p class="truncate text-xs text-base-content/60">
137 + <span class="font-mono">{String.upcase(issue.project.slug)}-{issue.short_id}</span>
138 + <span :if={issue.culprit}> · {issue.culprit}</span>
139 + </p>
140 + </div>
141 + <div class="shrink-0 text-right text-xs text-base-content/60">
142 + <p class="font-semibold tabular-nums text-base-content">
143 + {format_count(issue.count)}
144 + </p>
145 + <p title={DateTime.to_iso8601(issue.last_seen)}>{relative(issue.last_seen)}</p>
146 + </div>
147 + </.link>
148 + </li>
149 + </ul>
150 + </section>
151 +
152 + <section>
153 + <h2 class="mb-3 text-sm font-semibold">Projects</h2>
154 + <ul id="project-list" phx-update="stream" class="space-y-2">
155 + <li
156 + id="project-list-empty"
157 + class="hidden rounded-box border border-dashed border-base-300 p-6 text-center text-sm text-base-content/60 only:block"
158 + >
159 + No projects to show yet. A project is where one app's errors land.
160 + </li>
161 + <li :for={{dom_id, p} <- @streams.projects} id={dom_id}>
162 + <.link
163 + navigate={~p"/orgs/#{@current_scope.organization.slug}/projects/#{p.slug}"}
164 + class="group flex items-center justify-between gap-3 rounded-box border border-base-300 bg-base-100 px-4 py-3 transition hover:-translate-y-0.5 hover:border-primary/50 hover:shadow-md"
165 + >
166 + <div class="min-w-0">
167 + <p class="truncate font-semibold group-hover:text-primary">{p.name}</p>
168 + <p class="text-xs text-base-content/60">
169 + {Platforms.name(p.platform)}
170 + <span :if={is_nil(p.first_event_at)}> · waiting for its first event</span>
171 + </p>
172 + </div>
173 + <span class="text-right text-xs text-base-content/60">
174 + <span class="block text-base font-semibold tabular-nums text-base-content">
175 + {format_count(Map.get(@project_counts, p.id, 0))}
176 + </span>
177 + 24h
178 + </span>
179 + </.link>
180 + </li>
181 + </ul>
182 + </section>
183 + </div>
184 + </Layouts.app>
185 + """
186 + end
187 +
188 + attr :hourly, :list, required: true
189 +
190 + # One series, so no legend: the section title names it. Thin bars in the
191 + # theme's primary, 4px rounded tops anchored to the baseline, a 2px gap
192 + # between bars; recessive axis (peak and three time marks); a hover
193 + # tooltip per bar with a hit target the full column tall; and the same
194 + # numbers as a table for screen readers and anyone who wants them.
195 + defp hourly_bars(assigns) do
196 + max = assigns.hourly |> Enum.map(&elem(&1, 1)) |> Enum.max(fn -> 0 end)
197 + assigns = assign(assigns, max: max, bars: length(assigns.hourly))
198 +
199 + ~H"""
200 + <div class="mt-4">
201 + <div
202 + class="relative h-32"
203 + role="img"
204 + aria-label={"Events per hour over the last 24 hours, peak #{@max}"}
205 + >
206 + <div class="absolute inset-x-0 bottom-0 border-t border-base-300" aria-hidden="true" />
207 + <span
208 + :if={@max > 0}
209 + class="absolute -top-1 right-0 text-[0.65rem] tabular-nums text-base-content/50"
210 + aria-hidden="true"
53 211 >
54 − No projects to show yet. A project is where one app's errors land.
55 − </li>
56 − <li :for={{dom_id, p} <- @streams.projects} id={dom_id}>
57 − <.link
58 − navigate={~p"/orgs/#{@current_scope.organization.slug}/projects/#{p.slug}"}
59 − class="group block rounded-box border border-base-300 bg-base-100 p-4 transition hover:-translate-y-0.5 hover:border-primary/50 hover:shadow-md"
212 + {format_count(@max)}
213 + </span>
214 + <div class="flex h-full items-end gap-[2px]" id="events-bars">
215 + <div
216 + :for={{{hour, n}, i} <- Enum.with_index(@hourly)}
217 + id={"events-bar-#{i}"}
218 + class="group relative flex h-full flex-1 items-end"
60 219 >
61 − <div class="flex items-center justify-between gap-2">
62 − <p class="truncate font-semibold group-hover:text-primary">{p.name}</p>
63 − <span class="badge badge-ghost badge-sm">{Platforms.name(p.platform)}</span>
220 + <div
221 + class={[
222 + "w-full rounded-t-[4px] transition-colors",
223 + if(n > 0, do: "bg-primary group-hover:bg-primary/80", else: "bg-base-300/60")
224 + ]}
225 + style={"height: #{bar_height(n, @max)}"}
226 + />
227 + <div class="pointer-events-none absolute bottom-full left-1/2 z-10 mb-1 hidden -translate-x-1/2 whitespace-nowrap rounded-box border border-base-300 bg-base-100 px-2 py-1 text-xs shadow-md group-hover:block">
228 + <span class="font-semibold tabular-nums">{n}</span>
229 + at {Calendar.strftime(hour, "%H:00")} UTC
64 230 </div>
65 − <p class="mt-1 text-xs text-base-content/60">
66 − <%= if p.first_event_at do %>
67 − Receiving events
68 − <% else %>
69 − Waiting for its first event
70 − <% end %>
71 − </p>
72 − </.link>
73 − </li>
74 − </ul>
75 − </Layouts.app>
231 + </div>
232 + </div>
233 + </div>
234 + <div class="mt-1 flex justify-between text-[0.65rem] text-base-content/50" aria-hidden="true">
235 + <span :for={{hour, _} <- axis_marks(@hourly)}>{Calendar.strftime(hour, "%H:00")}</span>
236 + </div>
237 + <details class="mt-2 text-xs text-base-content/60">
238 + <summary class="cursor-pointer">Show as a table</summary>
239 + <table id="events-table" class="table table-xs mt-2">
240 + <thead>
241 + <tr>
242 + <th>Hour (UTC)</th><th class="text-right">Events</th>
243 + </tr>
244 + </thead>
245 + <tbody>
246 + <tr :for={{hour, n} <- @hourly}>
247 + <td>{Calendar.strftime(hour, "%Y-%m-%d %H:00")}</td>
248 + <td class="text-right tabular-nums">{n}</td>
249 + </tr>
250 + </tbody>
251 + </table>
252 + </details>
253 + </div>
76 254 """
77 255 end
256 +
257 + defp bar_height(0, _max), do: "2px"
258 + defp bar_height(n, max), do: "max(3px, #{Float.round(n / max * 100, 2)}%)"
259 +
260 + defp axis_marks([]), do: []
261 +
262 + defp axis_marks(hourly) do
263 + n = length(hourly)
264 + [Enum.at(hourly, 0), Enum.at(hourly, div(n, 2)), List.last(hourly)]
265 + end
266 +
267 + defp level_class("fatal"), do: "bg-error"
268 + defp level_class("error"), do: "bg-error/80"
269 + defp level_class("warning"), do: "bg-warning"
270 + defp level_class("info"), do: "bg-info"
271 + defp level_class(_), do: "bg-base-300"
272 +
273 + defp format_count(n) when n >= 1_000_000, do: "#{Float.round(n / 1_000_000, 1)}M"
274 + defp format_count(n) when n >= 10_000, do: "#{div(n, 1000)}k"
275 + defp format_count(n), do: Integer.to_string(n)
276 +
277 + defp relative(%DateTime{} = at) do
278 + seconds = DateTime.diff(DateTime.utc_now(), at)
279 +
280 + cond do
281 + seconds < 60 -> "just now"
282 + seconds < 3600 -> "#{div(seconds, 60)}m ago"
283 + seconds < 86_400 -> "#{div(seconds, 3600)}h ago"
284 + true -> "#{div(seconds, 86_400)}d ago"
285 + end
286 + end
78 287 end
added test/vigil_web/live/org_dashboard_test.exs
+79 −0
@@ -0,0 +1,79 @@
1 +defmodule VigilWeb.OrgDashboardTest 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 +
11 + setup :register_and_log_in_user
12 +
13 + setup %{user: user} do
14 + org = organization_fixture(user)
15 + project = project_fixture(org_scope(user, org), %{"name" => "web"})
16 +
17 + target = %Ingest.Target{
18 + project_id: project.id,
19 + dsn_id: project.dsn_id,
20 + organization_id: org.id,
21 + key_id: Ecto.UUID.generate()
22 + }
23 +
24 + %{org: org, project: project, target: target}
25 + end
26 +
27 + defp send_error(target, type) do
28 + event = %{
29 + "exception" => [%{"type" => type, "value" => "v"}],
30 + "event_id" => Vigil.Schema.uuid7() |> String.replace("-", "")
31 + }
32 +
33 + item = %Envelope.Item{type: "event", headers: %{}, payload: Jason.encode!(event)}
34 + Ingest.accept(target, %{headers: %{}, items: [item]}, %{})
35 + Drain.drain(target.project_id)
36 + end
37 +
38 + test "the chart, totals, projects and recent issues", %{conn: conn, org: org, target: target} do
39 + send_error(target, "KeyError")
40 + send_error(target, "KeyError")
41 +
42 + {:ok, view, _} = live(conn, ~p"/orgs/#{org.slug}")
43 + assert has_element?(view, "#events-total", "2")
44 + assert has_element?(view, "#events-bars #events-bar-23")
45 + assert has_element?(view, "#events-table")
46 + assert has_element?(view, "#recent-issues a", "KeyError: v")
47 + assert has_element?(view, "#project-list a", "web")
48 + end
49 +
50 + test "new events show up live", %{conn: conn, org: org, target: target} do
51 + {:ok, view, _} = live(conn, ~p"/orgs/#{org.slug}")
52 + assert has_element?(view, "#recent-empty")
53 +
54 + send_error(target, "ValueError")
55 + send(view.pid, :refresh)
56 + assert has_element?(view, "#recent-issues a", "ValueError: v")
57 + assert has_element?(view, "#events-total", "1")
58 + end
59 +
60 + test "only projects the member may see count", %{conn: conn, user: user} do
61 + owner = user_fixture()
62 + other = organization_fixture(owner)
63 + project = project_fixture(org_scope(owner, other))
64 + member_fixture(other, user, :member)
65 +
66 + target = %Ingest.Target{
67 + project_id: project.id,
68 + dsn_id: project.dsn_id,
69 + organization_id: other.id,
70 + key_id: Ecto.UUID.generate()
71 + }
72 +
73 + send_error(target, "Hidden")
74 +
75 + {:ok, view, _} = live(conn, ~p"/orgs/#{other.slug}")
76 + assert has_element?(view, "#events-total", "0")
77 + refute has_element?(view, "#recent-issues a", "Hidden")
78 + end
79 +end

Parents: 0aa6465