navigate to environment via uuid

This commit is contained in:
peaklabs-dev
2024-11-22 15:38:54 +01:00
parent e29c202e61
commit 4c21807b7a
2 changed files with 15 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ use App\Models\Environment;
use App\Models\Project; use App\Models\Project;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
use Livewire\Component; use Livewire\Component;
use Visus\Cuid2\Cuid2;
class Show extends Component class Show extends Component
{ {
@@ -33,17 +34,26 @@ class Show extends Component
$environment = Environment::create([ $environment = Environment::create([
'name' => $this->name, 'name' => $this->name,
'project_id' => $this->project->id, 'project_id' => $this->project->id,
'uuid' => (string) new Cuid2,
]); ]);
return redirect()->route('project.resource.index', [ return redirect()->route('project.resource.index', [
'project_uuid' => $this->project->uuid, 'project_uuid' => $this->project->uuid,
'environment_name' => $environment->name, 'environment_uuid' => $environment->uuid,
]); ]);
} catch (\Throwable $e) { } catch (\Throwable $e) {
handleError($e, $this); handleError($e, $this);
} }
} }
public function navigateToEnvironment($projectUuid, $environmentUuid)
{
return redirect()->route('project.resource.index', [
'project_uuid' => $projectUuid,
'environment_uuid' => $environmentUuid,
]);
}
public function render() public function render()
{ {
return view('livewire.project.show'); return view('livewire.project.show');

View File

@@ -17,18 +17,18 @@
<div class="text-xs truncate subtitle lg:text-sm">{{ $project->name }}.</div> <div class="text-xs truncate subtitle lg:text-sm">{{ $project->name }}.</div>
<div class="grid gap-2 lg:grid-cols-2"> <div class="grid gap-2 lg:grid-cols-2">
@forelse ($project->environments->sortBy('created_at') as $environment) @forelse ($project->environments->sortBy('created_at') as $environment)
<div class="gap-2 border border-transparent cursor-pointer box group" x-data <div class="gap-2 border border-transparent cursor-pointer box group"
x-on:click="goto('{{ $project->uuid }}','{{ $environment->name }}')"> wire:click="navigateToEnvironment('{{ $project->uuid }}', '{{ $environment->uuid }}')">
<div class="flex flex-1 mx-6"> <div class="flex flex-1 mx-6">
<a class="flex flex-col justify-center flex-1" <a class="flex flex-col justify-center flex-1"
href="{{ route('project.resource.index', [$project->uuid, $environment->name]) }}"> href="{{ route('project.resource.index', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid]) }}">
<div class="font-bold dark:text-white"> {{ $environment->name }}</div> <div class="font-bold dark:text-white"> {{ $environment->name }}</div>
<div class="description"> <div class="description">
{{ $environment->description }}</div> {{ $environment->description }}</div>
</a> </a>
<div class="flex items-center justify-center gap-2 text-xs"> <div class="flex items-center justify-center gap-2 text-xs">
<a class="font-bold hover:underline" <a class="font-bold hover:underline"
href="{{ route('project.environment.edit', ['project_uuid' => data_get($project, 'uuid'), 'environment_name' => $environment->name]) }}"> href="{{ route('project.environment.edit', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid]) }}">
Settings Settings
</a> </a>
</div> </div>
@@ -37,10 +37,5 @@
@empty @empty
<p>No environments found.</p> <p>No environments found.</p>
@endforelse @endforelse
<script>
function goto(projectUuid, environmentName) {
window.location.href = '/project/' + projectUuid + '/' + environmentName;
}
</script>
</div> </div>
</div> </div>