Browse Source

fix(gui-v2): handle renaming of active tab

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3005/head
Pranav C 2 years ago
parent
commit
bf96039c5e
  1. 11
      packages/nc-gui-v2/composables/useTabs.ts

11
packages/nc-gui-v2/composables/useTabs.ts

@ -26,7 +26,7 @@ export function useTabs() {
const tabs = useState<TabItem[]>('tabs', () => [])
const route = useRoute()
const router = useRouter()
const { tables } = useProject()
const activeTabIndex: WritableComputedRef<number> = computed({
@ -36,6 +36,8 @@ export function useTabs() {
const id = tables.value?.find((t) => t.title === tab.title)?.id
if (!id) return -1
tab.id = id as string
let index = tabs.value.findIndex((t) => t.id === tab.id)
@ -108,7 +110,14 @@ export function useTabs() {
const updateTab = (key: number | Partial<TabItem>, newTabItemProps: Partial<TabItem>) => {
const tab = typeof key === 'number' ? tabs.value[key] : tabs.value.find(getPredicate(key))
if (tab) {
const isActive = tabs.value.indexOf(tab) === activeTabIndex.value
Object.assign(tab, newTabItemProps)
if (isActive && tab.title)
router.replace({
params: {
title: tab.title,
},
})
}
}

Loading…
Cancel
Save