Something went wrong. Try again.
🔥 🔥 🔥 A Free & Self-hostable Airtable Alternative nocodb.com
Something went wrong. Try again.
3.2 kB · 131 lines
TypeScript
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132import { ProjectTypes } from 'nocodb-sdk'
export const useCopySharedBase = createSharedComposable(() => { const workspaceStore = useWorkspace()
const { populateWorkspace } = workspaceStore
const sharedBaseId = ref<string | null>(null)
const isDuplicateDlgOpen = ref(false)
const selectedWorkspace = ref<string>()
const isUseThisTemplate = ref(false)
const templateName = ref<string>('')
const isLoading = ref(false)
const options = ref({ includeData: true, includeViews: true, })
const optionsToExclude = computed(() => { const { includeData, includeViews } = options.value
return { excludeData: !includeData, excludeViews: !includeViews, } })
const { api } = useApi()
const { $e, $poller } = useNuxtApp()
const { ncNavigateTo } = useGlobal()
const { t } = useI18n()
const duplicateSharedBase = async ({ workspaceId, onComplete = (_status: 'success' | 'error') => undefined, failedToastMessage = isUseThisTemplate.value ? t('msg.error.failedToCopyTemplate') : t('msg.error.failedToDuplicateSharedBase'), }: { workspaceId: string onComplete?: (status: 'success' | 'error') => void failedToastMessage?: string }) => { if (!workspaceId && isEeUI) return
isLoading.value = true
try { const jobData = await api.base.duplicateShared(workspaceId ?? 'nc', sharedBaseId.value, { options: optionsToExclude.value, base: isEeUI ? { fk_workspace_id: workspaceId, type: ProjectTypes.DATABASE, } : {}, })
sharedBaseId.value = null
$poller.subscribe( { id: jobData.id }, async (data: { id: string status?: string data?: { error?: { message: string } message?: string result?: any } }) => { if (data.status !== 'close') { if (data.status === JobStatus.COMPLETED) { ncNavigateTo({ ...(isEeUI ? { workspaceId: jobData.fk_workspace_id } : {}), baseId: jobData.base_id, query: { openTable: 'true', }, }) isLoading.value = false onComplete?.('success') } else if (data.status === JobStatus.FAILED) { message.error(failedToastMessage) await populateWorkspace().catch(() => { // ignore }) isLoading.value = false onComplete?.('error') } } }, )
if (isUseThisTemplate.value) { $e('a:templates:use-this-template', { templateName: templateName.value, }) } else { $e('a:base:duplicate-shared-base') } } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) isLoading.value = false onComplete?.('error') } }
return { sharedBaseId, isUseThisTemplate, isLoading, options, optionsToExclude, duplicateSharedBase, isDuplicateDlgOpen, selectedWorkspace, templateName, }})