Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Dec 2, 2024
1 parent 859b0ee commit fee5319
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fee5319

Please sign in to comment.