Skip to content

Commit e1a6c3e

Browse files
committed
chore: Refactor terminal component and select form layout
1 parent f124a1e commit e1a6c3e

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

app/Livewire/Project/Shared/Terminal.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Terminal extends Component
1111
#[On('send-terminal-command')]
1212
public function sendTerminalCommand($isContainer, $identifier, $serverUuid)
1313
{
14+
1415
$server = Server::ownedByCurrentTeam()->whereUuid($serverUuid)->firstOrFail();
1516

1617
// if (auth()->user()) {
@@ -21,9 +22,7 @@ public function sendTerminalCommand($isContainer, $identifier, $serverUuid)
2122
// }
2223

2324
if ($isContainer) {
24-
ray($identifier);
2525
$status = getContainerStatus($server, $identifier);
26-
ray($status);
2726
if ($status !== 'running') {
2827
return handleError(new \Exception('Container is not running'), $this);
2928
}

app/Livewire/RunCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class RunCommand extends Component
99
{
10-
public $selected_uuid;
10+
public $selected_uuid = 'default';
1111

1212
public $servers = [];
1313

@@ -16,7 +16,6 @@ class RunCommand extends Component
1616
public function mount($servers)
1717
{
1818
$this->servers = $servers;
19-
$this->selected_uuid = $servers[0]->uuid;
2019
$this->containers = $this->getAllActiveContainers();
2120
}
2221

@@ -83,6 +82,11 @@ private function getAllActiveContainers()
8382
});
8483
}
8584

85+
public function updatedSelectedUuid($value)
86+
{
87+
$this->connectToContainer();
88+
}
89+
8690
#[On('connectToContainer')]
8791
public function connectToContainer()
8892
{

resources/views/components/forms/select.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="w-full">
22
@if ($label)
3-
<label class="flex items-center gap-1 mb-1 text-sm font-medium">{{ $label }}
3+
<label class="flex gap-1 items-center mb-1 text-sm font-medium">{{ $label }}
44
@if ($required)
55
<x-highlighted text="*" />
66
@endif
@@ -9,7 +9,8 @@
99
@endif
1010
</label>
1111
@endif
12-
<select {{ $attributes->merge(['class' => $defaultClass]) }} @required($required) wire:dirty.class.remove='dark:focus:ring-coolgray-300 dark:ring-coolgray-300'
12+
<select {{ $attributes->merge(['class' => $defaultClass]) }} @required($required)
13+
wire:dirty.class.remove='dark:focus:ring-coolgray-300 dark:ring-coolgray-300'
1314
wire:dirty.class="dark:focus:ring-warning dark:ring-warning" wire:loading.attr="disabled" name={{ $id }}
1415
@if ($attributes->whereStartsWith('wire:model')->first()) {{ $attributes->whereStartsWith('wire:model')->first() }} @else wire:model={{ $id }} @endif>
1516
{{ $slot }}

resources/views/livewire/project/shared/terminal.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ function flowControlCallback() {
117117
if (data === '\x04' || (data === '\r' && stripAnsiCommands(commandBuffer).trim() === 'exit')) {
118118
checkIfProcessIsRunningAndKillIt();
119119
setTimeout(() => {
120-
term.reset();
121120
$data.terminalActive = false;
121+
term.reset();
122122
}, 500);
123123
commandBuffer = '';
124124
} else if (data === '\r') {

resources/views/livewire/run-command.blade.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<div>
2-
<form class="flex flex-col justify-center gap-2 xl:items-end xl:flex-row"
2+
<form class="flex flex-col gap-2 justify-center xl:items-end xl:flex-row"
33
wire:submit="$dispatchSelf('connectToContainer')">
4-
<x-forms.select label="Select Server or Container" id="server" required wire:model="selected_uuid">
4+
<x-forms.select id="server" required wire:model.live="selected_uuid">
55
@foreach ($servers as $server)
66
@if ($loop->first)
7-
<option selected value="{{ $server->uuid }}">{{ $server->name }}</option>
8-
@else
9-
<option value="{{ $server->uuid }}">{{ $server->name }}</option>
7+
<option disabled value="default">Select a server or container</option>
108
@endif
9+
<option value="{{ $server->uuid }}">{{ $server->name }}</option>
1110
@foreach ($containers as $container)
1211
@if ($container['server_uuid'] == $server->uuid)
1312
<option value="{{ $container['uuid'] }}">

resources/views/livewire/terminal/index.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Terminal | Coolify
44
</x-slot>
55
<h1>Terminal</h1>
6-
<div class="subtitle">Execute commands on your servers without leaving the browser.</div>
6+
<div class="flex gap-2 items-end subtitle">
7+
<div>Execute commands on your servers and containers without leaving the browser.</div>
8+
<x-helper
9+
helper="If you're having trouble connecting to your server, make sure that the port is open.<br><br><a class='underline' href='https://coolify.io/docs/knowledge-base/server/firewall/#terminal' target='_blank'>Documentation</a>"></x-helper>
10+
</div>
711
@if ($servers->count() > 0)
812
<livewire:run-command :servers="$servers" />
913
@else

0 commit comments

Comments
 (0)