Skip to content

Commit

Permalink
Kreyu#88 Extract the RowActionBuilder methods in another interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-castelain committed Jul 11, 2024
1 parent 6a6f4fe commit 10913c8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Action/Type/DropdownActionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DropdownActionType extends AbstractActionType
{
public function buildView(ActionView $view, ActionInterface $action, array $options): void
{
$view->vars['actions'] = $options['actions'];
$view->vars['actions'] = [];
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
30 changes: 30 additions & 0 deletions src/Builder/RowActionBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace Kreyu\Bundle\DataTableBundle\Builder;

use Kreyu\Bundle\DataTableBundle\Action\ActionBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Action\Type\ActionTypeInterface;
use Kreyu\Bundle\DataTableBundle\Exception\InvalidArgumentException;

interface RowActionBuilderInterface
{
/**
* @throws InvalidArgumentException if row action of given name does not exist
*/
public function getRowAction(string $name): ActionBuilderInterface;

public function hasRowAction(string $name): bool;

/**
* @param class-string<ActionTypeInterface>|null $type
*/
public function createRowAction(string $name, ?string $type = null, array $options = []): ActionBuilderInterface;

/**
* @param class-string<ActionTypeInterface>|null $type
*/
public function addRowAction(ActionBuilderInterface|string $action, ?string $type = null, array $options = []): static;

public function removeRowAction(string $name): static;
}
22 changes: 2 additions & 20 deletions src/DataTableBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Kreyu\Bundle\DataTableBundle\Action\ActionBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Action\Type\ActionTypeInterface;
use Kreyu\Bundle\DataTableBundle\Builder\RowActionBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Column\ColumnBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface;
use Kreyu\Bundle\DataTableBundle\Exception\InvalidArgumentException;
Expand All @@ -15,7 +16,7 @@
use Kreyu\Bundle\DataTableBundle\Filter\Type\FilterTypeInterface;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;

interface DataTableBuilderInterface extends DataTableConfigBuilderInterface
interface DataTableBuilderInterface extends DataTableConfigBuilderInterface, RowActionBuilderInterface
{
public const BATCH_CHECKBOX_COLUMN_NAME = '__batch';

Expand Down Expand Up @@ -140,25 +141,6 @@ public function setAutoAddingBatchCheckboxColumn(bool $autoAddingBatchCheckboxCo
*/
public function getRowActions(): array;

/**
* @throws InvalidArgumentException if row action of given name does not exist
*/
public function getRowAction(string $name): ActionBuilderInterface;

public function hasRowAction(string $name): bool;

/**
* @param class-string<ActionTypeInterface>|null $type
*/
public function createRowAction(string $name, ?string $type = null, array $options = []): ActionBuilderInterface;

/**
* @param class-string<ActionTypeInterface>|null $type
*/
public function addRowAction(ActionBuilderInterface|string $action, ?string $type = null, array $options = []): static;

public function removeRowAction(string $name): static;

public function isAutoAddingActionsColumn(): bool;

public function setAutoAddingActionsColumn(bool $autoAddingActionsColumn): static;
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/views/themes/bootstrap_5.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,9 @@
</button>
<ul class="dropdown-menu" id="linkList" aria-labelledby="dropdownMenuButton"
data-kreyu--data-table-bundle--dropdown-target="content">
<li><a class="dropdown-item" href="https://example.com">Lien 1</a></li>
<li><a class="dropdown-item" href="https://example.com">Lien 2</a></li>
<li><a class="dropdown-item" href="https://example.com">Lien 3</a></li>
{% for action in actions %}
<li><a class="dropdown-item" href="https://example.com">Lien 1</a></li>
{% endfor %}
</ul>
</div>
{% endblock %}
Expand Down

0 comments on commit 10913c8

Please sign in to comment.