refactor: add Enum labels, fix indentation, and add URL links to StatsOverviewWidget
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

Adds `label()` methods to TrendDirection and PredictionSource enums for cleaner display. Fixes mixed tab/space indentation in StatsOverviewWidget. Links all stats cards to their respective Filament resources (searches, stations, oil-predictions, api-logs). Documents BrentPriceChartWidget's manual registration.
This commit is contained in:
Ovidiu U
2026-04-05 19:52:12 +01:00
parent 4f57c97015
commit 6249ed8fe2
4 changed files with 27 additions and 9 deletions

View File

@@ -7,4 +7,13 @@ enum PredictionSource: string
case Llm = 'llm'; case Llm = 'llm';
case LlmWithContext = 'llm_with_context'; case LlmWithContext = 'llm_with_context';
case Ewma = 'ewma'; case Ewma = 'ewma';
public function label(): string
{
return match ($this) {
self::Llm => 'LLM',
self::LlmWithContext => 'LLM+Context',
self::Ewma => 'EWMA',
};
}
} }

View File

@@ -7,4 +7,9 @@ enum TrendDirection: string
case Rising = 'rising'; case Rising = 'rising';
case Falling = 'falling'; case Falling = 'falling';
case Flat = 'flat'; case Flat = 'flat';
public function label(): string
{
return ucfirst($this->value);
}
} }

View File

@@ -11,6 +11,7 @@ class BrentPriceChartWidget extends ChartWidget
protected ?string $pollingInterval = null; protected ?string $pollingInterval = null;
/** Registered manually in AdminPanelProvider — excluded from auto-discovery to control placement. */
protected static bool $isDiscovered = false; protected static bool $isDiscovered = false;
protected function getData(): array protected function getData(): array

View File

@@ -19,7 +19,7 @@ class StatsOverviewWidget extends BaseWidget
{ {
return [ return [
$this->usersStat(), $this->usersStat(),
$this->searchesStat(), $this->searchesStat(),
$this->stationsStat(), $this->stationsStat(),
$this->oilPredictionStat(), $this->oilPredictionStat(),
$this->apiErrorsStat(), $this->apiErrorsStat(),
@@ -33,12 +33,13 @@ class StatsOverviewWidget extends BaseWidget
->color('primary'); ->color('primary');
} }
private function searchesStat(): Stat private function searchesStat(): Stat
{ {
return Stat::make('Total searches', Search::count()) return Stat::make('Total searches', Search::count())
->icon('heroicon-o-magnifying-glass') ->icon('heroicon-o-magnifying-glass')
->color('primary'); ->url(route('filament.admin.resources.searches.index'))
} ->color('primary');
}
private function stationsStat(): Stat private function stationsStat(): Stat
{ {
@@ -50,6 +51,7 @@ class StatsOverviewWidget extends BaseWidget
return Stat::make('Stations in DB', number_format($count)) return Stat::make('Stations in DB', number_format($count))
->description($description) ->description($description)
->url(route('filament.admin.resources.stations.index'))
->icon('heroicon-o-map-pin') ->icon('heroicon-o-map-pin')
->color('success'); ->color('success');
} }
@@ -66,11 +68,11 @@ class StatsOverviewWidget extends BaseWidget
$ageHours = $prediction->generated_at->diffInHours(now()); $ageHours = $prediction->generated_at->diffInHours(now());
$color = $ageHours > 24 ? 'warning' : 'success'; $color = $ageHours > 24 ? 'warning' : 'success';
$value = ucfirst($prediction->direction->value) $value = $prediction->direction->label().' · '.$prediction->confidence.'%';
.' · '.$prediction->confidence.'%';
return Stat::make('Latest oil prediction', $value) return Stat::make('Latest oil prediction', $value)
->description('Generated '.$prediction->generated_at->diffForHumans()) ->description('Generated '.$prediction->generated_at->diffForHumans())
->url(route('filament.admin.resources.oil-predictions.index'))
->icon('heroicon-o-beaker') ->icon('heroicon-o-beaker')
->color($color); ->color($color);
} }
@@ -87,6 +89,7 @@ class StatsOverviewWidget extends BaseWidget
return Stat::make('API errors (24h)', $errors) return Stat::make('API errors (24h)', $errors)
->icon('heroicon-o-exclamation-triangle') ->icon('heroicon-o-exclamation-triangle')
->url(route('filament.admin.resources.api-logs.index'))
->color($color); ->color($color);
} }
} }