Skip to content

Commit

Permalink
v3-Move ConfigurableAreas to Own Section WithConfigurableAreas (#1510)
Browse files Browse the repository at this point in the history
* Move ConfigurableAreas to Own Trait

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Oct 31, 2023
1 parent 2f07552 commit 4f57ad8
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 106 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## UNRELEASED
- Split ConfigurableArea into own Trait/Config/Helper Files

## [v3.1.0] - 2023-10-31
- Restore wire:confirm for Bulk Actions
- Stable Release of 3.1.0 Stable for Livewire v3 Support
Expand Down
2 changes: 2 additions & 0 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Rappasoft\LaravelLivewireTables\Traits\WithBulkActions;
use Rappasoft\LaravelLivewireTables\Traits\WithColumns;
use Rappasoft\LaravelLivewireTables\Traits\WithColumnSelect;
use Rappasoft\LaravelLivewireTables\Traits\WithConfigurableAreas;
use Rappasoft\LaravelLivewireTables\Traits\WithData;
use Rappasoft\LaravelLivewireTables\Traits\WithDebugging;
use Rappasoft\LaravelLivewireTables\Traits\WithEvents;
Expand All @@ -29,6 +30,7 @@ abstract class DataTableComponent extends Component
WithBulkActions,
WithColumns,
WithColumnSelect,
WithConfigurableAreas,
WithData,
WithDebugging,
WithEvents,
Expand Down
14 changes: 0 additions & 14 deletions src/Traits/ComponentUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ trait ComponentUtilities

protected array $additionalSelects = [];

protected bool $hideConfigurableAreasWhenReorderingStatus = true;

protected array $configurableAreas = [
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'before-pagination' => null,
'after-pagination' => null,
];

// Sets the Theme If Not Already Set
public function mountComponentUtilities(): void
{
Expand Down
31 changes: 0 additions & 31 deletions src/Traits/Configuration/ComponentConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,37 +210,6 @@ public function setAdditionalSelects(string|array $selects): self
return $this;
}

/**
* @param array<mixed> $areas
*/
public function setConfigurableAreas(array $areas): self
{
$this->configurableAreas = $areas;

return $this;
}

public function setHideConfigurableAreasWhenReorderingStatus(bool $status): self
{
$this->hideConfigurableAreasWhenReorderingStatus = $status;

return $this;
}

public function setHideConfigurableAreasWhenReorderingEnabled(): self
{
$this->setHideConfigurableAreasWhenReorderingStatus(true);

return $this;
}

public function setHideConfigurableAreasWhenReorderingDisabled(): self
{
$this->setHideConfigurableAreasWhenReorderingStatus(false);

return $this;
}

public function setDataTableFingerprint(string $dataTableFingerprint): self
{
$this->dataTableFingerprint = $dataTableFingerprint;
Expand Down
37 changes: 37 additions & 0 deletions src/Traits/Configuration/ConfigurableAreasConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Configuration;

trait ConfigurableAreasConfiguration
{
/**
* @param array<mixed> $areas
*/
public function setConfigurableAreas(array $areas): self
{
$this->configurableAreas = $areas;

return $this;
}

public function setHideConfigurableAreasWhenReorderingStatus(bool $status): self
{
$this->hideConfigurableAreasWhenReorderingStatus = $status;

return $this;
}

public function setHideConfigurableAreasWhenReorderingEnabled(): self
{
$this->setHideConfigurableAreasWhenReorderingStatus(true);

return $this;
}

public function setHideConfigurableAreasWhenReorderingDisabled(): self
{
$this->setHideConfigurableAreasWhenReorderingStatus(false);

return $this;
}
}
61 changes: 0 additions & 61 deletions src/Traits/Helpers/ComponentHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,65 +258,4 @@ public function getAdditionalSelects(): array
{
return $this->additionalSelects;
}

/**
* @return array<mixed>
*/
public function getConfigurableAreas(): array
{
return $this->configurableAreas;
}

public function hasConfigurableAreaFor(string $area): bool
{
if ($this->hideConfigurableAreasWhenReorderingIsEnabled() && $this->reorderIsEnabled() && $this->currentlyReorderingIsEnabled()) {
return false;
}

return isset($this->configurableAreas[$area]) && $this->getConfigurableAreaFor($area) !== null;
}

/**
* @param string|array<mixed> $area
*/
public function getConfigurableAreaFor($area): ?string
{
$area = $this->configurableAreas[$area] ?? null;

if (is_array($area)) {
return $area[0];
}

return $area;
}

/**
* @param string|array<mixed> $area
* @return array<mixed>
*/
public function getParametersForConfigurableArea($area): array
{
$area = $this->configurableAreas[$area] ?? null;

if (is_array($area) && isset($area[1]) && is_array($area[1])) {
return $area[1];
}

return [];
}

public function getHideConfigurableAreasWhenReorderingStatus(): bool
{
return $this->hideConfigurableAreasWhenReorderingStatus;
}

public function hideConfigurableAreasWhenReorderingIsEnabled(): bool
{
return $this->getHideConfigurableAreasWhenReorderingStatus() === true;
}

public function hideConfigurableAreasWhenReorderingIsDisabled(): bool
{
return $this->getHideConfigurableAreasWhenReorderingStatus() === false;
}
}
67 changes: 67 additions & 0 deletions src/Traits/Helpers/ConfigurableAreasHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;

trait ConfigurableAreasHelpers
{
/**
* @return array<mixed>
*/
public function getConfigurableAreas(): array
{
return $this->configurableAreas;
}

public function hasConfigurableAreaFor(string $area): bool
{
if ($this->hideConfigurableAreasWhenReorderingIsEnabled() && $this->reorderIsEnabled() && $this->currentlyReorderingIsEnabled()) {
return false;
}

return isset($this->configurableAreas[$area]) && $this->getConfigurableAreaFor($area) !== null;
}

/**
* @param string|array<mixed> $area
*/
public function getConfigurableAreaFor($area): ?string
{
$area = $this->configurableAreas[$area] ?? null;

if (is_array($area)) {
return $area[0];
}

return $area;
}

/**
* @param string|array<mixed> $area
* @return array<mixed>
*/
public function getParametersForConfigurableArea($area): array
{
$area = $this->configurableAreas[$area] ?? null;

if (is_array($area) && isset($area[1]) && is_array($area[1])) {
return $area[1];
}

return [];
}

public function getHideConfigurableAreasWhenReorderingStatus(): bool
{
return $this->hideConfigurableAreasWhenReorderingStatus;
}

public function hideConfigurableAreasWhenReorderingIsEnabled(): bool
{
return $this->getHideConfigurableAreasWhenReorderingStatus() === true;
}

public function hideConfigurableAreasWhenReorderingIsDisabled(): bool
{
return $this->getHideConfigurableAreasWhenReorderingStatus() === false;
}
}
26 changes: 26 additions & 0 deletions src/Traits/WithConfigurableAreas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits;

use Rappasoft\LaravelLivewireTables\Traits\Configuration\ConfigurableAreasConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ConfigurableAreasHelpers;

trait WithConfigurableAreas
{
use ConfigurableAreasConfiguration,
ConfigurableAreasHelpers;

protected bool $hideConfigurableAreasWhenReorderingStatus = true;

protected array $configurableAreas = [
'before-tools' => null,
'toolbar-left-start' => null,
'toolbar-left-end' => null,
'toolbar-right-start' => null,
'toolbar-right-end' => null,
'before-toolbar' => null,
'after-toolbar' => null,
'before-pagination' => null,
'after-pagination' => null,
];
}

0 comments on commit 4f57ad8

Please sign in to comment.