Skip to content

Commit

Permalink
Merge pull request #5709 from owncloud/fix-current-folder-actions-sid…
Browse files Browse the repository at this point in the history
…ebar

Disable actions for the current folder in the right sidebar
  • Loading branch information
kulmann authored Aug 20, 2021
2 parents b0c1452 + 1e455c2 commit 98797c0
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/4.1.0_2021-08-19/enhancement-toggle-sidebar
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions packages/web-app-files/src/helpers/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './asset'
export * from './filter'
export * from './privatePreviewBlob'
export * from './publicPreviewUrl'
export * from './sameResource'
5 changes: 5 additions & 0 deletions packages/web-app-files/src/helpers/resource/resource.ts
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions packages/web-app-files/src/helpers/resource/sameResource.ts
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions packages/web-app-files/src/mixins/actions/delete.js
Original file line number Diff line number Diff line change
@@ -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 [
{
Expand All @@ -15,6 +18,10 @@ export default {
return false
}

if (isSameResource(resource, this.currentFolder)) {
return false
}

return resource.canBeDeleted()
},
componentType: 'oc-button',
Expand Down
7 changes: 7 additions & 0 deletions packages/web-app-files/src/mixins/actions/navigate.js
Original file line number Diff line number Diff line change
@@ -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 [
{
Expand All @@ -14,6 +17,10 @@ export default {
return false
}

if (isSameResource(resource, this.currentFolder)) {
return false
}

return resource.type === 'folder'
},
canBeDefault: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/mixins/actions/rename.js
Original file line number Diff line number Diff line change
@@ -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 [
Expand All @@ -19,6 +20,10 @@ export default {
return false
}

if (isSameResource(resource, this.currentFolder)) {
return false
}

return resource.canRename()
},
componentType: 'oc-button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ describe('ContextActions', () => {
},
propsData: {
item: {
id: 1,
name: filename,
extension: extension,
type: type,
extension,
type,
canDownload: () => true,
isReceivedShare: () => true,
canBeDeleted: () => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 98797c0

Please sign in to comment.