mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat: add a shared base for integrations that connect an account through OAuth * fix: keep OAuth account scopes current and bound provider answers * fix: share parent registration between form APIs * fix: preserve refreshed OAuth tokens when actions fail * refactor: use absolute imports for parent OAuth modules * refactor: decouple OAuth cleanup from application publication models * refactor: use common import hooks for OAuth connections * fix: keep OAuth account integrations out of the workspace --------- Co-authored-by: Jeremie Pardou <571533+jrmi@users.noreply.github.com>
170 lines
4.6 KiB
Vue
170 lines
4.6 KiB
Vue
<template>
|
|
<Modal ref="modal" @show="shown">
|
|
<h2 class="box__title">
|
|
{{
|
|
create
|
|
? $t('integrationCreateEditModal.createTitle')
|
|
: $t('integrationCreateEditModal.editTitle')
|
|
}}
|
|
</h2>
|
|
<div>
|
|
<Alert v-if="actualIntegrationType.warning" type="warning">
|
|
<template #title>{{
|
|
$t('integrationCreateEditModal.warningTitle')
|
|
}}</template>
|
|
<p>{{ actualIntegrationType.warning }}</p>
|
|
</Alert>
|
|
|
|
<IntegrationEditForm
|
|
ref="form"
|
|
:application="application"
|
|
:default-values="create ? getDefaultIntegrationValues() : integration"
|
|
:integration-type="actualIntegrationType"
|
|
:service-types="serviceTypes"
|
|
@submitted="submit"
|
|
@created="createdBySelf"
|
|
/>
|
|
|
|
<Error :error="error"></Error>
|
|
|
|
<div
|
|
v-if="!create || !actualIntegrationType.createsItself"
|
|
class="actions actions--right"
|
|
>
|
|
<Button
|
|
size="large"
|
|
:loading="loading"
|
|
:disabled="loading"
|
|
@click.prevent="$refs.form.submit()"
|
|
>
|
|
{{ create ? $t('action.create') : $t('action.save') }}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapActions } from 'vuex'
|
|
import error from '@baserow/modules/core/mixins/error'
|
|
import modal from '@baserow/modules/core/mixins/modal'
|
|
import IntegrationEditForm from '@baserow/modules/core/components/integrations/IntegrationEditForm'
|
|
import { getNextAvailableNameInSequence } from '@baserow/modules/core/utils/string'
|
|
import { ResponseErrorMessage } from '@baserow/modules/core/plugins/clientHandler'
|
|
|
|
export default {
|
|
components: { IntegrationEditForm },
|
|
mixins: [modal, error],
|
|
props: {
|
|
application: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
integration: {
|
|
type: Object,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
integrationType: {
|
|
type: Object,
|
|
required: false,
|
|
default: null,
|
|
},
|
|
create: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: false,
|
|
},
|
|
/**
|
|
* The service types the integration is used for. See
|
|
* `IntegrationEditForm`.
|
|
*/
|
|
serviceTypes: {
|
|
type: Array,
|
|
required: false,
|
|
default: () => [],
|
|
},
|
|
},
|
|
emits: ['created'],
|
|
data() {
|
|
return { loading: false, initialValues: null }
|
|
},
|
|
computed: {
|
|
actualIntegrationType() {
|
|
if (this.create) {
|
|
return this.integrationType
|
|
}
|
|
return this.$registry.get('integration', this.integration.type)
|
|
},
|
|
integrations() {
|
|
return this.$store.getters['integration/getIntegrations'](
|
|
this.application
|
|
)
|
|
},
|
|
},
|
|
methods: {
|
|
...mapActions({
|
|
actionUpdateIntegration: 'integration/update',
|
|
actionCreateIntegration: 'integration/create',
|
|
}),
|
|
|
|
async shown() {
|
|
this.hideError()
|
|
await this.$nextTick()
|
|
this.initialValues = this.$refs.form.getFormValues()
|
|
},
|
|
getDefaultIntegrationValues() {
|
|
const name = getNextAvailableNameInSequence(
|
|
this.actualIntegrationType.name,
|
|
this.integrations.map(({ name }) => name)
|
|
)
|
|
|
|
return { name, ...this.actualIntegrationType.getDefaultValues() }
|
|
},
|
|
/**
|
|
* The integration's own form created it, e.g. after a sign-in, and stored
|
|
* it already.
|
|
*/
|
|
createdBySelf(integration) {
|
|
this.$emit('created', integration)
|
|
this.hide()
|
|
},
|
|
async submit(values) {
|
|
this.loading = true
|
|
this.hideError()
|
|
try {
|
|
if (this.create) {
|
|
const newIntegration = await this.actionCreateIntegration({
|
|
application: this.application,
|
|
integrationType: this.actualIntegrationType.type,
|
|
values,
|
|
})
|
|
this.$emit('created', newIntegration)
|
|
} else {
|
|
const differences = this.actualIntegrationType.getUpdatedValues(
|
|
values,
|
|
this.initialValues
|
|
)
|
|
if (Object.keys(differences).length > 0) {
|
|
await this.actionUpdateIntegration({
|
|
application: this.application,
|
|
integrationId: this.integration.id,
|
|
values: differences,
|
|
})
|
|
}
|
|
}
|
|
this.hide()
|
|
} catch (error) {
|
|
this.handleError(error, 'integration', {
|
|
ERROR_INTEGRATION_CREDENTIAL_REQUIRED: new ResponseErrorMessage(
|
|
this.$t('integrationCreateEditModal.credentialRequiredTitle'),
|
|
this.$t('integrationCreateEditModal.credentialRequiredMessage')
|
|
),
|
|
})
|
|
}
|
|
this.loading = false
|
|
},
|
|
},
|
|
}
|
|
</script>
|