Browse Source

fix(nc-gui): stay on erd while table change

pull/6553/head
Muhammed Mustafa 1 year ago
parent
commit
f6855d10e2
  1. 1
      packages/nc-gui/components/dashboard/TreeView/ViewsList.vue
  2. 10
      packages/nc-gui/composables/useTableNew.ts
  3. 37
      packages/nc-gui/store/views.ts

1
packages/nc-gui/components/dashboard/TreeView/ViewsList.vue

@ -192,6 +192,7 @@ async function changeView(view: ViewType) {
tableId: table.value.id!, tableId: table.value.id!,
baseId: base.value.id!, baseId: base.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id, hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
doNotSwitchTab: true,
}) })
if (isMobileMode.value) { if (isMobileMode.value) {

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

@ -49,6 +49,8 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
const { loadTables, baseUrl, isXcdbBase } = useBase() const { loadTables, baseUrl, isXcdbBase } = useBase()
const { openedViewsTab, viewsByTable } = storeToRefs(useViewsStore())
const workspaceId = computed(() => route.value.params.typeOrId as string) const workspaceId = computed(() => route.value.params.typeOrId as string)
const tables = computed(() => baseTables.value.get(param.baseId) || []) const tables = computed(() => baseTables.value.get(param.baseId) || [])
@ -84,6 +86,14 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v
tableId: table.id, tableId: table.id,
}) })
const views = viewsByTable.value.get(table.id as string) ?? []
if (openedViewsTab.value !== 'view' && views[0].id) {
await navigateTo({
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${views[0].id}/${openedViewsTab.value}`,
query: route.value.query,
})
} else
await navigateTo({ await navigateTo({
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`, path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`,
query: route.value.query, query: route.value.query,

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

@ -154,13 +154,15 @@ export const useViewsStore = defineStore('viewsStore', () => {
baseId, baseId,
tableId, tableId,
hardReload, hardReload,
doNotSwitchTab,
}: { }: {
view: ViewType view: ViewType
baseId: string baseId: string
tableId: string tableId: string
hardReload?: boolean hardReload?: boolean
doNotSwitchTab?: boolean
}) => { }) => {
const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle' const routeName = 'index-typeOrId-baseId-index-index-viewId-viewTitle-slugs'
let baseIdOrBaseId = baseId let baseIdOrBaseId = baseId
@ -168,6 +170,8 @@ export const useViewsStore = defineStore('viewsStore', () => {
baseIdOrBaseId = route.value.params.baseId as string baseIdOrBaseId = route.value.params.baseId as string
} }
const slugs = doNotSwitchTab ? router.currentRoute.value.params.slugs : undefined
if ( if (
router.currentRoute.value.query && router.currentRoute.value.query &&
router.currentRoute.value.query.page && router.currentRoute.value.query.page &&
@ -175,11 +179,24 @@ export const useViewsStore = defineStore('viewsStore', () => {
) { ) {
await router.push({ await router.push({
name: routeName, name: routeName,
params: { viewTitle: view.id || '', viewId: tableId, baseId: baseIdOrBaseId }, params: {
viewTitle: view.id || '',
viewId: tableId,
baseId: baseIdOrBaseId,
slugs,
},
query: router.currentRoute.value.query, query: router.currentRoute.value.query,
}) })
} else { } else {
await router.push({ name: routeName, params: { viewTitle: view.id || '', viewId: tableId, baseId: baseIdOrBaseId } }) await router.push({
name: routeName,
params: {
viewTitle: view.id || '',
viewId: tableId,
baseId: baseIdOrBaseId,
slugs,
},
})
} }
if (hardReload) { if (hardReload) {
@ -187,13 +204,23 @@ export const useViewsStore = defineStore('viewsStore', () => {
.replace({ .replace({
name: routeName, name: routeName,
query: { reload: 'true' }, query: { reload: 'true' },
params: { viewId: tableId, baseId: baseIdOrBaseId, viewTitle: view.id || '' }, params: {
viewId: tableId,
baseId: baseIdOrBaseId,
viewTitle: view.id || '',
slugs,
},
}) })
.then(() => { .then(() => {
router.replace({ router.replace({
name: routeName, name: routeName,
query: {}, query: {},
params: { viewId: tableId, viewTitle: view.id || '', baseId: baseIdOrBaseId }, params: {
viewId: tableId,
viewTitle: view.id || '',
baseId: baseIdOrBaseId,
slugs,
},
}) })
}) })
} }

Loading…
Cancel
Save