fix(livewire): refresh service config after required variable updates

This commit is contained in:
Andras Bacsai 2026-08-24 09:45:31 +02:00
parent 5d06c226a3
commit 50913dc409
3 changed files with 56 additions and 4 deletions

View file

@ -26,10 +26,17 @@ class Configuration extends Component
public array $parameters;
protected $listeners = [
'refreshServices' => 'refreshServices',
'refresh' => 'refreshServices',
];
public function getListeners(): array
{
$teamId = auth()->user()->currentTeam()->id;
return [
'refreshServices' => 'refreshServices',
'refresh' => 'refreshServices',
'configurationChanged' => 'refreshServices',
"echo-private:team.{$teamId},ApplicationConfigurationChanged" => 'refreshServices',
];
}
public function render()
{

View file

@ -2,6 +2,7 @@
namespace App\Livewire\Project\Shared\EnvironmentVariable;
use App\Events\ApplicationConfigurationChanged;
use App\Models\Application;
use App\Models\Environment;
use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;
@ -298,6 +299,10 @@ public function submit()
$this->dispatch('success', 'Environment variable updated.');
$this->dispatch('envsUpdated');
$this->dispatch('configurationChanged');
if ($this->is_required && $this->resource instanceof Service) {
event(new ApplicationConfigurationChanged($this->resource->team()->id));
}
} catch (\Exception $e) {
return handleError($e);
}

View file

@ -1,22 +1,29 @@
<?php
use App\Events\ApplicationConfigurationChanged;
use App\Livewire\Project\Service\Configuration;
use App\Livewire\Project\Shared\ConfigurationChecker;
use App\Livewire\Project\Shared\EnvironmentVariable\Show;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use App\Models\Environment;
use App\Models\EnvironmentVariable;
use App\Models\InstanceSettings;
use App\Models\LocalFileVolume;
use App\Models\Project;
use App\Models\Server;
use App\Models\Service;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Str;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
InstanceSettings::forceCreate(['id' => 0]);
$this->team = Team::factory()->create();
$this->user = User::factory()->create();
$this->team->members()->attach($this->user->id, ['role' => 'owner']);
@ -121,6 +128,39 @@ function markConfigurationCheckerApplicationDeployed(Application $application):
});
it('broadcasts a configuration update after a required service variable is set', function () {
Event::fake([ApplicationConfigurationChanged::class]);
$server = Server::factory()->create(['team_id' => $this->team->id]);
$service = Service::factory()->create([
'environment_id' => $this->environment->id,
'server_id' => $server->id,
]);
$environmentVariable = $service->environment_variables()->create([
'key' => 'PLUNK_API_KEY',
'value' => '',
'is_required' => true,
]);
Livewire::test(Show::class, ['env' => $environmentVariable, 'type' => 'service'])
->call('loadValues')
->set('value', 'secret')
->call('submit');
Event::assertDispatched(
ApplicationConfigurationChanged::class,
fn (ApplicationConfigurationChanged $event): bool => $event->teamId === $this->team->id,
);
});
it('refreshes the service configuration when a websocket configuration event arrives', function () {
$listeners = app(Configuration::class)->getListeners();
expect($listeners)
->toHaveKey("echo-private:team.{$this->team->id},ApplicationConfigurationChanged", 'refreshServices')
->toHaveKey('configurationChanged', 'refreshServices');
});
it('marks the service environment variables menu when required values are missing', function () {
$configuration = file_get_contents(resource_path('views/livewire/project/service/configuration.blade.php'));
$sidebar = file_get_contents(resource_path('views/components/service/configuration-sidebar.blade.php'));