Browse Source

fix: custom url with prefill form query param support

nc-feat/custom-url-support-for-shared-base-view
Ramesh Mane 1 day ago
parent
commit
4de6b084b8
  1. 3
      packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
  2. 14
      packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index.vue
  3. 63
      packages/nocodb/src/services/views.service.ts

3
packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue

@ -292,7 +292,8 @@ async function updateSharedView(custUrl = undefined) {
const res = await $api.dbViewShare.update(activeView.value.id!, { const res = await $api.dbViewShare.update(activeView.value.id!, {
meta, meta,
password: activeView.value.password, password: activeView.value.password,
...(custUrl !== undefined ? { custom_url_path: custUrl ?? null, original_url: sharedViewUrl(false) } : {}), original_url: sharedViewUrl(false),
...(custUrl !== undefined ? { custom_url_path: custUrl ?? null } : {}),
}) })
if (custUrl !== undefined) { if (custUrl !== undefined) {

14
packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index.vue

@ -13,9 +13,19 @@ onMounted(() => {
const shouldRedirect = (to: string) => { const shouldRedirect = (to: string) => {
if (sharedViewMeta.value.surveyMode) { if (sharedViewMeta.value.surveyMode) {
if (!to.includes('survey')) navigateTo(`/nc/form/${route.params.viewId}/survey`) if (!to.includes('survey')) {
navigateTo({
path: `/nc/form/${route.params.viewId}/survey`,
query: route.query,
})
}
} else { } else {
if (to.includes('survey')) navigateTo(`/nc/form/${route.params.viewId}`) if (to.includes('survey')) {
navigateTo({
path: `/nc/form/${route.params.viewId}`,
query: route.query,
})
}
} }
} }

63
packages/nocodb/src/services/views.service.ts

@ -278,38 +278,45 @@ export class ViewsService {
NcError.viewNotFound(param.viewId); NcError.viewNotFound(param.viewId);
} }
let customUrl: CustomUrl | undefined; let customUrl: CustomUrl | undefined = await CustomUrl.get({
view_id: view.id,
id: view.fk_custom_url_id,
});
if (param.sharedView.custom_url_path !== undefined) { // Update an existing custom URL if it exists
customUrl = await CustomUrl.get({ if (customUrl?.id) {
view_id: view.id, if (param.sharedView.custom_url_path || param.sharedView.original_url) {
id: view.fk_custom_url_id, // Prepare updated fields conditionally
}); const updates: Partial<CustomUrl> = {};
if (param.sharedView.custom_url_path !== undefined) {
updates.custom_path = param.sharedView.custom_url_path;
}
if (customUrl?.id) { if (customUrl.original_path !== param.sharedView.original_url) {
if (param.sharedView.custom_url_path) { updates.original_path = param.sharedView.original_url;
await CustomUrl.update(view.fk_custom_url_id, {
custom_path: param.sharedView.custom_url_path,
...(customUrl.original_path !== param.sharedView.original_url
? {
original_path: param.sharedView.original_url,
}
: {}),
});
} else {
await CustomUrl.delete({ id: view.fk_custom_url_id as string });
customUrl = undefined;
} }
} else if (param.sharedView.custom_url_path) {
customUrl = await CustomUrl.insert({ // Perform the update if there are changes
fk_workspace_id: view.fk_workspace_id, if (Object.keys(updates).length > 0) {
base_id: view.base_id, await CustomUrl.update(view.fk_custom_url_id, updates);
fk_model_id: view.fk_model_id, }
view_id: view.id, } else if (param.sharedView.custom_url_path !== undefined) {
original_path: param.sharedView.original_url, // Delete the custom URL if only the custom path is undefined
custom_path: param.sharedView.custom_url_path, await CustomUrl.delete({ id: view.fk_custom_url_id as string });
}); customUrl = undefined;
} }
} else if (param.sharedView.custom_url_path) {
// Insert a new custom URL if it doesn't exist
customUrl = await CustomUrl.insert({
fk_workspace_id: view.fk_workspace_id,
base_id: view.base_id,
fk_model_id: view.fk_model_id,
view_id: view.id,
original_path: param.sharedView.original_url,
custom_path: param.sharedView.custom_url_path,
});
} }
const result = await View.update(context, param.viewId, { const result = await View.update(context, param.viewId, {

Loading…
Cancel
Save