From a285cc6fc6c6f920bf7d3a0dff21b8d60848fa06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Fri, 17 Nov 2023 14:00:36 +0100 Subject: [PATCH] fix: resolve warnings about deprecated functions --- lib/logflare_web.ex | 11 +++- lib/logflare_web/core_components.ex | 50 ++++++++++--------- lib/logflare_web/live/access_tokens_live.ex | 2 +- .../live/alerts/actions/index.html.heex | 8 +-- .../live/alerts/actions/new.html.heex | 5 +- .../templates/edit.html.heex | 22 ++------ .../live/endpoints/actions/index.html.heex | 13 +++-- .../live/endpoints/actions/new.html.heex | 5 +- lib/logflare_web/live/modal_component.ex | 2 +- lib/logflare_web/live/modal_live_helpers.ex | 15 +++--- lib/logflare_web/live/plans_live.ex | 31 ++++++------ .../admin_shared/nav_links_live.html.heex | 16 +++--- .../templates/log/log_event.html.heex | 15 +----- .../templates/rule/source_rules.html.heex | 4 +- 14 files changed, 87 insertions(+), 112 deletions(-) diff --git a/lib/logflare_web.ex b/lib/logflare_web.ex index f660c13ff..784d3f658 100644 --- a/lib/logflare_web.ex +++ b/lib/logflare_web.ex @@ -78,10 +78,13 @@ defmodule LogflareWeb do end end - def live_view do + def live_view(opts \\ []) do quote do - use Phoenix.LiveView, + opts = Keyword.merge([ layout: {LogflareWeb.LayoutView, :live} + ], unquote(opts)) + + use Phoenix.LiveView, opts # declare endpoint and router for Phoenix.VerifiedRoutes @endpoint LogflareWeb.Endpoint @@ -180,4 +183,8 @@ defmodule LogflareWeb do defmacro __using__(which) when is_atom(which) do apply(__MODULE__, which, []) end + + defmacro __using__({which, opts}) when is_atom(which) do + apply(__MODULE__, which, [opts]) + end end diff --git a/lib/logflare_web/core_components.ex b/lib/logflare_web/core_components.ex index 58e76cff7..c006fe298 100644 --- a/lib/logflare_web/core_components.ex +++ b/lib/logflare_web/core_components.ex @@ -59,15 +59,9 @@ defmodule LogflareWeb.CoreComponents do def subheader_path_link(assigns) do ~H""" - <%= if @live_patch do %> - <%= live_patch to: @to, class: "tw-text-gray-600 tw-hover:text-black" do %> - <%= render_slot(@inner_block) %> - <% end %> - <% else %> - <%= Phoenix.HTML.Link.link to: @to, class: "tw-text-gray-600 tw-hover:text-black" do %> - <%= render_slot(@inner_block) %> - <% end %> - <% end %> + <.dynamic_link to={@to} patch={@live_patch} class="tw-text-gray-600 tw-hover:text-black"> + <%= render_slot(@inner_block) %> + """ end @@ -82,21 +76,9 @@ defmodule LogflareWeb.CoreComponents do def subheader_link(assigns) do ~H""" - <% attrs = [ - to: @to, - class: "tw-text-black tw-p-1 tw-flex tw-gap-1 tw-items-center tw-justify-center" - ] - - icon_class = "inline-block h-3 w-3 fas fa-#{@fa_icon}" %> - <%= if @live_patch do %> - <%= live_patch attrs do %> - <%= @text %> - <% end %> - <% else %> - <%= Phoenix.HTML.Link.link attrs do %> - <%= @text %> - <% end %> - <% end %> + <.dynamic_link to={@to} patch={@live_patch} class="tw-text-black tw-p-1 tw-flex tw-gap-1 tw-items-center tw-justify-center"> + <%= @text %> + """ end @@ -118,4 +100,24 @@ defmodule LogflareWeb.CoreComponents do """ end + + attr :to, :string + attr :patch, :boolean + attr :attrs, :global + slot :inner_block, required: true + + defp dynamic_link(assigns) do + link_type = + if assigns.patch do + :patch + else + :navigate + end + + assigns = assign(assigns, :to, %{link_type => assigns.to}) + + ~H""" + <.link {@to} {@attrs}><%= render_slot(@inner_block) %> + """ + end end diff --git a/lib/logflare_web/live/access_tokens_live.ex b/lib/logflare_web/live/access_tokens_live.ex index 4a9820265..c5ba06904 100644 --- a/lib/logflare_web/live/access_tokens_live.ex +++ b/lib/logflare_web/live/access_tokens_live.ex @@ -30,7 +30,7 @@ defmodule LogflareWeb.AccessTokensLive do <%= submit("Create") %> - + <%= if @created_token do %> diff --git a/lib/logflare_web/live/alerts/actions/index.html.heex b/lib/logflare_web/live/alerts/actions/index.html.heex index 01a6dcbbd..baf49e5a0 100644 --- a/lib/logflare_web/live/alerts/actions/index.html.heex +++ b/lib/logflare_web/live/alerts/actions/index.html.heex @@ -14,19 +14,19 @@

- <%= link("Documentation", to: "https://docs.logflare.app/concepts/alerts", target: "_blank") %> - <%= live_patch to: ~p"/alerts/new" do %> + Documentation + <.link patch={~p"/alerts/new"}> <.button variant="primary"> New alert - <% end %> +
@@ -90,7 +87,7 @@ defmodule LogflareWeb.PlansLive do per <%= @period %>
- <%= link("Continue", to: Routes.auth_path(@socket, :login), class: "btn btn-dark text-white w-75 mr-0") %> + <.link navigate={~p"/auth/login"} class="btn btn-dark text-white w-75 mr-0">Continue
diff --git a/lib/logflare_web/templates/admin_shared/nav_links_live.html.heex b/lib/logflare_web/templates/admin_shared/nav_links_live.html.heex index 7e3acb1eb..c7039a475 100644 --- a/lib/logflare_web/templates/admin_shared/nav_links_live.html.heex +++ b/lib/logflare_web/templates/admin_shared/nav_links_live.html.heex @@ -1,19 +1,19 @@
  • - <%= link to: Routes.admin_path(@socket, :sources) do %> + <.link navigate={~p"/admin/sources"}> sources - <% end %> +
  • - <%= link to: Routes.admin_path(@socket, :accounts) do %> + <.link navigate={~p"/admin/accounts"}> accounts - <% end %> +
  • - <%= link to: Routes.cluster_path(@socket, :index) do %> + <.link navigate={~p"/admin/cluster"}> cluster - <% end %> +
  • <%= link to: Routes.live_path(@socket, LogflareWeb.AdminSearchDashboardLive) do %> @@ -21,9 +21,9 @@ <% end %>
  • - <%= link to: Routes.admin_plan_path(@socket, :index) do %> + <.link navigate={~p"/admin/plans"}> plans - <% end %> +
diff --git a/lib/logflare_web/templates/log/log_event.html.heex b/lib/logflare_web/templates/log/log_event.html.heex index 138465265..165dfdec8 100644 --- a/lib/logflare_web/templates/log/log_event.html.heex +++ b/lib/logflare_web/templates/log/log_event.html.heex @@ -1,10 +1,7 @@
- ~/logs/<%= link(@source.name, - to: Routes.source_path(@socket, :show, @source), - class: "text-primary" - ) %>/event + ~/logs/<.link navigate={~p"/sources/#{@source}"} class="text-primary"><%= @source.name %>/event
    @@ -14,13 +11,5 @@
- <%= live_component( - LogflareWeb.Search.LogEventViewerComponent, - Map.merge(assigns, %{ - id: :log_event_viewer, - source: @source, - team_user: @team_user, - user: @user - }) - ) %> + <.live_component module={LogflareWeb.Search.LogEventViewerComponent} id="log_event_viewer" {assigns} />
diff --git a/lib/logflare_web/templates/rule/source_rules.html.heex b/lib/logflare_web/templates/rule/source_rules.html.heex index 6989680f4..a3b96fe6d 100644 --- a/lib/logflare_web/templates/rule/source_rules.html.heex +++ b/lib/logflare_web/templates/rule/source_rules.html.heex @@ -9,7 +9,7 @@ <% end %>
-
~/logs/<%= link(@source.name, to: Routes.source_path(@socket, :show, @source), class: "text-primary") %>/rules
+
~/logs/<.link navigate={~p"/sources/#{@source}"} class="text-primary" )><%= @source.name %>/rules
  • @@ -61,7 +61,7 @@ <% end %>
<.form :let={f} for={:rule} action="#" phx-submit="fsubmit"> - <%= live_component(Lql.LqlFormLVC, f: f, lql_string: @lql_string, loading: has_regex_rules?(@rules)) %> + <.live_component module={Lql.LqlFormLVC} f={f} lql_string={@lql_string} loading={has_regex_rules?(@rules)} />
<%= label(f, :sink, "Sink source", class: "control-label") %> <% sink_form_options = for s <- @sources, do: [key: s.name, value: s.token, disabled: s.disabled] %>