refactor(deployment): move copyLogs to client-side and hide refund when ineligible
Move copyLogs from PHP Livewire method to Alpine.js to avoid unnecessary server round-trips. Extract collectVisibleLogs() helper shared by both copy and download actions. Hide refund section entirely when not eligible instead of rendering a permanently disabled button.
This commit is contained in:
parent
8e22ce4ba7
commit
e89820b465
3 changed files with 31 additions and 38 deletions
|
|
@ -108,19 +108,6 @@ public function getLogLinesProperty()
|
||||||
return decode_remote_command_output($this->application_deployment_queue);
|
return decode_remote_command_output($this->application_deployment_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function copyLogs(): string
|
|
||||||
{
|
|
||||||
$logs = decode_remote_command_output($this->application_deployment_queue)
|
|
||||||
->map(function ($line) {
|
|
||||||
return $line['timestamp'].' '.
|
|
||||||
(isset($line['command']) && $line['command'] ? '[CMD]: ' : '').
|
|
||||||
trim($line['line']);
|
|
||||||
})
|
|
||||||
->join("\n");
|
|
||||||
|
|
||||||
return sanitizeLogsForExport($logs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function downloadAllLogs(): string
|
public function downloadAllLogs(): string
|
||||||
{
|
{
|
||||||
$logs = decode_remote_command_output($this->application_deployment_queue, includeAll: true)
|
$logs = decode_remote_command_output($this->application_deployment_queue, includeAll: true)
|
||||||
|
|
|
||||||
|
|
@ -155,9 +155,9 @@
|
||||||
|
|
||||||
this.matchCount = query ? count : 0;
|
this.matchCount = query ? count : 0;
|
||||||
},
|
},
|
||||||
downloadLogs() {
|
collectVisibleLogs() {
|
||||||
const logs = document.getElementById('logs');
|
const logs = document.getElementById('logs');
|
||||||
if (!logs) return;
|
if (!logs) return '';
|
||||||
const visibleLines = logs.querySelectorAll('[data-log-line]:not(.hidden)');
|
const visibleLines = logs.querySelectorAll('[data-log-line]:not(.hidden)');
|
||||||
let content = '';
|
let content = '';
|
||||||
visibleLines.forEach(line => {
|
visibleLines.forEach(line => {
|
||||||
|
|
@ -166,6 +166,17 @@
|
||||||
content += text + String.fromCharCode(10);
|
content += text + String.fromCharCode(10);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return content;
|
||||||
|
},
|
||||||
|
copyLogs() {
|
||||||
|
const content = this.collectVisibleLogs();
|
||||||
|
if (!content) return;
|
||||||
|
navigator.clipboard.writeText(content);
|
||||||
|
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
||||||
|
},
|
||||||
|
downloadLogs() {
|
||||||
|
const content = this.collectVisibleLogs();
|
||||||
|
if (!content) return;
|
||||||
const blob = new Blob([content], { type: 'text/plain' });
|
const blob = new Blob([content], { type: 'text/plain' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
|
|
@ -258,12 +269,7 @@ class="absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-6
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap items-center gap-1">
|
<div class="flex flex-wrap items-center gap-1">
|
||||||
<button
|
<button
|
||||||
x-on:click="
|
x-on:click="copyLogs()"
|
||||||
$wire.copyLogs().then(logs => {
|
|
||||||
navigator.clipboard.writeText(logs);
|
|
||||||
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
|
||||||
});
|
|
||||||
"
|
|
||||||
title="Copy Logs"
|
title="Copy Logs"
|
||||||
class="p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
|
class="p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
|
||||||
<svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
<svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
|
|
||||||
|
|
@ -249,23 +249,23 @@ class="w-20 px-2 py-1 text-xl font-bold text-center rounded border dark:bg-coolg
|
||||||
{{-- Refund --}}
|
{{-- Refund --}}
|
||||||
<section>
|
<section>
|
||||||
<h3 class="pb-2">Refund</h3>
|
<h3 class="pb-2">Refund</h3>
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
@if ($refundCheckLoading || ($isRefundEligible && !currentTeam()->subscription->stripe_cancel_at_period_end))
|
||||||
@if ($refundCheckLoading)
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<x-forms.button disabled>Request Full Refund</x-forms.button>
|
@if ($refundCheckLoading)
|
||||||
@elseif ($isRefundEligible && !currentTeam()->subscription->stripe_cancel_at_period_end)
|
<x-forms.button disabled>Request Full Refund</x-forms.button>
|
||||||
<x-modal-confirmation title="Request Full Refund?" buttonTitle="Request Full Refund"
|
@else
|
||||||
isErrorButton submitAction="refundSubscription"
|
<x-modal-confirmation title="Request Full Refund?" buttonTitle="Request Full Refund"
|
||||||
:actions="[
|
isErrorButton submitAction="refundSubscription"
|
||||||
'Your latest payment will be fully refunded.',
|
:actions="[
|
||||||
'Your subscription will be cancelled immediately.',
|
'Your latest payment will be fully refunded.',
|
||||||
'All servers will be deactivated.',
|
'Your subscription will be cancelled immediately.',
|
||||||
]" confirmationText="{{ currentTeam()->name }}"
|
'All servers will be deactivated.',
|
||||||
confirmationLabel="Enter your team name to confirm" shortConfirmationLabel="Team Name"
|
]" confirmationText="{{ currentTeam()->name }}"
|
||||||
step2ButtonText="Confirm Refund & Cancel" />
|
confirmationLabel="Enter your team name to confirm" shortConfirmationLabel="Team Name"
|
||||||
@else
|
step2ButtonText="Confirm Refund & Cancel" />
|
||||||
<x-forms.button disabled>Request Full Refund</x-forms.button>
|
@endif
|
||||||
@endif
|
</div>
|
||||||
</div>
|
@endif
|
||||||
<p class="mt-2 text-sm text-neutral-500">
|
<p class="mt-2 text-sm text-neutral-500">
|
||||||
@if ($refundCheckLoading)
|
@if ($refundCheckLoading)
|
||||||
Checking refund eligibility...
|
Checking refund eligibility...
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue