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') -