Skip to content

Commit

Permalink
Feature - Support extend tabs (#1725)
Browse files Browse the repository at this point in the history
This PR add support of extends tabs on BaseListRecords

Co-authored-by: Glenn Jacobs <glenn@neondigital.co.uk>
  • Loading branch information
lguichard and glennjacobs authored May 22, 2024
1 parent d76cb79 commit 764da69
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/admin/extending/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class MyCreateExtension extends CreatePageExtension
{
return $title . ' - Example';
}

public function getTabs(array $tabs): array
{
return [
...$tabs,
'review' => Tab::make('Review')
->modifyQueryUsing(fn (Builder $query) => $query->where('status', 'review')),
];
}

public function headerWidgets(array $widgets): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function getDefaultHeaderActions(): array
];
}

public function getTabs(): array
public function getDefaultTabs(): array
{
$statuses = collect(
config('lunar.orders.statuses', [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function createRecord(array $data, string $model): Model
return $product;
}

public function getTabs(): array
public function getDefaultTabs(): array
{
return [
'all' => Tab::make('All'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function createActionFormInputs(): array
return [];
}

public function getTabs(): array
public function getDefaultTabs(): array
{
return [];
}
Expand Down
5 changes: 5 additions & 0 deletions packages/admin/src/Support/Extending/ListPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function subheading($title): ?string
return $title;
}

public function getTabs(array $tabs): array
{
return $tabs;
}

public function relationManagers(array $managers): array
{
return $managers;
Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/Support/Pages/BaseListRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class BaseListRecords extends ListRecords
use Concerns\ExtendsHeaderWidgets;
use Concerns\ExtendsHeadings;
use Concerns\ExtendsTablePagination;
use Concerns\ExtendsTabs;
use \Lunar\Admin\Support\Concerns\CallsHooks;

protected function applySearchToTableQuery(Builder $query): Builder
Expand Down
16 changes: 16 additions & 0 deletions packages/admin/src/Support/Pages/Concerns/ExtendsTabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Lunar\Admin\Support\Pages\Concerns;

trait ExtendsTabs
{
protected function getDefaultTabs(): array
{
return [];
}

public function getTabs(): array
{
return $this->callLunarHook('getTabs', $this->getDefaultTabs());
}
}

0 comments on commit 764da69

Please sign in to comment.