Skip to content

Commit 0304d9a

Browse files
committed
Tweaks to Configure Approach
1 parent 4cd0f8b commit 0304d9a

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

src/Traits/ComponentUtilities.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
99
use Rappasoft\LaravelLivewireTables\Traits\Configuration\ComponentConfiguration;
1010
use Rappasoft\LaravelLivewireTables\Traits\Helpers\ComponentHelpers;
11+
use Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings\HasQueryString;
1112

1213
trait ComponentUtilities
1314
{
1415
use ComponentConfiguration,
1516
ComponentHelpers;
17+
use HasQueryString;
1618

1719
public array $table = [];
1820

@@ -48,6 +50,8 @@ trait ComponentUtilities
4850

4951
protected bool $useComputedProperties = true;
5052

53+
protected bool $hasRunConfigure = false;
54+
5155
/**
5256
* Set any configuration options
5357
*/
@@ -71,16 +75,7 @@ public function mountComponentUtilities(): void
7175
*/
7276
public function bootedComponentUtilities(): void
7377
{
74-
// Fire Lifecycle Hooks for configuring
75-
$this->callHook('configuring');
76-
$this->callTraitHook('configuring');
77-
78-
// Call the configure() method
79-
$this->configure();
80-
81-
// Fire Lifecycle Hooks for configured
82-
$this->callHook('configured');
83-
$this->callTraitHook('configured');
78+
$this->runCoreConfiguration();
8479

8580
// Make sure a primary key is set
8681
if (! $this->hasPrimaryKey()) {
@@ -89,6 +84,26 @@ public function bootedComponentUtilities(): void
8984

9085
}
9186

87+
protected function runCoreConfiguration(): void
88+
{
89+
if (!$this->hasRunConfigure)
90+
{
91+
// Fire Lifecycle Hooks for configuring
92+
$this->callHook('configuring');
93+
$this->callTraitHook('configuring');
94+
95+
// Call the configure() method
96+
$this->configure();
97+
98+
// Fire Lifecycle Hooks for configured
99+
$this->callHook('configured');
100+
$this->callTraitHook('configured');
101+
102+
$this->hasRunConfigure = true;
103+
104+
}
105+
}
106+
92107
/**
93108
* Returns a unique id for the table, used as an alias to identify one table from another session and query string to prevent conflicts
94109
*/

src/Traits/Configuration/QueryStringConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setQueryStringAlias(string $queryStringAlias): self
1414
public function setupQueryStringStatus(): void
1515
{
1616
if (! $this->hasQueryStringStatus()) {
17-
$this->configure();
17+
$this->runCoreConfiguration();
1818
if (! $this->hasQueryStringStatus()) {
1919
$this->setQueryStringEnabled();
2020
}

src/Traits/Core/QueryStrings/HasQueryStringForFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected function queryStringHasQueryStringForFilter(): array
2020
] : [];
2121
}
2222

23-
public function setupQueryStringStatusForFilter(): void
23+
protected function setupQueryStringStatusForFilter(): void
2424
{
2525
if (! $this->hasQueryStringStatusForFilter()) {
2626
$this->setQueryStringForFilterEnabled();

src/Traits/Core/QueryStrings/HasQueryStringForSort.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getQueryStringStatusForSort(): bool
2727
return $this->getQueryStringConfigStatus('sorts');
2828
}
2929

30-
protected function queryStringForSortEnabled(): bool
30+
public function queryStringForSortEnabled(): bool
3131
{
3232
$this->setupQueryStringStatusForSort();
3333

src/Traits/HasAllTraits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ trait HasAllTraits
1212
use WithLoadingPlaceholder;
1313
use HasTheme;
1414
use ComponentUtilities,
15+
WithQueryString,
1516
WithActions,
1617
WithData,
1718
WithColumns,
@@ -28,7 +29,6 @@ trait HasAllTraits
2829
WithEvents,
2930
WithFilters,
3031
WithFooter,
31-
WithQueryString,
3232
WithRefresh,
3333
WithReordering,
3434
WithSecondaryHeader,

0 commit comments

Comments
 (0)