Skip to content

Commit

Permalink
fix: resolve warnings about deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Nov 17, 2023
1 parent 3c8bfde commit a285cc6
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 112 deletions.
11 changes: 9 additions & 2 deletions lib/logflare_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
50 changes: 26 additions & 24 deletions lib/logflare_web/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
</.dynamic_link>
"""
end

Expand All @@ -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 %>
<i :if={@fa_icon} class={icon_class}></i><span> <%= @text %></span>
<% end %>
<% else %>
<%= Phoenix.HTML.Link.link attrs do %>
<i :if={@fa_icon} class={icon_class}></i><span> <%= @text %></span>
<% 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">
<i :if={@fa_icon} class={"inline-block h-3 w-3 fas fa-#{@fa_icon}"}></i><span> <%= @text %></span>
</.dynamic_link>
"""
end

Expand All @@ -118,4 +100,24 @@ defmodule LogflareWeb.CoreComponents do
</h5>
"""
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) %></.link>
"""
end
end
2 changes: 1 addition & 1 deletion lib/logflare_web/live/access_tokens_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule LogflareWeb.AccessTokensLive do
<label>Description</label>
<input name="description" autofocus />
<%= submit("Create") %>
<button type="button" phx-click="toggle-create-form" phx-value-show="false" ->Cancel</button>
<button type="button" phx-click="toggle-create-form" phx-value-show="false">Cancel</button>
</form>
<%= if @created_token do %>
Expand Down
8 changes: 4 additions & 4 deletions lib/logflare_web/live/alerts/actions/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
</p>

<div class="tw-flex tw-gap-4 tw-items-center">
<%= link("Documentation", to: "https://docs.logflare.app/concepts/alerts", target: "_blank") %>
<%= live_patch to: ~p"/alerts/new" do %>
<a href="https://docs.logflare.app/concepts/alerts" target="_blank">Documentation</a>
<.link patch={~p"/alerts/new"}>
<.button variant="primary">
New alert
</.button>
<% end %>
</.link>
</div>
</div>

<section class="mx-auto container">
<ul :for={alert <- Enum.sort_by(@alerts, & &1.name)} class="list-group">
<li class="list-group-item">
<%= live_patch(alert.name, to: ~p"/alerts/#{alert.id}", class: "tw-text-white") %>
<.link patch={~p"/alerts/#{alert.id}"} class="tw-text-white"><%= alert.name %></.link>
<span class="tw-block tw-text-sm">uuid: <%= alert.token %></span>
<p :if={alert.description} class="tw-pb-0 tw-mb-0 tw-text-sm text-muted">
<%= alert.description %>
Expand Down
5 changes: 1 addition & 4 deletions lib/logflare_web/live/alerts/actions/new.html.heex
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<.subheader>
<:path>
~/<%= live_patch("alerts",
to: ~p"/alerts",
"data-confirm": "Confirm navigate away? All unsaved changes will be lost"
) %>/new
~/<.link patch={~p"/alerts"} data-confirm="Confirm navigate away? All unsaved changes will be lost">alerts</.link>/new
</:path>
</.subheader>

Expand Down
22 changes: 4 additions & 18 deletions lib/logflare_web/live/billingaccount_live/templates/edit.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,8 @@
id: "dropdownMenuButton"
) %>
</.form>
<%= live_component(LogflareWeb.BillingAccountLive.ChartComponent,
id: :chart,
user: @user,
days: 30
) %>
<%= live_component(LogflareWeb.BillingAccountLive.EstimateUsageComponent,
id: :table,
user: @user,
plan: @plan
) %>
<.live_component module={LogflareWeb.BillingAccountLive.ChartComponent} id="chart" user={@user} days={30} />
<.live_component module={LogflareWeb.BillingAccountLive.EstimateUsageComponent} id="table" user={@user} plan={@plan} />
</div>
<div class="sub-form">
<%= section_header("Pricing") %>
Expand Down Expand Up @@ -117,20 +109,14 @@
<div class="sub-form">
<%= section_header("Payment Method") %>
<p>Manage your payment methods.</p>
<%= live_component(LogflareWeb.BillingAccountLive.PaymentMethodComponent,
id: :payment_method,
user: @user
) %>
<.live_component module={LogflareWeb.BillingAccountLive.PaymentMethodComponent} id="payment_method" user={@user} />
</div>
<div class="sub-form">
<%= section_header("Custom Invoice Fields") %>
<p>
Add custom fields to your invoices. These changes will take effect when your next invoice gets created.
</p>
<%= live_component(LogflareWeb.BillingAccountLive.CustomFieldComponent,
id: :custom_fields,
billing_account: @user.billing_account
) %>
<.live_component module={LogflareWeb.BillingAccountLive.CustomFieldComponent} id="custom_fields" billing_account={@user.billing_account} />
</div>
<div class="sub-form">
<%= section_header("Subscriptions") %>
Expand Down
13 changes: 6 additions & 7 deletions lib/logflare_web/live/endpoints/actions/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
</p>

<div class="tw-flex tw-gap-4 tw-items-center">
<%= link("Documentation",
to: "https://docs.logflare.app/concepts/endpoints",
target: "_blank"
) %>
<%= live_patch to: ~p"/endpoints/new" do %>
<a href="https://docs.logflare.app/concepts/endpoints" target="_blank">Documentation</a>
<.link patch={~p"/endpoints/new"}>
<.button variant="primary">
New endpoint
</.button>
<% end %>
</.link>
</div>
</div>

<section class="mx-auto container">
<ul :for={endpoint <- Enum.sort_by(@endpoints, & &1.name)} class="list-group">
<li class="list-group-item">
<%= live_patch(endpoint.name, to: ~p"/endpoints/#{endpoint.id}", class: "tw-text-white") %>
<.link patch={~p"/endpoints/#{endpoint.id}"} class="tw-text-white">
<%= endpoint.name %>
</.link>
<span class="tw-block tw-text-sm">uuid: <%= endpoint.token %></span>
<p :if={endpoint.description} class="tw-pb-0 tw-mb-0 tw-text-sm text-muted">
<%= endpoint.description %>
Expand Down
5 changes: 1 addition & 4 deletions lib/logflare_web/live/endpoints/actions/new.html.heex
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<.subheader>
<:path>
~/<%= live_patch("endpoints",
to: ~p"/endpoints",
"data-confirm": "Confirm navigate away? All unsaved changes will be lost"
) %>/new
~/<.link patch={~p"/endpoints"} data-confirm="Confirm navigate away? All unsaved changes will be lost">endpoints</.link>/new
</:path>
</.subheader>

Expand Down
2 changes: 1 addition & 1 deletion lib/logflare_web/live/modal_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule LogflareWeb.ModalComponent do
<%= if assigns[:live_view] do %>
<%= live_render(@socket, @live_view, @opts) %>
<% else %>
<%= live_component(@component, @opts) %>
<.live_component module={@component} {@opts} />
<% end %>
<% end %>
</div>
Expand Down
15 changes: 8 additions & 7 deletions lib/logflare_web/live/modal_live_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule LogflareWeb.ModalLiveHelpers do
@moduledoc """
Modal helpers to be imported where modals may be called
"""
import Phoenix.LiveView.Helpers
import Phoenix.Component, only: [assign: 3]
import Phoenix.HTML.Link, only: [link: 2]

Expand Down Expand Up @@ -96,32 +95,34 @@ defmodule LogflareWeb.ModalLiveHelpers do
path = Keyword.fetch!(opts, :return_to)
title = Keyword.fetch!(opts, :title)

modal_opts = [
modal_opts = %{
module: LogflareWeb.ModalComponent,
id: :modal,
return_to: path,
template: template,
opts: opts,
title: title,
view: Keyword.fetch!(opts, :view),
is_template?: true
]
}

live_component(LogflareWeb.ModalComponent, modal_opts)
Phoenix.Component.live_component(modal_opts)
end

def live_modal(component, opts) when is_atom(component) do
path = Keyword.fetch!(opts, :return_to)
title = Keyword.fetch!(opts, :title)

modal_opts = [
modal_opts = %{
module: LogflareWeb.ModalComponent,
id: :"logflare-modal",
return_to: path,
component: component,
opts: opts,
title: title,
is_template?: false
]
}

live_component(LogflareWeb.ModalComponent, modal_opts)
Phoenix.Component.live_component(modal_opts)
end
end
31 changes: 14 additions & 17 deletions lib/logflare_web/live/plans_live.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
defmodule LogflareWeb.PlansLive do
@moduledoc false
use Phoenix.LiveView, layout: {LogflareWeb.SharedView, :live_widget}
use Phoenix.HTML
use LogflareWeb, {:live_view, layout: {LogflareWeb.SharedView, :live_widget}}

alias Logflare.Billing
alias Logflare.Users

alias LogflareWeb.Router.Helpers, as: Routes

def render(assigns) do
~H"""
<div class="scrolling-wrapper">
Expand All @@ -20,45 +17,45 @@ defmodule LogflareWeb.PlansLive do
<li class="p-2">Team members</li>
<li class="p-2">
Sources
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#sources", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#sources"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<hr />
<li class="p-2">Alert frequency</li>
<li class="p-2">
Dashboards
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#dashboards", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#dashboards"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<hr />
<li class="p-2">
Backend
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#backend", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#backend"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<li class="p-2">
Fields
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#fields", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#fields"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<hr />
<li class="p-2">
Event Retention
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#retention", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#retention"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<li class="p-2">Events per month</li>
<hr />
<li class="p-2">
Rate limit
<%= link to: Routes.marketing_path(@socket, :pricing) <> "#rate-limit", class: "position-absolute absolute-right" do %>
<.link navigate={~p"/pricing#rate-limit"} class="position-absolute absolute-right">
<i class="fas fa-info-circle"></i>
<% end %>
</.link>
</li>
<li class="p-2">Rate burst</li>
</ul>
Expand Down Expand Up @@ -90,7 +87,7 @@ defmodule LogflareWeb.PlansLive do
<small class="text-muted">per <%= @period %></small>
</div>
<div class="py-4">
<%= 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</.link>
</div>
</div>
</div>
Expand Down
16 changes: 8 additions & 8 deletions lib/logflare_web/templates/admin_shared/nav_links_live.html.heex
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<div class="log-settings float-right">
<ul>
<li>
<%= link to: Routes.admin_path(@socket, :sources) do %>
<.link navigate={~p"/admin/sources"}>
<i class="fas fa-list"></i><span class="hide-on-mobile"> sources</span>
<% end %>
</.link>
</li>
<li>
<%= link to: Routes.admin_path(@socket, :accounts) do %>
<.link navigate={~p"/admin/accounts"}>
<i class="fas fa-users"></i><span class="hide-on-mobile"> accounts</span>
<% end %>
</.link>
</li>
<li>
<%= link to: Routes.cluster_path(@socket, :index) do %>
<.link navigate={~p"/admin/cluster"}>
<i class="fas fa-server"></i><span class="hide-on-mobile"> cluster</span>
<% end %>
</.link>
</li>
<li>
<%= link to: Routes.live_path(@socket, LogflareWeb.AdminSearchDashboardLive) do %>
<i class="fas fa-search"></i><span class="hide-on-mobile"> search</span>
<% end %>
</li>
<li>
<%= link to: Routes.admin_plan_path(@socket, :index) do %>
<.link navigate={~p"/admin/plans"}>
<i class="fas fa-dollar-sign"></i><span class="hide-on-mobile"> plans</span>
<% end %>
</.link>
</li>
</ul>
</div>
Loading

0 comments on commit a285cc6

Please sign in to comment.