Skip to content
16 changes: 16 additions & 0 deletions app-modules/community/database/factories/RetrospectiveFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Carbon\CarbonImmutable;
use He4rt\Community\Retrospective\DTOs\DeckConfig;
use He4rt\Community\Retrospective\DTOs\RetrospectiveSnapshot;
use He4rt\Community\Retrospective\Enums\CoverKind;
use He4rt\Community\Retrospective\Enums\RetrospectiveStatus;
use He4rt\Community\Retrospective\Models\Retrospective;
use He4rt\Identity\User\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -28,6 +30,7 @@ public function definition(): array
'since' => $since,
'until' => CarbonImmutable::now(),
'status' => RetrospectiveStatus::Draft,
'cover_kind' => CoverKind::Retrospective,
'cover_title' => fake()->sentence(3),
'cover_intro' => fake()->sentence(),
'closing_text' => fake()->sentence(),
Expand All @@ -46,4 +49,17 @@ public function published(?RetrospectiveSnapshot $snapshot = null): self
'snapshot' => $snapshot ?? new RetrospectiveSnapshot(),
]);
}

/**
* @param list<User> $hosts
*/
public function onboarding(array $hosts = []): self
{
return $this->state(fn (): array => [
'cover_kind' => CoverKind::Onboarding,
'deck_config' => new DeckConfig()->withHosts(
array_map(static fn (User $host): string => $host->id, $hosts),
),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use He4rt\Community\Retrospective\Enums\CoverKind;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('community_retrospectives', static function (Blueprint $table): void {
$table->string('cover_kind', 20)
->default(CoverKind::Retrospective->value)
->comment(CoverKind::stringifyCases())
->after('status');
});
}

public function down(): void
{
Schema::table('community_retrospectives', static function (Blueprint $table): void {
$table->dropColumn('cover_kind');
});
}
};
28 changes: 28 additions & 0 deletions app-modules/community/src/Retrospective/DTOs/DeckConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* @param list<string> $hiddenSlides kinds de slide ocultados (ex.: "github.repos")
* @param array<string, list<string>> $exclusions refs escondidos por key de fonte (ex.: ["github" => ["pr:142"]])
* @param list<PromotionEntry> $promotions as pessoas do slide da tag He4rt, na ordem de exibição
* @param list<string> $hosts ids de quem apresenta o onboarding, na ordem de exibição
*/
public function __construct(
public array $order = [],
public array $hiddenSources = [],
public array $hiddenSlides = [],
public array $exclusions = [],
public array $promotions = [],
public array $hosts = [],
) {}

/**
Expand All @@ -50,6 +52,7 @@ public static function makeFromPayload(array $payload): self
hiddenSlides: self::stringList($payload['hidden_slides'] ?? []),
exclusions: $exclusions,
promotions: self::promotionList($payload['promotions'] ?? []),
hosts: self::stringList($payload['hosts'] ?? []),
);
}

Expand All @@ -67,6 +70,7 @@ public function toArray(): array
static fn (PromotionEntry $entry): array => $entry->toArray(),
$this->promotions,
),
'hosts' => $this->hosts,
];
}

Expand Down Expand Up @@ -110,6 +114,7 @@ public function withSourceVisible(string $key, bool $visible): self
hiddenSlides: $this->hiddenSlides,
exclusions: $this->exclusions,
promotions: $this->promotions,
hosts: $this->hosts,
);
}

Expand All @@ -125,6 +130,7 @@ public function withSlideVisible(string $kind, bool $visible): self
hiddenSlides: $this->toggled($this->hiddenSlides, $kind, hidden: !$visible),
exclusions: $this->exclusions,
promotions: $this->promotions,
hosts: $this->hosts,
);
}

Expand All @@ -139,6 +145,7 @@ public function withOrder(array $order): self
hiddenSlides: $this->hiddenSlides,
exclusions: $this->exclusions,
promotions: $this->promotions,
hosts: $this->hosts,
);
}

Expand All @@ -165,6 +172,7 @@ public function withExclusionsFor(string $key, array $refs): self
hiddenSlides: $this->hiddenSlides,
exclusions: $exclusions,
promotions: $this->promotions,
hosts: $this->hosts,
);
}

Expand Down Expand Up @@ -222,6 +230,26 @@ public function withPromotionsFor(PromotionStage $stage, array $entries): self
hiddenSlides: $this->hiddenSlides,
exclusions: $this->exclusions,
promotions: [...$others, ...$entries],
hosts: $this->hosts,
);
}

/**
* Quem apresenta o onboarding, na ordem do operador. Curadoria de
* apresentação como o texto da capa: não entra no snapshot e não pede
* republicar (ADR-0002). Só a capa de onboarding lê isto.
*
* @param list<string> $hosts
*/
public function withHosts(array $hosts): self
{
return new self(
order: $this->order,
hiddenSources: $this->hiddenSources,
hiddenSlides: $this->hiddenSlides,
exclusions: $this->exclusions,
promotions: $this->promotions,
hosts: array_values(array_unique($this->normalizedRefs($hosts))),
);
}

Expand Down
64 changes: 64 additions & 0 deletions app-modules/community/src/Retrospective/Enums/CoverKind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace He4rt\Community\Retrospective\Enums;

use App\Enums\Concerns\StringifyEnum;
use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasDescription;
use Filament\Support\Contracts\HasIcon;
use Filament\Support\Contracts\HasLabel;
use Filament\Support\Icons\Heroicon;

/**
* Para quem a edição abre. O mesmo deck serve a dois rituais: o balanço do
* período (retrospectiva) e a recepção mensal de quem acabou de chegar
* (onboarding). Só a capa muda; o resto do deck é a mesma prova.
*
* Não é escala: dois públicos distintos, cada um com cor própria.
*/
enum CoverKind: string implements HasColor, HasDescription, HasIcon, HasLabel
Comment thread
danielhe4rt marked this conversation as resolved.
Resolved
{
use StringifyEnum;

case Retrospective = 'retrospective';
case Onboarding = 'onboarding';

public function getLabel(): string
{
return match ($this) {
self::Retrospective => 'Retrospectiva',
self::Onboarding => 'Onboarding',
};
}

public function getColor(): string
{
return match ($this) {
self::Retrospective => 'primary',
self::Onboarding => 'success',
};
}

public function getDescription(): string
{
return match ($this) {
self::Retrospective => 'Abre como balanço do período: "quem fez a He4rt bater".',
self::Onboarding => 'Abre como boas-vindas ao evento mensal de novos membros, com edição e apresentador.',
};
}

public function getIcon(): Heroicon
{
return match ($this) {
self::Retrospective => Heroicon::OutlinedSparkles,
self::Onboarding => Heroicon::OutlinedHandRaised,
};
}

public function isOnboarding(): bool
{
return $this === self::Onboarding;
}
}
24 changes: 24 additions & 0 deletions app-modules/community/src/Retrospective/Models/Retrospective.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use He4rt\Community\Retrospective\DTOs\Period;
use He4rt\Community\Retrospective\DTOs\RetrospectiveSnapshot;
use He4rt\Community\Retrospective\DTOs\SourceFilters;
use He4rt\Community\Retrospective\Enums\CoverKind;
use He4rt\Community\Retrospective\Enums\RetrospectiveStatus;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Attributes\UseFactory;
Expand All @@ -26,6 +27,7 @@
* @property CarbonInterface $since
* @property CarbonInterface $until
* @property RetrospectiveStatus $status
* @property CoverKind $cover_kind
* @property string|null $cover_title
* @property string|null $cover_intro
* @property string|null $closing_text
Expand All @@ -49,6 +51,7 @@ final class Retrospective extends Model
'since',
'until',
'status',
'cover_kind',
'cover_title',
'cover_intro',
'closing_text',
Expand Down Expand Up @@ -84,6 +87,26 @@ public function isPublished(): bool
return $this->status->isPublished();
}

/**
* Que edição do onboarding é esta: a posição entre as edições de onboarding,
* na ordem do início do período. Derivada e não digitada: um número que o
* operador esquece de atualizar mente no telão, e a ordem das edições já
* está no banco.
*
* Ancorada no `since` e não em "hoje": reabrir a 3ª edição em 2030 continua
* mostrando "3ª edição".
*/
public function editionNumber(): int
{
$earlierEditions = self::query()
->where('cover_kind', CoverKind::Onboarding->value)
->whereKeyNot($this->getKey())
->where('since', '<', $this->since)
Comment thread
danielhe4rt marked this conversation as resolved.
Resolved
->count();

return $earlierEditions + 1;
}

/**
* A edição publicada está exibindo números que não correspondem mais à curadoria
* atual, porque um filtro que MEXE NO DADO mudou depois do publish.
Expand Down Expand Up @@ -126,6 +149,7 @@ protected function casts(): array
'until' => 'datetime',
'published_at' => 'datetime',
'status' => RetrospectiveStatus::class,
'cover_kind' => CoverKind::class,
'hide_bots' => 'boolean',
'deck_config' => AsDeckConfig::class,
'snapshot' => AsRetrospectiveSnapshot::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use He4rt\Community\Retrospective\DTOs\RetrospectiveSnapshot;
use He4rt\Community\Retrospective\DTOs\SourceFilters;
use He4rt\Community\Retrospective\DTOs\SourceResult;
use He4rt\Community\Retrospective\Enums\CoverKind;
use He4rt\Community\Retrospective\Enums\PromotionStage;
use He4rt\Community\Retrospective\Enums\RetrospectiveStatus;
use He4rt\Community\Retrospective\Models\Retrospective;
Expand Down Expand Up @@ -193,3 +194,24 @@

expect($retrospective->fresh()->needsRepublish())->toBeFalse();
});

it('numera a edição de onboarding pela ordem do início do período', function (): void {
$may = Retrospective::factory()->onboarding()->create(['since' => CarbonImmutable::parse('2026-05-01')]);
$july = Retrospective::factory()->onboarding()->create(['since' => CarbonImmutable::parse('2026-07-01')]);
$june = Retrospective::factory()->onboarding()->create(['since' => CarbonImmutable::parse('2026-06-01')]);
// Retrospectiva comum no meio: não conta como edição do onboarding.
Retrospective::factory()->create(['since' => CarbonImmutable::parse('2026-05-15')]);

expect($may->editionNumber())->toBe(1)
->and($june->editionNumber())->toBe(2)
->and($july->editionNumber())->toBe(3);
});

it('abre como retrospectiva por padrão e persiste o tipo de capa como enum', function (): void {
$default = Retrospective::factory()->create();
$onboarding = Retrospective::factory()->onboarding()->create();

expect($default->fresh()->cover_kind)->toBe(CoverKind::Retrospective)
->and($default->fresh()->deck_config->hosts)->toBeEmpty()
->and($onboarding->fresh()->cover_kind)->toBe(CoverKind::Onboarding);
});
18 changes: 18 additions & 0 deletions app-modules/community/tests/Unit/Retrospective/CoverKindTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Filament\Support\Icons\Heroicon;
use He4rt\Community\Retrospective\Enums\CoverKind;

it('implementa os contratos Filament para todos os casos', function (CoverKind $kind): void {
expect($kind->getLabel())->toBeString()->not->toBeEmpty()
->and($kind->getColor())->toBeString()->not->toBeEmpty()
->and($kind->getDescription())->toBeString()->not->toBeEmpty()
->and($kind->getIcon())->toBeInstanceOf(Heroicon::class);
})->with(CoverKind::cases());

it('só o onboarding se declara onboarding', function (): void {
expect(CoverKind::Onboarding->isOnboarding())->toBeTrue()
->and(CoverKind::Retrospective->isOnboarding())->toBeFalse();
});
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,12 @@
expect($mexido->promotions)->toHaveCount(1)
->and($mexido->promotions[0]->userId)->toBe('u1');
});

it('guarda os apresentadores em ordem, sem repetição, e os preserva nas outras escritas', function (): void {
$config = new DeckConfig(order: ['github'])->withHosts(['u2', 'u1', 'u2', '']);

expect($config->hosts)->toBe(['u2', 'u1'])
->and($config->withSourceVisible('discord', visible: false)->hosts)->toBe(['u2', 'u1'])
->and(DeckConfig::makeFromPayload($config->toArray())->hosts)->toBe(['u2', 'u1'])
->and($config->withHosts([])->hosts)->toBeEmpty();
});
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,18 @@ class="flex items-start gap-2 overflow-x-auto pb-1"
<x-panel-admin::retrospective.filmstrip-group :label="\He4rt\PanelAdmin\Filament\Resources\Retrospectives\Support\InspectorMode::Cover->getLabel()" :icon="\He4rt\PanelAdmin\Filament\Resources\Retrospectives\Support\InspectorMode::Cover->getIcon()">
<x-panel-admin::retrospective.filmstrip-thumb
:index="0"
label="Abertura"
:label="$deck['coverKind']->getLabel()"
:selection="\He4rt\PanelAdmin\Filament\Resources\Retrospectives\Support\InspectorMode::Cover->value"
>
<x-portal::retro.slides.cover
:sources="$deck['sources']"
:since="$deck['since']"
:until="$deck['until']"
:coverTitle="$deck['coverTitle']"
:coverIntro="$deck['coverIntro']"
/>
</x-panel-admin::retrospective.filmstrip-thumb>
:view="\He4rt\Portal\Retrospective\SlideView::cover($deck['coverKind'])"
:props="[
'since' => $deck['since'],
'until' => $deck['until'],
'edition' => $deck['edition'],
'hosts' => $deck['hosts'],
'coverTitle' => $deck['coverTitle'],
'coverIntro' => $deck['coverIntro'],
]"
/>
</x-panel-admin::retrospective.filmstrip-group>

{{-- A He4rt: seção fixa do portal. Sem on/off e sem ordem — não é
Expand Down
Loading