fix(portal): Adopt LiveView 1.0 breaking changes (#5549)

Closes https://github.com/firezone/firezone/issues/5545
This commit is contained in:
Andrew Dryga
2024-06-25 13:30:46 -06:00
committed by GitHub
parent e3d1b3e5fd
commit 40d7889dd1
8 changed files with 78 additions and 61 deletions

View File

@@ -618,17 +618,23 @@ defmodule API.Client.Channel do
end
defp select_gateway_version_requirement(client) do
gateway_version_requirement =
Enum.find_value(
@gateway_compatibility,
fn {client_version_requirement, gateway_version_requirement} ->
if Version.match?(client.last_seen_version, client_version_requirement) do
gateway_version_requirement
end
end
)
case Version.parse(client.last_seen_version) do
{:ok, _version} ->
gateway_version_requirement =
Enum.find_value(
@gateway_compatibility,
fn {client_version_requirement, gateway_version_requirement} ->
if Version.match?(client.last_seen_version, client_version_requirement) do
gateway_version_requirement
end
end
)
gateway_version_requirement || "> 0.0.0"
gateway_version_requirement || "> 0.0.0"
:error ->
"> 0.0.0"
end
end
defp filter_compatible_gateways(gateways, gateway_version_requirement) do

View File

@@ -189,6 +189,20 @@ defmodule API.Client.ChannelTest do
|> subscribe_and_join(API.Client.Channel, "client")
assert socket.assigns.gateway_version_requirement == ">= 1.1.0"
client = %{client | last_seen_version: "development"}
{:ok, _reply, socket} =
API.Client.Socket
|> socket("client:#{client.id}", %{
opentelemetry_ctx: OpenTelemetry.Ctx.new(),
opentelemetry_span_ctx: OpenTelemetry.Tracer.start_span("test"),
client: client,
subject: subject
})
|> subscribe_and_join(API.Client.Channel, "client")
assert socket.assigns.gateway_version_requirement == "> 0.0.0"
end
test "sends list of resources after join", %{

View File

@@ -39,7 +39,7 @@ defmodule Domain.Types.INET do
defp cast_address(address) do
address
|> String.to_charlist()
|> :inet.parse_address()
|> :inet.parse_strict_address()
end
defp cast_netmask(nil), do: {:ok, nil}

View File

@@ -41,7 +41,7 @@ const firezoneColors = {
},
// neutral: chicago
"chicago": {
50: "#f6f6f6",
50: "#f6f6f6",
100: "#e7e7e7",
200: "#d1d1d1",
300: "#b0b0b0",
@@ -82,7 +82,6 @@ module.exports = {
charts: true,
}),
require("@tailwindcss/forms"),
plugin(({ addVariant }) => addVariant("phx-no-feedback", [".phx-no-feedback&", ".phx-no-feedback &"])),
plugin(({ addVariant }) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
plugin(({ addVariant }) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
plugin(({ addVariant }) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),

View File

@@ -350,7 +350,7 @@ defmodule Web.CoreComponents do
<p
class={[
"w-full flex gap-3 text-sm leading-6",
"text-rose-600 phx-no-feedback:hidden",
"text-rose-600",
(@inline && "ml-3") || "mt-3"
]}
{@rest}
@@ -380,7 +380,7 @@ defmodule Web.CoreComponents do
<p
:if={@error}
data-validation-error-for={"#{@form.id}[#{@field}]"}
class="mt-3 mb-3 flex gap-3 text-m leading-6 text-rose-600 phx-no-feedback:hidden"
class="mt-3 mb-3 flex gap-3 text-m leading-6 text-rose-600"
{@rest}
>
<.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" />

View File

@@ -60,13 +60,18 @@ defmodule Web.FormComponents do
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
errors =
if assigns.value_index do
Enum.filter(field.errors, fn {_error, meta} ->
Keyword.get(meta, :validated_as) == :list and
Keyword.get(meta, :at) == assigns.value_index
end)
else
field.errors
cond do
not Phoenix.Component.used_input?(field) ->
[]
not is_nil(assigns.value_index) ->
Enum.filter(field.errors, fn {_error, meta} ->
Keyword.get(meta, :validated_as) == :list and
Keyword.get(meta, :at) == assigns.value_index
end)
true ->
field.errors
end
|> Enum.map(&translate_error(&1))
@@ -94,7 +99,7 @@ defmodule Web.FormComponents do
def input(%{type: "radio"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<div>
<label class="flex items-center gap-2 text-neutral-900">
<input
type="radio"
@@ -126,7 +131,7 @@ defmodule Web.FormComponents do
end)
~H"""
<div phx-feedback-for={@name}>
<div>
<label class="flex items-center gap-4 text-sm leading-6 text-neutral-600">
<input
type="checkbox"
@@ -153,7 +158,7 @@ defmodule Web.FormComponents do
def input(%{type: "group_select"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<div>
<.label :if={@label} for={@id}><%= @label %></.label>
<input
:if={not is_nil(@value) and @rest[:disabled] == true}
@@ -167,8 +172,8 @@ defmodule Web.FormComponents do
class={[
"text-sm bg-neutral-50",
"border border-neutral-300 text-neutral-900 rounded",
"block w-full p-2.5",
@errors != [] && "border-rose-400"
"block w-full p-2",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
multiple={@multiple}
{@rest}
@@ -194,7 +199,7 @@ defmodule Web.FormComponents do
def input(%{type: "select"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<div>
<.label :if={@label} for={@id}><%= @label %></.label>
<input
:if={@rest[:disabled] in [true, "true"] and not is_nil(@value)}
@@ -209,7 +214,7 @@ defmodule Web.FormComponents do
"text-sm bg-neutral-50",
"border border-neutral-300 text-neutral-900 rounded",
"block w-full p-2.5",
@errors != [] && "border-rose-400"
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
multiple={@multiple}
{@rest}
@@ -226,7 +231,7 @@ defmodule Web.FormComponents do
def input(%{type: "textarea"} = assigns) do
~H"""
<div phx-feedback-for={@name}>
<div>
<.label :if={@label} for={@id}><%= @label %></.label>
<textarea
id={@id}
@@ -234,10 +239,9 @@ defmodule Web.FormComponents do
class={[
"block w-full rounded sm:text-sm sm:leading-6",
"bg-neutral-50",
"border border-neutral-300 text-neutral-900 rounded",
"phx-no-feedback:border-neutral-300",
"min-h-[6rem] border-neutral-300",
@errors != [] && "border-rose-400"
"border border-neutral-300 rounded",
"min-h-[6rem]",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %></textarea>
@@ -284,17 +288,16 @@ defmodule Web.FormComponents do
def input(%{type: "text", prefix: prefix} = assigns) when not is_nil(prefix) do
~H"""
<div phx-feedback-for={@name} class={@inline_errors && "flex flex-row items-center"}>
<div class={@inline_errors && "flex flex-row items-center"}>
<.label :if={@label} for={@id}><%= @label %></.label>
<div class={[
"flex",
"text-sm text-neutral-900 bg-neutral-50",
"border-neutral-300 border rounded",
"border border-neutral-300 rounded",
"w-full",
"phx-no-feedback:border-neutral-300",
"focus-within:outline-none focus-within:border-accent-600",
"peer-disabled:bg-neutral-50 peer-disabled:text-neutral-500 peer-disabled:border-neutral-200 peer-disabled:shadow-none",
@errors != [] && "border-rose-400"
@errors != [] && "border-rose-400 focus:border-rose-400"
]}>
<span
class={[
@@ -328,7 +331,7 @@ defmodule Web.FormComponents do
def input(assigns) do
~H"""
<div phx-feedback-for={@name} class={@inline_errors && "flex flex-row items-center"}>
<div class={@inline_errors && "flex flex-row items-center"}>
<.label :if={@label} for={@id}><%= @label %></.label>
<input
type={@type}
@@ -336,11 +339,12 @@ defmodule Web.FormComponents do
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"bg-neutral-50 p-2.5 block w-full rounded border text-neutral-900 text-sm",
"phx-no-feedback:border-neutral-300",
"block w-full",
"p-2.5 rounded",
"bg-neutral-50 text-neutral-900 text-sm",
"border border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-200 disabled:shadow-none",
"border-neutral-300",
@errors != [] && "border-rose-400"
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
/>

View File

@@ -54,6 +54,7 @@ defmodule Web.Policies.Components do
) do
Map.update(condition_attrs, "values", [], fn values ->
values
|> Enum.filter(fn {dow, _} -> dow in ["M", "T", "W", "R", "F", "S", "U"] end)
|> Enum.sort_by(fn {dow, _} -> day_of_week_index(dow) end)
|> Enum.map(fn {dow, time_ranges} ->
"#{dow}/#{time_ranges}/#{timezone}"

View File

@@ -91,7 +91,7 @@ defmodule Web.LiveTable do
def datetime_input(assigns) do
~H"""
<div phx-feedback-for={@field.name} class={["flex items-center"]}>
<div class={["flex items-center"]}>
<input
placeholder={"#{@filter.title} Started At"}
type="date"
@@ -104,10 +104,8 @@ defmodule Web.LiveTable do
class={[
"bg-neutral-50 border border-neutral-300 text-neutral-900 text-sm rounded",
"block w-1/2 mr-1",
"phx-no-feedback:border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-200 disabled:shadow-none",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-300 disabled:shadow-none",
"focus:outline-none focus:border-1 focus:ring-0",
"border-neutral-300",
@field.errors != [] && "border-rose-400"
]}
/>
@@ -119,12 +117,11 @@ defmodule Web.LiveTable do
id={@field.id <> "[#{@from_or_to}][time]"}
value={normalize_value("time", Map.get(@field.value || %{}, @from_or_to)) || "00:00:00"}
class={[
"bg-neutral-50 border border-neutral-300 text-neutral-900 text-sm rounded",
"bg-neutral-50 border text-neutral-900 text-sm rounded",
"block w-1/2",
"phx-no-feedback:border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-200 disabled:shadow-none",
"focus:outline-none focus:border-1 focus:ring-0",
"border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-300 disabled:shadow-none",
"focus:outline-none focus:border-1 focus:ring-0",
@field.errors != [] && "border-rose-400"
]}
/>
@@ -205,10 +202,8 @@ defmodule Web.LiveTable do
class={[
"bg-neutral-50 border border-neutral-300 text-neutral-900 text-sm rounded",
"block w-full pl-10 p-2",
"phx-no-feedback:border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-200 disabled:shadow-none",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-300 disabled:shadow-none",
"focus:outline-none focus:border-1 focus:ring-0",
"border-neutral-300",
@form[@filter.name].errors != [] && "border-rose-400"
]}
/>
@@ -240,10 +235,8 @@ defmodule Web.LiveTable do
class={[
"bg-neutral-50 border border-neutral-300 text-neutral-900 text-sm rounded",
"block w-full pl-10 p-2",
"phx-no-feedback:border-neutral-300",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-200 disabled:shadow-none",
"disabled:bg-neutral-50 disabled:text-neutral-500 disabled:border-neutral-300 disabled:shadow-none",
"focus:outline-none focus:border-1 focus:ring-0",
"border-neutral-300",
@form[@filter.name].errors != [] && "border-rose-400"
]}
/>
@@ -286,7 +279,7 @@ defmodule Web.LiveTable do
<label
for={"#{@live_table_id}-#{@filter.name}-__all__"}
class={[
"px-4 py-2 text-sm border-neutral-200 text-neutral-900",
"px-4 py-2 text-sm border-neutral-300 text-neutral-900",
"hover:bg-neutral-200 hover:text-neutral-700",
"cursor-pointer",
"border-y border-l rounded-l",
@@ -309,7 +302,7 @@ defmodule Web.LiveTable do
<label
for={"#{@live_table_id}-#{@filter.name}-#{value}"}
class={[
"px-4 py-2 text-sm border-neutral-200 text-neutral-900",
"px-4 py-2 text-sm border-neutral-300 text-neutral-900",
"hover:bg-neutral-200 hover:text-neutral-700",
"cursor-pointer",
@form[@filter.name].value == value && "bg-neutral-100",
@@ -345,7 +338,7 @@ defmodule Web.LiveTable do
<label
for={"#{@live_table_id}-#{@filter.name}-__all__"}
class={[
"px-4 py-2 text-sm border-neutral-200 text-neutral-900",
"px-4 py-2 text-sm border-neutral-300 text-neutral-900",
"hover:bg-neutral-200 hover:text-neutral-700",
"cursor-pointer",
"border-y border-l rounded-l",
@@ -368,7 +361,7 @@ defmodule Web.LiveTable do
<label
for={"#{@live_table_id}-#{@filter.name}-#{value}"}
class={[
"px-4 py-2 text-sm border-neutral-200 text-neutral-900",
"px-4 py-2 text-sm border-neutral-300 text-neutral-900",
"hover:bg-neutral-200 hover:text-neutral-700",
"cursor-pointer",
@form[@filter.name].value && value in @form[@filter.name].value && "bg-neutral-100",