From 6b2c5a59e29e37ae4dbf1cf39acc28a675fa6243 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 26 Nov 2024 05:46:56 +0000 Subject: [PATCH] fix(nc-gui): custom url support in shared base --- .../dlg/share-and-collaborate/ShareBase.vue | 45 ++++++++++++---- .../dlg/share-and-collaborate/SharePage.vue | 2 +- .../controllers/shared-bases.controller.ts | 2 + packages/nocodb/src/models/Base.ts | 2 + packages/nocodb/src/models/View.ts | 3 +- packages/nocodb/src/schema/swagger-v2.json | 18 ++++++- packages/nocodb/src/schema/swagger.json | 14 ++++- .../src/services/shared-bases.service.ts | 52 ++++++++++++++++++- 8 files changed, 123 insertions(+), 15 deletions(-) diff --git a/packages/nc-gui/components/dlg/share-and-collaborate/ShareBase.vue b/packages/nc-gui/components/dlg/share-and-collaborate/ShareBase.vue index d171ce9a11..f5c9ef077d 100644 --- a/packages/nc-gui/components/dlg/share-and-collaborate/ShareBase.vue +++ b/packages/nc-gui/components/dlg/share-and-collaborate/ShareBase.vue @@ -3,6 +3,7 @@ interface ShareBase { uuid?: string url?: string role?: string + fk_custom_url_id?: string } enum ShareBaseRole { @@ -14,6 +15,8 @@ const { dashboardUrl } = useDashboard() const { $api, $e } = useNuxtApp() +const { copy } = useCopy() + const sharedBase = ref(null) const { base } = storeToRefs(useBase()) @@ -22,18 +25,21 @@ const { getBaseUrl, appInfo } = useGlobal() const workspaceStore = useWorkspace() -const url = computed(() => { - if (!sharedBase.value || !sharedBase.value.uuid) return '' - +const dashboardBaseUrl = computed(() => { // get base url for workspace const baseUrl = getBaseUrl(workspaceStore.activeWorkspaceId) - let dashboardUrl1 = dashboardUrl.value - if (baseUrl) { - dashboardUrl1 = `${baseUrl}${appInfo.value?.dashboardPath}` + return `${baseUrl}${appInfo.value?.dashboardPath}` } - return encodeURI(`${dashboardUrl1}#/base/${sharedBase.value.uuid}`) + + return dashboardUrl.value +}) + +const url = computed(() => { + if (!sharedBase.value || !sharedBase.value.uuid) return '' + + return encodeURI(`${dashboardBaseUrl.value}#/base/${sharedBase.value.uuid}`) }) const loadBase = async () => { @@ -46,24 +52,32 @@ const loadBase = async () => { uuid: res.uuid, url: res.url, role: res.roles, + fk_custom_url_id: res?.fk_custom_url_id, } } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) } } -const createShareBase = async (role = ShareBaseRole.Viewer) => { +const createShareBase = async (role = ShareBaseRole.Viewer, custUrl = undefined) => { try { if (!base.value.id) return const res = await $api.base.sharedBaseUpdate(base.value.id, { roles: role, + original_url: url.value, + ...(custUrl !== undefined ? { custom_url_path: custUrl ?? null } : {}), }) sharedBase.value = res ?? {} sharedBase.value!.role = role base.value.uuid = res.uuid + + if (custUrl !== undefined) { + sharedBase.value!.fk_custom_url_id = res.fk_custom_url_id + base.value.fk_custom_url_id = res.fk_custom_url_id + } } catch (e: any) { message.error(await extractSdkResponseErrorMsg(e)) } @@ -126,6 +140,10 @@ const onRoleToggle = async () => { isRoleToggleLoading.value = false } } + +const copyCustomUrl = async (custUrl = '') => { + return await copy(`${dashboardBaseUrl.value}#/p/${encodeURIComponent(custUrl)}`) +}