Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

feat: use table and view name in url as slug

Ramesh Mane6816d5e74f7f
diff --git a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
index 274c2fd8e8..a74b10edc3 100644
--- a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
+++ b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
@@ -319,6 +319,7 @@ async function onDuplicate() {
navigateToView({
view,
tableId: table.value!.id!,
+ tableTitle: table.value.title,
baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM,
})
diff --git a/packages/nc-gui/components/dashboard/TreeView/Views/List.vue b/packages/nc-gui/components/dashboard/TreeView/Views/List.vue
index 7122a7f160..c39ad93160 100644
--- a/packages/nc-gui/components/dashboard/TreeView/Views/List.vue
+++ b/packages/nc-gui/components/dashboard/TreeView/Views/List.vue
@@ -208,6 +208,7 @@ async function changeView(view: ViewType) {
await navigateToView({
view,
tableId: table.value.id!,
+ tableTitle: table.value.title,
baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
doNotSwitchTab: true,
@@ -229,6 +230,7 @@ async function onRename(view: ViewType, originalTitle?: string, undo = false) {
navigateToView({
view,
tableId: table.value.id!,
+ tableTitle: table.value.title,
baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
})
@@ -358,6 +360,7 @@ function onOpenModal({
navigateToView({
view,
tableId: table.value.id!,
+ tableTitle: table.value.title,
baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
})
diff --git a/packages/nc-gui/components/smartsheet/details/Fields.vue b/packages/nc-gui/components/smartsheet/details/Fields.vue
index 84cb0cf8d1..bdf744ea96 100644
--- a/packages/nc-gui/components/smartsheet/details/Fields.vue
+++ b/packages/nc-gui/components/smartsheet/details/Fields.vue
@@ -1312,7 +1312,7 @@ const rightPanelWidth = computed(() => {
})
const confirmUnsavedChangesBeforeLeaving = (from: RouteLocationNormalizedLoadedGeneric, next: NavigationGuardNext) => {
- if (!hasUnsavedChanges.value || !(ncIsArray(from.params?.slugs) && from.params?.slugs?.includes('field'))) {
+ if (!hasUnsavedChanges.value || !(ncIsArray(from.params?.slugs) && from.params?.slugs?.[1] === 'field')) {
next()
return
}
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
index a02a744b75..9cf496319a 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
@@ -143,6 +143,7 @@ async function onDuplicate() {
navigateToView({
view: duplicatedView,
tableId: table.value!.id!,
+ tableTitle: table.value.title,
baseId: base.value.id!,
hardReload: duplicatedView.type === ViewTypes.FORM,
})
diff --git a/packages/nc-gui/components/smartsheet/topbar/ViewListDropdown.vue b/packages/nc-gui/components/smartsheet/topbar/ViewListDropdown.vue
index 4532105cab..b1b6b6c68f 100644
--- a/packages/nc-gui/components/smartsheet/topbar/ViewListDropdown.vue
+++ b/packages/nc-gui/components/smartsheet/topbar/ViewListDropdown.vue
@@ -48,6 +48,7 @@ const handleNavigateToView = async (view: ViewType) => {
await navigateToView({
view,
tableId: activeTable.value.id!,
+ tableTitle: activeTable.value?.title,
baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM && activeView.value?.id === view.id,
doNotSwitchTab: true,
diff --git a/packages/nc-gui/composables/useTableNew.ts b/packages/nc-gui/composables/useTableNew.ts
index ea9330ac3c..8d24c76f14 100644
--- a/packages/nc-gui/composables/useTableNew.ts
+++ b/packages/nc-gui/composables/useTableNew.ts
@@ -37,7 +37,7 @@ export function useTableNew(param: {
const { loadTables, baseUrl, isXcdbBase } = useBase()
- const { loadViews } = useViewsStore()
+ const { loadViews, getViewReadableUrlSlug } = useViewsStore()
const { openedViewsTab, viewsByTable } = storeToRefs(useViewsStore())
@@ -93,9 +93,9 @@ export function useTableNew(param: {
const defaultView = views.find((v) => v.is_default) || views[0]
await navigateTo(
- `${cmdOrCtrl ? '#' : ''}/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${defaultView.id}/${
- openedViewsTab.value
- }`,
+ `${cmdOrCtrl ? '#' : ''}/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${
+ defaultView.id
+ }/${getViewReadableUrlSlug({ tableTitle: table.title, viewOrViewTitle: defaultView })}}/${openedViewsTab.value}`,
cmdOrCtrl
? {
open: navigateToBlankTargetOpenOption,
diff --git a/packages/nc-gui/store/views.ts b/packages/nc-gui/store/views.ts
index 98125b2045..699cf7631e 100644
--- a/packages/nc-gui/store/views.ts
+++ b/packages/nc-gui/store/views.ts
@@ -98,10 +98,10 @@ export const useViewsStore = defineStore('viewsStore', () => {
const openedViewsTab = computed<ViewPageType>(() => {
// For types in ViewPageType type
- if (!route.value.params?.slugs || route.value.params.slugs?.length === 0) return 'view'
+ if (!route.value.params?.slugs || route.value.params.slugs?.length <= 1) return 'view'
- if (['field', 'permissions', 'relation', 'api', 'webhook'].includes(route.value.params.slugs[0] as ViewPageType)) {
- return route.value.params.slugs[0] as ViewPageType
+ if (['field', 'permissions', 'relation', 'api', 'webhook'].includes(route.value.params.slugs[1] as ViewPageType)) {
+ return route.value.params.slugs[1] as ViewPageType
}
return 'view'
@@ -138,6 +138,16 @@ export const useViewsStore = defineStore('viewsStore', () => {
},
})
+ const activeViewUrlSlug = computed(() => {
+ return route.value.params.slugs?.[0] || ''
+ })
+
+ const activeViewReadableUrlSlug = computed(() => {
+ if (sharedView.value || !activeView.value) return ''
+
+ return getViewReadableUrlSlug({ tableTitle: activeTable.value?.title, viewOrViewTitle: activeView.value })
+ })
+
const isActiveViewLocked = computed(() => activeView.value?.lock_type === 'locked')
const isLockedView = computed(() => activeView.value?.lock_type === 'locked')
@@ -180,12 +190,14 @@ export const useViewsStore = defineStore('viewsStore', () => {
view,
baseId,
tableId,
+ tableTitle,
hardReload,
doNotSwitchTab,
}: {
view: ViewType
baseId: string
tableId: string
+ tableTitle?: string
hardReload?: boolean
doNotSwitchTab?: boolean
}) => {
@@ -199,7 +211,11 @@ export const useViewsStore = defineStore('viewsStore', () => {
baseIdOrBaseId = route.value.params.baseId as string
}
- const slugs = doNotSwitchTab ? router.currentRoute.value.params.slugs : undefined
+ const slugs = doNotSwitchTab ? router.currentRoute.value.params.slugs || [] : []
+
+ if (ncIsArray(slugs)) {
+ ;(slugs as string[])[0] = getViewReadableUrlSlug({ tableTitle, viewOrViewTitle: view })
+ }
if (
router.currentRoute.value.query &&
@@ -585,7 +601,7 @@ export const useViewsStore = defineStore('viewsStore', () => {
baseId: route.value.params.baseId,
viewId: route.value.params.viewId,
viewTitle: activeViewTitleOrId.value,
- slugs: [page],
+ slugs: [activeViewReadableUrlSlug.value, page],
},
})
}
@@ -769,6 +785,12 @@ export const useViewsStore = defineStore('viewsStore', () => {
}
}
+ function getViewReadableUrlSlug({ tableTitle, viewOrViewTitle }: { tableTitle?: string; viewOrViewTitle: ViewType | string }) {
+ const viewTitle = ncIsObject(viewOrViewTitle) ? (viewOrViewTitle.is_default ? '' : viewOrViewTitle.title) : viewOrViewTitle
+
+ return toReadableUrlSlug([tableTitle, viewTitle])
+ }
+
watch(
() => tablesStore.activeTableId,
async (newId, oldId) => {
@@ -826,6 +848,35 @@ export const useViewsStore = defineStore('viewsStore', () => {
},
)
+ watch(
+ [activeViewReadableUrlSlug, activeViewUrlSlug],
+ ([newactiveViewReadableUrlSlug]) => {
+ if (!newactiveViewReadableUrlSlug || activeViewUrlSlug.value === newactiveViewReadableUrlSlug) return
+
+ const slugs = (route.value.params.slugs as string[]) || []
+
+ const newSlug = [newactiveViewReadableUrlSlug]
+
+ if (slugs.length > 1) {
+ newSlug.push(...slugs.slice(1))
+ }
+
+ router.replace({
+ name: 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs',
+ params: {
+ ...route.value.params,
+ viewTitle: route.value.params.viewTitle || activeView.value?.id,
+ slugs: newSlug,
+ },
+ force: true,
+ })
+ },
+ {
+ immediate: true,
+ flush: 'post',
+ },
+ )
+
refreshViewTabTitle.on(() => {
updateTabTitle()
})
@@ -867,6 +918,7 @@ export const useViewsStore = defineStore('viewsStore', () => {
setCurrentViewExpandedFormMode,
setCurrentViewExpandedFormAttachmentColumn,
onOpenViewCreateModal,
+ getViewReadableUrlSlug,
}
})
diff --git a/packages/nc-gui/store/webhooks.ts b/packages/nc-gui/store/webhooks.ts
index 95c9d9add5..dfdff087d7 100644
--- a/packages/nc-gui/store/webhooks.ts
+++ b/packages/nc-gui/store/webhooks.ts
@@ -8,10 +8,6 @@ export const useWebhooksStore = defineStore('webhooksStore', () => {
const { $api, $e } = useNuxtApp()
- const router = useRouter()
-
- const route = router.currentRoute
-
const { getMeta } = useMetas()
const { activeTable } = toRefs(useTablesStore())
@@ -19,18 +15,6 @@ export const useWebhooksStore = defineStore('webhooksStore', () => {
return hooks.value.some((hook) => hook.version === 'v2')
})
- const createWebhookUrl = computed(() => {
- return navigateToWebhookRoute({
- openCreatePage: true,
- })
- })
-
- const webhookMainUrl = computed(() => {
- return navigateToWebhookRoute({
- openMainPage: true,
- })
- })
-
async function loadHooksList() {
isHooksLoading.value = true
try {
@@ -178,64 +162,13 @@ export const useWebhooksStore = defineStore('webhooksStore', () => {
return hook
}
- function navigateToWebhookRoute({
- hookId,
- openCreatePage,
- openMainPage,
- }: {
- hookId?: string
- openCreatePage?: Boolean
- openMainPage?: Boolean
- }) {
- const { activeView } = useViewsStore()
- if (!activeView) throw new Error('activeView is not defined')
-
- if (!openMainPage && !openCreatePage && !hookId) throw new Error('hook id is not defined')
-
- return {
- name: 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs',
- params: {
- typeOrId: route.value.params.typeOrId,
- baseId: route.value.params.baseId,
- viewId: route.value.params.viewId,
- viewTitle: activeView.id,
- slugs: openMainPage ? ['webhook'] : ['webhook', openCreatePage ? 'create' : hookId!],
- },
- }
- }
-
- const navigateToWebhook = async ({
- hookId,
- openCreatePage,
- openMainPage,
- }: {
- hookId?: string
- openCreatePage?: Boolean
- openMainPage?: Boolean
- }) => {
- const { activeView } = useViewsStore()
- if (!activeView) return
-
- await router.push(
- navigateToWebhookRoute({
- hookId,
- openCreatePage,
- openMainPage,
- }),
- )
- }
-
return {
hooks,
loadHooksList,
deleteHook,
copyHook,
saveHooks,
- navigateToWebhook,
- createWebhookUrl,
- webhookMainUrl,
isHooksLoading,
- navigateToWebhookRoute,
hasV2Webhooks,
}
})
diff --git a/packages/nc-gui/utils/urlUtils.ts b/packages/nc-gui/utils/urlUtils.ts
index e3546202d2..1329d58606 100644
--- a/packages/nc-gui/utils/urlUtils.ts
+++ b/packages/nc-gui/utils/urlUtils.ts
@@ -296,3 +296,43 @@ export const extractYoutubeVideoId = (url: string) => {
return ''
}
+
+/**
+ * Converts an array of strings into a URL-safe slug.
+ *
+ * - Each part is trimmed and internal spaces are replaced with a single dash (`-`).
+ * - Existing dashes are preserved as-is.
+ * - Special characters are URL-encoded using `encodeURIComponent`.
+ * - Parts that are empty or only whitespace are ignored.
+ * - All output is lowercased.
+ * - The final slug is created by joining all parts with a dash (`-`).
+ *
+ * @example
+ * ```ts
+ * toReadableUrlSlug(['Feature Table', 'Default View']);
+ * // "feature-table-default-view"
+ *
+ * toReadableUrlSlug(['Orders-Invoices', 'Grid View']);
+ * // "orders-invoices-grid-view"
+ *
+ * toReadableUrlSlug(['User Activity', 'Calendar - View']);
+ * // "user-activity-calendar--view"
+ * ```
+ *
+ * @param parts - Array of strings (e.g., tableName, viewName) to be combined into a slug.
+ * @returns A URL-safe slug string, or an empty string if no valid parts are provided.
+ */
+export function toReadableUrlSlug(parts: (string | undefined)[] = []): string {
+ return (
+ parts
+ .map((part) => {
+ if (!part?.trim()) return ''
+
+ return encodeURIComponent(
+ part.trim().replace(/\s+/g, '-'), // replace one or more spaces with a single dash
+ ).toLowerCase()
+ })
+ .filter(Boolean) // remove empty parts
+ .join('-') ?? ''
+ )
+}