From 8ca0d72011ef55374f608e9edad30cbd19d13717 Mon Sep 17 00:00:00 2001 From: "Elias W. BA" Date: Mon, 11 Nov 2024 13:07:13 +0200 Subject: [PATCH] Rename last activity to last updated at and fixing sorting of null values (#2653) --- lib/lightning/projects.ex | 8 +++---- .../live/dashboard_live/components.ex | 20 +++++++++------- .../dashboard_live/user_projects_section.ex | 14 +++++------ test/lightning/projects_test.exs | 14 +++++++---- .../live/dashboard_live_test.exs | 24 +++++++++---------- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/lib/lightning/projects.ex b/lib/lightning/projects.ex index f4157c3fc6..ee5951c0f3 100644 --- a/lib/lightning/projects.ex +++ b/lib/lightning/projects.ex @@ -45,12 +45,12 @@ defmodule Lightning.Projects do :role, :workflows_count, :collaborators_count, - :last_activity + :last_updated_at ] end def get_projects_overview(%User{id: user_id}, opts \\ []) do - order_by = Keyword.get(opts, :order_by, {:asc, :name}) + order_by = Keyword.get(opts, :order_by, {:asc_nulls_last, :name}) from(p in Project, join: pu in assoc(p, :project_users), @@ -64,7 +64,7 @@ defmodule Lightning.Projects do role: pu.role, workflows_count: count(w.id, :distinct), collaborators_count: count(pu_all.user_id, :distinct), - last_activity: max(w.updated_at) + last_updated_at: max(w.updated_at) }, order_by: ^dynamic_order_by(order_by) ) @@ -75,7 +75,7 @@ defmodule Lightning.Projects do {direction, dynamic([p, _pu, _w, _pu_all], field(p, :name))} end - defp dynamic_order_by({direction, :last_activity}) do + defp dynamic_order_by({direction, :last_updated_at}) do {direction, dynamic([_p, _pu, w, _pu_all], max(w.updated_at))} end diff --git a/lib/lightning_web/live/dashboard_live/components.ex b/lib/lightning_web/live/dashboard_live/components.ex index 3381f22e02..e7af7da215 100644 --- a/lib/lightning_web/live/dashboard_live/components.ex +++ b/lib/lightning_web/live/dashboard_live/components.ex @@ -123,14 +123,18 @@ defmodule LightningWeb.DashboardLive.Components do end def user_projects_table(assigns) do - next_sort_icon = %{asc: "hero-chevron-up", desc: "hero-chevron-down"} + next_sort_icon = %{ + asc_nulls_last: "hero-chevron-up", + desc_nulls_last: "hero-chevron-down" + } assigns = assign(assigns, projects_count: assigns.projects |> Enum.count(), empty?: assigns.projects |> Enum.empty?(), name_sort_icon: next_sort_icon[assigns.name_direction], - last_activity_sort_icon: next_sort_icon[assigns.last_activity_direction] + last_updated_at_sort_icon: + next_sort_icon[assigns.last_updated_at_direction] ) ~H""" @@ -163,14 +167,14 @@ defmodule LightningWeb.DashboardLive.Components do <.th>Collaborators <.th>
- Last Activity + Last Updated - <.icon name={@last_activity_sort_icon} /> + <.icon name={@last_updated_at_sort_icon} />
@@ -207,13 +211,13 @@ defmodule LightningWeb.DashboardLive.Components do <.td> - <%= if project.last_activity do %> + <%= if project.last_updated_at do %> <%= Lightning.Helpers.format_date( - project.last_activity, + project.last_updated_at, "%d/%m/%Y %H:%M:%S" ) %> <% else %> - No activity + N/A <% end %> <.td class="text-right"> diff --git a/lib/lightning_web/live/dashboard_live/user_projects_section.ex b/lib/lightning_web/live/dashboard_live/user_projects_section.ex index c2b31b7f06..4b596b980a 100644 --- a/lib/lightning_web/live/dashboard_live/user_projects_section.ex +++ b/lib/lightning_web/live/dashboard_live/user_projects_section.ex @@ -16,8 +16,8 @@ defmodule LightningWeb.DashboardLive.UserProjectsSection do socket |> assign(assigns) |> assign(:projects, projects) - |> assign(:name_sort_direction, :asc) - |> assign(:last_activity_sort_direction, :asc)} + |> assign(:name_sort_direction, :asc_nulls_last) + |> assign(:last_updated_at_sort_direction, :asc_nulls_last)} end @impl true @@ -27,7 +27,7 @@ defmodule LightningWeb.DashboardLive.UserProjectsSection do sort_direction = socket.assigns - |> Map.get(sort_key, :asc) + |> Map.get(sort_key, :asc_nulls_last) |> switch_sort_direction() projects = @@ -41,11 +41,11 @@ defmodule LightningWeb.DashboardLive.UserProjectsSection do |> assign(sort_key, sort_direction)} end - defp switch_sort_direction(:asc), do: :desc - defp switch_sort_direction(:desc), do: :asc + defp switch_sort_direction(:asc_nulls_last), do: :desc_nulls_last + defp switch_sort_direction(:desc_nulls_last), do: :asc_nulls_last defp projects_for_user(%User{} = user, opts \\ []) do - order_by = Keyword.get(opts, :order_by, {:asc, :name}) + order_by = Keyword.get(opts, :order_by, {:asc_nulls_last, :name}) Projects.get_projects_overview(user, order_by: order_by) end @@ -59,7 +59,7 @@ defmodule LightningWeb.DashboardLive.UserProjectsSection do user={@current_user} target={@myself} name_direction={@name_sort_direction} - last_activity_direction={@last_activity_sort_direction} + last_updated_at_direction={@last_updated_at_sort_direction} > <:empty_state>