From 15172b1d86afe42802898b1f78ea729fac3aefb7 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 18 Jan 2026 16:33:09 -0500 Subject: [PATCH] Add github eggs to egg importer (#2116) --- .../Components/Actions/ImportEggAction.php | 99 +++++++++++++------ lang/en/admin/egg.php | 2 +- 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/app/Filament/Components/Actions/ImportEggAction.php b/app/Filament/Components/Actions/ImportEggAction.php index a3ed53345..f363e07a4 100644 --- a/app/Filament/Components/Actions/ImportEggAction.php +++ b/app/Filament/Components/Actions/ImportEggAction.php @@ -3,24 +3,24 @@ namespace App\Filament\Components\Actions; use App\Console\Commands\Egg\UpdateEggIndexCommand; +use App\Jobs\InstallEgg; use App\Models\Egg; use App\Services\Eggs\Sharing\EggImporterService; use Closure; use Exception; use Filament\Actions\Action; +use Filament\Forms\Components\CheckboxList; use Filament\Forms\Components\FileUpload; use Filament\Forms\Components\Repeater; -use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; +use Filament\Infolists\Components\TextEntry; use Filament\Notifications\Notification; use Filament\Schemas\Components\Tabs; use Filament\Schemas\Components\Tabs\Tab; -use Filament\Schemas\Components\Utilities\Get; -use Filament\Schemas\Components\Utilities\Set; use Filament\Support\Enums\IconSize; +use Filament\Support\Enums\Width; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Str; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; class ImportEggAction extends Action @@ -42,10 +42,31 @@ class ImportEggAction extends Action $this->iconSize(IconSize::ExtraLarge); + $this->modalWidth(Width::ScreenExtraLarge); + $this->authorize(fn () => user()?->can('import egg')); $this->action(function (array $data, EggImporterService $eggImportService): void { + + $gitHubEggs = array_get($this->data, 'eggs', []); $eggs = array_merge(collect($data['urls'])->flatten()->whereNotNull()->unique()->all(), Arr::wrap($data['files'])); + + if ($gitHubEggs) { + foreach ($gitHubEggs as $category => $sortedEggs) { + foreach ($sortedEggs as $downloadUrl) { + InstallEgg::dispatch($downloadUrl); + } + } + + Notification::make() + ->title(trans('installer.egg.background_install_started')) + ->body(trans('installer.egg.background_install_description', ['count' => array_sum(array_map('count', $gitHubEggs))])) + ->success() + ->persistent() + ->send(); + + } + if (empty($eggs)) { return; } @@ -115,6 +136,7 @@ class ImportEggAction extends Action Tabs::make('Tabs') ->contained(false) ->tabs([ + $this->importEggsFromGitHub(), Tab::make('file') ->label(trans('admin/egg.import.file')) ->icon('tabler-file-upload') @@ -132,30 +154,6 @@ class ImportEggAction extends Action ->label(trans('admin/egg.import.url')) ->icon('tabler-world-upload') ->schema([ - Select::make('github') - ->label(trans('admin/egg.import.github')) - ->options(fn () => cache('eggs.index')) - ->selectablePlaceholder(false) - ->searchable() - ->preload() - ->live() - ->hintAction( - Action::make('refresh') - ->iconButton() - ->icon('tabler-refresh') - ->tooltip(trans('admin/egg.import.refresh')) - ->action(function () { - Artisan::call(UpdateEggIndexCommand::class); - }) - ) - ->afterStateUpdated(function ($state, Set $set, Get $get) use ($isMultiple) { - if ($state) { - $urls = $isMultiple ? $get('urls') : []; - $urls[Str::uuid()->toString()] = ['url' => $state]; - $set('urls', $urls); - $set('github', null); - } - }), Repeater::make('urls') ->hiddenLabel() ->itemLabel(fn (array $state) => str($state['url'])->afterLast('/egg-')->beforeLast('.')->headline()) @@ -181,4 +179,49 @@ class ImportEggAction extends Action return $this; } + + public function importEggsFromGitHub(): Tab + { + if (!cache()->get('eggs.index')) { + Artisan::call(UpdateEggIndexCommand::class); + } + + $eggs = cache()->get('eggs.index', []); + $categories = array_keys($eggs); + $tabs = array_map(function (string $label) use ($eggs) { + $id = str_slug($label, '_'); + $eggCount = count($eggs[$label]); + + return Tab::make($id) + ->label($label) + ->badge($eggCount) + ->schema([ + CheckboxList::make("eggs.$id") + ->hiddenLabel() + ->options(fn () => array_sort($eggs[$label])) + ->searchable($eggCount > 0) + ->bulkToggleable($eggCount > 0) + ->columns(4), + ]); + }, $categories); + + if (empty($tabs)) { + $tabs[] = Tab::make('no_eggs') + ->label(trans('installer.egg.no_eggs')) + ->schema([ + TextEntry::make('no_eggs') + ->hiddenLabel() + ->state(trans('installer.egg.exceptions.no_eggs')), + ]); + } + + return Tab::make('github') + ->label(trans('admin/egg.import.github')) + ->icon('tabler-brand-github') + ->columnSpanFull() + ->schema([ + Tabs::make('egg_tabs') + ->tabs($tabs), + ]); + } } diff --git a/lang/en/admin/egg.php b/lang/en/admin/egg.php index 99e05bc0c..65416a7da 100644 --- a/lang/en/admin/egg.php +++ b/lang/en/admin/egg.php @@ -24,7 +24,7 @@ return [ 'import_result' => 'Imported :success of :total eggs', 'imported_eggs' => 'Imported: :eggs', 'failed_import_eggs' => 'Failed: :eggs', - 'github' => 'Add from Github', + 'github' => 'GitHub', 'refresh' => 'Refresh', 'import_image' => 'Import Image', 'no_local_ip' => 'Local IP Addresses are not allowed',