Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions playwright/e2e/note-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ test.describe('Note actions', () => {
await expect(noteRow(page, noteId)).toContainText(renamedTitle)
})

test('keeps a note when deletion is canceled', async ({ page }, testInfo: TestInfo) => {
const title = uniqueTitle('cancel-delete', testInfo)
const noteId = await createNote(page, title)

await openNoteActions(page, noteId)
await page.getByRole('menuitem', { name: 'Delete note' }).click()

const confirmationDialog = page.getByRole('dialog', { name: 'Delete note' })
await expect(confirmationDialog).toBeVisible()

await confirmationDialog.getByRole('button', { name: 'Cancel' }).click()

await expect(confirmationDialog).not.toBeVisible()
await expect(noteRow(page, noteId)).toBeVisible()
})

test('deletes a note and undoes the deletion', async ({ page }, testInfo: TestInfo) => {
const title = uniqueTitle('delete', testInfo)
const autotitleSettled = page.waitForResponse((response) => response.url().includes('/autotitle')).catch(() => null)
Expand All @@ -63,6 +79,14 @@ test.describe('Note actions', () => {
await openNoteActions(page, noteId)
await page.getByRole('menuitem', { name: 'Delete note' }).click()

const confirmationDialog = page.getByRole('dialog', { name: 'Delete note' })
await expect(confirmationDialog).toBeVisible()
await expect(confirmationDialog).toContainText(title)

await expect(noteRow(page, noteId)).toHaveCount(1)

await confirmationDialog.getByRole('button', { name: 'Delete', exact: true }).click()

await expect(noteRow(page, noteId)).toHaveCount(0)

const undoButton = page.getByRole('button', { name: 'Undo Delete', exact: true })
Expand Down
45 changes: 39 additions & 6 deletions src/components/NoteItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,32 @@
<NcActionSeparator />

<NcActionButton v-if="!note.readonly"
:icon="actionDeleteIcon"
class="delete-note-action"
:closeAfterClick="true"
@click="onDeleteNote"
>
<template #icon>
<NcLoadingIcon v-if="loading.delete" :size="20" />
<DeleteOutlineIcon v-else :size="20" />
</template>
{{ t('notes', 'Delete note') }}
</NcActionButton>
</template>
</NcListItem>
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { showConfirmation, showError } from '@nextcloud/dialogs'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { getSidebarTabs } from '@nextcloud/files'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActionInput from '@nextcloud/vue/components/NcActionInput'
import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
import NcListItem from '@nextcloud/vue/components/NcListItem'
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
import AlertOctagonOutlineIcon from 'vue-material-design-icons/AlertOctagonOutline.vue'
import BackupRestoreIcon from 'vue-material-design-icons/BackupRestore.vue'
import DeleteOutlineIcon from 'vue-material-design-icons/DeleteOutline.vue'
import FolderOutlineIcon from 'vue-material-design-icons/FolderOutline.vue'
import InformationOutlineIcon from 'vue-material-design-icons/InformationOutline.vue'
import PencilOutlineIcon from 'vue-material-design-icons/PencilOutline.vue'
Expand All @@ -147,6 +153,8 @@ export default {
NcActionInput,
PencilOutlineIcon,
ShareVariantOutlineIcon,
NcLoadingIcon,
DeleteOutlineIcon,
},

props: {
Expand Down Expand Up @@ -174,6 +182,7 @@ export default {
note: false,
category: false,
favorite: false,
delete: false,
},

newTitle: '',
Expand Down Expand Up @@ -220,10 +229,6 @@ export default {
return categoryLabel(this.note.category)
},

actionDeleteIcon() {
return 'icon-delete' + (this.loading.delete ? ' loading' : '')
},

categories() {
return [
{
Expand Down Expand Up @@ -332,7 +337,30 @@ export default {
},

async onDeleteNote() {
if (this.loading.delete) {
return
}
let confirmed
try {
confirmed = await showConfirmation({
name: this.t('notes', 'Delete note'),
text: this.t('notes', 'Delete note "{title}"?', { title: this.note.title }, undefined, { escape: false }),
labelConfirm: this.t('notes', 'Delete'),
labelReject: this.t('notes', 'Cancel'),
severity: 'warning',
})
} catch (error) {
if (error instanceof Error && error.message === 'Dialog closed') {
return
}
throw error
}
if (!confirmed) {
return
}

this.loading.delete = true

try {
const note = await fetchNote(this.note.id)
if (note.errorType) {
Expand Down Expand Up @@ -392,4 +420,9 @@ export default {
height: calc(var(--list-item-height) + 2 * var(--default-grid-baseline));
padding: var(--list-item-padding);
}

:global(.action.delete-note-action .action-button__text),
:global(.action.delete-note-action .material-design-icon) {
color: var(--color-text-error);
}
</style>
Loading