From b41c4ed9e4059d8f03e986f77d54e369af5ba478 Mon Sep 17 00:00:00 2001 From: bmanifold Date: Wed, 19 Jul 2023 14:56:49 -0400 Subject: [PATCH] Create vertical table component for show pages (#1805) Why: * The `show` pages for all of the Firezone resources (i.e. Gateways, Resources, Devices, etc...) were all very similar but were explicitly defined in individual tables with their styling also explicitly defined in each table. This commit creates a `vertical_table` component and a `vertical_table_row` component to allow the styling to be defined once and then consistently applied to each `show` page. --- .../lib/web/components/table_components.ex | 71 ++++++ .../web/lib/web/live/gateways_live/show.ex | 202 ++++++------------ 2 files changed, 137 insertions(+), 136 deletions(-) diff --git a/elixir/apps/web/lib/web/components/table_components.ex b/elixir/apps/web/lib/web/components/table_components.ex index d7a4a4514..d88f5dcf6 100644 --- a/elixir/apps/web/lib/web/components/table_components.ex +++ b/elixir/apps/web/lib/web/components/table_components.ex @@ -197,4 +197,75 @@ defmodule Web.TableComponents do """ end + + @doc ~S""" + Renders a table with 2 columns and generic styling. + + The component will likely be used when displaying the properties of an + individual resource (e.g. Gateway, Resource, Device, etc...) + + The component renders a table that is meant to be viewed vertically, with + the first column being the label and the second column being the value. + + This component is intended to be used with the `vertical_table_row` component + + ## Examples + + <.vertical_table> + <.vertical_table_row> + <:label>First Name + <:value>User First Name Here + + <.vertical_table_row> + <:label>Last Name + <:value>User Last Name Here + + + """ + + def vertical_table(assigns) do + ~H""" + + + <%= render_slot(@inner_block) %> + +
+ """ + end + + @doc ~S""" + Renders a row with 2 columns and generic styling. The first column will be + the header and the second column will be the value. + + The component will likely be used when displaying the properties of an + individual resource (e.g. Gateway, Resource, Device, etc...) + + This component is intended to be used with the `vertical_table` component. + + ## Examples + + <.vertical_table_row> + <:label>First Name + <:value>User First Name Here + + """ + + slot :label, doc: "the slot for rendering the label of a row" + slot :value, doc: "the slot for rendering the value of a row" + + def vertical_table_row(assigns) do + ~H""" + + + <%= render_slot(@label) %> + + + <%= render_slot(@value) %> + + + """ + end end diff --git a/elixir/apps/web/lib/web/live/gateways_live/show.ex b/elixir/apps/web/lib/web/live/gateways_live/show.ex index 0cd5607e9..a802f8261 100644 --- a/elixir/apps/web/lib/web/live/gateways_live/show.ex +++ b/elixir/apps/web/lib/web/live/gateways_live/show.ex @@ -29,142 +29,72 @@ defmodule Web.GatewaysLive.Show do
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Instance Group Name - - <.badge type="info"> - <%= @gateway.group.name_prefix %> - -
- Instance Name - - <%= @gateway.name_suffix %> -
- Connectivity - - TODO: Peer to Peer -
- Status - - <.badge type="success"> - TODO: Online - -
- Location - - - <%= @gateway.last_seen_remote_ip %> - -
- Last seen - - <.relative_datetime relative={@gateway.last_seen_at} /> -
- <%= @gateway.last_seen_at %> -
- Remote IPv4 - - <%= @gateway.ipv4 %> -
- Remote IPv6 - - <%= @gateway.ipv6 %> -
- Transfer - - TODO: 4.43 GB up, 1.23 GB down -
- Gateway version - - <%= "Gateway Version: #{@gateway.last_seen_version}" %> -
- - <%= "User Agent: #{@gateway.last_seen_user_agent}" %> -
- Deployment method - - TODO: Docker -
+ <.vertical_table> + <.vertical_table_row> + <:label>Instance Group Name + <:value><%= @gateway.group.name_prefix %> + + <.vertical_table_row> + <:label>Instance Name + <:value><%= @gateway.name_suffix %> + + <.vertical_table_row> + <:label>Connectivity + <:value>TODO: Peer to Peer + + <.vertical_table_row> + <:label>Status + <:value> + <.badge type="success">TODO: Online + + + <.vertical_table_row> + <:label>Location + <:value> + + <%= @gateway.last_seen_remote_ip %> + + + + <.vertical_table_row> + <:label> + Last seen + + <:value> + <.relative_datetime relative={@gateway.last_seen_at} /> +
+ <%= @gateway.last_seen_at %> + + + <.vertical_table_row> + <:label>Remote IPv4 + <:value> + <%= @gateway.ipv4 %> + + + <.vertical_table_row> + <:label>Remote IPv6 + <:value> + <%= @gateway.ipv6 %> + + + <.vertical_table_row> + <:label>Transfer + <:value>TODO: 4.43 GB up, 1.23 GB down + + <.vertical_table_row> + <:label>Gateway Version + <:value> + <%= "Gateway Version: #{@gateway.last_seen_version}" %> +
+ <%= "User Agent: #{@gateway.last_seen_user_agent}" %> + + + <.vertical_table_row> + <:label>Deployment Method + <:value>TODO: Docker + +