mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-02 10:37:22 +00:00
* feat: integration hooks * feat: data reflection * feat: improved UX for data reflection * chore: lint * fix(nc-gui): update nocodb integration ui * fix(nocodb): type error * fix(nc-gui): nocodb integration icon and modal gap issue * fix: defer integration hooks * fix: check proper state * refactor(nc-gui): integration modal * refactor(nc-gui): integration modal ui changes * refactor: change default port * fix(nc-gui): add base id copy input * fix(nc-gui): schema dropdown placement and item height issue * fix(nc-gui): nocodb connection bg color issue * fix(nc-gui): update nocodb integration count and user logo * fix: rspack keep class * feat: get connection menu item * chore: rebase issue * fix: hide nc from sources * feat: move data reflection to model level * fix: remove deprecated fn & fix type errors * feat: reflection settings * feat: feature flag for data reflection * refactor: avoid save on feature flags * fix: properly show host * fix: PR requested changes * fix: use named parameters for queries --------- Co-authored-by: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com>
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
export function useDataReflection() {
|
|
const { appInfo } = useGlobal()
|
|
|
|
const { $api } = useNuxtApp()
|
|
|
|
const { activeWorkspace } = storeToRefs(useWorkspace())
|
|
|
|
const connectionDetails = ref()
|
|
|
|
const selectedBase = ref<string>()
|
|
|
|
const dataReflectionEnabled = computed(() => activeWorkspace.value?.data_reflection_enabled)
|
|
|
|
const connectionHost = computed(
|
|
() => connectionDetails.value?.host || (appInfo.value.ncSiteUrl ? `${new URL(appInfo.value.ncSiteUrl).hostname}` : ''),
|
|
)
|
|
|
|
const connectionUrl = computed(() => {
|
|
return `postgresql://${connectionDetails.value.username}:${connectionDetails.value.password}@${connectionHost.value}:${
|
|
connectionDetails.value.port
|
|
}/${connectionDetails.value.database}${
|
|
selectedBase.value ? `?options=-c%20search_path%3D${encodeURIComponent(selectedBase.value)}` : ''
|
|
}`
|
|
})
|
|
|
|
const getConnectionDetails = async (baseId?: string) => {
|
|
if (!activeWorkspace.value?.id) return
|
|
|
|
const res = await $api.internal.getOperation(activeWorkspace.value.id, NO_SCOPE, {
|
|
operation: 'getDataReflection',
|
|
})
|
|
|
|
if (baseId) {
|
|
selectedBase.value = baseId
|
|
}
|
|
|
|
return (connectionDetails.value = res)
|
|
}
|
|
|
|
const createConnectionDetails = async (baseId?: string) => {
|
|
if (!activeWorkspace.value?.id) return
|
|
|
|
try {
|
|
const res = await $api.internal.postOperation(
|
|
activeWorkspace.value.id,
|
|
NO_SCOPE,
|
|
{
|
|
operation: 'createDataReflection',
|
|
},
|
|
{},
|
|
)
|
|
|
|
if (baseId) {
|
|
selectedBase.value = baseId
|
|
}
|
|
|
|
connectionDetails.value = res
|
|
;(activeWorkspace.value as any).data_reflection_enabled = true
|
|
} catch (e) {
|
|
message.error(await extractSdkResponseErrorMsg(e))
|
|
}
|
|
|
|
return connectionDetails.value
|
|
}
|
|
|
|
const deleteConnectionDetails = async () => {
|
|
if (!activeWorkspace.value?.id) return
|
|
|
|
try {
|
|
await $api.internal.postOperation(
|
|
activeWorkspace.value.id,
|
|
NO_SCOPE,
|
|
{
|
|
operation: 'deleteDataReflection',
|
|
},
|
|
{},
|
|
)
|
|
connectionDetails.value = null
|
|
;(activeWorkspace.value as any).data_reflection_enabled = false
|
|
} catch (e) {
|
|
message.error(await extractSdkResponseErrorMsg(e))
|
|
}
|
|
}
|
|
|
|
return {
|
|
connectionUrl,
|
|
connectionHost,
|
|
connectionDetails,
|
|
selectedBase,
|
|
dataReflectionEnabled,
|
|
getConnectionDetails,
|
|
createConnectionDetails,
|
|
deleteConnectionDetails,
|
|
}
|
|
}
|