Skip to content

Commit

Permalink
Upgrade to Phoenix 1.7 (#2831)
Browse files Browse the repository at this point in the history
* Upgrade to phoenix 1.7

* Api redirector test refactored to match the new internals phx routert

* Upgrade project dependencies

- removed eventstore_dashboard, it's not mantained anymore
- upgraded floki
- upgraded phoenix
- upgraded phoenix_ecto
- upgraded phoenix_html
- upgraded phoenix_live_dashboard
- upgraded phoenix_live_view
- upgraded pow
- upgraded polymorphic_embed
- added phoenix_view to mantain compatibility with pre 1.7 views
- added phoenix_html_helpers

* Removed eventstore from live dashboard

* refactored live_flash warning

* ignore statics in codespell job
  • Loading branch information
CDimonaco authored Jul 29, 2024
1 parent 30ba3c7 commit 54cb9ba
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 92 deletions.
7 changes: 4 additions & 3 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[
import_deps: [:ecto, :phoenix, :commanded, :open_api_spex],
import_deps: [:ecto, :phoenix, :ecto_sql, :commanded, :open_api_spex],
locals_without_parens: [
# mock
assert_called: :*,
assert_not_called: :*
],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter]
]
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
version-type: strict
env:
ImageOS: ubuntu20
- name: Retrieve Cached Dependencies
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
sudo apt-get install -y git python3 python3-pip
python3 -m pip install codespell
- name: codespell
run: codespell -S priv*,*package*json,deps*,*node_modules*,*svg,*.git,*.app -L enque,daa,afterall
run: codespell -S priv*,*package*json,deps*,*node_modules*,*svg,*.git,*.app -L enque,daa,afterall,statics

generate-docs:
name: Generate project documentation
Expand Down Expand Up @@ -961,7 +961,7 @@ jobs:
cp $FOLDER/_service $OSC_CHECKOUT_DIR
cp $FOLDER/trento-web.spec $OSC_CHECKOUT_DIR
rm -vf $OSC_CHECKOUT_DIR/*.tar.gz
pushd $OSC_CHECKOUT_DIR
pushd $OSC_CHECKOUT_DIR
osc service manualrun
rm -vf $OSC_CHECKOUT_DIR/*.tgz
cp /__w/web/web/deps.tar.gz .
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/users/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Trento.Users.User do

use Pow.Ecto.Schema,
user_id_field: :username,
password_hash_methods: {&Argon2.hash_pwd_salt/1, &Argon2.verify_pass/2}
password_hash_verify: {&Argon2.hash_pwd_salt/1, &Argon2.verify_pass/2}

use Pow.Extension.Ecto.Schema,
extensions: [PowPersistentSession]
Expand Down
21 changes: 19 additions & 2 deletions lib/trento_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ defmodule TrentoWeb do
below. Instead, define any helper function in modules
and import those modules here.
"""
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)

def controller do
quote do
use Phoenix.Controller, namespace: TrentoWeb

import Plug.Conn
import TrentoWeb.Gettext

unquote(verified_routes())
alias TrentoWeb.Router.Helpers, as: Routes
end
end
Expand Down Expand Up @@ -79,17 +82,31 @@ defmodule TrentoWeb do
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
import Phoenix.LiveView.Helpers
# https://elixirforum.com/t/phoenix-liveview-0-18-and-live-flash/50841
import Phoenix.Component

# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View

import TrentoWeb.ErrorHelpers
import TrentoWeb.Gettext
alias TrentoWeb.Router.Helpers, as: Routes

unquote(verified_routes())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: TrentoWeb.Endpoint,
router: TrentoWeb.Router,
statics: TrentoWeb.static_paths()
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/trento_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule TrentoWeb.Endpoint do
at: "/",
from: :trento,
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt)
only: TrentoWeb.static_paths()

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
Expand Down
5 changes: 1 addition & 4 deletions lib/trento_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ defmodule TrentoWeb.Router do
pipe_through :browser

live_dashboard "/dashboard",
metrics: TrentoWeb.Telemetry,
additional_pages: [
eventstores: {EventStore.Dashboard, event_stores: [Trento.EventStore]}
]
metrics: TrentoWeb.Telemetry
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/trento_web/templates/layout/live.html.heex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<main class="container">
<p class="alert alert-info" role="alert"
phx-click="lv:clear-flash"
phx-value-key="info"><%= live_flash(@flash, :info) %></p>
<p class="alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
<%= Phoenix.Flash.get(@flash, :info) %>
</p>

<p class="alert alert-danger" role="alert"
phx-click="lv:clear-flash"
phx-value-key="error"><%= live_flash(@flash, :error) %></p>
<p class="alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
<%= Phoenix.Flash.get(@flash, :error) %>
</p>

<%= @inner_content %>
</main>
20 changes: 14 additions & 6 deletions lib/trento_web/templates/layout/root.html.heex
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %>
<%= live_title_tag assigns[:page_title] || "Trento" %>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
<.live_title>
<%= assigns[:page_title] || "Trento" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")} />
<script
defer
phx-track-static
type="text/javascript"
src={Routes.static_path(@conn, "/assets/app.js")}
>
</script>
</head>
<body>
<%= @inner_content %>
Expand Down
20 changes: 13 additions & 7 deletions lib/trento_web/templates/page/index.html.heex
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<div id="trento" />

<script>
const config = {
checksServiceBaseUrl: '<%= @check_service_base_url %>',
deregistrationDebounce: <%= @deregistration_debounce %>,
chartsEnabled: <%= @charts_enabled %>,
suseManagerEnabled: <%= @suse_manager_enabled %>,
};
const config = {
checksServiceBaseUrl: '<%= @check_service_base_url %>',
deregistrationDebounce: <%= @deregistration_debounce %>,
chartsEnabled: <%= @charts_enabled %>,
suseManagerEnabled: <%= @suse_manager_enabled %>,
};
</script>

<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/trento.js")}></script>
<script
defer
phx-track-static
type="text/javascript"
src={Routes.static_path(@conn, "/assets/trento.js")}
>
</script>
3 changes: 2 additions & 1 deletion lib/trento_web/views/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ defmodule TrentoWeb.ErrorHelpers do
Conveniences for translating and building error messages.
"""

use Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

@doc """
Generates tag for inlined form input errors.
Expand Down
22 changes: 12 additions & 10 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ defmodule Trento.MixProject do
{:esbuild, "~> 0.2", runtime: Mix.env() == :dev},
{:eventstore, "~> 1.1",
[env: :prod, git: "https://github.com/commanded/eventstore.git", override: true]},
{:eventstore_dashboard, github: "commanded/eventstore-dashboard"},
# {:eventstore_dashboard, github: "commanded/eventstore-dashboard"},
{:ex_doc, "~> 0.29", only: [:dev, :test], runtime: false},
{:ex_machina, "~> 2.7.0", only: :test},
{:excoveralls, "~> 0.10", only: :test},
{:faker, "~> 0.17", only: [:dev, :test]},
{:floki, ">= 0.30.0", only: :test},
{:flop, "~> 0.25.0"},
{:floki, ">= 0.36.2", only: :test},
{:fun_with_flags, "~> 1.8.1"},
{:fun_with_flags_ui, "~> 0.8.0"},
{:gettext, "~> 0.18"},
Expand All @@ -82,16 +82,16 @@ defmodule Trento.MixProject do
{:jason, "~> 1.2"},
{:mox, "~> 1.0", only: :test},
{:open_api_spex, "~> 3.19.1"},
{:phoenix, "~> 1.6.2"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_html, "~> 3.0"},
{:phoenix_live_dashboard, "~> 0.6"},
{:phoenix, "~> 1.7.14"},
{:phoenix_ecto, "~> 4.5"},
{:phoenix_html, "~> 4.1"},
{:phoenix_live_dashboard, "~> 0.8.4"},
{:phoenix_live_reload, "~> 1.2", only: [:dev, :wanda]},
{:phoenix_live_view, "~> 0.17.1"},
{:phoenix_live_view, "~> 0.20.17"},
{:phoenix_swoosh, "~> 1.0"},
{:plug_cowboy, "~> 2.5"},
{:postgrex, ">= 0.0.0"},
{:pow, "~> 1.0.26"},
{:pow, "~> 1.0.38"},
{:quantum, ">= 1.8.0"},
{:swoosh, "~> 1.3"},
{:telemetry_metrics, "~> 0.6"},
Expand All @@ -103,7 +103,7 @@ defmodule Trento.MixProject do
sparse: "elixir"},
{:unplug, "~> 1.0.0"},
{:proper_case, "~> 1.3.1"},
{:polymorphic_embed, "~> 2.0.0"},
{:polymorphic_embed, "~> 4.1"},
{:joken, "~> 2.5.0"},
# required overrides to upgrade to elixir 1.15.7 and erlang otp 26
# https://stackoverflow.com/questions/76562092/hi-i-had-created-elixir-project-with-phoenix-framework-there-is-yaml-file-when
Expand All @@ -115,7 +115,9 @@ defmodule Trento.MixProject do
{:argon2_elixir, "~> 4.0"},
{:ecto_commons, "~> 0.3.4"},
{:bodyguard, "~> 2.4"},
{:nimble_totp, "~> 1.0"}
{:nimble_totp, "~> 1.0"},
{:phoenix_view, "~> 2.0"},
{:phoenix_html_helpers, "~> 1.0"}
]
end

Expand Down
Loading

0 comments on commit 54cb9ba

Please sign in to comment.