Fix SpiceChart: query spice IDs directly in extraJsOptions and guard formatter against null regex match
Deploy / deploy (push) Successful in 15s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-13 00:33:05 +02:00
1 parent 7d45e3027c
commit 118552d093
1 file changed
+7 -8
@@ -11,18 +11,14 @@ class SpiceChart extends ApexChartWidget
protected static ?string $chartId = 'spiceChart'; protected static ?string $chartId = 'spiceChart';
protected static ?string $heading = 'Rohstoffmengen im Lager'; protected static ?string $heading = 'Rohstoffmengen im Lager';
private array $spiceIds = [];
protected function getOptions(): array protected function getOptions(): array
{ {
$spices = Spice::all(); $spices = Spice::orderBy('id')->get();
$data = []; $data = [];
$labels = []; $labels = [];
foreach ($spices as $spice) { foreach ($spices as $spice) {
$this->spiceIds[] = $spice->id;
if ($spice->unit === 'grams') { if ($spice->unit === 'grams') {
$data[] = round($spice->quantity / 1000, 2); $data[] = round($spice->quantity / 1000, 2);
$labels[] = $spice->name . ' (kg)'; $labels[] = $spice->name . ' (kg)';
@@ -65,8 +61,9 @@ class SpiceChart extends ApexChartWidget
protected function extraJsOptions(): ?RawJs protected function extraJsOptions(): ?RawJs
{ {
$urls = collect($this->spiceIds) $urls = Spice::orderBy('id')
->map(fn ($id) => url('/dashboard/rohstoffe/' . $id . '/edit')) ->get()
->map(fn ($spice) => url('/dashboard/rohstoffe/' . $spice->id . '/edit'))
->values() ->values()
->toJson(); ->toJson();
@@ -91,7 +88,9 @@ class SpiceChart extends ApexChartWidget
dataLabels: { dataLabels: {
enabled: true, enabled: true,
formatter: function (val, opt) { 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 } dropShadow: { enabled: true }
} }