-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Customisation for "Search" in QueryString (#2017)
* AddSearchQueryString * Add tests for hasQueryStringAliasFor... * Additional Tests For SearchQueryString * Move Livewire to Visuals section * Simplify the queryString methods * Add hasQueryStringAliasForSearch test * PCOV Runs as PHPUnit not ParaTest * Remove PCOV From Workflows Where Not Used * Fix styling --------- Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
299 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; | ||
|
||
use Livewire\Attributes\Locked; | ||
|
||
trait HasQueryStringForSearch | ||
{ | ||
#[Locked] | ||
public ?bool $queryStringStatusForSearch; | ||
|
||
protected ?string $queryStringAliasForSearch; | ||
|
||
protected function queryStringHasQueryStringForSearch(): array | ||
{ | ||
return ($this->queryStringForSearchEnabled() && $this->searchIsEnabled()) ? ['search' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForSearch()]] : []; | ||
|
||
} | ||
|
||
public function setupQueryStringStatusForSearch(): void | ||
{ | ||
if (! $this->hasQueryStringStatusForSearch()) { | ||
$this->setQueryStringForSearchEnabled(); | ||
} | ||
} | ||
|
||
public function hasQueryStringStatusForSearch(): bool | ||
{ | ||
return isset($this->queryStringStatusForSearch); | ||
} | ||
|
||
public function getQueryStringStatusForSearch(): bool | ||
{ | ||
return $this->queryStringStatusForSearch ?? true; | ||
} | ||
|
||
public function queryStringForSearchEnabled(): bool | ||
{ | ||
$this->setupQueryStringStatusForSearch(); | ||
|
||
return $this->getQueryStringStatusForSearch() && $this->searchIsEnabled(); | ||
} | ||
|
||
public function setQueryStringStatusForSearch(bool $status): self | ||
{ | ||
$this->queryStringStatusForSearch = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function setQueryStringForSearchEnabled(): self | ||
{ | ||
$this->setQueryStringStatusForSearch(true); | ||
|
||
return $this; | ||
} | ||
|
||
public function setQueryStringForSearchDisabled(): self | ||
{ | ||
$this->setQueryStringStatusForSearch(false); | ||
|
||
return $this; | ||
} | ||
|
||
public function hasQueryStringAliasForSearch(): bool | ||
{ | ||
return isset($this->queryStringAliasForSearch); | ||
} | ||
|
||
public function getQueryStringAliasForSearch(): string | ||
{ | ||
return $this->queryStringAliasForSearch ?? $this->getQueryStringAlias().'-search'; | ||
} | ||
|
||
public function setQueryStringAliasForSearch(string $alias): self | ||
{ | ||
$this->queryStringAliasForSearch = $alias; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
tests/Traits/Core/QueryStrings/QueryStringForSearchTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Core\QueryStrings; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Depends; | ||
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; | ||
use Rappasoft\LaravelLivewireTables\Tests\TestCase; | ||
|
||
final class QueryStringForSearchTest extends TestCase | ||
{ | ||
public function test_can_get_default_search_query_string_status(): void | ||
{ | ||
$mock = new class extends PetsTable | ||
{ | ||
public ?array $testAttributesArray; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setDataTableFingerprint('test'); | ||
} | ||
}; | ||
|
||
$mock->configure(); | ||
$mock->boot(); | ||
|
||
$this->assertSame(true, $mock->getQueryStringStatusForSearch()); | ||
} | ||
|
||
public function test_can_disable_search_query_string_status(): void | ||
{ | ||
$mock = new class extends PetsTable | ||
{ | ||
public ?array $testAttributesArray; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setDataTableFingerprint('test'); | ||
$this->setQueryStringForSearchDisabled(); | ||
} | ||
}; | ||
|
||
$mock->configure(); | ||
$mock->boot(); | ||
|
||
$this->assertSame(false, $mock->getQueryStringStatusForSearch()); | ||
} | ||
|
||
public function test_can_enable_search_query_string_status(): void | ||
{ | ||
$mock = new class extends PetsTable | ||
{ | ||
public ?array $testAttributesArray; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setDataTableFingerprint('test'); | ||
$this->setQueryStringForSearchDisabled(); | ||
} | ||
}; | ||
|
||
$mock->configure(); | ||
$mock->boot(); | ||
|
||
$this->assertSame(false, $mock->getQueryStringStatusForSearch()); | ||
$mock->setQueryStringForSearchEnabled(); | ||
$this->assertSame(true, $mock->getQueryStringStatusForSearch()); | ||
|
||
} | ||
|
||
public function test_can_get_default_search_query_string_alias(): void | ||
{ | ||
$mock = new class extends PetsTable | ||
{ | ||
public ?array $testAttributesArray; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setDataTableFingerprint('test'); | ||
} | ||
}; | ||
|
||
$mock->configure(); | ||
$mock->boot(); | ||
|
||
$this->assertSame('table-search', $mock->getQueryStringAliasForSearch()); | ||
} | ||
|
||
public function test_can_change_default_search_query_string_alias(): void | ||
{ | ||
$mock = new class extends PetsTable | ||
{ | ||
public ?array $testAttributesArray; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setDataTableFingerprint('test'); | ||
} | ||
}; | ||
|
||
$mock->configure(); | ||
$mock->boot(); | ||
|
||
$this->assertFalse($mock->hasQueryStringAliasForSearch()); | ||
$this->assertSame('table-search', $mock->getQueryStringAliasForSearch()); | ||
$mock->setQueryStringAliasForSearch('pet-search'); | ||
$this->assertSame('pet-search', $mock->getQueryStringAliasForSearch()); | ||
$this->assertTrue($mock->hasQueryStringAliasForSearch()); | ||
} | ||
} |
Oops, something went wrong.