Skip to content

Add enum helper to column#100

Merged
ManukMinasyan merged 5 commits intorelaticle:4.xfrom
paulhennell:patch-1
Apr 22, 2026
Merged

Add enum helper to column#100
ManukMinasyan merged 5 commits intorelaticle:4.xfrom
paulhennell:patch-1

Conversation

@paulhennell
Copy link
Copy Markdown
Contributor

A helper method to the Column class to set column properties directly from an enum.

Allows a config like this and will set the column label, icon and colour if the standard interfaces are setup.

 ->columns([
                Column::enum(State::OPEN),
                Column::enum(State::WAITING),
                Column::enum(State::CLOSED),
            ]);

A helper method to the Column class to set column properties directly from an enum.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a convenience factory on Column to build a column directly from a backed enum value, optionally applying Filament enum metadata (label/color/icon) when available.

Changes:

  • Introduces Column::enum(BackedEnum $enum) static helper.
  • Sets column name from $enum->value and conditionally derives label/color/icon from Filament enum contracts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Column.php
Comment thread src/Column.php Outdated
Comment thread src/Column.php Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@ManukMinasyan ManukMinasyan left a comment

Choose a reason for hiding this comment

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

Clean, focused addition. The Column::enum() factory method correctly handles:

  • Both string-backed and int-backed enums via BackedEnum type hint
  • Graceful degradation when enum only partially implements Filament contracts (HasLabel, HasColor, HasIcon)
  • Consistent fluent API (delegates to existing make(), label(), color(), icon())

Minor suggestions (non-blocking):

  • Consider using import statements for the Filament contracts instead of inline FQCNs
  • A docblock on the new method would help discoverability
  • Tests would be nice in a follow-up (basic enum, partial interfaces, int-backed enum)

LGTM -- ready to merge.

Copy link
Copy Markdown
Contributor

@ManukMinasyan ManukMinasyan left a comment

Choose a reason for hiding this comment

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

Updating my review -- the implementation itself is clean and correct, but this needs test coverage before merging.

Required: Tests

The Column::enum() method introduces new public API that should be tested. At minimum:

  1. String-backed enum with all interfaces (HasLabel + HasColor + HasIcon) -- verify label, color, icon are set
  2. Enum with partial interfaces (e.g., only HasLabel) -- verify it doesn't error on missing interfaces
  3. Enum without any Filament interfaces -- verify it falls back to basic make() behavior
  4. Int-backed enum -- verify $enum->value works as column identifier

Example test structure:

test('enum helper creates column from backed enum with label, color, and icon', function () {
    $column = Column::enum(TestStatusEnum::Active);
    
    expect($column->getName())->toBe('active')
        ->and($column->getLabel())->toBe('Active')
        ->and($column->getColor())->toBe('success')
        ->and($column->getIcon())->toBe('heroicon-o-check');
});

Minor (non-blocking)

  • Consider importing the Filament contracts at the top of the file instead of inline FQCNs
  • A docblock would help discoverability

…ked support

- Import BackedEnum so the typehint resolves correctly inside the
  Relaticle\Flowforge namespace (previously relied on the implicit
  relative lookup that would fail).
- Import Filament contracts (HasColor, HasIcon, HasLabel) via aliases
  to avoid inline FQCNs while keeping the trait/contract name split.
- Cast $enum->value to string before handing it to make(), so
  int-backed enums no longer hit a TypeError under strict_types.
- Add a docblock describing the method for discoverability.
Adds a ColumnEnumTest with four scenarios:

- Enum implementing HasLabel + HasColor + HasIcon applies all three.
- Enum implementing only HasLabel leaves color/icon unset without
  error.
- Plain enum without any Filament contracts falls back to the
  generated default label.
- Int-backed enum value is coerced to a string identifier.

Fixtures live in tests/Fixtures so they can be reused if other
tests need enum coverage later.
@ManukMinasyan
Copy link
Copy Markdown
Contributor

Thanks for the reviews! Pushed two commits addressing all feedback:

  • b1edbb2 (Copilot unresolved thread on BackedEnum, @ManukMinasyan's minor points):
    • Imported BackedEnum so the typehint resolves correctly from inside the Relaticle\Flowforge namespace.
    • Imported Filament's HasColor/HasIcon/HasLabel contracts (aliased where they'd collide with the existing trait imports) instead of inline FQCNs.
    • Cast $enum->value to string before handing it to make(), so int-backed enums no longer hit a TypeError under strict_types=1 (also covers the previously-resolved int-backed-enum thread).
    • Added a docblock for discoverability.
  • 197c5e5 (@ManukMinasyan's required tests): new tests/Unit/ColumnEnumTest.php with fixtures covering the four scenarios you asked for:
    1. Full-interface enum (HasLabel + HasColor + HasIcon) — label/color/icon all applied.
    2. Partial-interface enum (HasLabel only) — no error, color/icon untouched.
    3. Plain enum without any Filament contracts — falls back to generated default label.
    4. Int-backed enum — value coerced to string identifier.

vendor/bin/pint, vendor/bin/phpstan, and vendor/bin/pest (116 tests) all green locally.

Adds a "Building Columns From Enums" section to the customization guide
with a complete example, and a short reference entry in the API
reference linking back to it.
@ManukMinasyan ManukMinasyan merged commit 5b61219 into relaticle:4.x Apr 22, 2026
3 checks passed
ManukMinasyan added a commit to paulhennell/flowforge that referenced this pull request Apr 22, 2026
Resolve conflicts in docs/content/2.essentials/2.customization.md and
docs/content/2.essentials/4.api-reference.md — both the Conditional
Visibility sections from this PR and the Building Columns From Enums
sections from relaticle#100 belong in the final docs, placed after the existing
Column Configuration block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants