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

Add support for hiding visibility of an action from the Toolbar #7

Closed gobrightspot closed 4 years ago

gobrightspot commented 4 years ago

One thing we currently cannot do with this package, is use the default Nova Action visibility properties, (e.g. public $showOnIndex = false;) to effect the DetachedAction button in order to hide it on the Index view.

We may need to add a property and helper method to DetachedAction in order to set the visibility for the Vue component:

<?php

namespace Brightspot\Nova\Tools\DetachedActions;

use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionMethod;
use Laravel\Nova\Exceptions\MissingActionHandlerException;
use Laravel\Nova\Http\Requests\ActionRequest;
use Laravel\Nova\Nova;

abstract class DetachedAction extends Action
{
...
    /**
     * Indicates if this action is only available on the custom index toolbar.
     *
     * @var bool
     */
    public $showOnIndexToolbar = true;

    /**
     * Determine if the action is to be shown on the custom index toolbar.
     *
     * @return bool
     */
    public function shownOnIndexToolbar()
    {
        return $this->showOnIndexToolbar;
    }

    /**
     * Prepare the action for JSON serialization.
     *
     * @return array
     */
    public function jsonSerialize()
    {
        return array_merge([
            'detachedAction' => true,
            'label' => $this->label(),
            'showOnIndexToolbar' => $this->shownOnIndexToolbar(),
        ], parent::jsonSerialize(), $this->meta());
    }
...