From 7ca07b76124341def079bc5209c66622e9b73ef7 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 2 Dec 2024 14:03:05 +0200 Subject: [PATCH] Backup --- lib/sanbase_web/components/core_components.ex | 3 +- .../metric_registry_index_live.ex | 92 +++++++++++++++---- 2 files changed, 78 insertions(+), 17 deletions(-) diff --git a/lib/sanbase_web/components/core_components.ex b/lib/sanbase_web/components/core_components.ex index d67690ea3..aaaf4ec7d 100644 --- a/lib/sanbase_web/components/core_components.ex +++ b/lib/sanbase_web/components/core_components.ex @@ -39,6 +39,7 @@ defmodule SanbaseWeb.CoreComponents do attr(:id, :string, required: true) attr(:show, :boolean, default: false) attr(:on_cancel, JS, default: %JS{}) + attr(:max_modal_width, :string, default: "max-w-3xl") slot(:inner_block, required: true) def modal(assigns) do @@ -60,7 +61,7 @@ defmodule SanbaseWeb.CoreComponents do tabindex="0" >
-
+
<.focus_wrap id={"#{@id}-container"} phx-window-keydown={JS.exec("data-cancel", to: "##{@id}")} diff --git a/lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex b/lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex index 44781dfaf..ad1f5971f 100644 --- a/lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex +++ b/lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex @@ -14,7 +14,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do show_verified_changes_modal: false, visible_metrics: metrics, metrics: metrics, - metrics_verified_updates: %{}, + verified_metrics_updates_map: %{}, filter: %{} )} end @@ -26,9 +26,13 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do :if={@show_verified_changes_modal} show id="verified_changes_modal" - on_cancel={JS.push("update_show_verified_changes_modal", value: %{"bool" => false})} + max_modal_width="max-w-6xl" + on_cancel={JS.push("hide_show_verified_changes_modal")} > - <.list_metrics_verified_status_changed metrics={@metrics} /> + <.list_metrics_verified_status_changed + verified_metrics_updates_map={@verified_metrics_updates_map} + metrics={@metrics} + />
@@ -97,16 +101,16 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do )} end - def handle_event("apply_verified_changes", _params, socket) do + def handle_event("show_verified_changes_modal", _params, socket) do {:noreply, socket |> assign(show_verified_changes_modal: true)} end - def handle_event("update_show_verified_changes_modal", %{"bool" => value}, socket) do + def handle_event("hide_show_verified_changes_modal", _params, socket) do {:noreply, socket - |> assign(show_verified_changes_modal: value)} + |> assign(show_verified_changes_modal: false)} end def handle_event( @@ -116,7 +120,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do ) do new_map = Map.update( - socket.assigns.metrics_verified_updates, + socket.assigns.verified_metrics_updates_map, id, # This will be invoked only the first time the metric registry is updated %{old: Enum.find(socket.assigns.metrics, &(&1.id == id)).is_verified, new: bool}, @@ -125,14 +129,53 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do {:noreply, assign(socket, - verified_metrics_update: new_map, + verified_metrics_updates_map: new_map, metrics: update_metric(socket.assigns.metrics, id, :is_verified, bool), visible_metrics: update_metric(socket.assigns.visible_metrics, id, :is_verified, bool) )} end defp list_metrics_verified_status_changed(assigns) do + changed_metrics_ids = + assigns.verified_metrics_updates_map + |> Enum.reduce([], fn {id, map}, acc -> + if map.new != map.old, do: [id | acc], else: acc + end) + + changed_metrics = Enum.filter(assigns.metrics, &(&1.id in changed_metrics_ids)) + assigns = assign(assigns, changed_metrics: changed_metrics) + ~H""" +
+ No changes +
+
+ <.table id="uploaded_images" rows={@changed_metrics}> + <:col :let={row} label="Metric"> + <.metric_names + metric={row.metric} + internal_metric={row.internal_metric} + human_readable_name={row.human_readable_name} + /> + + <:col :let={row} label="New Status"> + VERIFIED + UNVERIFIED + + +
+ <.phx_click_button + phx_click="confirm_verified_changes_update" + class="bg-green-500 hover:bg-green-900 text-white" + text="Confirm Changes" + /> + <.phx_click_button + phx_click="close_verified_changes_update" + class="bg-white hover:bg-gray-100 text-gray-800" + text="Close" + /> +
+
""" end @@ -152,7 +195,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do
VERIFIED - UNVERIFIED + UNVERIFIED """ end @@ -200,12 +243,11 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do <.filter_not_verified />
- <.button - phx-click="apply_verified_changes" - class="text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center gap-x-2" - > - Apply Verified Status Changes - + <.phx_click_button + phx_click="show_verified_changes_modal" + class="text-gray-900 bg-white hover:bg-gray-100" + text="Apply Verified Status Changes" + />
""" end @@ -256,6 +298,25 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do """ end + attr :phx_click, :string, required: true + attr :text, :string, required: true + attr :class, :string, required: true + + defp phx_click_button(assigns) do + ~H""" + + """ + end + defp metric_names(assigns) do ~H"""
@@ -270,7 +331,6 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do Enum.map(metrics, fn metric -> if metric.id == id do %{metric | key => value} - |> dbg() else metric end