gobrightspot / nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.
MIT License
168 stars 50 forks source link

Can't make the button appear on Index #19

Closed xoco70 closed 4 years ago

xoco70 commented 4 years ago

Hi,

I want to use your plugin, but I follow the docs, and the button never shows.

Here is my model:

<?php

namespace App\Nova;

use App\Nova\Actions\FillMissingData;
use App\Nova\Actions\ScanMissingData;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Badge;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;

class MissingData extends Resource
{
    public static function label()
    {
        return 'Trous de données';
    }

    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \App\MissingData::class;

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->hide(),
            BelongsTo::make('Opération', 'operation', 'App\Nova\Operation')->sortable()->required()->withoutTrashed(),
            BelongsTo::make('Compteur', 'meter', 'App\Nova\Meter')->sortable()->required()->withoutTrashed(),
            Date::make('Date de début', 'date_ini')->sortable(),
            Date::make('Date de fin', 'date_end')->sortable(),
            Text::make('Taille', function () {
                return 0;
            })->exceptOnForms(),
            Badge::make('Status')->map([
                'Non traité' => 'danger',
                'Traité' => 'success',
            ]),
        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [
            new ScanMissingData,

        ];
    }

    public static function availableForNavigation(Request $request)
    {
        return auth()->user()->isSuperAdmin();
    }
}

And here is my action:

<?php

namespace App\Nova\Actions;

use Brightspot\Nova\Tools\DetachedActions\DetachedAction;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Laravel\Nova\Fields\ActionFields;

class ScanMissingData extends DetachedAction
{
    use InteractsWithQueue, Queueable;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @return mixed
     */
    public function handle(ActionFields $fields)
    {
        return DetachedAction::message('It worked!');
    }

    /**
     * Get the fields available on the action.
     *
     * @return array
     */
    public function fields()
    {
        return [
        ];
    }
}

Relevant data: PHP 7.4, Nova 3.8.3, Laravel 7.25, I'm using gregoriohc/laravel-nova-theme-responsive

Am I missing something ?

xoco70 commented 4 years ago

Ok, fixed, I had to add the method: view() for policy

    public function view()
    {
        return true;
    }
xoco70 commented 4 years ago

Ok, I can make it appear on the view resource page: /nova/resources/myresource/1, but can't make it appear in index.

I tried:

public function actions(Request $request)
    {
        return [
            (new ScanMissingData())->onlyOnIndex(true),

        ];
    }

On the resource page. It disappear from view ressource page, but doesn't show up on index.

I also remove completely my Policy, and reload with

composer dump-autoload, but still doesn't showing...

eoghanobrien commented 4 years ago

Have you figured it out, it seems like the issue is localized to your set up but perhaps the solution could help somebody else?

xoco70 commented 4 years ago

Nop, I tried everything I could. Double checked docs... Nobody seems to have the problem.

I can see the button on the details page, but not on index ... Tried to completely remove my Policy, didn't change anything.

I will try to replicate it in a fresh laravel nova to see if it happens ! This is my last shot !

xoco70 commented 4 years ago

I think I will use standalone action now it has been released. Just waiting proper docs.

vesper8 commented 2 years ago

This is happening because you have another nova tool that's extending CustomIndexToolbar

As a workaround you can add public $showOnIndex = true; in your detached action and it will show the dropdown inside the resource toolbar.

Or you can determine which other plugin is conflicting and decide whether you want to disable it