From fcd98c903a8fb41fd0c96c32e318a4de97bd1f68 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Fri, 22 Sep 2023 15:23:19 +0000 Subject: [PATCH] fix: Fixed view duplication and delete --- .../dashboard/TreeView/ViewsList.vue | 78 +++++++++++++++---- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/packages/nc-gui/components/dashboard/TreeView/ViewsList.vue b/packages/nc-gui/components/dashboard/TreeView/ViewsList.vue index 4551df02b5..d50038fd14 100644 --- a/packages/nc-gui/components/dashboard/TreeView/ViewsList.vue +++ b/packages/nc-gui/components/dashboard/TreeView/ViewsList.vue @@ -43,6 +43,8 @@ const isDefaultBase = computed(() => { const { viewsByTable, activeView } = storeToRefs(useViewsStore()) +const { navigateToTable } = useTablesStore() + const views = computed(() => viewsByTable.value.get(table.value.id!)?.filter((v) => !v.is_default) ?? []) const { api } = useApi() @@ -53,7 +55,7 @@ const { refreshCommandPalette } = useCommandPalette() const { addUndo, defineModelScope } = useUndoRedo() -const { navigateToView } = useViewsStore() +const { navigateToView, loadViews } = useViewsStore() /** Selected view(s) for menu */ const selected = ref([]) @@ -205,10 +207,11 @@ async function onRename(view: ViewType, originalTitle?: string, undo = false) { order: view.order, }) - await router.replace({ - params: { - viewTitle: view.id, - }, + navigateToView({ + view, + tableId: table.value.id!, + projectId: project.value.id!, + hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id, }) refreshCommandPalette() @@ -250,20 +253,22 @@ function openDeleteDialog(view: ViewType) { 'modelValue': isOpen, 'view': view, 'onUpdate:modelValue': closeDialog, - 'onDeleted': () => { + 'onDeleted': async () => { closeDialog() emits('deleted') refreshCommandPalette() - if (activeView.value === view) { - // return to the default view - router.replace({ - params: { - viewTitle: views.value[0].id, - }, + if (activeView.value?.id === view.id) { + navigateToTable({ + tableId: table.value.id!, + projectId: project.value.id!, }) } + + await loadViews({ + tableId: table.value.id!, + }) }, }) @@ -291,6 +296,53 @@ const setIcon = async (icon: string, view: ViewType) => { message.error(await extractSdkResponseErrorMsg(e)) } } + +function onOpenModal({ + title = '', + type, + copyViewId, + groupingFieldColumnId, +}: { + title?: string + type: ViewTypes + copyViewId?: string + groupingFieldColumnId?: string +}) { + const isOpen = ref(true) + + const { close } = useDialog(resolveComponent('DlgViewCreate'), { + 'modelValue': isOpen, + title, + type, + 'tableId': table.value.id, + 'selectedViewId': copyViewId, + groupingFieldColumnId, + 'views': views, + 'onUpdate:modelValue': closeDialog, + 'onCreated': async (view: ViewType) => { + closeDialog() + + refreshCommandPalette() + + await loadViews() + + navigateToView({ + view, + tableId: table.value.id!, + projectId: project.value.id!, + hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id, + }) + + $e('a:view:create', { view: view.type }) + }, + }) + + function closeDialog() { + isOpen.value = false + + close(1000) + } +}