Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/error_tracker/web/live/dashboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,27 @@ defmodule ErrorTracker.Web.Live.Dashboard do

total_errors = Repo.aggregate(query, :count)

errors_query =
query
|> order_by(desc: :last_occurrence_at)
|> offset((^page - 1) * @per_page)
|> limit(@per_page)
errors =
Repo.all(
from query,
order_by: [desc: :last_occurrence_at],
offset: (^page - 1) * @per_page,
limit: @per_page
)

error_ids = Enum.map(errors, & &1.id)

occurrences =
errors
|> Ecto.assoc(:occurrences)
|> where([o], o.error_id in ^error_ids)
|> group_by([o], o.error_id)
|> select([o], {o.error_id, count(o.id)})
|> Repo.all()

assign(socket,
errors: Repo.all(errors_query),
errors: errors,
occurrences: Map.new(occurrences),
total_pages: (total_errors / @per_page) |> Float.ceil() |> trunc
)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/error_tracker/web/live/dashboard.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-600 dark:text-gray-400">
<tr>
<th scope="col" class="px-4 pr-2 py-3 w-128">Error</th>
<th scope="col" class="px-4 py-3 w-72">Last occurrence</th>
<th scope="col" class="px-4 py-3 w-72">Occurrences</th>
<th scope="col" class="px-4 py-3 w-28">Status</th>
<th scope="col" class="px-4 py-3 w-32"></th>
</tr>
Expand All @@ -62,7 +62,8 @@
</p>
</th>
<td class="px-4 py-4">
<%= format_datetime(error.last_occurrence_at) %>
<p>Last: <%= format_datetime(error.last_occurrence_at) %></p>
<p>Total: <%= @occurrences[error.id] %></p>
</td>
<td class="px-4 py-4">
<.badge :if={error.status == :resolved} color={:green}>Resolved</.badge>
Expand Down
9 changes: 8 additions & 1 deletion lib/error_tracker/web/live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ defmodule ErrorTracker.Web.Live.Show do
|> List.flatten()
|> Enum.reverse()

assign(socket, :occurrences, occurrences)
total_occurrences =
socket.assigns.error
|> Ecto.assoc(:occurrences)
|> Repo.aggregate(:count)

socket
|> assign(:occurrences, occurrences)
|> assign(:total_occurrences, total_occurrences)
end

defp related_occurrences(query, num_results) do
Expand Down
6 changes: 5 additions & 1 deletion lib/error_tracker/web/live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>

<div class="px-3 md:pl-0 space-y-8">
<.section title="Occurrence">
<.section title={"Occurrence (#{@total_occurrences} total)"}>
<form phx-change="occurrence_navigation">
<select name="occurrence_id" class="text-black w-full">
<option
Expand All @@ -85,6 +85,10 @@
<pre><%= format_datetime(@error.last_occurrence_at) %></pre>
</.section>

<.section title="First seen">
<pre><%= format_datetime(@error.inserted_at) %></pre>
</.section>

<.section title="Status" title_class="mb-3">
<.badge :if={@error.status == :resolved} color={:green}>Resolved</.badge>
<.badge :if={@error.status == :unresolved} color={:red}>Unresolved</.badge>
Expand Down