-
-
Notifications
You must be signed in to change notification settings - Fork 49
Adding filament style hidden option to columns #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Relaticle\Flowforge\Concerns; | ||
|
|
||
| use Closure; | ||
|
|
||
| trait CanBeHidden | ||
| { | ||
| protected bool | Closure $isHidden = false; | ||
|
|
||
| protected bool | Closure $isVisible = true; | ||
|
|
||
| public function hidden(bool | Closure $condition = true): static | ||
| { | ||
| $this->isHidden = $condition; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function visible(bool | Closure $condition = true): static | ||
| { | ||
| $this->isVisible = $condition; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function isHidden(): bool | ||
| { | ||
| if ($this->evaluate($this->isHidden)) { | ||
| return true; | ||
| } | ||
|
|
||
| return ! $this->evaluate($this->isVisible); | ||
| } | ||
|
|
||
| public function isVisible(): bool | ||
| { | ||
| return ! $this->isHidden(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ public function columns(array | Closure $columns): static | |
| */ | ||
| public function getColumns(): array | ||
| { | ||
| return $this->columns; | ||
| return array_filter($this->columns, fn (Column $column) => $column->isVisible()); | ||
| } | ||
|
Comment on lines
39
to
42
|
||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,16 @@ | |||||||||||||||||||||||
| ->assertStatus(200) | ||||||||||||||||||||||||
| ->assertSee('To Do') | ||||||||||||||||||||||||
| ->assertSee('In Progress') | ||||||||||||||||||||||||
| ->assertSee('Completed'); | ||||||||||||||||||||||||
| ->assertSee('Completed') | ||||||||||||||||||||||||
| ->assertDontSee('Hidden Column'); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| test('renders board with unhidden column', function () { | ||||||||||||||||||||||||
| Livewire::test(TestBoard::class) | ||||||||||||||||||||||||
| ->assertStatus(200) | ||||||||||||||||||||||||
| ->assertDontSee('Hidden Column') | ||||||||||||||||||||||||
| ->set('showAllColumns', true) | ||||||||||||||||||||||||
| ->assertSee('Hidden Column'); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
| test('re-hides hidden column when hidden condition becomes true again', function () { | |
| Livewire::test(TestBoard::class) | |
| ->assertStatus(200) | |
| ->assertDontSee('Hidden Column') | |
| ->set('showAllColumns', true) | |
| ->assertSee('Hidden Column') | |
| ->set('showAllColumns', false) | |
| ->assertDontSee('Hidden Column'); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CanBeHiddencalls$this->evaluate(...), but the trait itself doesn’t document or enforce that the consuming class provides anevaluate()implementation. If this trait is ever reused outsideFilament\Support\Components\ViewComponent, it will fatally error. Consider adding a docblock contract (e.g.,@method mixed evaluate(mixed $value)/@mixin \Filament\Support\Components\ViewComponent) or otherwise constraining usage so the requirement is explicit.