Browse Source

feat(nc-gui): open base/table/view in new tab on pressing cltr & cliking on then

pull/7818/head
Ramesh Mane 9 months ago
parent
commit
e68b313126
  1. 23
      packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue
  2. 9
      packages/nc-gui/components/dashboard/TreeView/TableNode.vue
  3. 31
      packages/nc-gui/composables/useTableNew.ts
  4. 79
      packages/nc-gui/store/views.ts
  5. 8
      packages/nc-gui/utils/urlUtils.ts

23
packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue

@ -32,6 +32,8 @@ import {
useTablesStore, useTablesStore,
useTabs, useTabs,
useToggle, useToggle,
useMagicKeys,
navigateToBlankTargetOpenOption,
} from '#imports' } from '#imports'
import type { NcProject } from '#imports' import type { NcProject } from '#imports'
@ -71,6 +73,8 @@ const { orgRoles, isUIAllowed } = useRoles()
useTabs() useTabs()
const { meta: metaKey, ctrlKey } = useMagicKeys()
const editMode = ref(false) const editMode = ref(false)
const tempTitle = ref('') const tempTitle = ref('')
@ -253,12 +257,29 @@ const onProjectClick = async (base: NcProject, ignoreNavigation?: boolean, toggl
if (!base) { if (!base) {
return return
} }
const cmdOrCtrl = isMac() ? metaKey.value : ctrlKey.value
if (!toggleIsExpanded) $e('c:base:open') if (!toggleIsExpanded && !cmdOrCtrl) $e('c:base:open')
ignoreNavigation = isMobileMode.value || ignoreNavigation ignoreNavigation = isMobileMode.value || ignoreNavigation
toggleIsExpanded = isMobileMode.value || toggleIsExpanded toggleIsExpanded = isMobileMode.value || toggleIsExpanded
if (cmdOrCtrl && !ignoreNavigation) {
await navigateTo(
`${cmdOrCtrl ? '#' : ''}${baseUrl({
id: base.id!,
type: 'database',
isSharedBase: isSharedBase.value,
})}`,
cmdOrCtrl
? {
open: navigateToBlankTargetOpenOption,
}
: undefined,
)
return
}
if (toggleIsExpanded) { if (toggleIsExpanded) {
base.isExpanded = !base.isExpanded base.isExpanded = !base.isExpanded
} else { } else {

9
packages/nc-gui/components/dashboard/TreeView/TableNode.vue

@ -4,7 +4,7 @@ import { toRef } from '@vue/reactivity'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { ProjectRoleInj, TreeViewInj, useNuxtApp, useRoles, useTabs } from '#imports' import { ProjectRoleInj, TreeViewInj, useNuxtApp, useRoles, useTabs, useMagicKeys } from '#imports'
import type { SidebarTableNode } from '~/lib' import type { SidebarTableNode } from '~/lib'
const props = withDefaults( const props = withDefaults(
@ -39,6 +39,8 @@ useTableNew({
baseId: base.value.id!, baseId: base.value.id!,
}) })
const { meta: metaKey, ctrlKey } = useMagicKeys()
const baseRole = inject(ProjectRoleInj) const baseRole = inject(ProjectRoleInj)
provide(SidebarTableInj, table) provide(SidebarTableInj, table)
@ -106,6 +108,11 @@ const onExpand = async () => {
} }
const onOpenTable = async () => { const onOpenTable = async () => {
if (isMac() ? metaKey.value : ctrlKey.value) {
await _openTable(table.value, true)
return
}
isLoading.value = true isLoading.value = true
try { try {
await _openTable(table.value) await _openTable(table.value)

31
packages/nc-gui/composables/useTableNew.ts

@ -19,6 +19,8 @@ import {
useNuxtApp, useNuxtApp,
useTabs, useTabs,
watch, watch,
useMagicKeys,
navigateToBlankTargetOpenOption,
} from '#imports' } from '#imports'
export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => void; baseId: string; sourceId?: string }) { export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => void; baseId: string; sourceId?: string }) {
@ -60,7 +62,7 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
const tables = computed(() => baseTables.value.get(param.baseId) || []) const tables = computed(() => baseTables.value.get(param.baseId) || [])
const base = computed(() => bases.value.get(param.baseId)) const base = computed(() => bases.value.get(param.baseId))
const openTable = async (table: SidebarTableNode) => { const openTable = async (table: SidebarTableNode, cmdOrCtrl: boolean = false) => {
if (!table.base_id) return if (!table.base_id) return
let base = bases.value.get(table.base_id) let base = bases.value.get(table.base_id)
@ -86,7 +88,14 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
const navigateToTable = async () => { const navigateToTable = async () => {
if (openedViewsTab.value === 'view') { if (openedViewsTab.value === 'view') {
await navigateTo(`/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`) await navigateTo(
`${cmdOrCtrl ? '#' : ''}/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`,
cmdOrCtrl
? {
open: navigateToBlankTargetOpenOption,
}
: undefined,
)
} }
table.isViewsLoading = true table.isViewsLoading = true
@ -99,7 +108,16 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
// find the default view and navigate to it, if not found navigate to the first one // find the default view and navigate to it, if not found navigate to the first one
const defaultView = views.find((v) => v.is_default) || views[0] const defaultView = views.find((v) => v.is_default) || views[0]
await navigateTo(`/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${defaultView.id}/${openedViewsTab.value}`) await navigateTo(
`${cmdOrCtrl ? '#' : ''}/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${defaultView.id}/${
openedViewsTab.value
}`,
cmdOrCtrl
? {
open: navigateToBlankTargetOpenOption,
}
: undefined,
)
} }
} catch (e) { } catch (e) {
console.error(e) console.error(e)
@ -119,8 +137,11 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
table.isMetaLoading = false table.isMetaLoading = false
} }
} }
if (cmdOrCtrl) {
await Promise.all([navigateToTable(), loadTableMeta()]) await navigateToTable()
} else {
await Promise.all([navigateToTable(), loadTableMeta()])
}
} }
const createTable = async () => { const createTable = async () => {

79
packages/nc-gui/store/views.ts

@ -1,6 +1,7 @@
import type { FilterType, SortType, ViewType, ViewTypes } from 'nocodb-sdk' import type { FilterType, SortType, ViewType, ViewTypes } from 'nocodb-sdk'
import { acceptHMRUpdate, defineStore } from 'pinia' import { acceptHMRUpdate, defineStore } from 'pinia'
import type { ViewPageType } from '~/lib' import type { ViewPageType } from '~/lib'
import { useMagicKeys, navigateToBlankTargetOpenOption } from '#imports'
export const useViewsStore = defineStore('viewsStore', () => { export const useViewsStore = defineStore('viewsStore', () => {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
@ -27,6 +28,8 @@ export const useViewsStore = defineStore('viewsStore', () => {
const { activeWorkspaceId } = storeToRefs(useWorkspace()) const { activeWorkspaceId } = storeToRefs(useWorkspace())
const { meta: metaKey, ctrlKey } = useMagicKeys()
const recentViews = computed<RecentView[]>(() => const recentViews = computed<RecentView[]>(() =>
allRecentViews.value.filter((f) => f.workspaceId === activeWorkspaceId.value).splice(0, 10), allRecentViews.value.filter((f) => f.workspaceId === activeWorkspaceId.value).splice(0, 10),
) )
@ -216,6 +219,8 @@ export const useViewsStore = defineStore('viewsStore', () => {
hardReload?: boolean hardReload?: boolean
doNotSwitchTab?: boolean doNotSwitchTab?: boolean
}) => { }) => {
const cmdOrCtrl = isMac() ? metaKey.value : ctrlKey.value
const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs' const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs'
let baseIdOrBaseId = baseId let baseIdOrBaseId = baseId
@ -231,29 +236,63 @@ export const useViewsStore = defineStore('viewsStore', () => {
router.currentRoute.value.query.page && router.currentRoute.value.query.page &&
router.currentRoute.value.query.page === 'fields' router.currentRoute.value.query.page === 'fields'
) { ) {
await router.push({ if (cmdOrCtrl) {
name: routeName, await navigateTo(
params: { router.resolve({
viewTitle: view.id || '', name: routeName,
viewId: tableId, params: {
baseId: baseIdOrBaseId, viewTitle: view.id || '',
slugs, viewId: tableId,
}, baseId: baseIdOrBaseId,
query: router.currentRoute.value.query, slugs,
}) },
query: router.currentRoute.value.query,
}).href,
{
open: navigateToBlankTargetOpenOption,
},
)
} else {
await router.push({
name: routeName,
params: {
viewTitle: view.id || '',
viewId: tableId,
baseId: baseIdOrBaseId,
slugs,
},
query: router.currentRoute.value.query,
})
}
} else { } else {
await router.push({ if (cmdOrCtrl) {
name: routeName, const href = router.resolve({
params: { name: routeName,
viewTitle: view.id || '', params: {
viewId: tableId, viewTitle: view.id || '',
baseId: baseIdOrBaseId, viewId: tableId,
slugs, baseId: baseIdOrBaseId,
}, slugs,
}) },
}).href
await navigateTo(href, {
open: navigateToBlankTargetOpenOption,
})
} else {
await router.push({
name: routeName,
params: {
viewTitle: view.id || '',
viewId: tableId,
baseId: baseIdOrBaseId,
slugs,
},
})
}
} }
if (hardReload) { if (!cmdOrCtrl && hardReload) {
await router await router
.replace({ .replace({
name: routeName, name: routeName,

8
packages/nc-gui/utils/urlUtils.ts

@ -35,3 +35,11 @@ export const openLink = (path: string, baseURL?: string, target = '_blank') => {
const url = new URL(path, baseURL) const url = new URL(path, baseURL)
window.open(url.href, target, 'noopener,noreferrer') window.open(url.href, target, 'noopener,noreferrer')
} }
export const navigateToBlankTargetOpenOption = {
target: '_blank',
windowFeatures: {
noopener: true,
noreferrer: true,
},
}

Loading…
Cancel
Save