多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
9.4 KiB

Nc feat/integrations (#8903) * feat: integrations backend (WIP) * feat: migration - source table * feat: updated migration * feat: integration APIs - WIP * feat: integration - crud, acl, api tests * feat: integration - crud, acl, api tests * feat: integration - GUI integration * feat: private integration config * feat: integration GUI * feat: delete api and source creation * feat: add hint for input fields * fix: source creation bugs * refactor: placeholder text correction * refactor: include context * feat: integration delete with transaction * refactor: permission scope correction and move ee logic * refactor: migration correction and improvements * feat: confirm dialog * refactor: review comments * refactor: meta service changes * feat: add oss support - WIP * feat: add oss support * refactor: coderabbt suggestions * refactor: exclude config from api response * refactor: coderabbit review comments * refactor: rename migration names * fix: method name correction * fix(nc-gui): integration ui changes * fix(nc-gui): add edit integration ui changes * fix(nc-gui): add shared badge in integrations list * feat(nc-gui): duplicate integration * fix(nocodb): add copy from id integration support in create integration api * fix(nc-gui): update useIntegration store * fix(nc-gui): test connection btn style update * fix(nc-gui): update new integration modal * feat(nc-gui): add sort integration list support * fix(nc-gui): integration table to be center aligned * fix(nc-gui): move form item required mark to right side * fix: remove divider * fix(nc-gui): add input shadow * fix(nc-gui): base name validator error message * fix(nc-gui): add border if search connection input has some value * fix(nc-gui): add close btn in integration modal * chore(nc-gui): lint * fix(nc-gui): pr review changes * chore(nc-gui): cleanup unused code * chore(nc-gui): lint * fix(nc-gui): integrationsType not found issue * fix(nc-gui): update data source table * fix(nc-gui): populate integration name only on input value change * fix(nc-gui): create data source form update * fix: type correction * fix: label correction * fix: font corrections * fix: remove help text * fix: grammar in help text * fix(nc-gui): edit source ui changes * fix(nc-gui): base settings modal changes & datasource search feat * fix(nc-gui): update data source table * fix(nc-gui): move integrations outside team & settings * fix(nc-gui): make connections table full width * fix(nc-gui): modal height issue in small screen * fix(nc-gui): disable editing selected connection in edit data source * fix(nc-gui): add data sources in base settings tab * fix(nc-gui): ant design multiple warnings issue * fix(nc-gui): create source page scrollbar issue * feat(nc-gui): create connection from create source page * chore(nc-gui): lint * fix(nc-gui): update project members tab content margin * chore: label text change * fix: font changes * chore: font corrections * chore: integration => connection * fix(nc-gui): disable auto editing database name on changing connection name * fix(nc-gui): table header overflow issue * fix(nc-gui): show connection crud operation messages in toast * feat(nc-gui): request new integration ui * fix(nc-gui): text area height adjust issue * fix(nc-gui): add connection from source create issue * fix(nc-gui): show data source details in modal * fix(nc-gui): hide private connection option * fix(nc-gui): user should able to edit & save connection without test connection if only title updated * fix(nc-gui): add integration page in oss * fix(nc-gui): typo currection * fix(nc-gui): oss create base ui changes * misc: minor formatting changes * misc: formatting corrections * fix(nc-gui): overlay close btn issue * fix(nc-gui): some review changes * fix(nc-gui): remove link beetween connection name & database name * fix(nc-gui): update edit base/source modal oss * fix(nc-gui): add db type icon in select connection * chore(nc-gui): lint * fix: integration list - allow access based on base level role * fix(nc-gui): load integrations on creating integration from source create issue * fix(nc-gui): add connection count in tab * fix: correction in soft delete logic * fix(nc-gui): reset use ssl on panel collapse * fix(nc-gui): reduce select input font weight * fix(nc-gui): update connection edit access control * fix: integration read api correction * fix(nc-gui): some review changes * fix(nc-gui): labels update * fix(nc-gui): udpate text in delete modal integration -> connection * fix: remove permission from wrong scope * refactor: swagger description correction * fix(nc-gui): remove connection between source name & database name * fix(nc-gui): test connection is not needed form source name. inflection field changes * refactor: include integration title with source * feat: integration pagination * fix: remove unused prop * fix(nc-gui): update all tables tab btns tooltip * feat: new integration request * refactor: replace delete statement and use assigning undefined for better performance * feat(nc-gui): sync data support in project page * fix(nc-gui): all sync data type list * fix(nc-gui): close sync data modal issue * fix(nc-gui): add bg gray color on db icon of tooltip * fix(nc-gui): make connection as required field * fix(nc-gui): show connection name if not found and reload page * fix(nc-gui): show connection name in ds list * fix(nc-gui): ssl related changes * fix: oss permission * fix(nc-gui): active tab issue on clicking source * feat: include source count and sources in api response * fix(nc-gui): add getIntegration fun in useIntegrationStore * fix(nc-gui): source list udpate issue on updating source details * fix(nc-gui): fix external source icon alignment * feat: include base name and source count * fix: query correction * fix(nc-gui): show liked sources list in delete connection modal * fix(nc-gui): display connection usage information in list * fix(nc-gui): add sync data types icons * fix(nc-gui): add pagination support in connection list * fix(nc-gui): connection pagination issue * fix(nc-gui): connection tab count update issue * test(nc-gui): some of test cases updated * fix(nc-gui): some minor review changes * fix(nc-gui): minor ui changes * fix(nc-gui): Cannot read properties of undefined (reading 'sub_type') * fix(nc-gui): udpate all tables btn text * fix(nc-gui): ui changes * fix(nc-gui): overflow issue * fix(nc-gui): add connection icon & back btn in modal * fix(nc-gui): some minor ui changes * test(nc-gui): update source restriction test cases * chore(test): remove only from test * fix(nc-gui): update style of delete connection modal * test(nc-gui): update acl pw test cases * fix(test): ws collaboration role accss test fail issue * fix(nc-gui): add connection successfully added modal * fix(nc-gui): update connection added modal * fix(nc-gui): trigger sync request event on upvote * chore(nc-gui): lint * fix(nc-gui): add learn more btn in connection successfull modal * fix(nc-gui): add integration docs link support * fix(nc-gui): integration table name field text truncate issue * fix: misc corrections * misc: button width change * fix(nc-gui): update icons * fix(nc-gui): update test connection btn icons * fix(nc-gui): all tables btn gap issue * feat(nc-gui): search option in sync data modal * feat(nc-gui): search connection through api * fix(nc-gui): add base and source icon in delete connection modal * fix: update sync request event * fix(nc-gui): rebase conflict issue * fix: connections text length * fix(nc-gui): enable integration/create source supported docs option * fix(nc-gui): update advanced option header style --------- Co-authored-by: mertmit <mertmit99@gmail.com> Co-authored-by: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Co-authored-by: Raju Udava <86527202+dstala@users.noreply.github.com>
4 months ago
import type { IntegrationType, PaginatedType } from 'nocodb-sdk'
import { IntegrationsType } from 'nocodb-sdk'
import { ClientType } from '../lib/enums'
import GeneralBaseLogo from '~/components/general/BaseLogo.vue'
import type { IntegrationStoreEvents as IntegrationStoreEventsTypes } from '#imports'
enum IntegrationsPageMode {
LIST,
ADD,
EDIT,
}
const integrationType: Record<'PostgreSQL' | 'MySQL', ClientType> = {
PostgreSQL: ClientType.PG,
MySQL: ClientType.MYSQL,
}
type IntegrationsSubType = (typeof integrationType)[keyof typeof integrationType]
function defaultValues(type: IntegrationsSubType) {
const genericValues = {
payload: {},
}
switch (type) {
case integrationType.PostgreSQL:
return {
...genericValues,
type: integrationType.PostgreSQL,
title: 'PostgreSQL',
logo: h(GeneralBaseLogo, {
'source-type': 'pg',
'class': 'logo',
}),
}
case integrationType.MySQL:
return {
...genericValues,
type: integrationType.MySQL,
title: 'MySQL',
logo: h(GeneralBaseLogo, {
'source-type': 'mysql2',
'class': 'logo',
}),
}
}
}
const [useProvideIntegrationViewStore, _useIntegrationStore] = useInjectionState(() => {
const router = useRouter()
const route = router.currentRoute
const { api } = useApi()
const pageMode = ref<IntegrationsPageMode | null>(null)
const activeIntegration = ref<IntegrationType | null>(null)
const workspaceStore = useWorkspace()
const { activeWorkspaceId } = storeToRefs(workspaceStore)
const integrations = ref<IntegrationType[]>([])
const searchQuery = ref('')
const integrationPaginationData = ref<PaginatedType>({ page: 1, pageSize: 25, totalRows: 0 })
const deleteConfirmText = ref<string | null>()
const isLoadingIntegrations = ref(false)
const eventBus = useEventBus<IntegrationStoreEventsTypes>(Symbol('integrationStore'))
const { $e } = useNuxtApp()
const { t } = useI18n()
const isFromIntegrationPage = ref(false)
const successConfirmModal = ref({
isOpen: false,
title: t('msg.success.connectionAdded'),
connectionTitle: '',
description: t('msg.success.connectionAddedDesc'),
})
const requestIntegration = ref({
isOpen: false,
msg: '',
isLoading: false,
})
const activeViewTab = computed({
get() {
return (route.value.query?.tab as string) ?? 'integrations'
},
set(tab: string) {
if (requestIntegration.value.isOpen) {
requestIntegration.value.isOpen = false
}
router.push({ query: { ...route.value.query, tab } })
},
})
const loadIntegrations = async (
databaseOnly = false,
baseId = undefined,
page: number = integrationPaginationData.value.page!,
limit: number = integrationPaginationData.value.pageSize!,
) => {
try {
if (!activeWorkspaceId.value) return
isLoadingIntegrations.value = true
if (!databaseOnly && limit * (page - 1) > integrationPaginationData.value.totalRows!) {
integrationPaginationData.value.page = 1
page = 1
}
const { list, pageInfo } = await api.integration.list(
databaseOnly
? {
type: IntegrationsType.Database,
includeDatabaseInfo: true,
baseId,
}
: {
offset: limit * (page - 1),
limit,
...(searchQuery.value.trim() ? { query: searchQuery.value } : {}),
},
)
integrations.value = list
if (!databaseOnly) {
integrationPaginationData.value.totalRows = pageInfo.totalRows ?? 0
}
} catch (e) {
await message.error(await extractSdkResponseErrorMsg(e))
integrations.value = []
integrationPaginationData.value.totalRows = 0
integrationPaginationData.value.page = 1
} finally {
isLoadingIntegrations.value = false
}
}
const addIntegration = (type: IntegrationsSubType) => {
activeIntegration.value = defaultValues(type)
pageMode.value = IntegrationsPageMode.ADD
$e('c:integration:add')
}
const deleteIntegration = async (integration: IntegrationType, force = false) => {
if (!integration?.id) return
try {
await api.integration.delete(integration.id, {
query: force ? { force: 'true' } : {},
})
$e('a:integration:delete')
await loadIntegrations()
// await message.success(`Connection ${integration.title} deleted successfully`)
return true
} catch (e) {
const error = await extractSdkResponseErrorMsgv2(e)
if (error.error === NcErrorType.INTEGRATION_NOT_FOUND) {
await message.error(error.message?.replace(integration.id, integration.title!))
window.location.reload()
return
}
await message.error(await extractSdkResponseErrorMsg(e))
}
deleteConfirmText.value = null
}
const updateIntegration = async (integration: IntegrationType) => {
if (!integration.id) return
try {
await api.integration.update(integration.id, integration)
$e('a:integration:update')
await loadIntegrations()
pageMode.value = null
activeIntegration.value = null
await message.success(`Connection "${integration.title}" updated successfully`)
} catch (e) {
await message.error(await extractSdkResponseErrorMsg(e))
}
}
const saveIntegration = async (
integration: IntegrationType,
mode: 'create' | 'duplicate' = 'create',
loadDatasourceInfo = false,
baseId: string | undefined = undefined,
) => {
try {
const response = await api.integration.create(integration)
if (mode === 'create') {
$e('a:integration:create')
} else {
$e('a:integration:duplicate')
}
if (response && response?.id) {
if (!loadDatasourceInfo) {
integrations.value.push(response)
}
}
await loadIntegrations(loadDatasourceInfo, baseId)
eventBus.emit(IntegrationStoreEvents.INTEGRATION_ADD, response)
pageMode.value = null
activeIntegration.value = null
if (response?.title && mode === 'create') {
if (isFromIntegrationPage.value) {
activeViewTab.value = 'connections'
successConfirmModal.value.connectionTitle = response.title ?? ''
successConfirmModal.value.isOpen = true
} else {
await message.success(`Connection "${response.title}" created successfully`)
}
}
} catch (e) {
await message.error(await extractSdkResponseErrorMsg(e))
}
}
const duplicateIntegration = async (integration: IntegrationType) => {
if (!integration?.id) return
try {
isLoadingIntegrations.value = true
saveIntegration(
{
title: integration.title,
config: {},
type: integration.type,
copy_from_id: integration.id,
},
'duplicate',
)
} catch (e) {
await message.error(await extractSdkResponseErrorMsg(e))
} finally {
isLoadingIntegrations.value = false
}
}
const getIntegration = async (
integration: IntegrationType,
options?: {
includeConfig?: boolean
includeSources?: boolean
},
) => {
if (!integration?.id) return
try {
const integrationWithConfig = await api.integration.read(integration.id, {
...(options || {}),
})
return integrationWithConfig
} catch (e) {
const error = await extractSdkResponseErrorMsgv2(e)
if (error.error === NcErrorType.INTEGRATION_NOT_FOUND) {
await message.error(error.message?.replace(integration.id!, integration.title!))
window.location.reload()
return
}
await message.error(await extractSdkResponseErrorMsg(e))
}
}
const editIntegration = async (integration: IntegrationType) => {
if (!integration?.id) return
try {
const integrationWithConfig = await getIntegration(integration, { includeConfig: true })
activeIntegration.value = integrationWithConfig
pageMode.value = IntegrationsPageMode.EDIT
$e('c:integration:edit')
} catch {}
}
const saveIntegraitonRequest = async (msg: string) => {
if (!msg?.trim()) return
requestIntegration.value.isLoading = true
try {
$e('a:integration:new-request', {
value: requestIntegration.value.msg,
})
requestIntegration.value.isLoading = false
requestIntegration.value.isOpen = false
requestIntegration.value.msg = ''
await message.success('Your request has been successfully submitted')
} catch (e) {
requestIntegration.value.isLoading = false
await message.error(await extractSdkResponseErrorMsg(e))
}
}
return {
IntegrationsPageMode,
integrationType,
pageMode,
activeIntegration,
integrations,
isLoadingIntegrations,
deleteConfirmText,
eventBus,
requestIntegration,
integrationPaginationData,
activeViewTab,
isFromIntegrationPage,
successConfirmModal,
searchQuery,
addIntegration,
loadIntegrations,
deleteIntegration,
updateIntegration,
saveIntegration,
editIntegration,
duplicateIntegration,
saveIntegraitonRequest,
getIntegration,
}
}, 'integrations-store')
export { useProvideIntegrationViewStore }
export function useIntegrationStore() {
const integrationStore = _useIntegrationStore()
if (integrationStore == null) return useProvideIntegrationViewStore()
return integrationStore
}