diff --git a/changelog/4.1.0_2021-08-19/enhancement-toggle-sidebar b/changelog/4.1.0_2021-08-19/enhancement-toggle-sidebar index 5a7f0ff4e46..d1db727997b 100644 --- a/changelog/4.1.0_2021-08-19/enhancement-toggle-sidebar +++ b/changelog/4.1.0_2021-08-19/enhancement-toggle-sidebar @@ -4,3 +4,4 @@ We introduced a button above the files list to toggle the right sidebar (open/cl https://github.com/owncloud/web/issues/5165 https://github.com/owncloud/web/pull/5678 +https://github.com/owncloud/web/pull/5709 diff --git a/packages/web-app-files/src/helpers/resource/index.ts b/packages/web-app-files/src/helpers/resource/index.ts index 4c59608d416..5f74156ef0d 100644 --- a/packages/web-app-files/src/helpers/resource/index.ts +++ b/packages/web-app-files/src/helpers/resource/index.ts @@ -2,3 +2,4 @@ export * from './asset' export * from './filter' export * from './privatePreviewBlob' export * from './publicPreviewUrl' +export * from './sameResource' diff --git a/packages/web-app-files/src/helpers/resource/resource.ts b/packages/web-app-files/src/helpers/resource/resource.ts new file mode 100644 index 00000000000..4a126ab42f6 --- /dev/null +++ b/packages/web-app-files/src/helpers/resource/resource.ts @@ -0,0 +1,5 @@ +// TODO: find a good location for the Resource interface. Needed in other repos as well, so it needs to be deployed to npm. +// TODO: add more fields to the resource interface. Extend into different resource types: FileResource, FolderResource, ShareResource, IncomingShareResource, OutgoingShareResource, ... +export interface Resource { + id: number | string +} diff --git a/packages/web-app-files/src/helpers/resource/sameResource.ts b/packages/web-app-files/src/helpers/resource/sameResource.ts new file mode 100644 index 00000000000..60b09cebeb1 --- /dev/null +++ b/packages/web-app-files/src/helpers/resource/sameResource.ts @@ -0,0 +1,6 @@ +import { Resource } from './resource' + +export const isSameResource = (r1: Resource, r2: Resource): boolean => { + if (!r1 || !r2) return false + return r1.id === r2.id +} diff --git a/packages/web-app-files/src/mixins/actions/delete.js b/packages/web-app-files/src/mixins/actions/delete.js index 7bc44f09c4f..96bbd2810f9 100644 --- a/packages/web-app-files/src/mixins/actions/delete.js +++ b/packages/web-app-files/src/mixins/actions/delete.js @@ -1,9 +1,12 @@ import MixinDeleteResources from '../../mixins/deleteResources' import { checkRoute } from '../../helpers/route' +import { mapState } from 'vuex' +import { isSameResource } from '../../helpers/resource' export default { mixins: [MixinDeleteResources], computed: { + ...mapState('Files', ['currentFolder']), $_delete_items() { return [ { @@ -15,6 +18,10 @@ export default { return false } + if (isSameResource(resource, this.currentFolder)) { + return false + } + return resource.canBeDeleted() }, componentType: 'oc-button', diff --git a/packages/web-app-files/src/mixins/actions/navigate.js b/packages/web-app-files/src/mixins/actions/navigate.js index 33cd78926bb..19b3a8e9f1f 100644 --- a/packages/web-app-files/src/mixins/actions/navigate.js +++ b/packages/web-app-files/src/mixins/actions/navigate.js @@ -1,7 +1,10 @@ import { isTrashbinRoute } from '../../helpers/route' +import { mapState } from 'vuex' +import { isSameResource } from '../../helpers/resource' export default { computed: { + ...mapState('Files', ['currentFolder']), $_navigate_items() { return [ { @@ -14,6 +17,10 @@ export default { return false } + if (isSameResource(resource, this.currentFolder)) { + return false + } + return resource.type === 'folder' }, canBeDefault: true, diff --git a/packages/web-app-files/src/mixins/actions/rename.js b/packages/web-app-files/src/mixins/actions/rename.js index 585763aba20..c322fc9554f 100644 --- a/packages/web-app-files/src/mixins/actions/rename.js +++ b/packages/web-app-files/src/mixins/actions/rename.js @@ -1,10 +1,11 @@ import { mapActions, mapGetters } from 'vuex' import { isTrashbinRoute } from '../../helpers/route' +import { isSameResource } from '../../helpers/resource' export default { computed: { - ...mapGetters('Files', ['files']), + ...mapGetters('Files', ['files', 'currentFolder']), $_rename_items() { return [ @@ -19,6 +20,10 @@ export default { return false } + if (isSameResource(resource, this.currentFolder)) { + return false + } + return resource.canRename() }, componentType: 'oc-button', diff --git a/packages/web-app-files/tests/unit/components/FilesList/ContextActions.spec.js b/packages/web-app-files/tests/unit/components/FilesList/ContextActions.spec.js index 71e36d914b1..fc9a79daea8 100644 --- a/packages/web-app-files/tests/unit/components/FilesList/ContextActions.spec.js +++ b/packages/web-app-files/tests/unit/components/FilesList/ContextActions.spec.js @@ -108,9 +108,10 @@ describe('ContextActions', () => { }, propsData: { item: { + id: 1, name: filename, - extension: extension, - type: type, + extension, + type, canDownload: () => true, isReceivedShare: () => true, canBeDeleted: () => true, diff --git a/packages/web-app-files/tests/unit/helpers/resource/sameResource.spec.ts b/packages/web-app-files/tests/unit/helpers/resource/sameResource.spec.ts new file mode 100644 index 00000000000..06a0dfb0a4d --- /dev/null +++ b/packages/web-app-files/tests/unit/helpers/resource/sameResource.spec.ts @@ -0,0 +1,23 @@ +import { isSameResource } from '../../../../src/helpers/resource' + +describe('isSameResource', () => { + test('evaluates to false if one of the resources is nullish', () => { + expect(isSameResource(null, null)).toBe(false) + expect(isSameResource(undefined, undefined)).toBe(false) + expect(isSameResource(null, { id: 1 })).toBe(false) + expect(isSameResource(undefined, { id: 1 })).toBe(false) + expect(isSameResource({ id: 1 }, null)).toBe(false) + expect(isSameResource({ id: 1 }, undefined)).toBe(false) + }) + test('evaluates to false if ids are of different types', () => { + expect(isSameResource({ id: 1 }, { id: '1' })).toBe(false) + }) + test('evaluates to false if ids are different values', () => { + expect(isSameResource({ id: 1 }, { id: 2 })).toBe(false) + expect(isSameResource({ id: '1' }, { id: '2' })).toBe(false) + }) + test('evaluates to true if ids are the same', () => { + expect(isSameResource({ id: 1 }, { id: 1 })).toBe(true) + expect(isSameResource({ id: '1' }, { id: '1' })).toBe(true) + }) +})