Paginate beta history and refresh pages from events
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
import type { BetaPromotionPreview } from '$lib/beta-promotion.js';
|
||||
import { coverageSummary, requirementSummary } from '$lib/beta-plan-summary.js';
|
||||
import type { ActivityEvent } from '$lib/operation-flow.js';
|
||||
import { pollVisible } from '$ui/poll.js';
|
||||
import { betaUpdates } from '$ui/beta-updates.js';
|
||||
import { confirmAction } from '$ui/confirm.js';
|
||||
import type { BetaRevision } from '$lib/beta-revision.js';
|
||||
import BetaRevisionDialog from '$ui/components/BetaRevisionDialog.svelte';
|
||||
@@ -34,6 +34,8 @@
|
||||
let scripts = $state<BetaFile[]>([]);
|
||||
let servers = $state<BetaServer[]>([]);
|
||||
let events = $state<ActivityEvent[]>([]);
|
||||
let activityBefore = $state<number|null>(null), nextBefore = $state<number|null>(null), activityLoading = $state(false);
|
||||
let activityRequest = 0;
|
||||
let promotion = $state<Promotion|null>(null);
|
||||
let rollbackCampaign = $state<{ id: string }|null>(null);
|
||||
let loading = $state(true), loadError = $state(''), flash = $state(''), success = $state('');
|
||||
@@ -67,15 +69,33 @@
|
||||
if (!res.ok) throw new Error(res.status === 404 ? 'Beta not found.' : 'Could not refresh beta. Showing the last loaded results.');
|
||||
const body = await res.json();
|
||||
if (current !== request || requestedId !== id) return;
|
||||
test = body.test; beta = body.beta; scripts = body.scripts; servers = body.servers; events = body.events; promotion = body.promotion ?? null;
|
||||
test = body.test; beta = body.beta; scripts = body.scripts; servers = body.servers;
|
||||
if (activityBefore === null) { events = body.events; nextBefore = body.eventsNextBefore ?? null; }
|
||||
promotion = body.promotion ?? null;
|
||||
rollbackCampaign = body.rollback ?? null;
|
||||
revision = body.revision; revisions = body.revisions ?? [];
|
||||
now = Date.now(); loadError = '';
|
||||
} catch (error) { if (current === request && requestedId === id) loadError = (error as Error).message; }
|
||||
finally { if (current === request && requestedId === id) loading = false; }
|
||||
}
|
||||
$effect(() => { id; beta = null; loading = true; loadError = ''; flash = ''; success = ''; reviewOpen = false; updateOpen = false; void load(); });
|
||||
onMount(() => pollVisible(load, 5000, false));
|
||||
$effect(() => { id; activityRequest++; activityBefore = null; activityLoading = false; beta = null; loading = true; loadError = ''; flash = ''; success = ''; reviewOpen = false; updateOpen = false; void load(); });
|
||||
onMount(() => {
|
||||
const stop = betaUpdates(load, () => id);
|
||||
const clock = setInterval(() => { now = Date.now(); }, 30000);
|
||||
return () => { stop(); clearInterval(clock); request++; activityRequest++; };
|
||||
});
|
||||
async function loadActivity(before: number|null) {
|
||||
const current = ++activityRequest, requestedId = id;
|
||||
activityLoading = true;
|
||||
try {
|
||||
const res = await fetch(`/api/betas/${id}/events` + (before === null ? '' : `?before=${before}`));
|
||||
if (!res.ok) throw new Error('Could not load beta activity.');
|
||||
const body = await res.json();
|
||||
if (current !== activityRequest || requestedId !== id) return;
|
||||
activityBefore = before; events = body.events; nextBefore = body.nextBefore; loadError = '';
|
||||
} catch (error) { if (current === activityRequest) loadError = (error as Error).message; }
|
||||
finally { if (current === activityRequest) activityLoading = false; }
|
||||
}
|
||||
async function reviewPromotion() {
|
||||
reviewOpen = true; preview = null; reviewError = ''; acting = 'preview';
|
||||
try {
|
||||
@@ -181,6 +201,7 @@
|
||||
</div></details>
|
||||
{/if}
|
||||
<OperationHistory {events} active={!closed} showOverview={false}/>
|
||||
<div class="ui-toolbar" aria-label="Activity pagination">{#if activityBefore !== null}<Button size="sm" disabled={activityLoading} onclick={() => loadActivity(null)}>Latest activity</Button>{/if}{#if nextBefore !== null}<Button size="sm" disabled={activityLoading} onclick={() => loadActivity(nextBefore)}>Older activity</Button>{/if}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user