feat: add delete folder
This commit is contained in:
@@ -124,6 +124,6 @@ function formatDate(v?: string | null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onNodeSelect(node: { key?: string; data?: DocumentNode }) {
|
function onNodeSelect(node: { key?: string; data?: DocumentNode }) {
|
||||||
if (node.key && node.data?.type === 'Document') emit('select', node.key)
|
if (node.key) emit('select', node.key)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<Button v-if="canEdit" icon="pi pi-pencil" label="Edit" size="small" @click="$emit('edit')" />
|
<Button v-if="canEdit && doc?.type === 'Document'" icon="pi pi-pencil" label="Edit" size="small" @click="$emit('edit')" />
|
||||||
<Button v-if="canEdit" icon="pi pi-folder-open" text severity="secondary" size="small" aria-label="Move to folder" @click="$emit('move')" />
|
<Button v-if="canEdit" icon="pi pi-folder-open" text severity="secondary" size="small" aria-label="Move to folder" @click="$emit('move')" />
|
||||||
<Button v-if="canDelete" icon="pi pi-trash" text severity="danger" size="small" aria-label="Delete" @click="$emit('delete')" />
|
<Button v-if="canDelete" icon="pi pi-trash" text severity="danger" size="small" aria-label="Delete" @click="$emit('delete')" />
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -329,10 +329,33 @@ async function onMove() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function countDescendants(nodes: DocumentNode[]): number {
|
||||||
|
return nodes.reduce((sum, node) => sum + 1 + countDescendants(node.children), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function findNode(nodes: DocumentNode[], id: string): DocumentNode | null {
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.id === id) return node
|
||||||
|
const found = findNode(node.children, id)
|
||||||
|
if (found) return found
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteMessage(): string {
|
||||||
|
if (!doc.value) return ''
|
||||||
|
if (doc.value.type !== 'Folder') return `Delete "${doc.value.title}"?`
|
||||||
|
const node = findNode(tree.value, doc.value.id)
|
||||||
|
const count = node ? countDescendants(node.children) : 0
|
||||||
|
return count > 0
|
||||||
|
? `Delete folder "${doc.value.title}" and the ${count} item${count === 1 ? '' : 's'} inside it? This cannot be undone.`
|
||||||
|
: `Delete folder "${doc.value.title}"?`
|
||||||
|
}
|
||||||
|
|
||||||
function confirmDelete() {
|
function confirmDelete() {
|
||||||
if (!doc.value) return
|
if (!doc.value) return
|
||||||
confirm.require({
|
confirm.require({
|
||||||
message: `Delete "${doc.value.title}"?`,
|
message: deleteMessage(),
|
||||||
header: 'Delete',
|
header: 'Delete',
|
||||||
acceptProps: { severity: 'danger' },
|
acceptProps: { severity: 'danger' },
|
||||||
rejectProps: { severity: 'secondary', outlined: true },
|
rejectProps: { severity: 'secondary', outlined: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user