-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fee5319
commit 7ca07b7
Showing
2 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} | ||
/> | ||
</.modal> | ||
<div class="flex flex-col items-start justify-evenly"> | ||
<div class="text-gray-400 text-sm py-2"> | ||
|
@@ -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""" | ||
<div :if={@changed_metrics == []}> | ||
No changes | ||
</div> | ||
<div :if={@changed_metrics != []}> | ||
<.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> | ||
<:col :let={row} label="New Status"> | ||
<span :if={row.is_verified} class="ms-3 text-sm font-bold text-green-900">VERIFIED</span> | ||
<span :if={!row.is_verified} class="ms-3 text-sm font-bold text-red-700">UNVERIFIED</span> | ||
</:col> | ||
</.table> | ||
<div class="mt-4"> | ||
<.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" | ||
/> | ||
</div> | ||
</div> | ||
""" | ||
end | ||
|
||
|
@@ -152,7 +195,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do | |
<div class="relative w-11 h-6 bg-red-500 rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-green-600"> | ||
</div> | ||
<span :if={@row.is_verified} class="ms-3 text-sm font-bold text-green-900">VERIFIED</span> | ||
<span :if={[email protected]_verified} class="ms-3 text-sm font-bold text-red-900">UNVERIFIED</span> | ||
<span :if={[email protected]_verified} class="ms-3 text-sm font-bold text-red-700">UNVERIFIED</span> | ||
</label> | ||
""" | ||
end | ||
|
@@ -200,12 +243,11 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do | |
<.filter_not_verified /> | ||
</div> | ||
</form> | ||
<.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 | ||
</.button> | ||
<.phx_click_button | ||
phx_click="show_verified_changes_modal" | ||
class="text-gray-900 bg-white hover:bg-gray-100" | ||
text="Apply Verified Status Changes" | ||
/> | ||
</div> | ||
""" | ||
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""" | ||
<button | ||
type="button" | ||
phx-click={@phx_click} | ||
class={[ | ||
"border border-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center gap-x-2", | ||
@class | ||
]} | ||
> | ||
<%= @text %> | ||
</button> | ||
""" | ||
end | ||
|
||
defp metric_names(assigns) do | ||
~H""" | ||
<div class="flex flex-col"> | ||
|
@@ -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 | ||
|