From 118552d0932bd262b6f54172e2863f8bc7b2a101 Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sun, 13 Sep 2026 00:33:05 +0200 Subject: [PATCH] Fix SpiceChart: query spice IDs directly in extraJsOptions and guard formatter against null regex match Co-Authored-By: Claude Sonnet 4.6 --- .../SpiceResource/Widgets/SpiceChart.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Filament/User/Resources/SpiceResource/Widgets/SpiceChart.php b/app/Filament/User/Resources/SpiceResource/Widgets/SpiceChart.php index b1b05c2..e935d3a 100644 --- a/app/Filament/User/Resources/SpiceResource/Widgets/SpiceChart.php +++ b/app/Filament/User/Resources/SpiceResource/Widgets/SpiceChart.php @@ -11,18 +11,14 @@ class SpiceChart extends ApexChartWidget protected static ?string $chartId = 'spiceChart'; protected static ?string $heading = 'Rohstoffmengen im Lager'; - private array $spiceIds = []; - protected function getOptions(): array { - $spices = Spice::all(); + $spices = Spice::orderBy('id')->get(); $data = []; $labels = []; foreach ($spices as $spice) { - $this->spiceIds[] = $spice->id; - if ($spice->unit === 'grams') { $data[] = round($spice->quantity / 1000, 2); $labels[] = $spice->name . ' (kg)'; @@ -65,8 +61,9 @@ class SpiceChart extends ApexChartWidget protected function extraJsOptions(): ?RawJs { - $urls = collect($this->spiceIds) - ->map(fn ($id) => url('/dashboard/rohstoffe/' . $id . '/edit')) + $urls = Spice::orderBy('id') + ->get() + ->map(fn ($spice) => url('/dashboard/rohstoffe/' . $spice->id . '/edit')) ->values() ->toJson(); @@ -91,7 +88,9 @@ class SpiceChart extends ApexChartWidget dataLabels: { enabled: true, formatter: function (val, opt) { - return val + '' + opt.w.globals.labels[opt.dataPointIndex].match(/\((.*?)\)/)[1]; + var label = opt.w.globals.labels[opt.dataPointIndex]; + var match = label ? label.match(/\((.*?)\)/) : null; + return val + (match ? match[1] : ''); }, dropShadow: { enabled: true } }