fix(ui): live task updates refresh in place instead of flashing the loading state
This commit is contained in:
1 file changed
+35
-10
@@ -168,10 +168,12 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
cacheKey: string,
|
||||
fetcher: () => Promise<T>,
|
||||
cache: Ref<Cache<T>>,
|
||||
{ force = false }: { force?: boolean } = {},
|
||||
{ force = false, keep = false }: { force?: boolean; keep?: boolean } = {},
|
||||
): void {
|
||||
if (cache.value.has(cacheKey) && cache.value.get(cacheKey) !== null && !force) return;
|
||||
cache.value = new Map(cache.value).set(cacheKey, undefined);
|
||||
// keep leaves a loaded payload on screen while it is re-read, so a live
|
||||
// refresh replaces it in place instead of flashing the loading state.
|
||||
if (!keep || cache.value.get(cacheKey) == null) cache.value = new Map(cache.value).set(cacheKey, undefined);
|
||||
// A read that never settles would pin the panel's loading line forever:
|
||||
// after a quiet minute the read is declared broken so the retry button
|
||||
// can appear. A late response after the timeout is discarded by the race.
|
||||
@@ -202,9 +204,9 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
});
|
||||
}
|
||||
|
||||
function loadAttempts(): void {
|
||||
function loadAttempts(keep = false): void {
|
||||
if (id.value == null) return;
|
||||
attempts.value = undefined;
|
||||
if (!keep || !attempts.value) attempts.value = undefined;
|
||||
missing.value = false;
|
||||
api
|
||||
.taskAttempts<AttemptsState>(String(id.value))
|
||||
@@ -217,9 +219,9 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
});
|
||||
}
|
||||
|
||||
function loadEvents(): void {
|
||||
function loadEvents(keep = false): void {
|
||||
if (id.value == null) return;
|
||||
events.value = undefined;
|
||||
if (!keep || !events.value) events.value = undefined;
|
||||
api
|
||||
.task<TaskEvent[]>(String(id.value))
|
||||
.then((res) => {
|
||||
@@ -230,7 +232,7 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
});
|
||||
}
|
||||
|
||||
function loadLogs(attempt: number, opts?: { force?: boolean }): void {
|
||||
function loadLogs(attempt: number, opts?: { force?: boolean; keep?: boolean }): void {
|
||||
if (id.value == null) return;
|
||||
const current = filters.value;
|
||||
keyedLoad(
|
||||
@@ -247,7 +249,7 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
);
|
||||
}
|
||||
|
||||
function loadChanges(attempt: number, opts?: { force?: boolean }): void {
|
||||
function loadChanges(attempt: number, opts?: { force?: boolean; keep?: boolean }): void {
|
||||
if (id.value == null) return;
|
||||
keyedLoad(
|
||||
attemptKey(id.value, attempt),
|
||||
@@ -257,7 +259,7 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
);
|
||||
}
|
||||
|
||||
function loadDebug(attempt: number, opts?: { force?: boolean }): void {
|
||||
function loadDebug(attempt: number, opts?: { force?: boolean; keep?: boolean }): void {
|
||||
if (id.value == null) return;
|
||||
keyedLoad(
|
||||
attemptKey(id.value, attempt),
|
||||
@@ -283,7 +285,30 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
|
||||
refreshToken.value += 1;
|
||||
}
|
||||
|
||||
useLiveResource("tasks", refreshAll, 500);
|
||||
/** Re-read what is on screen after a live event, keeping it visible until
|
||||
* the new response lands. Cached payloads for other tabs and attempts are
|
||||
* dropped so they are re-read when shown. */
|
||||
function refreshLive(): void {
|
||||
const attempt = attemptNumber.value;
|
||||
const visible = attempt == null ? null : tab.value;
|
||||
const keepOnly = <T>(cache: Ref<Cache<T>>, key: string | null) => {
|
||||
const value = key == null ? undefined : cache.value.get(key);
|
||||
cache.value = value == null || key == null ? new Map() : new Map([[key, value]]);
|
||||
};
|
||||
keepOnly(logs, visible === "log" ? logKey.value : null);
|
||||
keepOnly(changes, visible === "changes" ? changeKey.value : null);
|
||||
keepOnly(debug, visible === "debug" ? debugKey.value : null);
|
||||
loadTaskList();
|
||||
loadAttempts(true);
|
||||
loadEvents(true);
|
||||
if (attempt == null) return;
|
||||
const opts = { force: true, keep: true };
|
||||
if (visible === "log") loadLogs(attempt, opts);
|
||||
else if (visible === "changes") loadChanges(attempt, opts);
|
||||
else if (visible === "debug") loadDebug(attempt, opts);
|
||||
}
|
||||
|
||||
useLiveResource("tasks", refreshLive, 500);
|
||||
|
||||
async function performRetry(): Promise<void> {
|
||||
if (id.value == null) return;
|
||||
|
||||
Reference in new issue
Block a user