mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* fix: don't throw when switching from a data sync to a new table The modal resets the form on a type change before the data sync form is swapped out, and the data sync form had no reset method. * fix: reset the sync options when switching data sync type A two-way sync left on from PostgreSQL was sent for iCal, which doesn't support it, so creating the table failed. * fix: clear leftover data sync state when the type changes Keeps the sync option defaults in one place, shows a failed restored sync as an error with the form, and ignores properties for a previous type. * test: reuse the data sync mount helper
177 lines
4.7 KiB
JavaScript
177 lines
4.7 KiB
JavaScript
import DataSyncService from '@baserow/modules/database/services/dataSync'
|
|
import error from '@baserow/modules/core/mixins/error'
|
|
import job from '@baserow/modules/core/mixins/job'
|
|
import { ResponseErrorMessage } from '@baserow/modules/core/plugins/clientHandler'
|
|
|
|
export default {
|
|
mixins: [error, job],
|
|
data() {
|
|
return {
|
|
loadingProperties: false,
|
|
loadedProperties: false,
|
|
// Increased for every properties request, so a reply to an older one is
|
|
// ignored.
|
|
propertiesRequestId: 0,
|
|
properties: null,
|
|
syncedProperties: [],
|
|
updateLoading: false,
|
|
syncLoading: false,
|
|
}
|
|
},
|
|
computed: {
|
|
orderedProperties() {
|
|
if (!this.properties) {
|
|
return []
|
|
}
|
|
|
|
// Show the properties where `initially_selected == True` first.
|
|
return this.properties
|
|
.slice()
|
|
.sort((a, b) =>
|
|
a.initially_selected === b.initially_selected
|
|
? 0
|
|
: a.initially_selected
|
|
? -1
|
|
: 1
|
|
)
|
|
},
|
|
},
|
|
methods: {
|
|
toggleVisibleField(key) {
|
|
const index = this.syncedProperties.findIndex((f) => key === f)
|
|
if (index > -1) {
|
|
this.syncedProperties.splice(index, 1)
|
|
} else {
|
|
this.syncedProperties.push(key)
|
|
}
|
|
},
|
|
getFieldTypeIconClass(fieldType) {
|
|
return this.$registry.get('field', fieldType).getIconClass()
|
|
},
|
|
async fetchExistingProperties(table) {
|
|
this.loadingProperties = true
|
|
|
|
try {
|
|
const { data } = await DataSyncService(
|
|
this.$client
|
|
).fetchPropertiesOfDataSync(table.data_sync.id)
|
|
this.loadedProperties = true
|
|
this.properties = data
|
|
} catch (error) {
|
|
if (error.handler && error.handler.code === 'ERROR_SYNC_ERROR') {
|
|
this.showError(
|
|
this.$t('dataSyncType.syncError'),
|
|
error.handler.detail
|
|
)
|
|
error.handler.handled()
|
|
return
|
|
}
|
|
this.handleError(error)
|
|
} finally {
|
|
this.loadingProperties = false
|
|
}
|
|
},
|
|
async fetchNonExistingProperties(type, values, databaseId) {
|
|
if (!databaseId) {
|
|
throw new Error('databaseId is required to fetch data sync properties')
|
|
}
|
|
|
|
values.type = type
|
|
|
|
const requestId = ++this.propertiesRequestId
|
|
this.loadingProperties = true
|
|
this.hideError()
|
|
|
|
try {
|
|
const { data } = await DataSyncService(this.$client).fetchProperties(
|
|
databaseId,
|
|
values
|
|
)
|
|
if (requestId !== this.propertiesRequestId) {
|
|
return
|
|
}
|
|
this.loadedProperties = true
|
|
this.properties = data
|
|
this.syncedProperties = data
|
|
.filter((p) => p.initially_selected)
|
|
.map((p) => p.key)
|
|
} catch (error) {
|
|
if (requestId !== this.propertiesRequestId) {
|
|
return
|
|
}
|
|
if (error.handler && error.handler.code === 'ERROR_SYNC_ERROR') {
|
|
this.showError(
|
|
this.$t('dataSyncType.syncError'),
|
|
error.handler.detail
|
|
)
|
|
error.handler.handled()
|
|
return
|
|
}
|
|
this.handleError(error)
|
|
} finally {
|
|
if (requestId === this.propertiesRequestId) {
|
|
this.loadingProperties = false
|
|
}
|
|
}
|
|
},
|
|
async syncTable(table) {
|
|
if (this.jobIsRunning) {
|
|
return
|
|
}
|
|
|
|
this.hideError()
|
|
this.job = null
|
|
this.syncLoading = true
|
|
|
|
try {
|
|
const { data: job } = await DataSyncService(this.$client).syncTable(
|
|
table.data_sync.id
|
|
)
|
|
await this.createAndMonitorJob(job)
|
|
} catch (error) {
|
|
this.handleError(error)
|
|
} finally {
|
|
this.syncLoading = false
|
|
}
|
|
},
|
|
async update(table, values, syncTable = true) {
|
|
this.updateLoading = true
|
|
|
|
try {
|
|
const { data } = await DataSyncService(this.$client).update(
|
|
this.table.data_sync.id,
|
|
values
|
|
)
|
|
await this.$store.dispatch('table/forceUpdate', {
|
|
database: this.database,
|
|
table: this.table,
|
|
values: { data_sync: data },
|
|
})
|
|
if (syncTable) {
|
|
await this.syncTable(this.table)
|
|
}
|
|
} catch (error) {
|
|
if (error.handler && error.handler.code === 'ERROR_SYNC_ERROR') {
|
|
this.showError(
|
|
this.$t('dataSyncType.syncError'),
|
|
error.handler.detail
|
|
)
|
|
error.handler.handled()
|
|
return
|
|
}
|
|
this.handleError(error)
|
|
} finally {
|
|
this.updateLoading = false
|
|
}
|
|
},
|
|
onJobFailed() {
|
|
this.showError(
|
|
new ResponseErrorMessage(
|
|
this.$t('createDataSync.error'),
|
|
this.job.human_readable_error
|
|
)
|
|
)
|
|
},
|
|
},
|
|
}
|