|
2 | 2 |
|
3 | 3 | namespace Backstage\Fields\Filament\RelationManagers; |
4 | 4 |
|
5 | | -use Backstage\Fields\Concerns\HasConfigurableFields; |
6 | | -use Backstage\Fields\Concerns\HasFieldTypeResolver; |
7 | | -use Backstage\Fields\Enums\Field as FieldEnum; |
8 | | -use Backstage\Fields\Facades\Fields; |
| 5 | +use Filament\Tables; |
| 6 | +use Filament\Forms\Get; |
| 7 | +use Filament\Forms\Set; |
| 8 | +use Livewire\Component; |
| 9 | +use Filament\Forms\Form; |
| 10 | +use Filament\Tables\Table; |
| 11 | +use Illuminate\Support\Str; |
9 | 12 | use Backstage\Fields\Models\Field; |
10 | 13 | use Filament\Forms\Components\Grid; |
11 | | -use Filament\Forms\Components\Section; |
| 14 | +use Filament\Tables\Grouping\Group; |
| 15 | +use Backstage\Fields\Facades\Fields; |
12 | 16 | use Filament\Forms\Components\Select; |
| 17 | +use Filament\Forms\Components\Section; |
| 18 | +use Illuminate\Database\Eloquent\Model; |
13 | 19 | use Filament\Forms\Components\TextInput; |
14 | | -use Filament\Forms\Form; |
15 | | -use Filament\Forms\Get; |
16 | | -use Filament\Forms\Set; |
| 20 | +use Backstage\Fields\Enums\Field as FieldEnum; |
| 21 | +use Backstage\Fields\Concerns\HasFieldTypeResolver; |
| 22 | +use Backstage\Fields\Concerns\HasConfigurableFields; |
17 | 23 | use Filament\Resources\RelationManagers\RelationManager; |
18 | | -use Filament\Tables; |
19 | | -use Filament\Tables\Table; |
20 | | -use Illuminate\Database\Eloquent\Model; |
21 | | -use Illuminate\Support\Str; |
22 | | -use Livewire\Component; |
23 | 24 |
|
24 | 25 | class FieldsRelationManager extends RelationManager |
25 | 26 | { |
@@ -86,25 +87,24 @@ public function form(Form $form): Form |
86 | 87 | $set('config', $this->initializeConfig($state)); |
87 | 88 | }), |
88 | 89 |
|
89 | | - Select::make('tab') |
90 | | - ->label(__('Tab')) |
| 90 | + Select::make('group') |
| 91 | + ->label(__('Group')) |
91 | 92 | ->createOptionForm([ |
92 | | - TextInput::make('tab') |
93 | | - ->label(__('Tab')) |
| 93 | + TextInput::make('group') |
| 94 | + ->label(__('Group')) |
94 | 95 | ->required(), |
95 | 96 | ]) |
96 | | - ->createOptionUsing(function (?string $state) { |
97 | | - dd($state); |
98 | | - if (blank($state)) { |
99 | | - return null; |
100 | | - } |
101 | | - return Field::where('tab', $state)->exists() ? null : $state; |
| 97 | + ->createOptionUsing(function (array $data) { |
| 98 | + return $data['group'] ?? null; |
102 | 99 | }) |
103 | 100 | ->searchable() |
104 | 101 | ->preload() |
105 | 102 | ->options(function () { |
106 | | - // Load with earlier used tabs |
107 | | - return Field::pluck('tab')->filter()->unique()->toArray() ?? []; |
| 103 | + return Field::pluck('group') |
| 104 | + ->filter() |
| 105 | + ->unique() |
| 106 | + ->mapWithKeys(fn ($group) => [$group => $group]) |
| 107 | + ->toArray(); |
108 | 108 | }), |
109 | 109 |
|
110 | 110 | ]), |
@@ -163,7 +163,11 @@ public function table(Table $table): Table |
163 | 163 | ->recordTitleAttribute('name') |
164 | 164 | ->reorderable('position') |
165 | 165 | ->defaultSort('position', 'asc') |
166 | | - ->defaultGroup('tab') |
| 166 | + ->defaultGroup('group') |
| 167 | + ->groups([ |
| 168 | + Group::make('group') |
| 169 | + ->label(__('Group')) |
| 170 | + ]) |
167 | 171 | ->columns([ |
168 | 172 | Tables\Columns\TextColumn::make('name') |
169 | 173 | ->label(__('Name')) |
|
0 commit comments