Skip to content

Commit 4d652f4

Browse files
authored
Merge pull request #9 from jelleroorda/feat/server-and-site-search
Add search functionality to selecting server + site.
2 parents ada5b6a + a333e8d commit 4d652f4

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

app/Commands/Concerns/InteractWithServer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Commands\Concerns;
44

5-
use function Laravel\Prompts\select;
5+
use function Laravel\Prompts\search;
66
use function Laravel\Prompts\spin;
77

88
trait InteractWithServer
@@ -16,12 +16,13 @@ protected function selectServer(): string
1616
exit(1);
1717
}
1818

19-
return select(
20-
'Select a server:',
21-
collect($servers)
19+
return search(
20+
label: 'Select a server:',
21+
options: fn($search) => collect($servers)
2222
->mapWithKeys(fn ($server) => [
2323
$server['name'] => $server['name'].' ('.$server['ip_address'].')',
2424
])
25+
->filter(fn($name) => str_contains($name, $search))
2526
->toArray(),
2627
scroll: 10
2728
);

app/Commands/Concerns/InteractWithSite.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace App\Commands\Concerns;
44

55
use App\Traits\DomainSuggestions;
6-
use function Laravel\Prompts\select;
6+
7+
use function Laravel\Prompts\search;
78

89
trait InteractWithSite
910
{
@@ -37,9 +38,15 @@ protected function getServerAndSite(): array
3738
protected function selectSite($serverId): array
3839
{
3940
$sites = collect($this->ploi->getSiteList($serverId)['data'])
40-
->pluck('domain', 'domain')
41-
->toArray();
42-
$domain = select('Select a site by domain:', $sites, scroll: 10);
41+
->pluck('domain', 'domain');
42+
43+
$domain = search(
44+
label: 'Select a site by domain:',
45+
options: fn(string $search) => $sites
46+
->filter(fn($name) => str_contains($name, $search))
47+
->toArray(),
48+
scroll: 10
49+
);
4350

4451
return ['domain' => $domain];
4552
}

0 commit comments

Comments
 (0)