resource-navigation-tab icon indicating copy to clipboard operation
resource-navigation-tab copied to clipboard

Nova Partition Metric does not display the chart when display in tab detail

Open tititorn opened this issue 4 years ago • 1 comments

Laravel 7.7.1 Nova 3.4.0 PHP 7.2.24

before after Nova Partition Metric in Post Detail can only display once but when I click refresh it disappear. But the Value Metric seem to be working ok. I also attach the screen capture of this issue. The PostByType is Partiton Metric and PostCount is Value Metric. When I try without resource-navigation-tab, they are both working fine. I'm not sure what went wrong. I also attached the screen capture.

Post.php `<?php

namespace App\Nova;

use Laravel\Nova\Fields\ID; use Illuminate\Http\Request; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; use DigitalCreative\ResourceNavigationTab\ResourceNavigationTab; use DigitalCreative\ResourceNavigationTab\HasResourceNavigationTabTrait;

class Post extends Resource { use HasResourceNavigationTabTrait; public static $model = \App\Post::class;

public static $title = 'id';
public static $search = [
    'id',
];
public function fields(Request $request)
{
    return [
        ResourceNavigationTab::make([
            'label' => 'Post',
            'behaveAsPanel' => true,
            'fields' => [
                ID::make()->sortable(),
                Text::make('Title'),
                Text::make('Type'),
            ]
        ]),
        ResourceNavigationTab::make([
            'label' => 'Body',
            'behaveAsPanel' => true,
            'fields' => [
                Text::make('Body')->onlyOnDetail(),
            ]
        ])
    ];
}
public function cards(Request $request)
{
    return [
        (new \App\Nova\Metrics\PostByType)->onlyOnDetail(),
        (new \App\Nova\Metrics\PostCount)->onlyOnDetail()
    ];
}

PostByType.php <?php

namespace App\Nova\Metrics;

use App\Post; use Laravel\Nova\Metrics\Partition; use Laravel\Nova\Http\Requests\NovaRequest;

class PostByType extends Partition { public function calculate(NovaRequest $request) { return $this->count($request, \App\Post::whereUserId(1)->orderBy('type'), 'type'); } public function cacheFor() { // return now()->addMinutes(5); } public function uriKey() { return 'post-by-type'; } } PostCount.php<?php

namespace App\Nova\Metrics;

use App\Post; use Laravel\Nova\Metrics\Value; use Laravel\Nova\Http\Requests\NovaRequest;

class PostCount extends Value { public function calculate(NovaRequest $request) { return $this->count($request, \App\Post::class); }

public function ranges()
{
    return [
        30 => '30 Days',
        60 => '60 Days',
        365 => '365 Days',
        'TODAY' => 'Today',
        'MTD' => 'Month To Date',
        'QTD' => 'Quarter To Date',
        'YTD' => 'Year To Date',
    ];
}
public function uriKey()
{
    return 'post-count';
}

}`

tititorn avatar Apr 25 '20 10:04 tititorn

I'm not sure whats the issue, if you are still having this problem can you have a look at the network request to see if there are any exceptions being thrown or check if there is any error on the console?

milewski avatar Jul 27 '20 11:07 milewski