Remember for each user which Kanban cards have their task list open

The open cards are kept in the user's board preferences (expanded_cards,
at most 500), saved without redrawing the board and restored on return.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-30 11:25:58 +02:00
co-authored by Claude Opus 5.5
parent e274a8d2b1
commit 9eac4c4d4e
10 changed files with 172 additions and 21 deletions
@@ -12,20 +12,26 @@ use App\Modules\Shared\Domain\ValueObjects\HexColor;
/**
* One user's Kanban board settings: card density, the urgent threshold,
* and their own colour and order for each column. A column without a
* colour of its own uses the design's default colour.
* their own colour and order for each column, and which cards they keep
* open (task list shown). A column without a colour of its own uses the
* design's default colour.
*/
final readonly class BoardPreferences
{
/** At most this many open cards are remembered, the latest kept. */
public const int MAX_EXPANDED_CARDS = 500;
/**
* @param array<string, HexColor> $columnColors by BoardColumn value
* @param array<string, ColumnSort> $columnSorts by BoardColumn value
* @param list<string> $expandedCards card keys ("job-12", "task-34"), oldest first
*/
public function __construct(
public BoardDensity $density = BoardDensity::Normal,
public UrgentThreshold $urgentThreshold = UrgentThreshold::Urgent,
public array $columnColors = [],
public array $columnSorts = [],
public array $expandedCards = [],
) {}
public static function defaults(): self
@@ -33,14 +39,20 @@ final readonly class BoardPreferences
return new self;
}
public static function isCardKey(string $key): bool
{
return preg_match('/^(job|task)-\d+$/', $key) === 1;
}
/**
* Rebuilds stored settings, dropping unknown columns and invalid values
* so a bad stored value never breaks the board.
*
* @param array<array-key, mixed> $colors
* @param array<array-key, mixed> $sorts
* @param array<array-key, mixed> $expanded
*/
public static function fromStored(?string $density, ?string $threshold, array $colors, array $sorts): self
public static function fromStored(?string $density, ?string $threshold, array $colors, array $sorts, array $expanded = []): self
{
$columnColors = [];
@@ -60,11 +72,14 @@ final readonly class BoardPreferences
}
}
$expandedCards = array_values(array_unique(array_filter($expanded, fn ($key): bool => is_string($key) && self::isCardKey($key))));
return new self(
BoardDensity::tryFrom((string) $density) ?? BoardDensity::Normal,
UrgentThreshold::tryFrom((string) $threshold) ?? UrgentThreshold::Urgent,
$columnColors,
$columnSorts,
array_slice($expandedCards, -self::MAX_EXPANDED_CARDS),
);
}
@@ -83,14 +98,19 @@ final readonly class BoardPreferences
return $this->columnSorts[$column->value] ?? ColumnSort::Manual;
}
public function isCardExpanded(string $key): bool
{
return in_array($key, $this->expandedCards, true);
}
public function withDensity(BoardDensity $density): self
{
return new self($density, $this->urgentThreshold, $this->columnColors, $this->columnSorts);
return new self($density, $this->urgentThreshold, $this->columnColors, $this->columnSorts, $this->expandedCards);
}
public function withUrgentThreshold(UrgentThreshold $threshold): self
{
return new self($this->density, $threshold, $this->columnColors, $this->columnSorts);
return new self($this->density, $threshold, $this->columnColors, $this->columnSorts, $this->expandedCards);
}
/**
@@ -106,7 +126,7 @@ final readonly class BoardPreferences
$colors[$column->value] = $color;
}
return new self($this->density, $this->urgentThreshold, $colors, $this->columnSorts);
return new self($this->density, $this->urgentThreshold, $colors, $this->columnSorts, $this->expandedCards);
}
public function withColumnSort(BoardColumn $column, ColumnSort $sort): self
@@ -114,7 +134,26 @@ final readonly class BoardPreferences
$sorts = $this->columnSorts;
$sorts[$column->value] = $sort;
return new self($this->density, $this->urgentThreshold, $this->columnColors, $sorts);
return new self($this->density, $this->urgentThreshold, $this->columnColors, $sorts, $this->expandedCards);
}
/**
* Opens or closes a card's task list for this user. A card key that is
* not one ("job-12" / "task-34") changes nothing.
*/
public function withCardExpanded(string $key, bool $expanded): self
{
if (! self::isCardKey($key)) {
return $this;
}
$cards = array_values(array_diff($this->expandedCards, [$key]));
if ($expanded) {
$cards[] = $key;
}
return new self($this->density, $this->urgentThreshold, $this->columnColors, $this->columnSorts, array_slice($cards, -self::MAX_EXPANDED_CARDS));
}
/**