Skip to content

Commit 38e48e0

Browse files
authored
Merge pull request #31 from stephenjude/main
Filament v4 Support
2 parents bd32c8d + b709624 commit 38e48e0

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.2",
20-
"filament/filament": "^3.0",
21-
"illuminate/contracts": "^10.0|^11.0|^12.0",
19+
"php": "^8.3",
20+
"filament/filament": "^4.0",
2221
"laravel/pennant": "^1.10",
2322
"spatie/laravel-package-tools": "^1.14.0"
2423
},
2524
"require-dev": {
2625
"laravel/pint": "^1.0",
27-
"nunomaduro/collision": "^7.8",
26+
"nunomaduro/collision": "^7.8|^8.0",
2827
"orchestra/testbench": "^8.8|^10.0",
2928
"pestphp/pest": "^2.20|^3.7",
3029
"pestphp/pest-plugin-arch": "^2.0|^3.0",

src/FeatureFlagPlugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ public function getId(): string
1717

1818
public function register(Panel $panel): void
1919
{
20-
$panel->resources(config('filament-feature-flags.resources'));
20+
$panel->when(
21+
value: fn () => $this->authorized(),
22+
callback: function (Panel $panel) {
23+
$panel->resources(config('filament-feature-flags.resources'));
24+
}
25+
);
2126
}
2227

2328
public function boot(Panel $panel): void {}

src/Resources/FeatureSegmentResource.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Stephenjude\FilamentFeatureFlag\Resources;
44

5+
use Filament\Actions\DeleteAction;
6+
use Filament\Actions\EditAction;
57
use Filament\Facades\Filament;
68
use Filament\Forms\Components\Select;
7-
use Filament\Forms\Form;
8-
use Filament\Forms\Get;
9-
use Filament\Forms\Set;
109
use Filament\Resources\Resource;
10+
use Filament\Schemas\Components\Utilities\Get;
11+
use Filament\Schemas\Components\Utilities\Set;
12+
use Filament\Schemas\Schema;
1113
use Filament\Support\Enums\FontWeight;
1214
use Filament\Tables;
1315
use Filament\Tables\Table;
@@ -41,9 +43,9 @@ public static function getNavigationIcon(): ?string
4143
return config('filament-feature-flags.panel.icon');
4244
}
4345

44-
public static function form(Form $form): Form
46+
public static function form(Schema $schema): Schema
4547
{
46-
return $form
48+
return $schema
4749
->schema([
4850
Select::make('feature')
4951
->required()
@@ -70,7 +72,7 @@ public static function form(Form $form): Form
7072
->where('active', $get('active'))
7173
)
7274
->validationMessages([
73-
'unique' => 'Feature segmentation already exists! Please note that each feature scope can only have an activated and a deactivated segment. Modify existing segment or remove it and create a new segment.',
75+
'unique' => 'Feature segmentation already exists. Each feature scope can only have one activated segment and one deactivated segment. To continue, please modify the existing segment, or remove it and create a new one.',
7476
])
7577
->required()
7678
->columnSpanFull(),
@@ -106,24 +108,24 @@ public static function table(Table $table): Table
106108
Tables\Filters\SelectFilter::make('scope')
107109
->options(FeatureSegment::segmentOptionsList()),
108110
])
109-
->actions([
110-
Tables\Actions\EditAction::make()
111+
->recordActions([
112+
EditAction::make()
111113
->label('Modify')
112114
->modalHeading('Modify Feature Segment')
113115
->after(fn (FeatureSegment $record) => FeatureSegmentModified::dispatch(
114116
$record,
115117
Filament::auth()->user()
116118
)),
117119

118-
Tables\Actions\DeleteAction::make()
120+
DeleteAction::make()
121+
->label('Remove')
119122
->modalHeading('Removing this feature segment cannot be undone!')
120123
->modalDescription(fn (FeatureSegment $record) => $record->description)
121-
->label('Remove')
124+
->after(fn () => FeatureSegmentRemoved::dispatch(Filament::auth()->user()))
122125
->before(fn (FeatureSegment $record) => RemovingFeatureSegment::dispatch(
123126
$record,
124127
Filament::auth()->user()
125-
))
126-
->after(fn () => FeatureSegmentRemoved::dispatch(Filament::auth()->user())),
128+
)),
127129
]);
128130
}
129131

@@ -145,15 +147,24 @@ function ($segment) {
145147
$key = $segment['source']['key'];
146148

147149
return Select::make('values')
148-
->label(str($column)->plural()->title())
149-
->hidden(fn (Get $get) => $get('scope') !== $column)
150-
->required()
150+
->preload()
151151
->multiple()
152+
->required()
152153
->searchable()
153154
->columnSpanFull()
155+
->label(str($column)->plural()->title())
156+
->hidden(fn (Get $get) => $get('scope') !== $column)
157+
->getOptionLabelsUsing(
158+
fn (array $values): array => $model::query()
159+
->whereIn($value, $values)
160+
->pluck($value, $key)
161+
->all()
162+
)
154163
->getSearchResultsUsing(
155-
fn (string $search): array => $model::where($value, 'like', "%{$search}%")
156-
->limit(50)->pluck($value, $key)->toArray()
164+
fn (string $search): array => $model::query()
165+
->where($value, 'like', "%{$search}%")
166+
->limit(50)->pluck($value, $key)
167+
->toArray()
157168
);
158169
}
159170
)

src/Resources/ManageFeatureSegments.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Stephenjude\FilamentFeatureFlag\Resources;
44

55
use Filament\Actions;
6+
use Filament\Actions\Action;
67
use Filament\Facades\Filament;
78
use Filament\Forms\Components\Select;
89
use Filament\Notifications\Notification;
@@ -27,11 +28,11 @@ protected function getHeaderActions(): array
2728
->label(__('Segment Feature'))
2829
->after(fn (FeatureSegment $record) => $this->afterCreate($record)),
2930

30-
Actions\Action::make('activate_for_all')
31+
Action::make('activate_for_all')
3132
->label(__('Activate'))
3233
->modalWidth('md')
3334
->modalDescription(fn ($record) => __('This action will activate the selected feature for users.'))
34-
->form([
35+
->schema([
3536
Select::make('feature')
3637
->label(__('Feature'))
3738
->required()
@@ -41,12 +42,12 @@ protected function getHeaderActions(): array
4142
->modalSubmitActionLabel(__('Activate'))
4243
->action(fn ($data) => $this->activateForAll($data['feature'])),
4344

44-
Actions\Action::make('deactivate_for_all')
45+
Action::make('deactivate_for_all')
4546
->label(__('Deactivate for All'))
4647
->modalWidth('md')
4748
->label(__('Deactivate'))
4849
->modalDescription(fn ($record) => __('This action will deactivate this feature for users.'))
49-
->form([
50+
->schema([
5051
Select::make('feature')
5152
->label(__('Feature'))
5253
->required()
@@ -57,11 +58,11 @@ protected function getHeaderActions(): array
5758
->color('danger')
5859
->action(fn ($data) => $this->deactivateForAll($data['feature'])),
5960

60-
Actions\Action::make('purge_features')
61+
Action::make('purge_features')
6162
->modalWidth('md')
6263
->label(__('Purge'))
6364
->modalDescription(fn ($record) => __('This action will purge resolved features from storage.'))
64-
->form([
65+
->schema([
6566
Select::make('feature')
6667
->label(__('Feature'))
6768
->selectablePlaceholder(false)

0 commit comments

Comments
 (0)