From 76b12b4e943f50e68ac7b450496adbd86eb4c28e Mon Sep 17 00:00:00 2001 From: Dima Levischenko Date: Wed, 18 Jun 2025 16:28:00 +0300 Subject: [PATCH] add lint to tabs --- resources/views/layouts/tabs.blade.php | 56 ++++++++++++++------------ src/Screen/Layouts/Tabs.php | 44 +++++++++++++++++++- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/resources/views/layouts/tabs.blade.php b/resources/views/layouts/tabs.blade.php index 349e36bb28..23f1cf278e 100644 --- a/resources/views/layouts/tabs.blade.php +++ b/resources/views/layouts/tabs.blade.php @@ -9,20 +9,24 @@ class="mb-3" @@ -32,17 +36,19 @@ class="mb-3"
@foreach($manyForms as $name => $forms) -
$activeTab === $name || ($loop->first && is_null($activeTab)) - ]) - > - @foreach($forms as $form) - {!! $form !!} - @endforeach -
+ @if(!isset($menuItems[$name])) +
$activeTab === $name || ($loop->first && is_null($activeTab)) + ]) + > + @foreach($forms as $form) + {!! $form !!} + @endforeach +
+ @endif @endforeach
diff --git a/src/Screen/Layouts/Tabs.php b/src/Screen/Layouts/Tabs.php index af452bf686..d5755691cc 100644 --- a/src/Screen/Layouts/Tabs.php +++ b/src/Screen/Layouts/Tabs.php @@ -4,6 +4,9 @@ namespace Orchid\Screen\Layouts; +use Illuminate\Support\Arr; +use Orchid\Screen\Actions\Link; +use Orchid\Screen\Actions\Menu; use Orchid\Screen\Layout; use Orchid\Screen\Repository; @@ -27,7 +30,7 @@ abstract class Tabs extends Layout /** * Layout constructor. * - * @param Layout[] $layouts + * @param Layout[]|Link[]|Menu[] $layouts */ public function __construct(array $layouts = []) { @@ -39,7 +42,44 @@ public function __construct(array $layouts = []) */ public function build(Repository $repository) { - return $this->buildAsDeep($repository); + $this->query = $repository; + + if (! $this->isSee()) { + return; + } + + $layouts = collect($this->layouts); + $build = []; + $linkItems = []; + + foreach ($layouts as $key => $layout) { + if ($layout instanceof Link) { + $linkItems[$key] = true; + $build[$key][] = $layout->build($repository); + } else { + $wrappedLayouts = Arr::wrap($layout); + $childLayouts = collect($wrappedLayouts) + ->flatten() + ->map(fn ($item) => is_object($item) ? $item : resolve($item)) + ->filter(fn () => $this->isSee()) + ->reduce(function ($carry, $item) use ($key, $repository) { + $carry[$key][] = $item->build($repository); + return $carry; + }, []); + + if (!empty($childLayouts)) { + $build = array_merge_recursive($build, $childLayouts); + } + } + } + + $variables = array_merge($this->variables, [ + 'templateSlug' => $this->getSlug(), + 'manyForms' => $build, + 'menuItems' => $linkItems, + ]); + + return view($this->template, $variables); } /**