-
Notifications
You must be signed in to change notification settings - Fork 22
feat: configurable description position for custom fields [3.x] #133
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cdc25d9
feat: add DescriptionPosition enum and translations
ManukMinasyan e6890d1
feat: add FIELD_DESCRIPTION_POSITION feature flag (disabled by default)
ManukMinasyan 33edb01
feat: add descriptionPosition property to CustomFieldSettingsData
ManukMinasyan d2556d5
feat: position-aware description rendering in AbstractFormComponent
ManukMinasyan e0d44cd
feat: add description position Select to field management form
ManukMinasyan 6fb12ed
fix: resolve PHPStan errors and simplify code
ManukMinasyan 2b4609f
fix: consolidate test imports and add HTML content assertions
ManukMinasyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Relaticle\CustomFields\Enums; | ||
|
|
||
| use Filament\Support\Contracts\HasLabel; | ||
|
|
||
| enum DescriptionPosition: string implements HasLabel | ||
| { | ||
| case BELOW = 'below'; | ||
| case ABOVE = 'above'; | ||
|
|
||
| public function getLabel(): string | ||
| { | ||
| return match ($this) { | ||
| self::BELOW => __('custom-fields::custom-fields.field.form.description_position_options.below'), | ||
| self::ABOVE => __('custom-fields::custom-fields.field.form.description_position_options.above'), | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Relaticle\CustomFields\Data\CustomFieldSettingsData; | ||
| use Relaticle\CustomFields\Enums\CustomFieldsFeature; | ||
| use Relaticle\CustomFields\Enums\DescriptionPosition; | ||
| use Relaticle\CustomFields\FeatureSystem\FeatureConfigurator; | ||
| use Relaticle\CustomFields\FeatureSystem\FeatureManager; | ||
| use Relaticle\CustomFields\Models\CustomField; | ||
| use Relaticle\CustomFields\Models\CustomFieldSection; | ||
| use Relaticle\CustomFields\Tests\Fixtures\Models\Post; | ||
| use Relaticle\CustomFields\Tests\Fixtures\Models\User; | ||
| use Relaticle\CustomFields\Tests\Fixtures\Resources\Posts\Pages\CreatePost; | ||
|
|
||
| it('has the correct backing values', function (): void { | ||
| expect(DescriptionPosition::BELOW->value)->toBe('below'); | ||
| expect(DescriptionPosition::ABOVE->value)->toBe('above'); | ||
| }); | ||
|
|
||
| it('returns translatable labels', function (): void { | ||
| expect(DescriptionPosition::BELOW->getLabel())->toBeString()->not->toBeEmpty(); | ||
| expect(DescriptionPosition::ABOVE->getLabel())->toBeString()->not->toBeEmpty(); | ||
| }); | ||
|
|
||
| it('has FIELD_DESCRIPTION_POSITION feature flag disabled by default', function (): void { | ||
| expect(FeatureManager::isEnabled(CustomFieldsFeature::FIELD_DESCRIPTION_POSITION))->toBeFalse(); | ||
| }); | ||
|
|
||
| it('can enable FIELD_DESCRIPTION_POSITION feature flag', function (): void { | ||
| $config = FeatureConfigurator::configure() | ||
| ->enable(CustomFieldsFeature::FIELD_DESCRIPTION_POSITION); | ||
|
|
||
| config(['custom-fields.features' => $config]); | ||
|
|
||
| expect(FeatureManager::isEnabled(CustomFieldsFeature::FIELD_DESCRIPTION_POSITION))->toBeTrue(); | ||
| }); | ||
|
|
||
| it('includes descriptionPosition as null by default in settings', function (): void { | ||
| $settings = new CustomFieldSettingsData; | ||
|
|
||
| expect($settings->descriptionPosition)->toBeNull(); | ||
| }); | ||
|
|
||
| it('stores descriptionPosition enum in settings', function (): void { | ||
| $settings = new CustomFieldSettingsData( | ||
| descriptionPosition: DescriptionPosition::ABOVE, | ||
| ); | ||
|
|
||
| expect($settings->descriptionPosition)->toBe(DescriptionPosition::ABOVE); | ||
| }); | ||
|
|
||
| it('serializes and deserializes descriptionPosition through settings', function (): void { | ||
| $settings = new CustomFieldSettingsData( | ||
| descriptionPosition: DescriptionPosition::ABOVE, | ||
| ); | ||
|
|
||
| $array = $settings->toArray(); | ||
| $restored = CustomFieldSettingsData::from($array); | ||
|
|
||
| expect($restored->descriptionPosition)->toBe(DescriptionPosition::ABOVE); | ||
| }); | ||
|
|
||
| it('renders description below field by default', function (): void { | ||
| $this->actingAs(User::factory()->create()); | ||
|
|
||
| $config = FeatureConfigurator::configure() | ||
| ->enable( | ||
| CustomFieldsFeature::FIELD_DESCRIPTION, | ||
| CustomFieldsFeature::SYSTEM_SECTIONS, | ||
| ); | ||
| config(['custom-fields.features' => $config]); | ||
|
|
||
| $section = CustomFieldSection::factory()->create([ | ||
| 'entity_type' => Post::class, | ||
| ]); | ||
|
|
||
| CustomField::factory()->create([ | ||
| 'custom_field_section_id' => $section->id, | ||
| 'name' => 'Test Field', | ||
| 'code' => 'test_field', | ||
| 'type' => 'text', | ||
| 'entity_type' => Post::class, | ||
| 'settings' => new CustomFieldSettingsData( | ||
| description: 'Help text below', | ||
| ), | ||
| ]); | ||
|
|
||
| livewire(CreatePost::class) | ||
| ->assertSuccessful() | ||
| ->assertSeeHtml('Help text below'); | ||
| }); | ||
|
|
||
| it('renders description above field when position is ABOVE and feature enabled', function (): void { | ||
| $this->actingAs(User::factory()->create()); | ||
|
|
||
| $config = FeatureConfigurator::configure() | ||
| ->enable( | ||
| CustomFieldsFeature::FIELD_DESCRIPTION, | ||
| CustomFieldsFeature::FIELD_DESCRIPTION_POSITION, | ||
| CustomFieldsFeature::SYSTEM_SECTIONS, | ||
| ); | ||
| config(['custom-fields.features' => $config]); | ||
|
|
||
| $section = CustomFieldSection::factory()->create([ | ||
| 'entity_type' => Post::class, | ||
| ]); | ||
|
|
||
| CustomField::factory()->create([ | ||
| 'custom_field_section_id' => $section->id, | ||
| 'name' => 'Test Field Above', | ||
| 'code' => 'test_field_above', | ||
| 'type' => 'text', | ||
| 'entity_type' => Post::class, | ||
| 'settings' => new CustomFieldSettingsData( | ||
| description: 'Help text above', | ||
| descriptionPosition: DescriptionPosition::ABOVE, | ||
| ), | ||
| ]); | ||
|
|
||
| livewire(CreatePost::class) | ||
| ->assertSuccessful() | ||
| ->assertSeeHtml('Help text above'); | ||
| }); | ||
|
|
||
| it('ignores description position when FIELD_DESCRIPTION_POSITION feature is disabled', function (): void { | ||
| $this->actingAs(User::factory()->create()); | ||
|
|
||
| $config = FeatureConfigurator::configure() | ||
| ->enable( | ||
| CustomFieldsFeature::FIELD_DESCRIPTION, | ||
| CustomFieldsFeature::SYSTEM_SECTIONS, | ||
| ) | ||
| ->disable(CustomFieldsFeature::FIELD_DESCRIPTION_POSITION); | ||
| config(['custom-fields.features' => $config]); | ||
|
|
||
| $section = CustomFieldSection::factory()->create([ | ||
| 'entity_type' => Post::class, | ||
| ]); | ||
|
|
||
| CustomField::factory()->create([ | ||
| 'custom_field_section_id' => $section->id, | ||
| 'name' => 'Test Field Fallback', | ||
| 'code' => 'test_field_fallback', | ||
| 'type' => 'text', | ||
| 'entity_type' => Post::class, | ||
| 'settings' => new CustomFieldSettingsData( | ||
| description: 'Should render below despite ABOVE setting', | ||
| descriptionPosition: DescriptionPosition::ABOVE, | ||
| ), | ||
| ]); | ||
|
|
||
| livewire(CreatePost::class) | ||
| ->assertSuccessful() | ||
| ->assertSeeHtml('Should render below despite ABOVE setting'); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.