From 749acc85eb4ea0ef24283f485b54837d35d1eb6b Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Wed, 18 Dec 2024 10:03:46 +0100 Subject: [PATCH 1/4] fix: disable paste button in same folder We've fixed the state of the "paste files" action when copied resources are from the same folder. The button will be disabled in such case and a tooltip with explanation message displayed. --- ...fix-disable-paste-action-in-same-folder.md | 6 +++ .../src/components/AppBar/CreateAndUpload.vue | 46 +++++++++++++++---- .../components/AppBar/CreateAndUpload.spec.ts | 28 +++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 changelog/unreleased/bugfix-disable-paste-action-in-same-folder.md diff --git a/changelog/unreleased/bugfix-disable-paste-action-in-same-folder.md b/changelog/unreleased/bugfix-disable-paste-action-in-same-folder.md new file mode 100644 index 00000000000..c45be6c54a2 --- /dev/null +++ b/changelog/unreleased/bugfix-disable-paste-action-in-same-folder.md @@ -0,0 +1,6 @@ +Bugfix: Disable paste action in same folder + +We've fixed the state of the "paste files" action when copied resources are from the same folder. The button will be disabled in such case and a tooltip with explanation message displayed. + +https://github.com/owncloud/web/pull/12044 +https://github.com/owncloud/web/issues/12021 diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index eaedb4c63ab..e6335597711 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -158,14 +158,12 @@
@@ -270,6 +268,7 @@ export default defineComponent({ const sharesStore = useSharesStore() const route = useRoute() const language = useGettext() + const { $gettext } = language const clipboardStore = useClipboardStore() const { clearClipboard } = clipboardStore @@ -401,6 +400,36 @@ export default defineComponent({ } } + const uploadOrFileCreationBlocked = computed(() => { + return !unref(canUpload) + }) + + const isPastingIntoSameFolder = computed(() => { + if (!unref(clipboardResources) || unref(clipboardResources).length < 1) { + return false + } + + return !unref(clipboardResources).some( + (resource) => resource.parentFolderId !== unref(currentFolder).id + ) + }) + + const isPasteHereButtonDisabled = computed(() => { + return unref(uploadOrFileCreationBlocked) || unref(isPastingIntoSameFolder) + }) + + const pasteHereButtonTooltip = computed(() => { + if (unref(uploadOrFileCreationBlocked)) { + return $gettext('You have no permission to paste files here!') + } + + if (unref(isPastingIntoSameFolder)) { + return $gettext('You cannot paste resources into the same folder where you copied them.') + } + + return '' + }) + onMounted(() => { uploadCompletedSub = uppyService.subscribe('uploadCompleted', onUploadComplete) document.addEventListener('paste', handlePasteFileEvent) @@ -446,6 +475,9 @@ export default defineComponent({ areFileExtensionsShown, clearClipboard, clipboardResources, + uploadOrFileCreationBlocked, + isPasteHereButtonDisabled, + pasteHereButtonTooltip, // HACK: exported for unit tests: onUploadComplete @@ -493,10 +525,6 @@ export default defineComponent({ return this.$gettext('Upload files or folders') }, - uploadOrFileCreationBlocked() { - return !this.canUpload - }, - folderIconResource() { return { isFolder: true, extension: '' } as Resource } diff --git a/packages/web-app-files/tests/unit/components/AppBar/CreateAndUpload.spec.ts b/packages/web-app-files/tests/unit/components/AppBar/CreateAndUpload.spec.ts index 82d88fc4682..19a1c46cb5e 100644 --- a/packages/web-app-files/tests/unit/components/AppBar/CreateAndUpload.spec.ts +++ b/packages/web-app-files/tests/unit/components/AppBar/CreateAndUpload.spec.ts @@ -104,6 +104,34 @@ describe('CreateAndUpload component', () => { const clipboardStore = useClipboardStore() expect(clipboardStore.clearClipboard).toHaveBeenCalled() }) + it('should disable the "paste files"-action when clipboardResources are from same folder', () => { + const { wrapper } = getWrapper({ + clipboardResources: [mock({ parentFolderId: 'current-folder' })], + currentFolder: mock({ + id: 'current-folder', + canUpload: vi.fn().mockReturnValue(true) + }) + }) + expect( + wrapper.findComponent(elSelector.pasteFilesBtn).vm.disabled + ).toStrictEqual(true) + }) + + it('should not disable the "paste files"-action when at least one clipboardResources is not from same folder', () => { + const { wrapper } = getWrapper({ + clipboardResources: [ + mock({ parentFolderId: 'current-folder' }), + mock({ parentFolderId: 'another-folder' }) + ], + currentFolder: mock({ + id: 'current-folder', + canUpload: vi.fn().mockReturnValue(true) + }) + }) + expect( + wrapper.findComponent(elSelector.pasteFilesBtn).vm.disabled + ).toStrictEqual(false) + }) }) describe('method "onUploadComplete"', () => { it.each([ From cf059bcd7392093a6bf9b899dfaff45fab274d29 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Thu, 19 Dec 2024 15:29:06 +0545 Subject: [PATCH 2/4] test: move away mouse position --- .../e2e/support/objects/app-files/resource/actions.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/e2e/support/objects/app-files/resource/actions.ts b/tests/e2e/support/objects/app-files/resource/actions.ts index 372cf30db7d..156c8b6cbef 100644 --- a/tests/e2e/support/objects/app-files/resource/actions.ts +++ b/tests/e2e/support/objects/app-files/resource/actions.ts @@ -51,7 +51,7 @@ const uploadInfoCloseButton = '#close-upload-info-btn' const uploadErrorCloseButton = '.oc-notification-message-danger button[aria-label="Close"]' const filesBatchAction = '.files-app-bar-actions .oc-files-actions-%s-trigger' const pasteButton = '.paste-files-btn' -const breadcrumbRoot = '//nav[contains(@class, "oc-breadcrumb")]/ol/li[1]' +const breadcrumbRoot = '//nav[@id="files-breadcrumb"]//li[1]' const fileRenameInput = '.oc-text-input' const deleteButtonSidebar = '#oc-files-actions-sidebar .oc-files-actions-delete-trigger' const actionConfirmationButton = @@ -881,6 +881,11 @@ export const pasteResource = async (args: moveOrCopyResourceArgs): Promise } } +const selectBatchAction = async (page: Page, action: string): Promise => { + await page.locator(util.format(filesBatchAction, action)).click() + await page.mouse.move(0, 0) +} + export const moveOrCopyMultipleResources = async ( args: moveOrCopyMultipleResourceArgs ): Promise => { @@ -922,7 +927,7 @@ export const moveOrCopyMultipleResources = async ( break } case 'batch-action': { - await page.locator(util.format(filesBatchAction, action)).click() + await selectBatchAction(page, action) await page.locator(breadcrumbRoot).click() const newLocationPath = newLocation.split('/') @@ -994,7 +999,7 @@ export const moveOrCopyResource = async (args: moveOrCopyResourceArgs): Promise< } case 'batch-action': { await page.locator(util.format(checkBox, resourceBase)).click() - await page.locator(util.format(filesBatchAction, action)).click() + await selectBatchAction(page, action) await pasteResource({ page, resource: resourceBase, newLocation, action, method, option }) break } From aa5a8a4b753b214513b2242279426330549963c6 Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Thu, 19 Dec 2024 11:56:34 +0100 Subject: [PATCH 3/4] Update packages/web-app-files/src/components/AppBar/CreateAndUpload.vue Co-authored-by: Sawjan Gurung --- .../web-app-files/src/components/AppBar/CreateAndUpload.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index e6335597711..093aedfb09a 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -424,7 +424,7 @@ export default defineComponent({ } if (unref(isPastingIntoSameFolder)) { - return $gettext('You cannot paste resources into the same folder where you copied them.') + return $gettext('You cannot paste resources into the same folder.') } return '' From bc3da28c45802eabcd73c2c334714e9da636f5eb Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Thu, 19 Dec 2024 11:56:41 +0100 Subject: [PATCH 4/4] Update packages/web-app-files/src/components/AppBar/CreateAndUpload.vue Co-authored-by: Sawjan Gurung --- .../web-app-files/src/components/AppBar/CreateAndUpload.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 093aedfb09a..8d1ab2678ee 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -420,7 +420,7 @@ export default defineComponent({ const pasteHereButtonTooltip = computed(() => { if (unref(uploadOrFileCreationBlocked)) { - return $gettext('You have no permission to paste files here!') + return $gettext('You have no permission to paste files here.') } if (unref(isPastingIntoSameFolder)) {