From 4147cfa537dbb0f34c234bbd5e656bf89756eebd Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 25 Nov 2025 10:11:49 +0100 Subject: [PATCH] refactor: use Laravel route() helper for shared variable URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace hardcoded URL paths in getScopeUrl() with Laravel's route() helper - Add scopeUrls property to EnvVarInput component with named routes - Pass projectUuid and environmentUuid to enable context-specific environment links - Environment scope link now navigates to the specific project/environment shared variables page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/View/Components/Forms/EnvVarInput.php | 16 ++++++++++++++++ .../components/forms/env-var-input.blade.php | 13 ++++--------- .../shared/environment-variable/add.blade.php | 4 +++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/View/Components/Forms/EnvVarInput.php b/app/View/Components/Forms/EnvVarInput.php index 6b37e3a7b..7cf8ee8fa 100644 --- a/app/View/Components/Forms/EnvVarInput.php +++ b/app/View/Components/Forms/EnvVarInput.php @@ -14,6 +14,8 @@ class EnvVarInput extends Component public ?string $htmlId = null; + public array $scopeUrls = []; + public function __construct( public ?string $id = null, public ?string $name = null, @@ -33,6 +35,8 @@ public function __construct( public mixed $canResource = null, public bool $autoDisable = true, public array $availableVars = [], + public ?string $projectUuid = null, + public ?string $environmentUuid = null, ) { // Handle authorization-based disabling if ($this->canGate && $this->canResource && $this->autoDisable) { @@ -68,6 +72,18 @@ public function render(): View|Closure|string $this->name = $this->modelBinding !== 'null' ? $this->modelBinding : (string) $this->id; } + $this->scopeUrls = [ + 'team' => route('shared-variables.team.index'), + 'project' => route('shared-variables.project.index'), + 'environment' => $this->projectUuid && $this->environmentUuid + ? route('shared-variables.environment.show', [ + 'project_uuid' => $this->projectUuid, + 'environment_uuid' => $this->environmentUuid, + ]) + : route('shared-variables.environment.index'), + 'default' => route('shared-variables.index'), + ]; + return view('components.forms.env-var-input'); } } diff --git a/resources/views/components/forms/env-var-input.blade.php b/resources/views/components/forms/env-var-input.blade.php index c621f566b..5639cdbca 100644 --- a/resources/views/components/forms/env-var-input.blade.php +++ b/resources/views/components/forms/env-var-input.blade.php @@ -18,6 +18,7 @@ currentScope: null, availableScopes: ['team', 'project', 'environment'], availableVars: @js($availableVars), + scopeUrls: @js($scopeUrls), isAutocompleteDisabled() { const hasAnyVars = Object.values(this.availableVars).some(vars => vars.length > 0); @@ -28,13 +29,14 @@ const input = this.$refs.input; if (!input) return; + const value = input.value || ''; + if (this.isAutocompleteDisabled()) { this.showDropdown = false; return; } this.cursorPosition = input.selectionStart || 0; - const value = input.value || ''; const textBeforeCursor = value.substring(0, this.cursorPosition); const openBraces = '{' + '{'; @@ -107,14 +109,7 @@ }, getScopeUrl(scope) { - if (scope === 'team') { - return '/shared-variables/team'; - } else if (scope === 'project') { - return '/shared-variables/projects'; - } else if (scope === 'environment') { - return '/shared-variables/environments'; - } - return '/shared-variables'; + return this.scopeUrls[scope] || this.scopeUrls['default']; }, selectSuggestion(suggestion) { diff --git a/resources/views/livewire/project/shared/environment-variable/add.blade.php b/resources/views/livewire/project/shared/environment-variable/add.blade.php index 2016c8c9f..6b6c660ec 100644 --- a/resources/views/livewire/project/shared/environment-variable/add.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/add.blade.php @@ -3,7 +3,9 @@ + :availableVars="$shared ? [] : $this->availableSharedVariables" + :projectUuid="data_get($parameters, 'project_uuid')" + :environmentUuid="data_get($parameters, 'environment_uuid')" /> @if (!$shared)