From 3fa40f9cc2afad955efd91337dd3617d5ca32b87 Mon Sep 17 00:00:00 2001 From: "Elias W. BA" Date: Fri, 25 Oct 2024 10:57:22 +0000 Subject: [PATCH] Refactor Projects Dashboard & Fix Last Activity Bug (#2606) * Add arcade resources, unload video when modal is closed * Move Arcade implementation to live_component * Pass phx-target to component * Assign projects for picker * Cherry pick projects last activity fix --- CHANGELOG.md | 3 + lib/lightning/projects.ex | 44 +++ lib/lightning_web/live/components/modal.ex | 30 +- .../live/dashboard_live/components.ex | 134 +++++++-- .../live/dashboard_live/index.ex | 261 +---------------- .../dashboard_live/user_projects_section.ex | 90 ++++++ .../live/dashboard_live/welcome_section.ex | 104 +++++++ test/lightning/projects_test.exs | 195 +++++++++++++ .../live/dashboard_live_test.exs | 271 ++++++++++-------- 9 files changed, 730 insertions(+), 402 deletions(-) create mode 100644 lib/lightning_web/live/dashboard_live/user_projects_section.ex create mode 100644 lib/lightning_web/live/dashboard_live/welcome_section.ex diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f5b52ac1..681469c700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ and this project adheres to ### Fixed +- Refactor projects dashboard page and fix bug on last activity column + [#2593](https://github.com/OpenFn/lightning/issues/2593) + ## [v2.9.11] - 2024-10-23 ### Added diff --git a/lib/lightning/projects.ex b/lib/lightning/projects.ex index 2b5285a13e..7facecf0ac 100644 --- a/lib/lightning/projects.ex +++ b/lib/lightning/projects.ex @@ -34,6 +34,50 @@ defmodule Lightning.Projects do require Logger + defmodule ProjectOverviewRow do + @moduledoc """ + Represents a summarized view of a project for a user, used in the project overview table. + """ + defstruct [ + :id, + :name, + :role, + :workflows_count, + :collaborators_count, + :last_activity + ] + end + + def get_projects_overview(%User{id: user_id}, opts \\ []) do + order_by = Keyword.get(opts, :order_by, {:asc, :name}) + + from(p in Project, + join: pu in assoc(p, :project_users), + left_join: w in assoc(p, :workflows), + left_join: pu_all in assoc(p, :project_users), + where: pu.user_id == ^user_id and is_nil(w.deleted_at), + group_by: [p.id, pu.role], + select: %ProjectOverviewRow{ + id: p.id, + name: p.name, + role: pu.role, + workflows_count: count(w.id, :distinct), + collaborators_count: count(pu_all.user_id, :distinct), + last_activity: max(w.updated_at) + }, + order_by: ^dynamic_order_by(order_by) + ) + |> Repo.all() + end + + defp dynamic_order_by({direction, :name}) do + {direction, dynamic([p, _pu, _w, _pu_all], field(p, :name))} + end + + defp dynamic_order_by({direction, :last_activity}) do + {direction, dynamic([_p, _pu, w, _pu_all], max(w.updated_at))} + end + @doc """ Perform, when called with %{"type" => "purge_deleted"} will find projects that are ready for permanent deletion and purge them. diff --git a/lib/lightning_web/live/components/modal.ex b/lib/lightning_web/live/components/modal.ex index 5cd4e15679..d382440219 100644 --- a/lib/lightning_web/live/components/modal.ex +++ b/lib/lightning_web/live/components/modal.ex @@ -12,6 +12,7 @@ defmodule LightningWeb.Components.Modal do attr :id, :string, required: true attr :show, :boolean, default: false attr :with_frame, :boolean, default: true + attr :target, :any, default: nil attr :position, :string, default: "fixed inset-0" attr :width, :string, default: "max-w-3xl" attr :close_on_click_away, :boolean, default: true @@ -34,7 +35,7 @@ defmodule LightningWeb.Components.Modal do