Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | 65x 1x 2x 1x 55x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 137x 55x 3x 26x 26x 27x 10x 26x 25x 25x 25x 25x 22x 25x 10x 10x 10x 15x 15x 15x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 51x 44x 44x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 3x 2x 2x 2x 2x 2x 2x 1x 1x 11x 11x 11x 11x 11x 10x 10x 10x 30x 11x | <template>
<div class="row export-jobs-section">
<div class="col-12">
<LoadingSpinner v-if="loading" />
<ErrorAlert v-else-if="loadError" :title="t('common.error')" :message="loadError" />
<EmptyState v-else-if="jobs.length === 0">{{ t('exportJobs.empty') }}</EmptyState>
<template v-else>
<div class="row">
<div v-for="job in jobs" :key="job.id" class="col-md-4 mb-3">
<div class="card h-100 shadow-sm position-relative">
<!-- Action buttons (top-right overlay), matching EntityItemCard's convention -->
<div class="card-actions">
<button
class="btn btn-sm btn-danger action-icon"
:disabled="isActive(job)"
:title="t('common.delete')"
:aria-label="t('common.delete')"
@click.stop="requestDelete(job)"
>
<font-awesome-icon icon="fa-solid fa-trash" />
</button>
</div>
<div class="card-body d-flex flex-column">
<p class="text-muted small mb-1">{{ formatDateTime(job.createdAt) }}</p>
<p class="mb-2">
{{ t('exportJobs.entityCount').replace('{count}', String(entityCount(job))) }}
</p>
<!-- One slot for whichever is relevant, so replacing the progress bar with
the download/refresh button never leaves a gap where it was. -->
<div class="mt-auto">
<div v-if="isActive(job)" class="mb-1">
<div class="d-flex justify-content-between small text-muted mb-1">
<span>{{ progressLabel(job) }}</span>
<span v-if="job.progress">{{ progressPercent(job) }}%</span>
</div>
<div class="progress" style="height: 0.5rem">
<div
class="progress-bar"
:class="{ 'progress-bar-striped progress-bar-animated': !job.progress }"
role="progressbar"
:style="{ width: `${job.progress ? progressPercent(job) : 100}%` }"
:aria-valuenow="job.progress?.done ?? 0"
aria-valuemin="0"
:aria-valuemax="job.progress?.total ?? 1"
/>
</div>
</div>
<p v-else-if="job.status === 'failed'" class="text-danger small mb-0">
{{ job.error }}
</p>
<template v-else-if="job.status === 'completed'">
<button
v-if="isDownloadLinkFresh(job)"
class="btn btn-sm btn-success"
@click="download(job)"
>
<font-awesome-icon icon="fa-solid fa-download" class="me-1" />
{{ t('exportJobs.download') }}
</button>
<button
v-else
class="btn btn-sm btn-outline-secondary"
:disabled="refreshingJobIds.has(job.id)"
@click="refreshDownloadLink(job)"
>
<span
v-if="refreshingJobIds.has(job.id)"
class="spinner-border spinner-border-sm me-1"
role="status"
/>
<font-awesome-icon v-else icon="fa-solid fa-rotate-right" class="me-1" />
{{ t('exportJobs.refreshLink') }}
</button>
</template>
</div>
</div>
</div>
</div>
</div>
<div v-if="hasMore" class="d-flex justify-content-center">
<button
class="btn btn-sm btn-outline-secondary"
:disabled="loadingMore"
@click="loadMore"
>
<span v-if="loadingMore" class="spinner-border spinner-border-sm me-2" role="status" />
{{ t('exportJobs.loadMore') }}
</button>
</div>
</template>
</div>
<ConfirmModal
:is-open="confirmDelete.open"
:title="t('exportJobs.deleteTitle')"
:message="t('exportJobs.deleteMessage')"
variant="danger"
@confirm="doDelete"
@cancel="confirmDelete.open = false"
/>
</div>
</template>
<script setup lang="ts">
// @implements UC-ENTITY-024.1
import { onMounted, onUnmounted, reactive, ref } from 'vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import EmptyState from '@/components/EmptyState.vue'
import ErrorAlert from '@/components/ErrorAlert.vue'
import ConfirmModal from '@/components/ConfirmModal.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useDateFormat } from '@/composables/useDateFormat'
import { useEntitiesStore, type ExportJobSummary } from '@/stores/entities'
import { useToastStore } from '@/stores/toast'
import { getErrorMessage } from '@/utils/errors'
// Re-fetch the first page on this interval while any loaded job is still
// pending/processing — simpler than a generic per-job polling composable
// since fetchExportJobs() already returns fresh status for every job in
// one call (see composables/usePollUntilComplete.ts for the single-job
// equivalent used by ExportEntitySidebar).
const POLL_INTERVAL_MS = 3000
// GSI queries in DynamoDB are always eventually consistent — a job created
// moments ago (e.g. the user just submitted an export elsewhere and
// navigated straight here) can briefly be invisible to this list's very
// first fetch, or even a couple of early ones, before its flowIndex
// projection catches up. Keep polling through this short window even when
// nothing loaded looks active, so that case still self-corrects instead of
// permanently reporting "no export jobs yet".
const STARTUP_GRACE_PERIOD_MS = 15000
// The backend presigns each downloadUrl for 900s (see export-worker.js/get-export-job.js).
// Treat it as usable for a bit less than that — a minute of safety margin against clock
// drift and the time between rendering the button and the click actually reaching S3 —
// so the UI never offers a link that's about to (or already did) expire.
const DOWNLOAD_LINK_FRESH_WINDOW_MS = 14 * 60 * 1000
// How often to re-evaluate link freshness against the clock alone, with no new data —
// coarse is fine given the multi-minute window above.
const CLOCK_TICK_INTERVAL_MS = 30000
const { t } = useUILanguage()
const { formatDateTime } = useDateFormat()
const entitiesStore = useEntitiesStore()
const toastStore = useToastStore()
const jobs = ref<ExportJobSummary[]>([])
const loading = ref(true)
const loadError = ref('')
const nextToken = ref<string | null>(null)
const hasMore = ref(false)
const loadingMore = ref(false)
const confirmDelete = reactive<{ open: boolean; jobId: string }>({ open: false, jobId: '' })
// When each job's current downloadUrl was (re)generated — every successful list/refresh
// fetch presigns a brand new one, so this is reset on every fetch that returns the job.
const downloadLinkFetchedAt = reactive<Record<string, number>>({})
const refreshingJobIds = reactive(new Set<string>())
const now = ref(Date.now())
let pollTimer: ReturnType<typeof setInterval> | null = null
let clockTimer: ReturnType<typeof setInterval> | null = null
const mountedAt = Date.now()
function isActive(job: ExportJobSummary) {
return job.status === 'pending' || job.status === 'processing'
}
function entityCount(job: ExportJobSummary) {
return job.status === 'completed' && job.result
? job.result.entityCount
: job.requestedEntityCount
}
function progressPercent(job: ExportJobSummary) {
if (!job.progress || job.progress.total <= 0) return 0
return Math.min(100, Math.round((job.progress.done / job.progress.total) * 100))
}
function progressLabel(job: ExportJobSummary) {
return job.progress
? t('entity.exportProgress')
.replace('{done}', String(job.progress.done))
.replace('{total}', String(job.progress.total))
: t('entity.exportPreparing')
}
function recordDownloadLinkFetchTimestamps(items: ExportJobSummary[]) {
const fetchedAt = Date.now()
for (const item of items) {
if (item.status === 'completed' && item.result) {
downloadLinkFetchedAt[item.id] = fetchedAt
}
}
}
async function loadFirstPage() {
const data = await entitiesStore.fetchExportJobs()
jobs.value = data.items
nextToken.value = data.nextToken
hasMore.value = data.hasMore
recordDownloadLinkFetchTimestamps(data.items)
}
function withinStartupGracePeriod() {
return Date.now() - mountedAt < STARTUP_GRACE_PERIOD_MS
}
function shouldKeepPolling() {
return jobs.value.some(isActive) || withinStartupGracePeriod()
}
function ensurePolling() {
const shouldPoll = shouldKeepPolling()
if (shouldPoll && pollTimer === null) {
pollTimer = setInterval(async () => {
try {
await loadFirstPage()
} catch {
// Transient poll failure — the next tick retries, nothing to show here.
}
if (!shouldKeepPolling() && pollTimer !== null) {
clearInterval(pollTimer)
pollTimer = null
}
}, POLL_INTERVAL_MS)
} else Eif (!shouldPoll && pollTimer !== null) {
clearInterval(pollTimer)
pollTimer = null
}
}
async function loadMore() {
Iif (!hasMore.value || !nextToken.value || loadingMore.value) return
loadingMore.value = true
try {
const data = await entitiesStore.fetchExportJobs({ nextToken: nextToken.value })
jobs.value = [...jobs.value, ...data.items]
nextToken.value = data.nextToken
hasMore.value = data.hasMore
recordDownloadLinkFetchTimestamps(data.items)
} catch (err) {
toastStore.error(getErrorMessage(err, t('exportJobs.loadError')))
} finally {
loadingMore.value = false
}
}
function isDownloadLinkFresh(job: ExportJobSummary) {
if (!job.result) return false
const fetchedAt = downloadLinkFetchedAt[job.id]
return fetchedAt !== undefined && now.value - fetchedAt < DOWNLOAD_LINK_FRESH_WINDOW_MS
}
async function refreshDownloadLink(job: ExportJobSummary) {
Iif (refreshingJobIds.has(job.id)) return
refreshingJobIds.add(job.id)
try {
const status = await entitiesStore.getExportJobStatus(job.id)
Eif (status.status === 'completed' && status.result) {
const index = jobs.value.findIndex((j) => j.id === job.id)
Eif (index !== -1) {
jobs.value[index] = { ...jobs.value[index], result: status.result }
}
downloadLinkFetchedAt[job.id] = Date.now()
}
} catch (err) {
toastStore.error(getErrorMessage(err, t('exportJobs.refreshError')))
} finally {
refreshingJobIds.delete(job.id)
}
}
function download(job: ExportJobSummary) {
Eif (job.result) {
window.location.href = job.result.downloadUrl
}
}
function requestDelete(job: ExportJobSummary) {
if (isActive(job)) return
confirmDelete.jobId = job.id
confirmDelete.open = true
}
async function doDelete() {
const jobId = confirmDelete.jobId
confirmDelete.open = false
try {
await entitiesStore.deleteExportJob(jobId)
jobs.value = jobs.value.filter((job) => job.id !== jobId)
} catch (err) {
toastStore.error(getErrorMessage(err, t('exportJobs.deleteError')))
}
}
onMounted(async () => {
loading.value = true
loadError.value = ''
try {
await loadFirstPage()
ensurePolling()
} catch (err) {
loadError.value = getErrorMessage(err, t('exportJobs.loadError'))
} finally {
loading.value = false
}
// Forces a re-check of each download link's freshness purely against the
// clock, independent of any fetch — a job can sit completed on-screen for
// much longer than its link's validity window with no further poll to
// naturally trigger the download-button/refresh-button swap.
clockTimer = setInterval(() => {
now.value = Date.now()
}, CLOCK_TICK_INTERVAL_MS)
})
onUnmounted(() => {
if (pollTimer !== null) {
clearInterval(pollTimer)
pollTimer = null
}
if (clockTimer !== null) {
clearInterval(clockTimer)
clockTimer = null
}
})
</script>
<style scoped>
/* Matches EntityItemCard.vue's action-button convention exactly. */
.card-actions {
position: absolute;
top: 8px;
right: 8px;
z-index: 10;
display: flex;
gap: 4px;
}
.action-icon {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
border-radius: 4px;
opacity: 1;
}
.action-icon:hover {
opacity: 1;
}
</style>
|