laravel / nova-issues

551 stars 36 forks source link

Trend Metric appears outside of its card (and impossible to click on its filter) #6453

Open sysyl opened 1 week ago

sysyl commented 1 week ago

Description:

The trend below is displayed in a dashboard. As you can see, the trend is displayed outside of its card. The filter for this trend is blocked. I tried clearing my application and browser caches but that doesn't change anything.

Capture d’écran 2024-07-06 à 18 52 50

Detailed steps to reproduce the issue on a fresh Nova installation:

CostsPerDay Metric

<?php

namespace App\Nova\Metrics;

use App\Models\Cost;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;

class CostsPerDay extends Trend
{
    public function name()
    {
        return 'Coûts par jour';
    }

    /**
     * Calculate the value of the metric.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return mixed
     */
    public function calculate(NovaRequest $request)
    {
        return $this->countByDays($request, Cost::class)->showLatestValue()
            ->format(function ($value) {
                return round($value, 2);
            });
    }

    /**
     * Get the ranges available for the metric.
     *
     * @return array
     */
    public function ranges()
    {
        return [
            30 => '30 Days',
            60 => '60 Days',
            90 => '90 Days',
        ];
    }

    /**
     * Get the URI key for the metric.
     *
     * @return string
     */
    public function uriKey()
    {
        return 'costs-per-day';
    }
}

My model "Cost"

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Cost extends Model
{
    use HasFactory;

    protected $table = 'accounting.cost';

    protected $fillable = [
        'category_id',
        'external_id',
        'external_table_name',
        'name',
        'cost',
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];

    public function costCategory()
    {
        return $this->belongsTo(CostCategory::class, 'category_id');
    }
}
crynobone commented 1 week ago

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)