From 38175509d88483b5b7c15890a428b6aea1319ee4 Mon Sep 17 00:00:00 2001 From: mertmit Date: Mon, 20 Feb 2023 16:09:36 +0300 Subject: [PATCH] fix: tab control Signed-off-by: mertmit --- packages/nc-gui/composables/useTabs.ts | 25 +++++++++++++++++-- .../pages/[projectType]/[projectId]/index.vue | 11 ++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/nc-gui/composables/useTabs.ts b/packages/nc-gui/composables/useTabs.ts index c29f118961..e60a88b1a4 100644 --- a/packages/nc-gui/composables/useTabs.ts +++ b/packages/nc-gui/composables/useTabs.ts @@ -17,6 +17,10 @@ export const useTabs = createSharedComposable(() => { const route = $(router.currentRoute) + const { t } = useI18n() + + const { isUIAllowed } = useUIPermission() + const { bases, tables } = useProject() const projectType = $computed(() => route.params.projectType as string) @@ -55,8 +59,8 @@ export const useTabs = createSharedComposable(() => { } return index - } else if (routeName.startsWith('nc-projectId-index-index-auth')) { - return tabs.value.findIndex((t) => t.type === 'auth') + } else if (routeName.startsWith('projectType-projectId-index-index-auth')) { + return tabs.value.findIndex((t) => t.type === TabType.AUTH) } // by default, it's showing Team & Auth @@ -155,5 +159,22 @@ export const useTabs = createSharedComposable(() => { } } + watch( + () => route.name, + (n, o) => { + if (n === o) return + if (!n || !/^projectType-projectId-index-index/.test(n.toString())) return + const activeTabRoute = n.toString().replace('projectType-projectId-index-index-', '') + switch (activeTabRoute) { + case TabType.AUTH: + if (isUIAllowed('teamAndAuth')) addTab({ id: TabType.AUTH, type: TabType.AUTH, title: t('title.teamAndAuth') }) + break + default: + break + } + }, + { immediate: true }, + ) + return { tabs, addTab, activeTabIndex, activeTab, clearTabs, closeTab, updateTab } }) diff --git a/packages/nc-gui/pages/[projectType]/[projectId]/index.vue b/packages/nc-gui/pages/[projectType]/[projectId]/index.vue index cf00edd2dc..759c0bdee8 100644 --- a/packages/nc-gui/pages/[projectType]/[projectId]/index.vue +++ b/packages/nc-gui/pages/[projectType]/[projectId]/index.vue @@ -164,8 +164,6 @@ onKeyStroke( { eventName: 'keydown' }, ) -clearTabs() - onBeforeMount(async () => { try { await loadProject() @@ -179,8 +177,8 @@ onBeforeMount(async () => { message.error(await extractSdkResponseErrorMsg(e)) } - if (!route.params.type && isUIAllowed('teamAndAuth')) { - addTab({ type: TabType.AUTH, title: t('title.teamAndAuth') }) + if (route.name === 'projectType-projectId-index-index' && isUIAllowed('teamAndAuth')) { + addTab({ id: TabType.AUTH, type: TabType.AUTH, title: t('title.teamAndAuth') }) } /** If v1 url found navigate to corresponding new url */ @@ -195,7 +193,10 @@ onMounted(() => { toggleHasSidebar(true) }) -onBeforeUnmount(reset) +onBeforeUnmount(() => { + clearTabs() + reset() +}) function openKeyboardShortcutDialog() { $e('a:actions:keyboard-shortcut')