From 21d7c3f05cef40055380d65f9a22df4f32426ade Mon Sep 17 00:00:00 2001 From: crbelaus Date: Mon, 22 Jul 2024 18:59:30 +0200 Subject: [PATCH 1/3] Show occurrences count Include the total occurrence count both in the dashboard and in the error detail page. --- lib/error_tracker/web/live/dashboard.ex | 22 ++++++++++++++----- .../web/live/dashboard.html.heex | 5 +++-- lib/error_tracker/web/live/show.html.heex | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/error_tracker/web/live/dashboard.ex b/lib/error_tracker/web/live/dashboard.ex index d0b06be..6dab08e 100644 --- a/lib/error_tracker/web/live/dashboard.ex +++ b/lib/error_tracker/web/live/dashboard.ex @@ -64,14 +64,24 @@ 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 + ) + + occurrences = + errors + |> Ecto.assoc(:occurrences) + |> 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 diff --git a/lib/error_tracker/web/live/dashboard.html.heex b/lib/error_tracker/web/live/dashboard.html.heex index 35d24f6..057f72a 100644 --- a/lib/error_tracker/web/live/dashboard.html.heex +++ b/lib/error_tracker/web/live/dashboard.html.heex @@ -41,7 +41,7 @@ Error - Last occurrence + Occurrences Status @@ -62,7 +62,8 @@

- <%= format_datetime(error.last_occurrence_at) %> +

Last: <%= format_datetime(error.last_occurrence_at) %>

+

Total: <%= @occurrences[error.id] %>

<.badge :if={error.status == :resolved} color={:green}>Resolved diff --git a/lib/error_tracker/web/live/show.html.heex b/lib/error_tracker/web/live/show.html.heex index 1b06e5b..d3309f5 100644 --- a/lib/error_tracker/web/live/show.html.heex +++ b/lib/error_tracker/web/live/show.html.heex @@ -63,7 +63,7 @@
- <.section title="Occurrence"> + <.section title={"Occurrence (#{Enum.count(@occurrences)} total)"}>