From 07337d9df6d9862b27135f2c7c744af4c3cdb91a Mon Sep 17 00:00:00 2001 From: Rohit Tiwari Date: Tue, 26 May 2026 15:19:32 +0530 Subject: [PATCH] feat: add search functionality for environment variables --- .../Shared/EnvironmentVariable/All.php | 28 +++++++++++ .../shared/environment-variable/all.blade.php | 47 +++++++++++++++---- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index 53b55009e..1ddf024a7 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -25,6 +25,8 @@ class All extends Component public string $view = 'normal'; + public string $search = ''; + public bool $is_env_sorting_enabled = false; public bool $use_build_secrets = false; @@ -35,6 +37,14 @@ class All extends Component 'environmentVariableDeleted' => 'refreshEnvs', ]; + public function updatedSearch() + { + unset($this->environmentVariables); + unset($this->environmentVariablesPreview); + unset($this->hardcodedEnvironmentVariables); + unset($this->hardcodedEnvironmentVariablesPreview); + } + public function mount() { $this->is_env_sorting_enabled = data_get($this->resource, 'settings.is_env_sorting_enabled', false); @@ -68,6 +78,10 @@ public function getEnvironmentVariablesProperty() $query = $this->resource->environment_variables() ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END"); + if ($this->search !== '') { + $query->where('key', 'like', "%{$this->search}%"); + } + if ($this->is_env_sorting_enabled) { $query->orderBy('key'); } else { @@ -82,6 +96,10 @@ public function getEnvironmentVariablesPreviewProperty() $query = $this->resource->environment_variables_preview() ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END"); + if ($this->search !== '') { + $query->where('key', 'like', "%{$this->search}%"); + } + if ($this->is_env_sorting_enabled) { $query->orderBy('key'); } else { @@ -138,6 +156,12 @@ protected function getHardcodedVariables(bool $isPreview) return ! in_array($var['key'], $managedKeys); }); + if ($this->search !== '') { + $hardcodedVars = $hardcodedVars->filter(function ($var) { + return str($var['key'])->contains($this->search, true); + }); + } + // Apply sorting based on is_env_sorting_enabled if ($this->is_env_sorting_enabled) { $hardcodedVars = $hardcodedVars->sortBy('key')->values(); @@ -285,6 +309,8 @@ private function handleSingleSubmit($data) // Clear computed property cache to force refresh unset($this->environmentVariables); unset($this->environmentVariablesPreview); + unset($this->hardcodedEnvironmentVariables); + unset($this->hardcodedEnvironmentVariablesPreview); $this->dispatch('success', 'Environment variable added.'); } @@ -416,6 +442,8 @@ public function refreshEnvs() // Clear computed property cache to force refresh unset($this->environmentVariables); unset($this->environmentVariablesPreview); + unset($this->hardcodedEnvironmentVariables); + unset($this->hardcodedEnvironmentVariablesPreview); $this->getDevView(); } } diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.php index 2ae3ad166..5e308d980 100644 --- a/resources/views/livewire/project/shared/environment-variable/all.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php @@ -43,9 +43,35 @@ @endif @if ($view === 'normal') -
-

Production Environment Variables

-
Environment (secrets) variables for Production.
+
+
+

Production Environment Variables

+
Environment (secrets) variables for Production.
+
+
+
+ +
+
+ + + + + + + +
+
+
+
@forelse ($this->environmentVariables as $env) type() === 'service' || $resource?->build_pack === 'dockercompose') && $this->hardcodedEnvironmentVariables->isNotEmpty()) @foreach ($this->hardcodedEnvironmentVariables as $index => $env) + wire:key="hardcoded-prod-{{ $env['key'] }}-{{ $env['service_name'] ?? 'default' }}-{{ $index }}" :env="$env" /> @endforeach @endif @if ($resource->type() === 'application' && $resource->environment_variables_preview->count() > 0 && $showPreview) @@ -88,8 +113,9 @@ label="Production Environment Variables"> @if ($showPreview) - + @endif Save All Environment Variables @@ -98,10 +124,11 @@ label="Production Environment Variables" disabled> @if ($showPreview) - + @endif @endcan @endif -
+ \ No newline at end of file