diff --git a/README.md b/README.md index 7a617c4..57bec3e 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ library is part of the [DeployEx][dye] project. See the [installation guide](https://hexdocs.pm/observer_web/installation.html) for details on installing and Configuring. +## Theming + +Colors come from a small set of CSS custom properties in `assets/css/tokens.css`, one block for light mode and one for dark mode. +They're mapped to Tailwind utilities (`bg-primary`, `bg-base-100`, `text-muted`, `bg-success`, and so on) in the `@theme` block of `assets/css/app.css`, so a class built on a token needs no separate `dark:` variant - the underlying variable itself switches with the page's `dark` class. +To change the palette, edit the values in `tokens.css` and rebuild assets; nothing else needs to change. + ## Supported Versions Observer Web follows the same support policy as [DeployEx][dye]: the last two major Erlang/OTP releases, and the last two major Phoenix releases. diff --git a/assets/css/app.css b/assets/css/app.css index ccb0067..04a81cc 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -6,6 +6,7 @@ @import "tailwindcss"; @plugin "@tailwindcss/forms"; +@import "./tokens.css"; @source "../../lib/**/*.*ex"; @@ -16,4 +17,28 @@ --spacing-72: 18rem; --spacing-84: 21rem; --spacing-96: 24rem; + + /* Backed by the CSS variables in tokens.css, which already flip between light and dark - so + classes built on these (bg-primary, text-base-content, etc.) need no separate dark: variant. */ + --color-base-100: var(--dx-base-100); + --color-base-200: var(--dx-base-200); + --color-base-300: var(--dx-base-300); + --color-base-content: var(--dx-base-content); + --color-muted: var(--dx-muted); + + --color-primary: var(--dx-primary); + --color-primary-content: var(--dx-primary-content); + --color-secondary: var(--dx-secondary); + --color-secondary-content: var(--dx-secondary-content); + --color-neutral: var(--dx-neutral); + --color-neutral-content: var(--dx-neutral-content); + + --color-info: var(--dx-info); + --color-info-content: var(--dx-info-content); + --color-success: var(--dx-success); + --color-success-content: var(--dx-success-content); + --color-warning: var(--dx-warning); + --color-warning-content: var(--dx-warning-content); + --color-error: var(--dx-error); + --color-error-content: var(--dx-error-content); } diff --git a/assets/css/tokens.css b/assets/css/tokens.css new file mode 100644 index 0000000..db1dde4 --- /dev/null +++ b/assets/css/tokens.css @@ -0,0 +1,64 @@ +/* Design tokens, adapted from the deployex dashboard's shared token file so the two keep a matching + palette. Plain CSS custom properties, no Tailwind/daisyUI syntax - edit the values here and every + class built on them (in the @theme block in app.css) picks it up, without touching component files. + + The light values apply on :root; .dark overrides them, matching this project's own dark-mode + mechanism (a `dark` class toggled on by the Themer hook), not deployex's `data-theme` attr. */ + +:root { + --dx-base-100: oklch(98.6% 0.006 85); + --dx-base-200: oklch(95% 0.011 80); + --dx-base-300: oklch(88.5% 0.016 75); + --dx-base-content: oklch(23% 0.014 60); + --dx-muted: color-mix(in oklch, var(--dx-base-content) 66%, var(--dx-base-100)); + + --dx-primary: oklch(70% 0.213 47.604); + --dx-primary-content: oklch(98% 0.016 73.684); + --dx-primary-text: oklch(50% 0.16 42); + --dx-secondary: oklch(52% 0.02 60); + --dx-secondary-content: oklch(98.6% 0.006 85); + --dx-neutral: oklch(44% 0.017 60); + --dx-neutral-content: oklch(98.6% 0.006 85); + + --dx-info: oklch(62% 0.214 259.815); + --dx-info-content: oklch(97% 0.014 254.604); + --dx-info-text: oklch(47% 0.17 260); + --dx-success: oklch(70% 0.14 182.503); + --dx-success-content: oklch(98% 0.014 180.72); + --dx-success-text: oklch(44% 0.09 182); + --dx-warning: oklch(66% 0.179 58.318); + --dx-warning-content: oklch(98% 0.022 95.277); + --dx-warning-text: oklch(47% 0.12 58); + --dx-error: oklch(58% 0.253 17.585); + --dx-error-content: oklch(96% 0.015 12.422); + --dx-error-text: oklch(48% 0.19 20); +} + +.dark { + --dx-base-100: oklch(30.33% 0.016 252.42); + --dx-base-200: oklch(25.26% 0.014 253.1); + --dx-base-300: oklch(20.15% 0.012 254.09); + --dx-base-content: oklch(97.807% 0.029 256.847); + --dx-muted: color-mix(in oklch, var(--dx-base-content) 66%, var(--dx-base-100)); + + --dx-primary: oklch(58% 0.233 277.117); + --dx-primary-content: oklch(96% 0.018 272.314); + --dx-primary-text: oklch(80% 0.11 277); + --dx-secondary: oklch(58% 0.233 277.117); + --dx-secondary-content: oklch(96% 0.018 272.314); + --dx-neutral: oklch(37% 0.044 257.287); + --dx-neutral-content: oklch(98% 0.003 247.858); + + --dx-info: oklch(58% 0.158 241.966); + --dx-info-content: oklch(97% 0.013 236.62); + --dx-info-text: oklch(82% 0.09 240); + --dx-success: oklch(60% 0.118 184.704); + --dx-success-content: oklch(98% 0.014 180.72); + --dx-success-text: oklch(82% 0.09 182); + --dx-warning: oklch(66% 0.179 58.318); + --dx-warning-content: oklch(98% 0.022 95.277); + --dx-warning-text: oklch(84% 0.12 72); + --dx-error: oklch(58% 0.253 17.585); + --dx-error-content: oklch(96% 0.015 12.422); + --dx-error-text: oklch(80% 0.12 20); +} diff --git a/assets/js/app.js b/assets/js/app.js index 6d11eaa..ad2a28e 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -10,6 +10,7 @@ import NavOverflow from "./hooks/nav_overflow"; import ScrollBottom from "./hooks/scroll_bottom"; import Themer from "./hooks/themer"; import AutoDismissFlash from "./hooks/auto_dismiss_flash"; +import Countdown from "./hooks/countdown"; const hooks = { LiveMetricsEChart, @@ -19,6 +20,7 @@ const hooks = { ScrollBottom, Themer, AutoDismissFlash, + Countdown, }; // Topbar --- diff --git a/assets/js/hooks/countdown.js b/assets/js/hooks/countdown.js new file mode 100644 index 0000000..a5bf3d7 --- /dev/null +++ b/assets/js/hooks/countdown.js @@ -0,0 +1,27 @@ +// Ticks down to the timestamp in data-expires (ISO 8601), purely client-side so it doesn't need +// a server round-trip every second. The server re-renders data-expires whenever a new session +// starts, which this hook picks up via updated(). +const Countdown = { + mounted() { + this.tick(); + this.timer = setInterval(() => this.tick(), 1000); + }, + + updated() { + this.tick(); + }, + + destroyed() { + clearInterval(this.timer); + }, + + tick() { + const expiresAt = new Date(this.el.dataset.expires).getTime(); + const remainingMs = expiresAt - Date.now(); + const remainingSeconds = Math.max(0, Math.ceil(remainingMs / 1000)); + + this.el.textContent = `${remainingSeconds}s`; + }, +}; + +export default Countdown; diff --git a/lib/web/components/attention.ex b/lib/web/components/attention.ex index 4d4e731..7116d5f 100644 --- a/lib/web/components/attention.ex +++ b/lib/web/components/attention.ex @@ -11,10 +11,10 @@ defmodule Observer.Web.Components.Attention do def content(assigns) do ~H""" -
| {col[:label]} @@ -55,7 +55,7 @@ defmodule Observer.Web.Components.Core do |
|---|
|
{col[:label]}
@@ -551,4 +551,26 @@ defmodule Observer.Web.Components.Core do
instead of each button hand-rolling its own `disabled:` utilities.
"""
def gated_classes, do: "disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
+
+ @doc """
+ Shared class string for a toolbar's primary CTA button (REFRESH/RUN/UPDATE), so every page's
+ button stays visually identical without retyping the same Tailwind string at each call site.
+ """
+ def action_button_class,
+ do:
+ "phx-submit-loading:opacity-75 rounded-xl bg-success transform active:scale-75 transition-transform hover:opacity-90 ml-auto px-5 py-1.5 shrink-0 flex items-center justify-center text-sm font-semibold text-success-content active:opacity-75"
+
+ @doc """
+ Shared class string for a small stat/status pill. `tone` picks the color: `:info` (default),
+ `:warning`, or `:neutral`.
+ """
+ def badge_class(tone \\ :info)
+
+ def badge_class(:info), do: "px-2 py-1 rounded-full bg-info/10 border border-info text-info"
+
+ def badge_class(:warning),
+ do: "px-2 py-1 rounded-full bg-warning/10 border border-warning text-warning"
+
+ def badge_class(:neutral),
+ do: "px-2 py-1 rounded-full bg-base-200 border border-base-300 text-base-content"
end
diff --git a/lib/web/components/details_panel.ex b/lib/web/components/details_panel.ex
new file mode 100644
index 0000000..072dd59
--- /dev/null
+++ b/lib/web/components/details_panel.ex
@@ -0,0 +1,104 @@
+defmodule Observer.Web.Components.DetailsPanel do
+ @moduledoc """
+ Bottom-docked panel that slides up to show the details of whatever row/identifier a page's
+ user just selected (an ETS table, a process, a port, ...), with collapse/expand/close controls.
+ Each page keeps its own selection state and event names; this component only renders the
+ shared chrome around whatever content the caller puts in its `inner_block` slot.
+ """
+ use Phoenix.Component
+
+ alias Observer.Web.Components.Icons
+ alias Phoenix.LiveView.JS
+
+ attr :id, :string, required: true
+ attr :expand_id, :string, required: true
+ attr :collapse_id, :string, required: true
+ attr :close_id, :string, required: true
+ attr :collapsed, :boolean, required: true
+ attr :expanded, :boolean, required: true
+ attr :expand_event, :string, required: true
+ attr :collapse_event, :string, required: true
+ attr :close_event, :string, required: true
+
+ slot :title, required: true
+ slot :inner_block, required: true
+
+ def content(assigns) do
+ ~H"""
+
+
+ """
+ end
+
+ @doc """
+ Bottom padding for the page's root container, so the docked panel never overlaps the page's
+ own content. Sized to match the panel's own collapsed/expanded height.
+ """
+ def padding_class(shown?, collapsed?, expanded?)
+ def padding_class(false, _collapsed?, _expanded?), do: nil
+ def padding_class(true, true, _expanded?), do: "pb-16"
+ def padding_class(true, false, true), do: "pb-[92vh]"
+ def padding_class(true, false, false), do: "pb-[70vh]"
+end
diff --git a/lib/web/components/icons.ex b/lib/web/components/icons.ex
index 82be21a..0b4a9c6 100644
--- a/lib/web/components/icons.ex
+++ b/lib/web/components/icons.ex
@@ -415,6 +415,54 @@ defmodule Observer.Web.Components.Icons do
attr :rest, :global
+ def chevron_down(assigns) do
+ ~H"""
+ <.svg_outline {@rest}>
+
+
+
+ + {render_slot(@title)} ++
+
+
+
+
+
+ {render_slot(@inner_block)}
+
+
-
-
-
-
-
"""
end
- defp border_item_color("services"), do: "border-teal-300"
- defp border_item_color("apps"), do: "border-blue-400"
- defp border_item_color("metrics"), do: "border-orange-400"
- # coveralls-ignore-start
- defp border_item_color(_), do: "border-gray-300"
- # coveralls-ignore-stop
-
- defp bg_item_color("services"), do: "bg-teal-50"
- defp bg_item_color("apps"), do: "bg-blue-50"
- defp bg_item_color("metrics"), do: "bg-orange-50"
- # coveralls-ignore-start
- defp bg_item_color(_), do: "bg-gray-50"
- # coveralls-ignore-stop
-
- defp text_item_color("services"), do: "text-teal-700"
- defp text_item_color("apps"), do: "text-blue-700"
- defp text_item_color("metrics"), do: "text-orange-700"
- # coveralls-ignore-start
- defp text_item_color(_), do: "text-teal-700"
- # coveralls-ignore-stop
-
- defp unselected_highlight_color(key, unselected_highlight) do
- if key in unselected_highlight do
- "text-gray-700 dark:text-white bg-green-100 dark:bg-transparent border border-green-300"
- else
- "text-gray-700 dark:text-white bg-gray-100 dark:bg-transparent border border-gray-300"
- end
- end
+ defp highlighted?(key, unselected_highlight), do: key in unselected_highlight
end
diff --git a/lib/web/components/multi_select_list.ex b/lib/web/components/multi_select_list.ex
index 37bf8e4..2363790 100644
--- a/lib/web/components/multi_select_list.ex
+++ b/lib/web/components/multi_select_list.ex
@@ -1,14 +1,13 @@
defmodule Observer.Web.Components.MultiSelectList do
@moduledoc """
- Multi select list box
-
- References:
- * https://www.creative-tim.com/twcomponents/component/multi-select
-
+ Multi select list box, with a per-group search filter - the Tracing/Profiling pages' version of
+ `Observer.Web.Components.MultiSelect`, kept as a separate component because it supports up to
+ four groups, each with its own search box and an optional extra info label.
"""
use Phoenix.Component
alias Observer.Web.Components.Core
+ alias Observer.Web.Components.Icons
alias Observer.Web.Helpers
alias Phoenix.LiveView.JS
@@ -36,205 +35,108 @@ defmodule Observer.Web.Components.MultiSelectList do
end
end)
+ panel_id = "#{assigns.id}-panel"
+
+ close = JS.hide(to: "##{panel_id}") |> JS.push("close-options")
+
+ toggle =
+ JS.toggle(to: "##{panel_id}", in: "ease-in duration-150", out: "ease-out duration-100")
+ |> JS.push("toggle-options")
+
assigns =
assigns
|> assign(elements_to_filter: elements_to_filter)
|> assign(unselected: filtered_unselected)
+ |> assign(panel_id: panel_id, close: close, toggle: toggle)
~H"""
-
-
+
- {@selected_text}
-
+
+
+ <%= for item <- @selected do %>
+ <%= for key <- item.keys do %>
+
+ {"#{item.name}:#{key}"}
+
+
+ <% end %>
+ <% end %>
-
+ {@selected_text}
- <%= for item <- @selected do %>
- <%= for key <- item.keys do %>
-
-
-
- <% end %>
- <% end %>
-
- {"#{item.name}:#{key}"}
-
-
-
-
-
-
-
-
-
-
-
- <%= for item <- @unselected do %>
-
- <% end %>
-
-
-
-
+
+ {item.name}:
-
- <%= for key <- item.keys do %>
-
- <% end %>
-
-
+
+
+ {item.name}
+
-
-
-
-
-
-
"""
end
-
- # One column per selection group: the Tracing page passes four (services, modules, functions,
- # match_spec), the Profiling page three (no match-spec picker). Literal class names, not
- # interpolation - Tailwind only generates classes it finds verbatim in the source.
- defp grid_cols(3), do: "grid-cols-3"
- defp grid_cols(_four), do: "grid-cols-4"
-
- def border_item_color("services"), do: "border-teal-300"
- def border_item_color("modules"), do: "border-red-500"
- def border_item_color("functions"), do: "border-blue-400"
- def border_item_color("match_spec"), do: "border-yellow-400"
- # coveralls-ignore-start
- def border_item_color(_), do: "border-gray-300"
- # coveralls-ignore-stop
-
- def bg_item_color("services"), do: "bg-teal-50"
- def bg_item_color("modules"), do: "bg-red-50"
- def bg_item_color("functions"), do: "bg-blue-50"
- def bg_item_color("match_spec"), do: "bg-yellow-50"
- # coveralls-ignore-start
- def bg_item_color(_), do: "bg-gray-50"
- # coveralls-ignore-stop
-
- def text_item_color("services"), do: "text-teal-700"
- def text_item_color("modules"), do: "text-red-500"
- def text_item_color("functions"), do: "text-blue-400"
- def text_item_color("match_spec"), do: "text-yellow-700"
- # coveralls-ignore-start
- def text_item_color(_), do: "text-teal-700"
- # coveralls-ignore-stop
end
diff --git a/lib/web/components/settings_panel.ex b/lib/web/components/settings_panel.ex
new file mode 100644
index 0000000..8d84f10
--- /dev/null
+++ b/lib/web/components/settings_panel.ex
@@ -0,0 +1,51 @@
+defmodule Observer.Web.Components.SettingsPanel do
+ @moduledoc """
+ A toolbar "Settings" popover: a button that toggles a small form panel open, closing again on
+ click-away or Escape. Purely client-side (`Phoenix.LiveView.JS`), so opening/closing never
+ round-trips to the server. Each page supplies its own form as the `inner_block` slot.
+ """
+ use Phoenix.Component
+
+ alias Observer.Web.Components.Icons
+ alias Phoenix.LiveView.JS
+
+ attr :id, :string, required: true, doc: "prefix for this popover's wrap/toggle/panel ids"
+ attr :label, :string, required: true, doc: "title/aria-label for the toggle button"
+
+ slot :inner_block, required: true
+
+ def content(assigns) do
+ panel_id = "#{assigns.id}-panel"
+
+ assigns = assign(assigns, panel_id: panel_id)
+
+ ~H"""
+
- {@selected_text}
-
+
+
-
+ {@selected_text}
+
+ <%= for item <- @selected do %>
+ <%= for key <- item.keys do %>
+
+ {"#{item.name}:#{key}"}
+
+
+ <% end %>
+ <% end %>
+
+
+
- <%= for item <- @selected do %>
- <%= for key <- item.keys do %>
-
-
- <% end %>
- <% end %>
-
- {"#{item.name}:#{key}"}
-
-
-
-
-
-
-
-
+
+
+
+
+
+ {item.name}{if item[:info], do: item.info}
-
-
-
+
-
-
- <%= for item <- @unselected do %>
-
-
-
- <% end %>
-
- <.form
- for={@form_search}
- id={"multi-select-list-search-form-#{@id}-#{item.name}"}
- phx-change="form-multi-select-list-update-search"
- class="flex"
- >
- <%= if item[:info] do %>
-
-
- <%= for key <- item.keys do %>
-
- <% end %>
- {item.name}
- {item.info}:
- <% else %>
-
- {item.name}:
-
- <% end %>
- <%= if item.name in @elements_to_filter do %>
-
+
+
+
+ """
+ end
+end
diff --git a/lib/web/components/toolbar.ex b/lib/web/components/toolbar.ex
new file mode 100644
index 0000000..ef1ac4b
--- /dev/null
+++ b/lib/web/components/toolbar.ex
@@ -0,0 +1,14 @@
+defmodule Observer.Web.Components.Toolbar do
+ @moduledoc false
+ use Phoenix.Component
+
+ slot :inner_block, required: true
+
+ def content(assigns) do
+ ~H"""
+
+ {render_slot(@inner_block)}
+
+
+ {render_slot(@inner_block)}
+
+ """
+ end
+end
diff --git a/lib/web/helpers.ex b/lib/web/helpers.ex
index b0cbef9..c472f60 100644
--- a/lib/web/helpers.ex
+++ b/lib/web/helpers.ex
@@ -216,4 +216,16 @@ defmodule Observer.Web.Helpers do
do: true
defp literal_term?(ast), do: Macro.quoted_literal?(ast)
+
+ @doc """
+ Builds the ISO-8601 timestamp a tracing/profiling session expires at, `session_timeout_ms`
+ from now. Truncated to millisecond precision so the client's `new Date()` parse
+ (`assets/js/hooks/countdown.js`) stays within the ECMA-262 guaranteed format.
+ """
+ def trace_expires_at(session_timeout_ms) do
+ DateTime.utc_now()
+ |> DateTime.add(session_timeout_ms, :millisecond)
+ |> DateTime.truncate(:millisecond)
+ |> DateTime.to_iso8601()
+ end
end
diff --git a/lib/web/pages/apps/legend.ex b/lib/web/pages/apps/legend.ex
index 7b0ae61..211ce99 100644
--- a/lib/web/pages/apps/legend.ex
+++ b/lib/web/pages/apps/legend.ex
@@ -4,12 +4,12 @@ defmodule Observer.Web.Apps.Legend do
def content(assigns) do
~H"""
-
-
+ Legend
- Process (App)
+ Process (App)
|
|---|