Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static function getNavigationLabel(): string
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table->columns([
TranslatedTextColumn::make('attribute_data.name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static function getNavigationLabel(): string
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table->columns([
ProductResource::getNameTableColumn()->searchable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function form(Schema $schema): Schema
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
$record = $this->getOwnerRecord();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function reorderTable(array $order, string|int|null $draggedRecordKey = n
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table->columns([

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function form(Schema $schema): Schema
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table
->recordTitleAttribute('name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static function getNavigationLabel(): string
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table
->recordTitleAttribute('name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

namespace Lunar\Admin\Filament\Resources\ProductResource\Pages;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ViewAction;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
use Filament\Support\Facades\FilamentIcon;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Filament\Resources\ProductResource\Widgets\ProductOptionsWidget;
Expand Down Expand Up @@ -72,31 +64,11 @@ public function form(Schema $schema): Schema

public function table(Table $table): Table
{
return $table;
return parent::table($table);
}

return $table
->recordTitleAttribute('name')
->columns([
TextColumn::make('sku'),
])
->filters([
//
])
->headerActions([
CreateAction::make(),
// Tables\Actions\AssociateAction::make(),
])
->recordActions([
ViewAction::make(),
EditAction::make(),
// Tables\Actions\DissociateAction::make(),
DeleteAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
// Tables\Actions\DissociateBulkAction::make(),
DeleteBulkAction::make(),
]),
]);
protected function getDefaultTable(Table $table): Table
{
return $table;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public function getBreadcrumbs(): array
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table
->heading(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace Lunar\Admin\Support\Extending;

use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

abstract class RelationPageExtension extends BaseExtension
{
public function extendTable(Table $table): Table
{
return $table;
}

public function heading($title, Model $record): string
{
return $title;
Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/Support/Pages/BaseManageRelatedRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Lunar\Admin\Support\Pages\Concerns\ExtendsHeaderActions;
use Lunar\Admin\Support\Pages\Concerns\ExtendsHeaderWidgets;
use Lunar\Admin\Support\Pages\Concerns\ExtendsHeadings;
use Lunar\Admin\Support\Pages\Concerns\ExtendsTables;

abstract class BaseManageRelatedRecords extends ManageRelatedRecords
{
Expand All @@ -16,4 +17,5 @@ abstract class BaseManageRelatedRecords extends ManageRelatedRecords
use ExtendsHeaderActions;
use ExtendsHeaderWidgets;
use ExtendsHeadings;
use ExtendsTables;
}
18 changes: 18 additions & 0 deletions packages/admin/src/Support/Pages/Concerns/ExtendsTables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Lunar\Admin\Support\Pages\Concerns;

use Filament\Tables\Table;

trait ExtendsTables
{
public function table(Table $table): Table
{
return $this->callLunarHook('extendTable', $this->getDefaultTable($table));
}

protected function getDefaultTable(Table $table): Table
{
return $table;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function form(Schema $schema): Schema
}

public function table(Table $table): Table
{
return parent::table($table);
}

protected function getDefaultTable(Table $table): Table
{
return $table
->recordTitleAttribute('name')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
<?php

use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Livewire\Livewire;
use Lunar\Admin\Filament\Resources\CollectionResource\Pages\ManageCollectionProducts;
use Lunar\Admin\Filament\Resources\ProductResource\Pages\ManageProductMedia;
use Lunar\Admin\Support\Extending\RelationPageExtension;
use Lunar\Admin\Support\Facades\LunarPanel;
use Lunar\Models\Collection;
use Lunar\Models\Language;
use Lunar\Models\Product;
use Lunar\Tests\Admin\Feature\Filament\TestCase;

uses(TestCase::class)
->group('extending');

it('keeps the table method public on concrete relation pages', function () {
$method = new ReflectionMethod(ManageCollectionProducts::class, 'table');

expect($method->isPublic())->toBeTrue()
->and($method->getDeclaringClass()->getName())->toBe(ManageCollectionProducts::class);
});

it('keeps the default relation page table intact when no extension is registered', function () {
Language::factory()->create([
'default' => true,
]);

$collection = Collection::factory()->create();

$this->asStaff(admin: true);

Livewire::test(ManageCollectionProducts::class, [
'record' => $collection->getRouteKey(),
])->assertTableColumnExists('attribute_data.name');
});

it('can extend relation page table columns', function () {
$class = new class extends RelationPageExtension
{
public function extendTable(Table $table): Table
{
return $table->columns([
...$table->getColumns(),
TextColumn::make('test_column'),
]);
}
};

Language::factory()->create([
'default' => true,
]);

$collection = Collection::factory()->create();

LunarPanel::extensions([
ManageCollectionProducts::class => $class::class,
]);

$this->asStaff(admin: true);

Livewire::test(ManageCollectionProducts::class, [
'record' => $collection->getRouteKey(),
])->assertTableColumnExists('test_column');
});

it('can customise page headings', function () {
$class = new class extends RelationPageExtension
{
Expand Down
Loading