Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable actions for the current folder in the right sidebar #5709

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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
@@ -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)
})
})