Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(ui): make live refresh a toggle for any metrics and analytics range

Andras Bacsai1527917523d8
diff --git a/app/Livewire/Analytics.php b/app/Livewire/Analytics.php
index 007618501c..62c3aab048 100644
--- a/app/Livewire/Analytics.php
+++ b/app/Livewire/Analytics.php
@@ -56,8 +56,7 @@ class Analytics extends Component
#[Url(as: 'app')]
public string $appUuid = '';
- // Realtime refresh; off by default (click "Live" to arm it). Only meaningful on the
- // 24h range, which matches the 60s Sentinel cache TTL.
+ // Realtime refresh every 60s (the Sentinel cache TTL); off by default, works with every range.
public bool $live = false;
public ?array $overview = null;
@@ -186,12 +185,11 @@ class Analytics extends Component
$this->loadData();
}
- public function toggleLive(): void
+ public function updatedLive(): void
{
- if ($this->range !== '24h') {
- return;
+ if ($this->live) {
+ $this->loadData();
}
- $this->live = ! $this->live;
}
#[On('trafficAnalyticsStateChanged')]
@@ -211,11 +209,6 @@ class Analytics extends Component
}
}
- public function isLivePollable(): bool
- {
- return $this->live && $this->range === '24h';
- }
-
public function updatedServerUuid(): void
{
// Scope the app options to the newly selected server and drop an app filter
diff --git a/app/Livewire/Fleet/Metrics.php b/app/Livewire/Fleet/Metrics.php
index 5a681460e6..ccce6ae820 100644
--- a/app/Livewire/Fleet/Metrics.php
+++ b/app/Livewire/Fleet/Metrics.php
@@ -196,9 +196,11 @@ class Metrics extends Component
$this->loadData();
}
- public function isLivePollable(): bool
+ public function updatedLive(): void
{
- return $this->live && $this->range === '24h';
+ if ($this->live) {
+ $this->loadData();
+ }
}
/**
diff --git a/app/Livewire/Project/Shared/Metrics.php b/app/Livewire/Project/Shared/Metrics.php
index f4138fdd41..8b027d7b49 100644
--- a/app/Livewire/Project/Shared/Metrics.php
+++ b/app/Livewire/Project/Shared/Metrics.php
@@ -16,17 +16,7 @@ class Metrics extends Component
public int $interval = 5;
- public bool $poll = true;
-
- public function pollData()
- {
- if ($this->poll || $this->interval <= 10) {
- $this->loadData();
- if ($this->interval > 10) {
- $this->poll = false;
- }
- }
- }
+ public bool $live = true;
public function loadData()
{
@@ -47,12 +37,24 @@ class Metrics extends Component
public function setInterval()
{
- if ($this->interval <= 10) {
- $this->poll = true;
- }
$this->loadData();
}
+ public function updatedLive(): void
+ {
+ if ($this->live) {
+ $this->loadData();
+ }
+ }
+
+ /**
+ * Short ranges refresh every 5 seconds; longer ranges change slowly, so they refresh every minute.
+ */
+ public function pollSeconds(): int
+ {
+ return $this->interval <= 60 ? 5 : 60;
+ }
+
public function render()
{
return view('livewire.project.shared.metrics');
diff --git a/app/Livewire/Project/Shared/ResourceTrafficAnalytics.php b/app/Livewire/Project/Shared/ResourceTrafficAnalytics.php
index 02f1718ede..6357e77b6d 100644
--- a/app/Livewire/Project/Shared/ResourceTrafficAnalytics.php
+++ b/app/Livewire/Project/Shared/ResourceTrafficAnalytics.php
@@ -35,9 +35,8 @@ abstract class ResourceTrafficAnalytics extends Component
#[Locked]
public ?string $analyticsServerUuid = null;
- // Realtime refresh. Off by default (click "Live" to arm it). Only meaningful on the
- // 24h range; the 60s cadence matches the SentinelTrafficClient cache TTL and
- // Sentinel's per-minute rollups. The control is disabled for 7d/30d.
+ // Realtime refresh every 60s (the SentinelTrafficClient cache TTL); off by default,
+ // works with every range.
public bool $live = false;
public ?array $overview = null;
@@ -109,20 +108,11 @@ abstract class ResourceTrafficAnalytics extends Component
$this->loadData();
}
- public function toggleLive(): void
+ public function updatedLive(): void
{
- if ($this->range !== '24h') {
- return;
+ if ($this->live) {
+ $this->loadData();
}
- $this->live = ! $this->live;
- }
-
- /**
- * Realtime polling is only armed when the user has it on and the range is 24h.
- */
- public function isLivePollable(): bool
- {
- return $this->live && $this->range === '24h';
}
public function loadData(): void
diff --git a/app/Livewire/Server/Charts.php b/app/Livewire/Server/Charts.php
index c63cf47ed3..65ddde8a7d 100644
--- a/app/Livewire/Server/Charts.php
+++ b/app/Livewire/Server/Charts.php
@@ -22,7 +22,7 @@ class Charts extends Component
public int $interval = 5;
- public bool $poll = true;
+ public bool $live = true;
#[Validate(['required', 'integer', 'min:1'])]
public int|string $sentinelMetricsRefreshRateSeconds;
@@ -89,16 +89,6 @@ class Charts extends Component
}
}
- public function pollData()
- {
- if ($this->poll || $this->interval <= 10) {
- $this->loadData();
- if ($this->interval > 10) {
- $this->poll = false;
- }
- }
- }
-
public function loadData()
{
try {
@@ -157,9 +147,21 @@ class Charts extends Component
public function setInterval()
{
- if ($this->interval <= 10) {
- $this->poll = true;
- }
$this->loadData();
}
+
+ public function updatedLive(): void
+ {
+ if ($this->live) {
+ $this->loadData();
+ }
+ }
+
+ /**
+ * Short ranges refresh every 5 seconds; longer ranges change slowly, so they refresh every minute.
+ */
+ public function pollSeconds(): int
+ {
+ return $this->interval <= 60 ? 5 : 60;
+ }
}
diff --git a/resources/views/components/live-toggle.blade.php b/resources/views/components/live-toggle.blade.php
new file mode 100644
index 0000000000..2716d7c826
--- /dev/null
+++ b/resources/views/components/live-toggle.blade.php
@@ -0,0 +1,34 @@
+{{--
+ Live refresh toggle. Entangles the `live` bool of the host Livewire component, so it works
+ with any time range. The button shows "Live" with a pulsing dot when refresh is on and
+ "Paused" with a play icon when it is off. `storageKey` keeps the choice per browser.
+--}}
+@props([
+ 'active' => false,
+ 'storageKey' => null,
+ 'title' => 'Turn live refresh on or off',
+])
+
+<div x-data="{ live: $wire.entangle('live').live }"
+ @if ($storageKey) x-init="
+ const stored = localStorage.getItem(@js($storageKey));
+ if (stored === '0') { live = false; }
+ if (stored === '1') { live = true; }
+ $watch('live', value => localStorage.setItem(@js($storageKey), value ? '1' : '0'));
+ " @endif>
+ <button type="button" @click="live = !live" :aria-pressed="live ? 'true' : 'false'"
+ aria-pressed="{{ $active ? 'true' : 'false' }}" title="{{ $title }}"
+ class="inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium ring-1 ring-neutral-200 transition-colors dark:ring-white/[0.08]"
+ :class="live
+ ? 'bg-white text-black shadow-sm dark:bg-white/[0.09] dark:text-fg'
+ : 'text-neutral-500 hover:text-black dark:text-fg-faint dark:hover:text-fg'">
+ <span x-show="live" class="relative flex h-1.5 w-1.5 shrink-0" @style(['display: none' => ! $active]) aria-hidden="true">
+ <span class="absolute inline-flex h-full w-full rounded-full bg-emerald-500 opacity-75 motion-safe:animate-ping"></span>
+ <span class="relative inline-flex h-1.5 w-1.5 rounded-full bg-emerald-500"></span>
+ </span>
+ <svg x-show="!live" class="h-3 w-3 shrink-0" @style(['display: none' => $active]) viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
+ <path d="M8 5.5v13a1 1 0 0 0 1.5.86l11-6.5a1 1 0 0 0 0-1.72l-11-6.5A1 1 0 0 0 8 5.5Z" />
+ </svg>
+ <span x-text="live ? 'Live' : 'Paused'">{{ $active ? 'Live' : 'Paused' }}</span>
+ </button>
+</div>
diff --git a/resources/views/livewire/analytics.blade.php b/resources/views/livewire/analytics.blade.php
index f383f56506..4af35df784 100644
--- a/resources/views/livewire/analytics.blade.php
+++ b/resources/views/livewire/analytics.blade.php
@@ -1,7 +1,9 @@
<?php
-$tabButtonBase = 'relative inline-flex h-7 items-center justify-center rounded-md px-2.5 text-[12px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40';
-$tabButtonActive = 'bg-white text-black shadow-sm ring-1 ring-neutral-200 dark:bg-white/[0.09] dark:text-fg dark:ring-white/[0.08]';
-$tabButtonInactive = 'text-neutral-500 hover:text-black dark:text-fg-faint dark:hover:text-fg';
+$rangeListboxOptions = [
+ ['value' => '24h', 'label' => 'Last 24 hours'],
+ ['value' => '7d', 'label' => 'Last 7 days'],
+ ['value' => '30d', 'label' => 'Last 30 days'],
+];
$dimensionLabels = [
'referer' => 'Referrers',
@@ -61,28 +63,16 @@ $appListboxOptions = array_merge(
</div>
</div>
- <div class="flex items-center gap-2 sm:ml-auto">
- @include('livewire.traffic._live-toggle')
- <div class="inline-flex items-center gap-0.5 rounded-lg bg-neutral-100 p-1 dark:bg-white/[0.04]">
- <button type="button" wire:click="setRange('24h')"
- wire:loading.attr="disabled" wire:target="setRange"
- @class([$tabButtonBase, $range === '24h' ? $tabButtonActive : $tabButtonInactive])>
- <span wire:loading.class="invisible" wire:target="setRange('24h')">24 hours</span>
- <x-loading compact class="absolute" wire:loading wire:target="setRange('24h')" aria-label="Loading analytics" />
- </button>
- <button type="button" wire:click="setRange('7d')"
- wire:loading.attr="disabled" wire:target="setRange"
- @class([$tabButtonBase, $range === '7d' ? $tabButtonActive : $tabButtonInactive])>
- <span wire:loading.class="invisible" wire:target="setRange('7d')">7 days</span>
- <x-loading compact class="absolute" wire:loading wire:target="setRange('7d')" aria-label="Loading analytics" />
- </button>
- <button type="button" wire:click="setRange('30d')"
- wire:loading.attr="disabled" wire:target="setRange"
- @class([$tabButtonBase, $range === '30d' ? $tabButtonActive : $tabButtonInactive])>
- <span wire:loading.class="invisible" wire:target="setRange('30d')">30 days</span>
- <x-loading compact class="absolute" wire:loading wire:target="setRange('30d')" aria-label="Loading analytics" />
- </button>
+ <div class="flex w-full items-center gap-2 sm:ml-auto sm:w-auto">
+ <div class="relative w-full transition-opacity sm:w-44"
+ wire:loading.class="pointer-events-none opacity-60" wire:target="setRange">
+ <x-forms.listbox id="range" onChange="setRange" :onChangeArgs="[]" :options="$rangeListboxOptions" />
+ <div class="absolute inset-0 hidden items-center justify-center rounded-lg bg-white/70 dark:bg-base/70"
+ wire:loading.flex wire:target="setRange">
+ <x-loading compact aria-label="Loading analytics" />
+ </div>
</div>
+ <x-live-toggle :active="$live" storageKey="traffic-live" title="Turn live refresh on or off (updates every 60 seconds)" />
</div>
</div>
@endif
@@ -139,7 +129,7 @@ $appListboxOptions = array_merge(
description="We could not load traffic analytics for the selected filters and range. Try a different range or check back shortly."
icon-name="analytics" />
@else
- @if ($this->isLivePollable())
+ @if ($live)
<div wire:poll.60s="loadData" class="hidden"></div>
@endif
diff --git a/resources/views/livewire/fleet/metrics.blade.php b/resources/views/livewire/fleet/metrics.blade.php
index 71c40ca9a1..11a529c75b 100644
--- a/resources/views/livewire/fleet/metrics.blade.php
+++ b/resources/views/livewire/fleet/metrics.blade.php
@@ -6,6 +6,12 @@ $tabButtonInactive = 'text-neutral-500 hover:text-black dark:text-fg-faint dark:
// Tiles read "Fleet …" across all servers, but just "CPU / Memory / …" when scoped to one.
$scoped = $serverUuid !== '';
+$rangeListboxOptions = [
+ ['value' => '24h', 'label' => 'Last 24 hours'],
+ ['value' => '7d', 'label' => 'Last 7 days'],
+ ['value' => '30d', 'label' => 'Last 30 days'],
+];
+
$serverListboxOptions = array_merge(
[['value' => '', 'label' => 'All servers']],
collect($serverOptions)->map(fn ($name, $uuid) => ['value' => $uuid, 'label' => $name])->values()->all(),
@@ -37,45 +43,22 @@ $serverListboxOptions = array_merge(
</div>
</div>
- <div class="flex items-center gap-2 sm:ml-auto">
- @if ($range === '24h')
- <div x-data="{ live: $wire.entangle('live').live }"
- x-init="
- const stored = localStorage.getItem('metrics-live');
- if (stored === '0') { live = false; }
- if (stored === '1') { live = true; }
- $watch('live', value => localStorage.setItem('metrics-live', value ? '1' : '0'));
- ">
- <button type="button" @click="live = !live" :aria-pressed="live ? 'true' : 'false'"
- title="Toggle realtime refresh (updates every 60s)"
- class="inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium ring-1 transition-colors"
- :class="live
- ? 'bg-white text-black shadow-sm ring-neutral-200 dark:bg-white/[0.09] dark:text-fg dark:ring-white/[0.08]'
- : 'text-neutral-500 ring-neutral-200 hover:text-black dark:text-fg-faint dark:ring-white/[0.08] dark:hover:text-fg'">
- <span class="relative flex h-1.5 w-1.5 shrink-0" aria-hidden="true">
- <span x-show="live" class="absolute inline-flex h-full w-full rounded-full bg-emerald-500 opacity-75 motion-safe:animate-ping"></span>
- <span class="relative inline-flex h-1.5 w-1.5 rounded-full" :class="live ? 'bg-emerald-500' : 'bg-neutral-400 dark:bg-white/40'"></span>
- </span>
- <span>Live Refresh</span>
- </button>
+ <div class="flex w-full items-center gap-2 sm:ml-auto sm:w-auto">
+ <div class="relative w-full transition-opacity sm:w-44"
+ wire:loading.class="pointer-events-none opacity-60" wire:target="setRange">
+ <x-forms.listbox id="range" onChange="setRange" :onChangeArgs="[]" :options="$rangeListboxOptions" />
+ <div class="absolute inset-0 hidden items-center justify-center rounded-lg bg-white/70 dark:bg-base/70"
+ wire:loading.flex wire:target="setRange">
+ <x-loading compact aria-label="Loading metrics" />
</div>
- @endif
- <div class="inline-flex items-center gap-0.5 rounded-lg bg-neutral-100 p-1 dark:bg-white/[0.04]">
- @foreach (['24h' => '24 hours', '7d' => '7 days', '30d' => '30 days'] as $value => $label)
- <button type="button" wire:click="setRange('{{ $value }}')"
- wire:loading.attr="disabled" wire:target="setRange"
- @class([$tabButtonBase, $range === $value ? $tabButtonActive : $tabButtonInactive])>
- <span wire:loading.class="invisible" wire:target="setRange('{{ $value }}')">{{ $label }}</span>
- <x-loading compact class="absolute" wire:loading wire:target="setRange('{{ $value }}')" aria-label="Loading metrics" />
- </button>
- @endforeach
</div>
+ <x-live-toggle :active="$live" storageKey="metrics-live" title="Turn live refresh on or off (updates every 60 seconds)" />
</div>
</div>
@endif
</div>
- @if ($this->isLivePollable())
+ @if ($live)
<div wire:poll.60s="loadData" class="hidden"></div>
@endif
diff --git a/resources/views/livewire/project/application/analytics.blade.php b/resources/views/livewire/project/application/analytics.blade.php
index 53c09e5629..d034b66cc3 100644
--- a/resources/views/livewire/project/application/analytics.blade.php
+++ b/resources/views/livewire/project/application/analytics.blade.php
@@ -1,7 +1,9 @@
<?php
-$tabButtonBase = 'h-7 rounded-md px-2.5 text-[12px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40';
-$tabButtonActive = 'bg-white text-black shadow-sm ring-1 ring-neutral-200 dark:bg-white/[0.09] dark:text-fg dark:ring-white/[0.08]';
-$tabButtonInactive = 'text-neutral-500 hover:text-black dark:text-fg-faint dark:hover:text-fg';
+$rangeListboxOptions = [
+ ['value' => '24h', 'label' => 'Last 24 hours'],
+ ['value' => '7d', 'label' => 'Last 7 days'],
+ ['value' => '30d', 'label' => 'Last 30 days'],
+];
$dimensionLabels = [
'referer' => 'Referrers',
@@ -37,7 +39,7 @@ $approxBadge = fn (string $tooltip) => '<span title="'.e($tooltip).'" class="ml-
icon-name="network" />
</x-application.settings-section>
@else
- @if ($this->isLivePollable())
+ @if ($live)
<div wire:poll.60s="loadData" class="hidden"></div>
@endif
@@ -45,21 +47,15 @@ $approxBadge = fn (string $tooltip) => '<span title="'.e($tooltip).'" class="ml-
helper="Inspect traffic statistics reported by Sentinel.">
<x-slot:actions>
<div class="flex items-center gap-2">
- @include('livewire.traffic._live-toggle')
- <div class="inline-flex items-center gap-0.5 rounded-lg bg-neutral-100 p-1 dark:bg-white/[0.04]">
- <button type="button" wire:click="setRange('24h')"
- @class([$tabButtonBase, $range === '24h' ? $tabButtonActive : $tabButtonInactive])>
- 24 hours
- </button>
- <button type="button" wire:click="setRange('7d')"
- @class([$tabButtonBase, $range === '7d' ? $tabButtonActive : $tabButtonInactive])>
- 7 days
- </button>
- <button type="button" wire:click="setRange('30d')"
- @class([$tabButtonBase, $range === '30d' ? $tabButtonActive : $tabButtonInactive])>
- 30 days
- </button>
+ <div class="relative w-full transition-opacity sm:w-44"
+ wire:loading.class="pointer-events-none opacity-60" wire:target="setRange">
+ <x-forms.listbox id="range" onChange="setRange" :onChangeArgs="[]" :options="$rangeListboxOptions" />
+ <div class="absolute inset-0 hidden items-center justify-center rounded-lg bg-white/70 dark:bg-base/70"
+ wire:loading.flex wire:target="setRange">
+ <x-loading compact aria-label="Loading analytics" />
+ </div>
</div>
+ <x-live-toggle :active="$live" storageKey="traffic-live" title="Turn live refresh on or off (updates every 60 seconds)" />
</div>
</x-slot:actions>
diff --git a/resources/views/livewire/project/shared/metrics.blade.php b/resources/views/livewire/project/shared/metrics.blade.php
index aef98426a9..bcca527914 100644
--- a/resources/views/livewire/project/shared/metrics.blade.php
+++ b/resources/views/livewire/project/shared/metrics.blade.php
@@ -4,7 +4,6 @@
($resource->build_pack !== 'dockercompose' &&
$resource->destination->server->isMetricsEnabled() &&
str($resource->status)->contains('running'))) x-init="$wire.loadData()"
- @if ($poll) wire:poll.5000ms="pollData" @endif
@endif>
@if ($resource->getMorphClass() === 'App\Models\Application' && $resource->build_pack === 'dockercompose')
<x-application.settings-section id="metrics-overview-section" title="Metrics"
@@ -39,16 +38,18 @@
icon-name="dashboard" />
</x-application.settings-section>
@else
+ @if ($live)
+ <div wire:key="metrics-poll-{{ $this->pollSeconds() }}" wire:poll.{{ $this->pollSeconds() }}s="loadData" class="hidden"></div>
+ @endif
<x-application.settings-section id="metrics-overview-section" title="Metrics"
helper="Inspect recent CPU and memory usage reported by Sentinel.">
<x-slot:actions>
- <x-status-badge :status="$poll ? 'Live updates' : 'Historical range'"
- :type="$poll ? 'success' : 'neutral'" />
+ <x-live-toggle :active="$live" storageKey="resource-metrics-live" />
</x-slot:actions>
<div class="max-w-xs">
<x-forms.listbox id="interval" label="Time range" onChange="setInterval" :options="[
- ['value' => 5, 'label' => 'Last 5 minutes · live'],
- ['value' => 10, 'label' => 'Last 10 minutes · live'],
+ ['value' => 5, 'label' => 'Last 5 minutes'],
+ ['value' => 10, 'label' => 'Last 10 minutes'],
['value' => 30, 'label' => 'Last 30 minutes'],
['value' => 60, 'label' => 'Last hour'],
['value' => 720, 'label' => 'Last 12 hours'],
@@ -57,7 +58,7 @@
]" />
</div>
<p class="mt-3 text-xs leading-5 text-neutral-500 dark:text-fg-dim">
- Five and ten minute ranges refresh automatically every five seconds.
+ While live, ranges up to one hour refresh every five seconds. Longer ranges refresh every minute.
</p>
</x-application.settings-section>
diff --git a/resources/views/livewire/server/charts.blade.php b/resources/views/livewire/server/charts.blade.php
index c1b1992757..1867766e38 100644
--- a/resources/views/livewire/server/charts.blade.php
+++ b/resources/views/livewire/server/charts.blade.php
@@ -10,10 +10,11 @@
<x-server.sidebar :server="$server" activeMenu="metrics" />
<div class="application-settings-form flex w-full flex-col gap-6"
- @if ($server->isMetricsEnabled()) x-init="$wire.loadData()"
- @if ($poll) wire:poll.5000ms="pollData" @endif
- @endif>
+ @if ($server->isMetricsEnabled()) x-init="$wire.loadData()" @endif>
@if ($server->isMetricsEnabled())
+ @if ($live)
+ <div wire:key="metrics-poll-{{ $this->pollSeconds() }}" wire:poll.{{ $this->pollSeconds() }}s="loadData" class="hidden"></div>
+ @endif
<form wire:submit.prevent="saveMetricsSettings" class="contents">
<x-unsaved-bar action="saveMetricsSettings"
targets="sentinelMetricsRefreshRateSeconds,sentinelMetricsHistoryDays,sentinelPushIntervalSeconds" />
@@ -22,8 +23,7 @@
helper="Inspect recent CPU and memory usage reported by Sentinel.">
<x-slot:actions>
<div class="flex items-center gap-2">
- <x-status-badge :status="$poll ? 'Live updates' : 'Historical range'"
- :type="$poll ? 'success' : 'neutral'" />
+ <x-live-toggle :active="$live" storageKey="server-metrics-live" />
<x-forms.button canGate="update" :canResource="$server" wire:click="toggleMetrics">
Disable metrics
</x-forms.button>
@@ -44,8 +44,8 @@
<div class="mt-4 max-w-xs">
<x-forms.listbox id="interval" label="Time range" onChange="setInterval" :options="[
- ['value' => 5, 'label' => 'Last 5 minutes · live'],
- ['value' => 10, 'label' => 'Last 10 minutes · live'],
+ ['value' => 5, 'label' => 'Last 5 minutes'],
+ ['value' => 10, 'label' => 'Last 10 minutes'],
['value' => 30, 'label' => 'Last 30 minutes'],
['value' => 60, 'label' => 'Last hour'],
['value' => 720, 'label' => 'Last 12 hours'],
@@ -54,7 +54,7 @@
]" />
</div>
<p class="mt-3 text-xs leading-5 text-neutral-500 dark:text-fg-dim">
- Five and ten minute ranges refresh automatically every five seconds.
+ While live, ranges up to one hour refresh every five seconds. Longer ranges refresh every minute.
</p>
</x-application.settings-section>
</form>
diff --git a/resources/views/livewire/traffic/_live-toggle.blade.php b/resources/views/livewire/traffic/_live-toggle.blade.php
deleted file mode 100644
index 3cb76976eb..0000000000
--- a/resources/views/livewire/traffic/_live-toggle.blade.php
+++ /dev/null
@@ -1,32 +0,0 @@
-{{--
- "Live Refresh" toggle for realtime analytics. Sits next to the time-range selector.
- Realtime is only meaningful at the 24h range (minute-level rollups), so the control
- is hidden entirely for 7d/30d. The label is constant; the active state is shown by the
- button color + a pulsing emerald dot. The choice is persisted per-browser in
- localStorage. Expects `$range` in scope and a `live` bool on the host Livewire component.
- The pulse respects prefers-reduced-motion.
---}}
-@if ($range === '24h')
- <div x-data="{ live: $wire.entangle('live').live }"
- x-init="
- const stored = localStorage.getItem('traffic-live');
- if (stored === '0') { live = false; }
- if (stored === '1') { live = true; }
- $watch('live', value => localStorage.setItem('traffic-live', value ? '1' : '0'));
- ">
- <button type="button"
- @click="live = !live"
- :aria-pressed="live ? 'true' : 'false'"
- title="Toggle realtime refresh (updates every 60s)"
- class="inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-[12px] font-medium ring-1 transition-colors"
- :class="live
- ? 'bg-white text-black shadow-sm ring-neutral-200 dark:bg-white/[0.09] dark:text-fg dark:ring-white/[0.08]'
- : 'text-neutral-500 ring-neutral-200 hover:text-black dark:text-fg-faint dark:ring-white/[0.08] dark:hover:text-fg'">
- <span class="relative flex h-1.5 w-1.5 shrink-0" aria-hidden="true">
- <span x-show="live" class="absolute inline-flex h-full w-full rounded-full bg-emerald-500 opacity-75 motion-safe:animate-ping"></span>
- <span class="relative inline-flex h-1.5 w-1.5 rounded-full" :class="live ? 'bg-emerald-500' : 'bg-neutral-400 dark:bg-white/40'"></span>
- </span>
- <span>Live Refresh</span>
- </button>
- </div>
-@endif
diff --git a/tests/Feature/Server/ServerMetricsSettingsTest.php b/tests/Feature/Server/ServerMetricsSettingsTest.php
index 8d22aabb5e..6d4a069702 100644
--- a/tests/Feature/Server/ServerMetricsSettingsTest.php
+++ b/tests/Feature/Server/ServerMetricsSettingsTest.php
@@ -52,3 +52,20 @@ it('validates metrics collection settings on the server metrics page', function
'sentinelPushIntervalSeconds',
]);
});
+
+it('refreshes server metrics live for every time range until paused', function () {
+ $server = Server::factory()->create(['team_id' => $this->team->id]);
+ $server->settings->is_sentinel_enabled = true;
+ $server->settings->is_metrics_enabled = true;
+ $server->settings->saveQuietly();
+
+ Livewire::test(Charts::class, ['server_uuid' => $server->uuid])
+ ->assertSet('live', true)
+ ->assertSeeHtml('wire:poll.5s="loadData"')
+ ->set('interval', 43200)
+ ->assertSet('live', true)
+ ->assertSeeHtml('wire:poll.60s="loadData"')
+ ->set('live', false)
+ ->assertDontSeeHtml('wire:poll')
+ ->assertSee('Paused');
+});
diff --git a/tests/Feature/TrafficAnalytics/LiveRefreshTest.php b/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
index 4ec260dee5..b613add173 100644
--- a/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
+++ b/tests/Feature/TrafficAnalytics/LiveRefreshTest.php
@@ -52,50 +52,42 @@ function bootLiveServer(): Server
return $server;
}
-it('is paused by default and does not poll until Live Refresh is turned on', function () {
- $server = bootLiveServer();
+it('is paused by default and does not poll until live refresh is turned on', function () {
+ bootLiveServer();
loadLazy(Livewire::test(Analytics::class))
->assertOk()
->assertSet('live', false)
->assertDontSeeHtml('wire:poll.60s')
- ->assertSee('Live Refresh');
+ ->assertSee('Paused');
});
-it('starts polling when live is toggled on at the 24h range', function () {
- $server = bootLiveServer();
+it('polls when live refresh is turned on', function () {
+ bootLiveServer();
loadLazy(Livewire::test(Analytics::class))
- ->assertDontSeeHtml('wire:poll.60s')
- ->call('toggleLive')
- ->assertSet('live', true)
+ ->set('live', true)
->assertSeeHtml('wire:poll.60s')
- ->assertSee('Live Refresh');
+ ->assertSee('Live');
});
-it('hides the Live Refresh control and stops polling for the 7d and 30d ranges', function () {
- $server = bootLiveServer();
-
- $component = loadLazy(Livewire::test(Analytics::class))
- ->call('setRange', '7d')
- ->assertDontSeeHtml('wire:poll.60s')
- ->assertDontSee('Live Refresh');
-
- expect($component->instance()->isLivePollable())->toBeFalse();
+it('keeps live refresh and polling on for every range', function (string $range) {
+ bootLiveServer();
- $component->call('setRange', '30d')
- ->assertDontSeeHtml('wire:poll.60s')
- ->assertDontSee('Live Refresh');
-});
+ loadLazy(Livewire::test(Analytics::class))
+ ->set('live', true)
+ ->call('setRange', $range)
+ ->assertSet('range', $range)
+ ->assertSet('live', true)
+ ->assertSeeHtml('wire:poll.60s');
+})->with(['7d', '30d']);
-it('re-arms polling when returning to the 24h range after live was turned on', function () {
- $server = bootLiveServer();
+it('stops polling when live refresh is paused', function () {
+ bootLiveServer();
loadLazy(Livewire::test(Analytics::class))
- ->call('toggleLive') // arm live at 24h
- ->assertSeeHtml('wire:poll.60s')
- ->call('setRange', '7d')
+ ->set('live', true)
+ ->set('live', false)
->assertDontSeeHtml('wire:poll.60s')
- ->call('setRange', '24h')
- ->assertSeeHtml('wire:poll.60s');
+ ->assertSee('Paused');
});