From fee5319254ce296c1f3056ed66392da5b4755be8 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 2 Dec 2024 11:44:09 +0200 Subject: [PATCH] backup --- .../metric_registry_index_live.ex | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 bfbc41a39..44781dfaf 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: [], + metrics_verified_updates: %{}, filter: %{} )} end @@ -114,10 +114,20 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do %{"metric_registry_id" => id, "is_verified" => bool}, socket ) do + new_map = + Map.update( + socket.assigns.metrics_verified_updates, + 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}, + fn map -> Map.put(map, :new, bool) end + ) + {:noreply, assign(socket, - verified_metrics_update: [{id, bool} | socket.assigns.metrics_verified_updates], - metrics: update_metric(socket.assigns.metrics, id, :is_verified, bool) + verified_metrics_update: 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 @@ -259,7 +269,8 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do defp update_metric(metrics, id, key, value) do Enum.map(metrics, fn metric -> if metric.id == id do - Map.update!(metric, key, fn _ -> value end) + %{metric | key => value} + |> dbg() else metric end