mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
Why:
* When navigating around the portal, the title in the browser tab would
not show the accurate title of the current page. This commit adds
`page_title` to all pages. The value of the page title has been
choosen to correspond with the portal's left hand nav menu.
Additional:
* Along with the page titles, the `vertical_table` component was updated
to make the left hand headers use a class of `w-1/5` for consistency
across pages and to move the info a little further left on each page to
try and align it closer with other info on the page.
Here's an example of before and after:
<img width="1060" alt="before"
src="https://github.com/firezone/firezone/assets/2646332/6c56b550-98a5-4331-b1d3-c65ed9e24330">
<img width="1058" alt="after"
src="https://github.com/firezone/firezone/assets/2646332/c4753fee-ddea-4c67-9d5e-5b924260ea20">
125 lines
3.8 KiB
Elixir
125 lines
3.8 KiB
Elixir
defmodule Web.Resources.Edit do
|
|
use Web, :live_view
|
|
import Web.Resources.Components
|
|
alias Domain.{Gateways, Resources, Config}
|
|
|
|
def mount(%{"id" => id} = params, _session, socket) do
|
|
with {:ok, resource} <-
|
|
Resources.fetch_resource_by_id(id, socket.assigns.subject, preload: :gateway_groups),
|
|
nil <- resource.deleted_at,
|
|
{:ok, gateway_groups} <- Gateways.list_groups(socket.assigns.subject) do
|
|
form = Resources.change_resource(resource, socket.assigns.subject) |> to_form()
|
|
|
|
socket =
|
|
assign(
|
|
socket,
|
|
resource: resource,
|
|
gateway_groups: gateway_groups,
|
|
form: form,
|
|
params: Map.take(params, ["site_id"]),
|
|
traffic_filters_enabled?: Config.traffic_filters_enabled?(),
|
|
page_title: "Edit #{resource.name}"
|
|
)
|
|
|
|
{:ok, socket, temporary_assigns: [form: %Phoenix.HTML.Form{}]}
|
|
else
|
|
_other -> raise Web.LiveErrors.NotFoundError
|
|
end
|
|
end
|
|
|
|
def render(assigns) do
|
|
~H"""
|
|
<.breadcrumbs account={@account}>
|
|
<.breadcrumb path={~p"/#{@account}/resources"}>Resources</.breadcrumb>
|
|
<.breadcrumb path={~p"/#{@account}/resources/#{@resource.id}"}>
|
|
<%= @resource.name %>
|
|
</.breadcrumb>
|
|
<.breadcrumb path={~p"/#{@account}/resources/#{@resource.id}/edit"}>
|
|
Edit
|
|
</.breadcrumb>
|
|
</.breadcrumbs>
|
|
<.section>
|
|
<:title>
|
|
Edit Resource
|
|
</:title>
|
|
<:content>
|
|
<div class="max-w-2xl px-4 py-8 mx-auto lg:py-16">
|
|
<h2 class="mb-4 text-xl text-neutral-900">Edit Resource details</h2>
|
|
|
|
<.form for={@form} phx-change={:change} phx-submit={:submit} class="space-y-4 lg:space-y-6">
|
|
<.input
|
|
field={@form[:name]}
|
|
type="text"
|
|
label="Name"
|
|
placeholder="Name this resource"
|
|
required
|
|
/>
|
|
|
|
<.filters_form :if={@traffic_filters_enabled?} form={@form[:filters]} />
|
|
|
|
<.connections_form
|
|
:if={is_nil(@params["site_id"])}
|
|
id="connections_form"
|
|
phx-update="ignore"
|
|
form={@form[:connections]}
|
|
account={@account}
|
|
resource={@resource}
|
|
gateway_groups={@gateway_groups}
|
|
/>
|
|
|
|
<.submit_button phx-disable-with="Updating Resource...">
|
|
Save
|
|
</.submit_button>
|
|
</.form>
|
|
</div>
|
|
</:content>
|
|
</.section>
|
|
"""
|
|
end
|
|
|
|
def handle_event("change", %{"resource" => attrs}, socket) do
|
|
attrs =
|
|
attrs
|
|
|> map_filters_form_attrs()
|
|
|> map_connections_form_attrs()
|
|
|> maybe_delete_connections(socket.assigns.params)
|
|
|
|
changeset =
|
|
Resources.change_resource(socket.assigns.resource, attrs, socket.assigns.subject)
|
|
|> Map.put(:action, :validate)
|
|
|
|
{:noreply, assign(socket, form: to_form(changeset))}
|
|
end
|
|
|
|
def handle_event("submit", %{"resource" => attrs}, socket) do
|
|
attrs =
|
|
attrs
|
|
|> map_filters_form_attrs()
|
|
|> map_connections_form_attrs()
|
|
|> maybe_delete_connections(socket.assigns.params)
|
|
|
|
case Resources.update_resource(socket.assigns.resource, attrs, socket.assigns.subject) do
|
|
{:ok, resource} ->
|
|
if site_id = socket.assigns.params["site_id"] do
|
|
{:noreply,
|
|
push_navigate(socket, to: ~p"/#{socket.assigns.account}/sites/#{site_id}?#resources")}
|
|
else
|
|
{:noreply,
|
|
push_navigate(socket, to: ~p"/#{socket.assigns.account}/resources/#{resource.id}")}
|
|
end
|
|
|
|
{:error, changeset} ->
|
|
changeset = Map.put(changeset, :action, :validate)
|
|
{:noreply, assign(socket, form: to_form(changeset))}
|
|
end
|
|
end
|
|
|
|
defp maybe_delete_connections(attrs, params) do
|
|
if params["site_id"] do
|
|
Map.delete(attrs, "connections")
|
|
else
|
|
attrs
|
|
end
|
|
end
|
|
end
|