diff --git a/lib/logflare_web/live/alerts/alerts_live.ex b/lib/logflare_web/live/alerts/alerts_live.ex index 20fb5f7f8..7ae255007 100644 --- a/lib/logflare_web/live/alerts/alerts_live.ex +++ b/lib/logflare_web/live/alerts/alerts_live.ex @@ -5,10 +5,9 @@ defmodule LogflareWeb.AlertsLive do require Logger - alias Logflare.Endpoints alias Logflare.Users - alias LogflareWeb.Utils alias Logflare.Alerting + alias Logflare.Alerting.AlertQuery embed_templates("actions/*", suffix: "_action") embed_templates("components/*") @@ -34,8 +33,6 @@ defmodule LogflareWeb.AlertsLive do def mount(%{}, %{"user_id" => user_id}, socket) do user = Users.get(user_id) - allow_access = Enum.any?([Utils.flag("endpointsOpenBeta"), user.endpoints_beta]) - socket = socket |> assign(:user_id, user_id) @@ -44,8 +41,7 @@ defmodule LogflareWeb.AlertsLive do |> refresh() |> assign(:query_result_rows, nil) |> assign(:alert, nil) - |> assign(:endpoint_changeset, Endpoints.change_query(%Endpoints.Query{})) - |> assign(:allow_access, allow_access) + |> assign(:endpoint_changeset, Alerting.change_alert_query(%AlertQuery{})) |> assign(:base_url, LogflareWeb.Endpoint.url()) |> assign(:parse_error_message, nil) |> assign(:query_string, nil) @@ -63,10 +59,14 @@ defmodule LogflareWeb.AlertsLive do Alerting.get_alert_query_by(id: alert_id, user_id: socket.assigns.user_id) end + socket = assign(socket, :alert, alert) + socket = - socket - |> assign(:alert, alert) - |> assign(:changeset, nil) + if socket.assigns.live_action == :edit do + assign(socket, :changeset, Alerting.change_alert_query(alert)) + else + assign(socket, :changeset, nil) + end {:noreply, socket} end diff --git a/lib/logflare_web/live/alerts/components/alert_form.html.heex b/lib/logflare_web/live/alerts/components/alert_form.html.heex index ff4098f81..ab986de87 100644 --- a/lib/logflare_web/live/alerts/components/alert_form.html.heex +++ b/lib/logflare_web/live/alerts/components/alert_form.html.heex @@ -44,7 +44,6 @@ "select timestamp, event_message from `YourApp.SourceName` \nwhere regexp_contains(event_message, 'error')", class: "form-control form-control-margin", id: "alert-query", - value: Map.get(@params_form.params, "query"), style: "height: 20rem" ) %> <%= error_tag(f, :query) %>