Browse Source

fix: Fixed creating view of a different project's table

pull/6444/head
Muhammed Mustafa 1 year ago
parent
commit
f3aec3cf90
  1. 9
      packages/nc-gui/components/dashboard/TreeView/CreateViewBtn.vue
  2. 31
      packages/nc-gui/components/dashboard/TreeView/ViewsList.vue
  3. 37
      packages/nc-gui/store/views.ts

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

@ -9,9 +9,10 @@ const router = useRouter()
const { refreshCommandPalette } = useCommandPalette()
const viewsStore = useViewsStore()
const { views } = storeToRefs(viewsStore)
const { loadViews } = viewsStore
const { loadViews, navigateToView } = viewsStore
const table = inject(SidebarTableInj)!
const project = inject(ProjectInj)!
const isOpen = ref(false)
@ -46,7 +47,11 @@ function onOpenModal({
await loadViews()
router.push({ params: { viewTitle: view.id || '' } })
navigateToView({
view,
tableId: table.value.id!,
projectId: project.value.id!,
})
$e('a:view:create', { view: view.type })
},

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

@ -53,6 +53,8 @@ const { refreshCommandPalette } = useCommandPalette()
const { addUndo, defineModelScope } = useUndoRedo()
const { navigateToView } = useViewsStore()
/** Selected view(s) for menu */
const selected = ref<string[]>([])
@ -187,32 +189,13 @@ onMounted(() => menuRef.value && initSortable(menuRef.value.$el))
/** Navigate to view by changing url param */
function changeView(view: ViewType) {
const routeName = 'index-typeOrId-projectId-index-index-viewId-viewTitle'
if (
router.currentRoute.value.query &&
router.currentRoute.value.query.page &&
router.currentRoute.value.query.page === 'fields'
) {
router.push({
name: routeName,
params: { viewTitle: view.id || '', viewId: table.value.id, projectId: project.value.id },
query: router.currentRoute.value.query,
})
} else {
router.push({ name: routeName, params: { viewTitle: view.id || '', viewId: table.value.id, projectId: project.value.id } })
}
if (view.type === ViewTypes.FORM && selected.value[0] === view.id) {
// reload the page if the same form view is clicked
// router.go(0)
// fix me: router.go(0) reloads entire page. need to reload only the form view
router
.replace({ name: routeName, query: { reload: 'true' }, params: { viewId: table.value.id, projectId: project.value.id } })
.then(() => {
router.replace({ name: routeName, query: {}, params: { viewId: table.value.id, projectId: project.value.id } })
navigateToView({
view,
tableId: table.value.id!,
projectId: project.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
})
}
}
/** Rename a view */
async function onRename(view: ViewType, originalTitle?: string, undo = false) {

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

@ -1,4 +1,4 @@
import type { ViewType } from 'nocodb-sdk'
import { type ViewType } from 'nocodb-sdk'
import { acceptHMRUpdate, defineStore } from 'pinia'
import type { ViewPageType } from '~/lib'
@ -136,6 +136,40 @@ export const useViewsStore = defineStore('viewsStore', () => {
const isLockedView = computed(() => activeView.value?.lock_type === 'locked')
const navigateToView = async ({
view,
projectId,
tableId,
hardReload,
}: {
view: ViewType
projectId: string
tableId: string
hardReload?: boolean
}) => {
const routeName = 'index-typeOrId-projectId-index-index-viewId-viewTitle'
if (
router.currentRoute.value.query &&
router.currentRoute.value.query.page &&
router.currentRoute.value.query.page === 'fields'
) {
await router.push({
name: routeName,
params: { viewTitle: view.id || '', viewId: tableId, projectId },
query: router.currentRoute.value.query,
})
} else {
await router.push({ name: routeName, params: { viewTitle: view.id || '', viewId: tableId, projectId } })
}
if (hardReload) {
await router.replace({ name: routeName, query: { reload: 'true' }, params: { viewId: tableId, projectId } }).then(() => {
router.replace({ name: routeName, query: {}, params: { viewId: tableId, projectId } })
})
}
}
return {
isLockedView,
isViewsLoading,
@ -149,6 +183,7 @@ export const useViewsStore = defineStore('viewsStore', () => {
sharedView,
viewsByTable,
activeViewTitleOrId,
navigateToView,
}
})

Loading…
Cancel
Save