Browse Source

fix: Fixed view duplication and delete

pull/6444/head
Muhammed Mustafa 1 year ago
parent
commit
fcd98c903a
  1. 78
      packages/nc-gui/components/dashboard/TreeView/ViewsList.vue

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

@ -43,6 +43,8 @@ const isDefaultBase = computed(() => {
const { viewsByTable, activeView } = storeToRefs(useViewsStore()) const { viewsByTable, activeView } = storeToRefs(useViewsStore())
const { navigateToTable } = useTablesStore()
const views = computed(() => viewsByTable.value.get(table.value.id!)?.filter((v) => !v.is_default) ?? []) const views = computed(() => viewsByTable.value.get(table.value.id!)?.filter((v) => !v.is_default) ?? [])
const { api } = useApi() const { api } = useApi()
@ -53,7 +55,7 @@ const { refreshCommandPalette } = useCommandPalette()
const { addUndo, defineModelScope } = useUndoRedo() const { addUndo, defineModelScope } = useUndoRedo()
const { navigateToView } = useViewsStore() const { navigateToView, loadViews } = useViewsStore()
/** Selected view(s) for menu */ /** Selected view(s) for menu */
const selected = ref<string[]>([]) const selected = ref<string[]>([])
@ -205,10 +207,11 @@ async function onRename(view: ViewType, originalTitle?: string, undo = false) {
order: view.order, order: view.order,
}) })
await router.replace({ navigateToView({
params: { view,
viewTitle: view.id, tableId: table.value.id!,
}, projectId: project.value.id!,
hardReload: view.type === ViewTypes.FORM && selected.value[0] === view.id,
}) })
refreshCommandPalette() refreshCommandPalette()
@ -250,20 +253,22 @@ function openDeleteDialog(view: ViewType) {
'modelValue': isOpen, 'modelValue': isOpen,
'view': view, 'view': view,
'onUpdate:modelValue': closeDialog, 'onUpdate:modelValue': closeDialog,
'onDeleted': () => { 'onDeleted': async () => {
closeDialog() closeDialog()
emits('deleted') emits('deleted')
refreshCommandPalette() refreshCommandPalette()
if (activeView.value === view) { if (activeView.value?.id === view.id) {
// return to the default view navigateToTable({
router.replace({ tableId: table.value.id!,
params: { projectId: project.value.id!,
viewTitle: views.value[0].id,
},
}) })
} }
await loadViews({
tableId: table.value.id!,
})
}, },
}) })
@ -291,6 +296,53 @@ const setIcon = async (icon: string, view: ViewType) => {
message.error(await extractSdkResponseErrorMsg(e)) 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)
}
}
</script> </script>
<template> <template>
@ -333,7 +385,7 @@ const setIcon = async (icon: string, view: ViewType) => {
}" }"
:data-view-id="view.id" :data-view-id="view.id"
@change-view="changeView" @change-view="changeView"
@open-modal="$emit('openModal', $event)" @open-modal="onOpenModal"
@delete="openDeleteDialog" @delete="openDeleteDialog"
@rename="onRename" @rename="onRename"
@select-icon="setIcon($event, view)" @select-icon="setIcon($event, view)"

Loading…
Cancel
Save