Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
use Filament\Support\Concerns\HasIconPosition;
use Illuminate\Contracts\Support\Htmlable;
use Relaticle\Flowforge\Concerns\BelongsToBoard;
use Relaticle\Flowforge\Concerns\CanBeHidden;

class Column extends ViewComponent
{
use BelongsToBoard;
use CanBeHidden;
use HasColor;
use HasIcon;
use HasIconColor;
Expand Down
42 changes: 42 additions & 0 deletions src/Concerns/CanBeHidden.php
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);
}
Comment on lines +9 to +36
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CanBeHidden calls $this->evaluate(...), but the trait itself doesn’t document or enforce that the consuming class provides an evaluate() implementation. If this trait is ever reused outside Filament\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.

Copilot uses AI. Check for mistakes.

public function isVisible(): bool
{
return ! $this->isHidden();
}
}
2 changes: 1 addition & 1 deletion src/Concerns/HasBoardColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getColumns() now uses array_filter() which preserves the original array keys; if callers ever JSON-encode or otherwise depend on a sequential list, this can unexpectedly produce a sparse array / object-like structure. Consider wrapping with array_values(...) to reindex after filtering. Also, the callback is type-hinted as fn (Column $column) which will throw a TypeError if $this->columns ever contains non-Column values (even though they’re not prevented in columns()); either validate/throw when setting columns, or make the filter tolerant of non-Column entries.

Copilot uses AI. Check for mistakes.

/**
Expand Down
11 changes: 10 additions & 1 deletion tests/Feature/LivewireBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests cover the new visible(...) behavior, but the newly added hidden(...) API isn’t exercised anywhere in the suite. To prevent regressions, add a test case that configures a column with ->hidden(...) (and ideally one that verifies precedence when both hidden() and visible() are set).

Suggested change
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');
});

Copilot uses AI. Check for mistakes.
test('displays cards in correct columns', function () {
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class TestBoard extends BoardPage
{
public bool $showAllColumns = false;

public function getEloquentQuery(): Builder
{
return Task::query();
Expand All @@ -25,6 +27,7 @@ public function board(Board $board): Board
->positionIdentifier('order_position')
->columns([
Column::make('todo')->label('To Do')->color('gray'),
Column::make('hidden_column')->visible(fn () => $this->showAllColumns)->label('Hidden Column'),
Column::make('in_progress')->label('In Progress')->color('blue'),
Column::make('completed')->label('Completed')->color('green'),
]);
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/TestStandaloneBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TestStandaloneBoard extends Component implements HasActions, HasBoard, Has
}
use InteractsWithForms;

public bool $showAllColumns = false;

public function board(Board $board): Board
{
return $board
Expand All @@ -34,6 +36,7 @@ public function board(Board $board): Board
->positionIdentifier('order_position')
->columns([
Column::make('todo')->label('To Do')->color('gray'),
Column::make('hidden_column')->visible(fn () => $this->showAllColumns)->label('Hidden Column'),
Column::make('in_progress')->label('In Progress')->color('blue'),
Column::make('completed')->label('Completed')->color('green'),
]);
Expand Down
11 changes: 10 additions & 1 deletion tests/Standalone/StandaloneBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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(TestStandaloneBoard::class)
->assertStatus(200)
->assertDontSee('Hidden Column')
->set('showAllColumns', true)
->assertSee('Hidden Column');
});

test('displays cards in correct columns', function () {
Expand Down