Files
Davide Silvestri 03ffed6dba refactor: migrate table import to centralized job store with reload restore (#5264)
* feat: add dynamic concurrency limit for file import jobs

Override can_schedule_or_raise() on FileImportJobType to enforce:
- max 1 running import per table (existing table imports)
- max 1 running new-table-creation per database
- global max_count cap

Follows the same pattern as GenerateAIValuesJobType.

* refactor: migrate table import and data sync to centralized job store

Replace the deprecated jobProgress mixin with the job mixin in
ImportFileModal, CreateTable, CreateDataSync, and the shared dataSync
mixin. This enables:

- Restore running jobs after page refresh via loadRunningJob()
- Cancel support via the job mixin's cancelJob()
- Centralized polling through the Vuex job store

Also enriches FileImportJobType with lifecycle callbacks, disables type
selectors during import/sync, and exposes table_id in DataSyncSerializer
for job matching.

* feat: store importer metadata on FileImportJob for UI restore

Add importer_type and original_file_name fields to FileImportJob so the
frontend can show which importer and file were used when restoring a
running job after page reload. Both fields are passed through from the
table create and import API endpoints.

* test: add e2e test for CSV import restore after page reload

Uploads a large CSV, starts the import, reloads the page, reopens the
modal, and verifies the file name and cancel button are visible.

* fix: defensive handling when backend job data is missing new fields (pre-deploy jobs)

* test: verify cancel button stops the running import job

* test: add e2e test for CSV import into existing table restore after reload

* fix: address PR review — filter data sync jobs by database, restore importer type, prevent chooser click during import

* fix: reset importer selection after cancelling an import job

* address copilot feedback; fix tests

* fix: address review — database=table.database, opaque importer_type docs, avoid double goto for Firefox

* fix: stabilize e2e tests for Firefox — wait for job in store, use larger CSV

* feat: add on_cancelled hook and data sync cancellation support

Add on_cancelled lifecycle hook to the job system, invoked after a job
is cancelled. The data sync job type uses it to trash the table when a
first sync is cancelled before completing. Bump max_count to 3 and add
can_schedule_or_raise for per-data-sync concurrency. Frontend gets a
cancel button, optimistic table cleanup, and store lifecycle hooks.
Rework importer metadata migration to use ZDM-safe TextField(null=True).

* address copilot feedback

* address feedback
2026-05-12 17:29:25 +02:00

185 lines
5.4 KiB
Vue

<template>
<Modal
ref="modal"
:can-close="!uploadingBeforeJobCreated"
@show="onShow"
@hidden="callCreateComponentHide()"
>
<template #content>
<div class="import-modal__header">
<h2 class="import-modal__title">
{{ $t('createTableModal.title') }}
</h2>
</div>
<div class="control margin-bottom-2">
<FormGroup
:label="$t('createTableModal.importLabel')"
small-label
required
>
<ul class="choice-items margin-top-1">
<li>
<a
class="choice-items__link"
:class="{
active: chosenType === '',
disabled: importInProgress,
}"
@click="!importInProgress && setChosenType('')"
>
<i class="choice-items__icon iconoir-copy"></i>
<span>{{ $t('createTableModal.newTable') }}</span>
<i
v-if="chosenType === ''"
class="choice-items__icon-active iconoir-check-circle"
></i>
</a>
</li>
<li v-for="instance in importerTypes" :key="instance.type">
<a
class="choice-items__link"
:class="{
active: chosenType === instance.type,
disabled: importInProgress,
}"
@click="!importInProgress && setChosenType(instance.type)"
>
<i class="choice-items__icon" :class="instance.iconClass"></i>
<span> {{ instance.getName() }}</span>
<i
v-if="chosenType === instance.type"
class="choice-items__icon-active iconoir-check-circle"
></i>
</a>
</li>
<DataSyncTypeChoice
v-for="instance in dataSyncTypes"
:key="instance.type"
:active="chosenType === instance.type"
:data-sync-type="instance"
:database="database"
:disabled="importInProgress"
@selected="!importInProgress && setChosenType(instance.type)"
></DataSyncTypeChoice>
</ul>
</FormGroup>
</div>
<CreateTable
v-if="isImporter"
ref="createComponent"
:chosen-type="chosenType"
:database="database"
@hide="hide()"
@import-in-progress="importInProgress = $event"
@uploading-before-job-created="uploadingBeforeJobCreated = $event"
></CreateTable>
<CreateDataSync
v-else
ref="createComponent"
:chosen-type="chosenType"
:database="database"
@hide="hide()"
@import-in-progress="importInProgress = $event"
@uploading-before-job-created="uploadingBeforeJobCreated = $event"
></CreateDataSync>
</template>
</Modal>
</template>
<script>
import modal from '@baserow/modules/core/mixins/modal'
import CreateTable from '@baserow/modules/database/components/table/CreateTable'
import CreateDataSync from '@baserow/modules/database/components/table/CreateDataSync'
import DataSyncTypeChoice from '@baserow/modules/database/components/dataSync/DataSyncTypeChoice.vue'
import {
FileImportJobType,
SyncDataSyncTableJobType,
} from '@baserow/modules/database/jobTypes'
export default {
name: 'CreateTableModal',
components: { DataSyncTypeChoice, CreateTable, CreateDataSync },
mixins: [modal],
props: {
database: {
type: Object,
required: true,
},
},
data() {
return {
chosenType: '',
importInProgress: false,
uploadingBeforeJobCreated: false,
}
},
computed: {
importerTypes() {
return this.$registry.getAll('importer')
},
dataSyncTypes() {
return this.$registry.getAll('dataSync')
},
isImporter() {
return (
this.chosenType === '' ||
this.$registry.exists('importer', this.chosenType)
)
},
},
methods: {
onShow() {
const runningType = this.getRunningJobType()
this.setChosenType(runningType || '')
},
getRunningJobType() {
const jobs = this.$store.getters['job/getUnfinishedJobs']
const databaseId = this.database.id
// Check for a running file import (new table creation)
const fileImport = jobs.find(
(j) =>
j.type === FileImportJobType.getType() &&
j.table_id === null &&
j.database_id === databaseId
)
if (fileImport) {
const type = fileImport.importer_type || ''
if (type && this.$registry.exists('importer', type)) {
return type
}
return ''
}
// Check for a running data sync scoped to this database
const dataSync = jobs.find(
(j) =>
j.type === SyncDataSyncTableJobType.getType() &&
j.data_sync?.database_id === databaseId
)
if (dataSync) {
const type = dataSync.data_sync?.type || ''
if (type && this.$registry.exists('dataSync', type)) {
return type
}
return ''
}
return null
},
callCreateComponentHide() {
this.$refs.createComponent.hide()
},
setChosenType(type) {
if (type === this.chosenType && type !== '') {
return
}
this.chosenType = type
this.$refs.createComponent?.reset()
},
},
}
</script>