feat(transfer): show per-table failure details

This commit is contained in:
zipg authored and GitHub committed 2026-07-28 11:47:58 +08:00
1 parent 44cb4acbb7
commit 1e72d28ed3
20 files changed
+622 -65

No files matched your search

@@ -3,13 +3,14 @@ import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Button } from "@/components/ui/button";
import { Loader2, CheckCircle2, XCircle, AlertCircle, X, FileDown, DatabaseBackup, FileCode2, ArrowRightLeft } from "@lucide/vue";
import { Loader2, CheckCircle2, XCircle, AlertCircle, X, FileDown, DatabaseBackup, FileCode2, ArrowRightLeft, ChevronRight } from "@lucide/vue";
import { formatDataTransferDuration, useExportTracker, type ExportTask } from "@/composables/useExportTracker";
const { t } = useI18n();
const { tasks, activeCount, hasActive, clearFinished, cancelTask, removeTask } = useExportTracker();
const open = ref(false);
const showAll = ref(false);
const expandedFailureTaskIds = ref<string[]>([]);
const MAX_VISIBLE = 5;
const reversedTasks = computed(() => {
@@ -132,6 +133,18 @@ const statusColor = (status: string) => {
function toggleShowAll() {
showAll.value = !showAll.value;
}
function failureDetailsExpanded(exportId: string) {
return expandedFailureTaskIds.value.includes(exportId);
}
function toggleFailureDetails(exportId: string) {
expandedFailureTaskIds.value = failureDetailsExpanded(exportId) ? expandedFailureTaskIds.value.filter((id) => id !== exportId) : [...expandedFailureTaskIds.value, exportId];
}
function failureDetailCount(task: ExportTask) {
return (task.transferFailures?.length ?? 0) + (task.transferFailuresOmitted ?? 0);
}
</script>
<template>
@@ -175,6 +188,20 @@ function toggleShowAll() {
<span v-if="task.status === 'Error' && task.errorMessage" class="mt-1 block whitespace-normal break-words text-destructive" :title="task.errorMessage">
{{ task.errorMessage }}
</span>
<template v-if="task.kind === 'data-transfer' && failureDetailCount(task) > 0">
<button class="mt-1.5 flex items-center gap-1 text-xs font-medium text-foreground hover:text-primary" :aria-expanded="failureDetailsExpanded(task.exportId)" @click="toggleFailureDetails(task.exportId)">
<ChevronRight class="h-3.5 w-3.5 shrink-0 transition-transform" :class="{ 'rotate-90': failureDetailsExpanded(task.exportId) }" />
{{ failureDetailsExpanded(task.exportId) ? t("exportProgress.hideFailureDetails") : t("exportProgress.showFailureDetails", { count: failureDetailCount(task) }) }}
</button>
<div v-if="failureDetailsExpanded(task.exportId)" class="mt-1.5 max-h-44 overflow-y-auto rounded border border-destructive/20 bg-destructive/5">
<div v-for="failure in task.transferFailures" :key="failure.table" class="border-b border-destructive/15 px-2.5 py-2 last:border-b-0">
<div class="break-all font-mono font-medium text-foreground">{{ failure.table }}</div>
<div class="mt-0.5 select-text whitespace-pre-wrap break-words text-destructive">{{ failure.error }}</div>
<div v-if="failure.truncated" class="mt-0.5 text-muted-foreground">{{ t("exportProgress.failureDetailTruncated") }}</div>
</div>
<div v-if="task.transferFailuresOmitted" class="px-2.5 py-2 text-muted-foreground">{{ t("exportProgress.failureDetailsOmitted", { count: task.transferFailuresOmitted }) }}</div>
</div>
</template>
</div>
</div>
@@ -91,4 +91,72 @@ describe("ExportProgressPopover data transfer duration", () => {
expect(document.body.textContent).toContain("Elapsed: 1m 5s");
expect(document.body.textContent?.match(/Elapsed:/g)).toHaveLength(1);
});
it("expands complete per-table transfer failure details", async () => {
const tracker = useExportTracker();
const task = tracker.addDataTransferTask("failed-transfer", "source to target", 2);
tracker.updateDataTransferTask(task.exportId, {
transferId: task.exportId,
table: "users",
tableIndex: 0,
totalTables: 2,
rowsTransferred: 0,
totalRows: null,
status: "error",
error: "permission denied for relation users",
terminal: false,
});
tracker.updateDataTransferTask(task.exportId, {
transferId: task.exportId,
table: "",
tableIndex: 2,
totalTables: 2,
rowsTransferred: 0,
totalRows: null,
status: "error",
error: "1 table(s) failed: users",
terminal: true,
});
await mountPopover();
const detailsButton = document.body.querySelector<HTMLButtonElement>('button[aria-expanded="false"]');
expect(detailsButton?.textContent).toContain("Failure details (1)");
expect(document.body.textContent).not.toContain("permission denied for relation users");
detailsButton?.click();
await nextTick();
expect(detailsButton?.getAttribute("aria-expanded")).toBe("true");
expect(document.body.textContent).toContain("users");
expect(document.body.textContent).toContain("permission denied for relation users");
});
it("shows the total failure count and omitted-detail notice when the bounded list is full", async () => {
const tracker = useExportTracker();
const task = tracker.addDataTransferTask("bounded-failures", "source to target", 101);
for (let index = 0; index < 101; index += 1) {
tracker.updateDataTransferTask(task.exportId, {
transferId: task.exportId,
table: `table_${index}`,
tableIndex: index,
totalTables: 101,
rowsTransferred: 0,
totalRows: null,
status: "error",
error: `failure ${index}`,
terminal: false,
});
}
await mountPopover();
const detailsButton = document.body.querySelector<HTMLButtonElement>('button[aria-expanded="false"]');
expect(detailsButton?.textContent).toContain("Failure details (101)");
detailsButton?.click();
await nextTick();
expect(document.body.textContent).toContain("1 additional failure detail(s) not shown");
expect(document.body.textContent).not.toContain("failure 100");
});
});