refactor(SourceManagement): sort sources by name and improve UI for changing Git source with better error handling

This commit is contained in:
Andras Bacsai
2025-04-11 20:25:25 +02:00
parent 46fe0fd7c6
commit 4c95dccfb3
3 changed files with 26 additions and 18 deletions

View File

@@ -75,7 +75,7 @@ class Source extends Component
// filter the current source out
$this->sources = currentTeam()->sources()->whereNotNull('app_id')->reject(function ($source) {
return $source->id === $this->application->source_id;
});
})->sortBy('name');
}
public function setPrivateKey(int $privateKeyId)
@@ -113,6 +113,7 @@ class Source extends Component
'source_type' => $sourceType,
]);
$this->application->refresh();
$this->getSources();
$this->dispatch('success', 'Source updated!');
} catch (\Throwable $e) {
return handleError($e, $this);

View File

@@ -52,6 +52,9 @@ function generateGithubToken(GithubApp $source, string $type)
if (! $response->successful()) {
$error = data_get($response->json(), 'message', 'no error message found');
if ($error === 'Not Found') {
$error = 'Repository not found. Is it moved or deleted?';
}
throw new RuntimeException("Failed to get installation token for {$source->name} with error: ".$error);
}

View File

@@ -38,33 +38,37 @@
</div>
</div>
@if (filled($sources) && $sources->count() > 0)
<div class="pt-4">
<h3 class="pb-2">Change Git Source</h3>
<div class="grid grid-cols-1 gap-2">
@foreach ($sources as $source)
<div class="pt-4">
<h3 class="pb-2">Change Git Source</h3>
<div class="grid grid-cols-1 gap-2">
@forelse ($sources as $source)
<div wire:key="{{ $source->name }}">
<x-modal-confirmation title="Change Git Source" :actions="['Change git source to ' . $source->name]" :buttonFullWidth="true"
:isHighlightedButton="$application->source_id === $source->id" :disabled="$application->source_id === $source->id"
submitAction="changeSource('{{ $source->id }}', '{{ $source->getMorphClass() }}')"
submitAction="changeSource({{ $source->id }}, {{ $source->getMorphClass() }})"
:confirmWithText="true" confirmationText="Change Git Source"
confirmationLabel="Please confirm changing the git source by entering the text below"
shortConfirmationLabel="Confirmation Text" :confirmWithPassword="false">
<x-slot:customButton>
<div class="box-title">
{{ $source->name }}
@if ($application->source_id === $source->id)
<span class="text-xs">(current)</span>
@endif
</div>
<div class="box-description">
{{ $source->organization_name ?? 'Personal Account' }}
<div class="flex items-center gap-2">
<div class="box-title">
{{ $source->name }}
@if ($application->source_id === $source->id)
<span class="text-xs">(current)</span>
@endif
</div>
<div class="box-description">
{{ $source->organization ?? 'Personal Account' }}
</div>
</div>
</x-slot:customButton>
</x-modal-confirmation>
@endforeach
</div>
</div>
@empty
<div class="text-center">No sources found</div>
@endforelse
</div>
@endif
</div>
@if ($privateKeyId)
<h3 class="pt-4">Deploy Key</h3>