refactor: Remove redundant heading in backup settings page

This commit is contained in:
Andras Bacsai 2024-05-24 09:35:36 +02:00
parent 64f8583975
commit 63e64b8bcc
4 changed files with 62 additions and 56 deletions

View File

@ -2,11 +2,12 @@
namespace App\Livewire\Project\Database; namespace App\Livewire\Project\Database;
use App\Models\ScheduledDatabaseBackup;
use Livewire\Component; use Livewire\Component;
class BackupExecutions extends Component class BackupExecutions extends Component
{ {
public $backup; public ?ScheduledDatabaseBackup $backup = null;
public $executions = []; public $executions = [];
public $setDeletableBackup; public $setDeletableBackup;
public function getListeners() public function getListeners()
@ -20,8 +21,11 @@ class BackupExecutions extends Component
public function cleanupFailed() public function cleanupFailed()
{ {
if ($this->backup) {
$this->backup?->executions()->where('status', 'failed')->delete(); $this->backup?->executions()->where('status', 'failed')->delete();
$this->refreshBackupExecutions(); $this->refreshBackupExecutions();
$this->dispatch('success', 'Failed backups cleaned up.');
}
} }
public function deleteBackup($exeuctionId) public function deleteBackup($exeuctionId)
{ {
@ -45,6 +49,6 @@ class BackupExecutions extends Component
} }
public function refreshBackupExecutions(): void public function refreshBackupExecutions(): void
{ {
$this->executions = $this->backup->executions()->get()->sortByDesc('created_at'); $this->executions = $this->backup?->executions()->get()->sortByDesc('created_at');
} }
} }

View File

@ -36,7 +36,7 @@ class Backup extends Component
public function mount() public function mount()
{ {
$this->backup = $this->database?->scheduledBackups->first() ?? []; $this->backup = $this->database?->scheduledBackups->first() ?? null;
$this->executions = $this->backup?->executions ?? []; $this->executions = $this->backup?->executions ?? [];
} }
public function add_coolify_database() public function add_coolify_database()

View File

@ -1,4 +1,5 @@
<div> <div>
@isset($backup)
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<h3 class="py-4">Executions</h3> <h3 class="py-4">Executions</h3>
<x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button> <x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button>
@ -51,4 +52,6 @@
window.open('/download/backup/' + executionId, '_blank'); window.open('/download/backup/' + executionId, '_blank');
} }
</script> </script>
@endisset
</div> </div>

View File

@ -30,7 +30,6 @@
@endif @endif
</div> </div>
<div class="py-4"> <div class="py-4">
<h2 class="pb-4">Executions</h2>
<livewire:project.database.backup-executions :backup="$backup" :executions="$executions" /> <livewire:project.database.backup-executions :backup="$backup" :executions="$executions" />
</div> </div>
</div> </div>