Skip to content

Commit

Permalink
dependency updates including Phoenix.HTML 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFirstAvenger committed Jun 10, 2024
1 parent 4924c18 commit 7a46d8d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
plugins: [Phoenix.LiveView.HTMLFormatter],
import_deps: [:ecto],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
line_length: 120
line_length: 150
]
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
name: Test
strategy:
matrix:
otp: ["26.1.1"]
elixir: ["1.15.6"]
otp: ["26.1.1", "27.0"]
elixir: ["1.16.3"]
steps:
- uses: actions/checkout@v2

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Next

- `Phoenix.HTML` 4.0
- Bandit.Pipeline.run as default MFA when available (it's now the default in `mix phx_new`)
- Fix issue with changeset form not honoring initial node
- OTP 27/Elixir 1.16 in CI
- Increase formatter line length

## 0.6.0

- Upgrade Dialyxir
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You will now find a `Flame On` tab along the top of the LiveDashboard page

## Usage

Choose the Module, Function, and Arity of the function you want to profile, click "Flame On", and then trigger the function (e.g. make a web request in a new tab). Note that for Elixir modules, you will need to prefix them with `Elixir`, e.g. `Elixir.Phoenix.Controller`, while Erlang modules take simply the erlang module name, e.g. `cowboy_handler`. The default values of `cowboy_handler`/`execute`/`2` are the best way to capture a standard Phoenix Controller DeadView request or the DeadView request that kicks off a LiveView request.
Choose the Module, Function, and Arity of the function you want to profile, click "Flame On", and then trigger the function (e.g. make a web request in a new tab). Note that for Elixir modules, you will need to prefix them with `Elixir`, e.g. `Elixir.Phoenix.Controller`, while Erlang modules take simply the erlang module name, e.g. `cowboy_handler`. The default values of `Bandit.Pipeline`/`run`/`4` (for newer Phoenix apps) and `cowboy_handler`/`execute`/`2` (for older Phoenix apps) are the best way to capture a standard Phoenix Controller DeadView request or the DeadView request that kicks off a LiveView request.

### Zooming

Expand Down
12 changes: 8 additions & 4 deletions lib/flame_on/component.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule FlameOn.Component do
use Phoenix.LiveComponent
use Phoenix.HTML

import FlameOn.ErrorHelpers

use PhoenixHTMLHelpers

alias FlameOn.Capture.Block
alias FlameOn.Capture.Config
alias FlameOn.Component.CaptureSchema
Expand All @@ -30,17 +31,20 @@ defmodule FlameOn.Component do
end

def update(assigns, socket) do
target_node = Map.get(assigns, :node, Node.self())
capture_changeset = Map.put(CaptureSchema.changeset(target_node), :action, :validate)

socket =
if !Map.has_key?(socket.assigns, :id) do
socket
|> assign(:capturing?, false)
|> assign(:root_block, nil)
|> assign(:capture_changeset, CaptureSchema.changeset(Node.self()))
|> assign(:capture_changeset, capture_changeset)
|> assign(:viewing_block, nil)
|> assign(:view_block_path, [])
|> assign(:capture_timed_out?, false)
|> assign(:id, assigns.id)
|> assign(:target_node, Map.get(assigns, :node, Node.self()))
|> assign(:target_node, target_node)
else
socket
end
Expand Down Expand Up @@ -86,7 +90,7 @@ defmodule FlameOn.Component do
changeset =
socket.assigns.target_node
|> CaptureSchema.changeset(attrs)
|> Map.put(:action, :insert)
|> Map.put(:action, :validate)

{:noreply, assign(socket, :capture_changeset, changeset)}
end
Expand Down
23 changes: 21 additions & 2 deletions lib/flame_on/component/capture_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ defmodule FlameOn.Component.CaptureSchema do
import Ecto.Changeset
alias Ecto.Changeset

require Logger

schema "capture" do
field :module, :string
field :function, :string
field :arity, :integer
field :timeout, :integer
end

@default_attrs %{module: "cowboy_handler", function: "execute", arity: 2, timeout: 15000}
@default_cowboy_attrs %{module: "cowboy_handler", function: "execute", arity: 2, timeout: 15000}
@default_bandit_attrs %{module: "Bandit.Pipeline", function: "run", arity: 4, timeout: 15000}

def changeset(node, attrs \\ nil) do
attrs = attrs || default_attrs(node)

def changeset(node, attrs \\ @default_attrs) do
%__MODULE__{}
|> cast(attrs, [:module, :function, :arity, :timeout])
|> validate_required([:module, :function, :arity, :timeout])
Expand Down Expand Up @@ -86,4 +91,18 @@ defmodule FlameOn.Component.CaptureSchema do
defp rpc_function_exported?(module, function, arity, node) do
:rpc.call(node, Kernel, :function_exported?, [module, function, arity])
end

defp default_attrs(node) do
cond do
rpc_function_exported?(@default_bandit_attrs.module, @default_bandit_attrs.function, @default_bandit_attrs.arity, node) ->
@default_bandit_attrs

rpc_function_exported?(@default_cowboy_attrs.module, @default_cowboy_attrs.function, @default_cowboy_attrs.arity, node) ->
@default_cowboy_attrs

true ->
Logger.info("FlameOn did not detect Cowboy or Bandit modules")
%{}
end
end
end
4 changes: 3 additions & 1 deletion lib/flame_on/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ defmodule FlameOn.ErrorHelpers do
Conveniences for translating and building error messages.
"""

use Phoenix.HTML
# For Phoenix HTML 4 vs 3
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

@doc """
Generates tag for inlined form input errors.
Expand Down
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ defmodule FlameOn.MixProject do
{:meck, "~> 0.9.2"},
{:gettext, "~> 0.21"},
{:jason, "~> 1.0"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_live_dashboard, "~> 0.8.2"},
{:phoenix_live_view, "~> 0.20.0"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
{:phoenix_ecto, "~> 4.6.1"},
{:phoenix_live_dashboard, "~> 0.8.3"},
{:phoenix_live_view, "~> 0.20.14"},
{:phoenix_html, "~> 4.0"},
{:phoenix_html_helpers, "~> 1.0.1"}
]
end
end
Loading

0 comments on commit 7a46d8d

Please sign in to comment.