Skip to content

Commit

Permalink
Improve Metric.Registry LiveViews
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Dec 5, 2024
1 parent c147d5d commit 33804ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/sanbase/metric/registry/change_suggestion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ defmodule Sanbase.Metric.Registry.ChangeSuggestion do
# After change suggestion is applied, put the metric in a unverified state and mark
# is as not synced. Someone needs to manually verify the metric after it is tested.
# When the data is synced between stage and prod, the sync status will be updated.
params = Map.merge(params, %{is_verified: false, sync_status: "not_synced"})
# Note: Keep the keys as strings, not atoms, so the map is not mixed
params = Map.merge(params, %{"is_verified" => false, "sync_status" => "not_synced"})

case Registry.changeset(registry, params) do
%{valid?: false} = changeset ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule SanbaseWeb.MetricRegistryChangeSuggestionsLive do

alias SanbaseWeb.AdminFormsComponents
alias Sanbase.Metric.Registry.ChangeSuggestion
alias SanbaseWeb.AvailableMetricsComponents

@impl true
def mount(_params, _session, socket) do
Expand All @@ -16,12 +17,17 @@ defmodule SanbaseWeb.MetricRegistryChangeSuggestionsLive do
def render(assigns) do
~H"""
<div>
<AvailableMetricsComponents.available_metrics_button
text="Back to Metric Registry"
href={~p"/admin2/metric_registry"}
icon="hero-arrow-uturn-left"
/>
<div class="flex-1 p:2 sm:p-6 justify-evenly">
<.table id="metric_registry_changes_suggestions" rows={@rows}>
<:col :let={row} label="Status">
<AdminFormsComponents.status status={row.status} />
</:col>
<:col :let={row} label="Metric">
<:col :let={row} label="Metric" col_class="max-w-[320px] break-words">
<.link
class="underline text-blue-600"
href={~p"/admin2/metric_registry/show/#{row.metric_registry_id}"}
Expand Down
19 changes: 12 additions & 7 deletions lib/sanbase_web/live/metric_registry/metric_registry_index_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do
<.filters filter={@filter} changed_metrics_ids={@changed_metrics_ids} />
<AvailableMetricsComponents.table_with_popover_th
id="metrics_registry"
rows={Enum.filter(@metrics, &(&1.id in @visible_metrics_ids))}
rows={take_ordered(@metrics, @visible_metrics_ids)}
>
<:col :let={row} label="ID">
<%= row.id %>
Expand Down Expand Up @@ -278,7 +278,7 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do
/>
</div>
<div class="flex flex-col flex-wrap mt-4 space-y-2 items-start">
<.filter_not_verified />
<.filter_unverified />
</div>
</form>
<.phx_click_button
Expand All @@ -291,17 +291,17 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do
"""
end

defp filter_not_verified(assigns) do
defp filter_unverified(assigns) do
~H"""
<div class="flex items-center mb-4 ">
<input
id="not-verified-only"
name="not_verified_only"
id="unverified-only"
name="unverified_only"
type="checkbox"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded "
/>
<label for="default-checkbox" class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">
Show Not Verified Only
Show Unverified Only
</label>
</div>
"""
Expand Down Expand Up @@ -402,12 +402,17 @@ defmodule SanbaseWeb.MetricRegistryIndexLive do
end)
end

defp maybe_apply_filter(metrics, :match_table, %{"not_verified_only" => "on"}) do
defp maybe_apply_filter(metrics, :match_table, %{"unverified_only" => "on"}) do
metrics
|> Enum.filter(fn m ->
m.is_verified == false
end)
end

defp maybe_apply_filter(metrics, _, _), do: metrics

defp take_ordered(metrics, ids) do
metrics_map = Map.new(metrics, &{&1.id, &1})
Enum.map(ids, &Map.get(metrics_map, &1))
end
end

0 comments on commit 33804ec

Please sign in to comment.