Skip to content

Commit b6b4d93

Browse files
committed
fix: compose based terminal
1 parent 8385b7d commit b6b4d93

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

app/Livewire/Project/Shared/ExecuteContainerCommand.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class ExecuteContainerCommand extends Component
1313
{
14+
public $selected_container = 'default';
15+
1416
public $container;
1517

1618
public Collection $containers;
@@ -83,11 +85,14 @@ public function loadContainers()
8385
$containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true);
8486
}
8587
foreach ($containers as $container) {
86-
$payload = [
87-
'server' => $server,
88-
'container' => $container,
89-
];
90-
$this->containers = $this->containers->push($payload);
88+
// if container state is running
89+
if (data_get($container, 'State') === 'running') {
90+
$payload = [
91+
'server' => $server,
92+
'container' => $container,
93+
];
94+
$this->containers = $this->containers->push($payload);
95+
}
9196
}
9297
} elseif (data_get($this->parameters, 'database_uuid')) {
9398
if ($this->resource->isRunning()) {
@@ -100,7 +105,6 @@ public function loadContainers()
100105
}
101106
} elseif (data_get($this->parameters, 'service_uuid')) {
102107
$this->resource->applications()->get()->each(function ($application) {
103-
ray($application);
104108
if ($application->isRunning()) {
105109
$this->containers->push([
106110
'server' => $this->resource->server,
@@ -131,21 +135,26 @@ public function loadContainers()
131135
#[On('connectToContainer')]
132136
public function connectToContainer()
133137
{
138+
if ($this->selected_container === 'default') {
139+
$this->dispatch('error', 'Please select a container.');
140+
141+
return;
142+
}
134143
try {
135-
$container_name = data_get($this->container, 'container.Names');
136-
if (is_null($container_name)) {
144+
$container = collect($this->containers)->firstWhere('container.Names', $this->selected_container);
145+
if (is_null($container)) {
137146
throw new \RuntimeException('Container not found.');
138147
}
139148
$server = data_get($this->container, 'server');
140149

141150
if ($server->isForceDisabled()) {
142151
throw new \RuntimeException('Server is disabled.');
143152
}
144-
145-
$this->dispatch('send-terminal-command',
146-
true,
147-
$container_name,
148-
$server->uuid,
153+
$this->dispatch(
154+
'send-terminal-command',
155+
isset($container),
156+
data_get($container, 'container.Names'),
157+
data_get($container, 'server.uuid')
149158
);
150159

151160
} catch (\Throwable $e) {

resources/views/livewire/project/shared/execute-container-command.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
@if (count($containers) > 0)
2121
<form class="flex flex-col gap-2 justify-center pt-4 xl:items-end xl:flex-row"
2222
wire:submit="$dispatchSelf('connectToContainer')">
23-
<x-forms.select label="Container" id="container" required>
24-
<option disabled selected>Select container</option>
23+
<x-forms.select label="Container" id="container" required wire:model="selected_container">
2524
@foreach ($containers as $container)
25+
@if ($loop->first)
26+
<option disabled value="default">Select a container</option>
27+
@endif
2628
<option value="{{ data_get($container, 'container.Names') }}">
2729
{{ data_get($container, 'container.Names') }}
2830
({{ data_get($container, 'server.name') }})

0 commit comments

Comments
 (0)