improve navigation

This commit is contained in:
Andras Bacsai
2025-01-16 11:04:50 +01:00
parent 3f92c1e37b
commit 433dff2684
5 changed files with 32 additions and 37 deletions

View File

@@ -8,7 +8,6 @@ use App\Models\Project;
use App\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Redirect;
use Livewire\Component;
class Dashboard extends Component
@@ -52,16 +51,7 @@ class Dashboard extends Component
public function navigateToProject($projectUuid)
{
$project = Project::where('uuid', $projectUuid)->first();
if ($project && $project->environments->count() === 1) {
return Redirect::route('project.resource.index', [
'project_uuid' => $projectUuid,
'environment_uuid' => $project->environments->first()->uuid,
]);
}
return Redirect::route('project.show', ['project_uuid' => $projectUuid]);
return $this->redirect(collect($this->projects)->firstWhere('uuid', $projectUuid)->navigateTo(), true);
}
public function render()

View File

@@ -5,7 +5,6 @@ namespace App\Livewire\Project;
use App\Models\PrivateKey;
use App\Models\Project;
use App\Models\Server;
use Illuminate\Support\Facades\Redirect;
use Livewire\Component;
class Index extends Component
@@ -34,15 +33,8 @@ class Index extends Component
public function navigateToProject($projectUuid)
{
$project = Project::where('uuid', $projectUuid)->first();
$project = collect($this->projects)->firstWhere('uuid', $projectUuid);
if ($project && $project->environments->count() === 1) {
return Redirect::route('project.resource.index', [
'project_uuid' => $projectUuid,
'environment_uuid' => $project->environments->first()->uuid,
]);
}
return Redirect::route('project.show', ['project_uuid' => $projectUuid]);
return $this->redirect($project->navigateTo(), true);
}
}

View File

@@ -140,4 +140,16 @@ class Project extends BaseModel
{
return $this->postgresqls()->get()->merge($this->redis()->get())->merge($this->mongodbs()->get())->merge($this->mysqls()->get())->merge($this->mariadbs()->get())->merge($this->keydbs()->get())->merge($this->dragonflies()->get())->merge($this->clickhouses()->get());
}
public function navigateTo()
{
if ($this->environments->count() === 1) {
return route('project.resource.index', [
'project_uuid' => $this->uuid,
'environment_uuid' => $this->environments->first()->uuid,
]);
}
return route('project.show', ['project_uuid' => $this->uuid]);
}
}