summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-06-22 14:57:25 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-07-05 16:20:33 +0200
commit97d69c356f8bbd3cba75a3aa36ef8559b621e94d (patch)
tree08cbda91214fef2c10362f64abf927d71a40ec8e /apps
parentfa50f6ce14f60fa0b46cd20f9bfa0e8210754020 (diff)
downloadnextcloud-server-97d69c356f8bbd3cba75a3aa36ef8559b621e94d.tar.gz
nextcloud-server-97d69c356f8bbd3cba75a3aa36ef8559b621e94d.zip
fix(files): hidden default actions
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/deleteAction.spec.ts2
-rw-r--r--apps/files/src/actions/downloadAction.spec.ts2
-rw-r--r--apps/files/src/actions/editLocallyAction.spec.ts6
-rw-r--r--apps/files/src/actions/editLocallyAction.ts4
-rw-r--r--apps/files/src/actions/favoriteAction.spec.ts2
-rw-r--r--apps/files/src/actions/openFolderAction.spec.ts4
-rw-r--r--apps/files/src/actions/openFolderAction.ts4
-rw-r--r--apps/files/src/actions/renameAction.spec.ts2
-rw-r--r--apps/files/src/actions/sidebarAction.spec.ts6
-rw-r--r--apps/files/src/actions/sidebarAction.ts4
-rw-r--r--apps/files/src/components/FileEntry.vue39
-rw-r--r--apps/files/src/services/FileAction.ts11
12 files changed, 39 insertions, 47 deletions
diff --git a/apps/files/src/actions/deleteAction.spec.ts b/apps/files/src/actions/deleteAction.spec.ts
index af7722008b6..e45ef3d11c2 100644
--- a/apps/files/src/actions/deleteAction.spec.ts
+++ b/apps/files/src/actions/deleteAction.spec.ts
@@ -44,7 +44,7 @@ describe('Delete action conditions tests', () => {
expect(action.id).toBe('delete')
expect(action.displayName([], view)).toBe('Delete')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(false)
+ expect(action.default).toBeUndefined()
expect(action.order).toBe(100)
})
diff --git a/apps/files/src/actions/downloadAction.spec.ts b/apps/files/src/actions/downloadAction.spec.ts
index a9b51b39510..70f8f707099 100644
--- a/apps/files/src/actions/downloadAction.spec.ts
+++ b/apps/files/src/actions/downloadAction.spec.ts
@@ -39,7 +39,7 @@ describe('Download action conditions tests', () => {
expect(action.id).toBe('download')
expect(action.displayName([], view)).toBe('Download')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(false)
+ expect(action.default).toBeUndefined()
expect(action.order).toBe(30)
})
})
diff --git a/apps/files/src/actions/editLocallyAction.spec.ts b/apps/files/src/actions/editLocallyAction.spec.ts
index 3582c0d9138..7c5bed53391 100644
--- a/apps/files/src/actions/editLocallyAction.spec.ts
+++ b/apps/files/src/actions/editLocallyAction.spec.ts
@@ -22,7 +22,7 @@
import { action } from './editLocallyAction'
import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
-import { FileAction } from '../services/FileAction'
+import { DefaultType, FileAction } from '../services/FileAction'
import * as ncDialogs from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import type { Navigation } from '../services/Navigation'
@@ -38,7 +38,7 @@ describe('Edit locally action conditions tests', () => {
expect(action.id).toBe('edit-locally')
expect(action.displayName([], view)).toBe('Edit locally')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(true)
+ expect(action.default).toBe(DefaultType.DEFAULT)
expect(action.order).toBe(25)
})
})
@@ -140,7 +140,7 @@ describe('Edit locally action execute tests', () => {
test('Edit locally fails and show error', async () => {
jest.spyOn(axios, 'post').mockImplementation(async () => ({}))
- jest.spyOn(ncDialogs, 'showError').mockImplementation(async () => ({}))
+ jest.spyOn(ncDialogs, 'showError')
const file = new File({
id: 1,
diff --git a/apps/files/src/actions/editLocallyAction.ts b/apps/files/src/actions/editLocallyAction.ts
index ad7e805ec2e..4b42ce519eb 100644
--- a/apps/files/src/actions/editLocallyAction.ts
+++ b/apps/files/src/actions/editLocallyAction.ts
@@ -27,7 +27,7 @@ import DevicesSvg from '@mdi/svg/svg/devices.svg?raw'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
-import { registerFileAction, FileAction } from '../services/FileAction'
+import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
import { showError } from '@nextcloud/dialogs'
const openLocalClient = async function(path: string) {
@@ -65,7 +65,7 @@ export const action = new FileAction({
return null
},
- default: true,
+ default: DefaultType.DEFAULT,
order: 25,
})
diff --git a/apps/files/src/actions/favoriteAction.spec.ts b/apps/files/src/actions/favoriteAction.spec.ts
index 144c3a51dc8..1a026a6cc39 100644
--- a/apps/files/src/actions/favoriteAction.spec.ts
+++ b/apps/files/src/actions/favoriteAction.spec.ts
@@ -56,7 +56,7 @@ describe('Favorite action conditions tests', () => {
expect(action.id).toBe('favorite')
expect(action.displayName([file], view)).toBe('Add to favorites')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(false)
+ expect(action.default).toBeUndefined()
expect(action.order).toBe(-50)
})
diff --git a/apps/files/src/actions/openFolderAction.spec.ts b/apps/files/src/actions/openFolderAction.spec.ts
index 140b6722608..96c117c6229 100644
--- a/apps/files/src/actions/openFolderAction.spec.ts
+++ b/apps/files/src/actions/openFolderAction.spec.ts
@@ -22,7 +22,7 @@
import { action } from './openFolderAction'
import { expect } from '@jest/globals'
import { File, Folder, Node, Permission } from '@nextcloud/files'
-import { FileAction } from '../services/FileAction'
+import { DefaultType, FileAction } from '../services/FileAction'
import type { Navigation } from '../services/Navigation'
const view = {
@@ -43,7 +43,7 @@ describe('Open folder action conditions tests', () => {
expect(action.id).toBe('open-folder')
expect(action.displayName([folder], view)).toBe('Open folder FooBar')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(true)
+ expect(action.default).toBe(DefaultType.HIDDEN)
expect(action.order).toBe(-100)
})
})
diff --git a/apps/files/src/actions/openFolderAction.ts b/apps/files/src/actions/openFolderAction.ts
index 76467796a2b..1d45684deac 100644
--- a/apps/files/src/actions/openFolderAction.ts
+++ b/apps/files/src/actions/openFolderAction.ts
@@ -25,7 +25,7 @@ import Folder from '@mdi/svg/svg/folder.svg?raw'
import type { Navigation } from '../services/Navigation'
import { join } from 'path'
-import { registerFileAction, FileAction } from '../services/FileAction'
+import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
export const action = new FileAction({
id: 'open-folder',
@@ -66,7 +66,7 @@ export const action = new FileAction({
},
// Main action if enabled, meaning folders only
- default: true,
+ default: DefaultType.HIDDEN,
order: -100,
})
diff --git a/apps/files/src/actions/renameAction.spec.ts b/apps/files/src/actions/renameAction.spec.ts
index ae2cfcec7eb..4b44a32a0d0 100644
--- a/apps/files/src/actions/renameAction.spec.ts
+++ b/apps/files/src/actions/renameAction.spec.ts
@@ -37,7 +37,7 @@ describe('Rename action conditions tests', () => {
expect(action.id).toBe('rename')
expect(action.displayName([], view)).toBe('Rename')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(false)
+ expect(action.default).toBeUndefined()
expect(action.order).toBe(10)
})
})
diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts
index f6594090c53..133c6a4f6b5 100644
--- a/apps/files/src/actions/sidebarAction.spec.ts
+++ b/apps/files/src/actions/sidebarAction.spec.ts
@@ -22,7 +22,7 @@
import { action } from './sidebarAction'
import { expect } from '@jest/globals'
import { File } from '@nextcloud/files'
-import { FileAction } from '../services/FileAction'
+import { DefaultType, FileAction } from '../services/FileAction'
import type { Navigation } from '../services/Navigation'
import logger from '../logger'
@@ -35,9 +35,9 @@ describe('Open sidebar action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('details')
- expect(action.displayName([], view)).toBe('Details')
+ expect(action.displayName([], view)).toBe('Open details')
expect(action.iconSvgInline([], view)).toBe('SvgMock')
- expect(action.default).toBe(true)
+ expect(action.default).toBe(DefaultType.DEFAULT)
expect(action.order).toBe(-50)
})
})
diff --git a/apps/files/src/actions/sidebarAction.ts b/apps/files/src/actions/sidebarAction.ts
index 09a18480790..d3d6e2b5ec7 100644
--- a/apps/files/src/actions/sidebarAction.ts
+++ b/apps/files/src/actions/sidebarAction.ts
@@ -23,7 +23,7 @@ import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'
import type { Node } from '@nextcloud/files'
-import { registerFileAction, FileAction } from '../services/FileAction'
+import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
import logger from '../logger.js'
export const ACTION_DETAILS = 'details'
@@ -60,7 +60,7 @@ export const action = new FileAction({
}
},
- default: true,
+ default: DefaultType.DEFAULT,
order: -50,
})
diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue
index 9bb635f0d58..5c17ada6e84 100644
--- a/apps/files/src/components/FileEntry.vue
+++ b/apps/files/src/components/FileEntry.vue
@@ -100,7 +100,7 @@
:container="boundariesElement"
:disabled="source._loading"
:force-title="true"
- :force-menu="true"
+ :force-menu="enabledInlineActions.length === 0 /* forceMenu only if no inline actions */"
:inline="enabledInlineActions.length"
:open.sync="openedMenu">
<NcActionButton v-for="action in enabledMenuActions"
@@ -141,7 +141,7 @@
<script lang='ts'>
import { debounce } from 'debounce'
-import { emit, subscribe } from '@nextcloud/event-bus'
+import { emit } from '@nextcloud/event-bus'
import { formatFileSize } from '@nextcloud/files'
import { Fragment } from 'vue-frag'
import { showError, showSuccess } from '@nextcloud/dialogs'
@@ -160,7 +160,7 @@ import StarIcon from 'vue-material-design-icons/Star.vue'
import Vue from 'vue'
import { ACTION_DETAILS } from '../actions/sidebarAction.ts'
-import { getFileActions } from '../services/FileAction.ts'
+import { getFileActions, DefaultType } from '../services/FileAction.ts'
import { hashCode } from '../utils/hashUtils.ts'
import { isCachedPreview } from '../services/PreviewService.ts'
import { useActionsMenuStore } from '../store/actionsmenu.ts'
@@ -350,42 +350,29 @@ export default Vue.extend({
return ''
},
+ // Sorted actions that are enabled for this node
enabledActions() {
return actions
.filter(action => !action.enabled || action.enabled([this.source], this.currentView))
.sort((a, b) => (a.order || 0) - (b.order || 0))
},
+
+ // Enabled action that are displayed inline
enabledInlineActions() {
if (this.filesListWidth < 768) {
return []
}
return this.enabledActions.filter(action => action?.inline?.(this.source, this.currentView))
},
- enabledMenuActions() {
- if (this.filesListWidth < 768) {
- // If we have a default action, do not render the first one
- if (this.enabledDefaultActions.length > 0) {
- return this.enabledActions.slice(1)
- }
- return this.enabledActions
- }
-
- const actions = [
- ...this.enabledInlineActions,
- ...this.enabledActions.filter(action => !action.inline),
- ]
-
- // If we have a default action, do not render the first one
- if (this.enabledDefaultActions.length > 0) {
- return actions.slice(1)
- }
- return actions
- },
+ // Default actions
enabledDefaultActions() {
- return [
- ...this.enabledActions.filter(action => action.default),
- ]
+ return this.enabledActions.filter(action => !!action.default)
+ },
+
+ // Actions shown in the menu
+ enabledMenuActions() {
+ return this.enabledActions.filter(action => action.default !== DefaultType.HIDDEN)
},
openedMenu: {
get() {
diff --git a/apps/files/src/services/FileAction.ts b/apps/files/src/services/FileAction.ts
index 03cc957e1e5..4798128671c 100644
--- a/apps/files/src/services/FileAction.ts
+++ b/apps/files/src/services/FileAction.ts
@@ -31,6 +31,11 @@ declare global {
}
}
+export enum DefaultType {
+ DEFAULT = 'default',
+ HIDDEN = 'hidden',
+}
+
/**
* TODO: remove and move to @nextcloud/files
* @see https://github.com/nextcloud/nextcloud-files/pull/608
@@ -60,7 +65,7 @@ interface FileActionData {
/** This action order in the list */
order?: number,
/** Make this action the default */
- default?: boolean,
+ default?: DefaultType,
/**
* If true, the renderInline function will be called
*/
@@ -110,7 +115,7 @@ export class FileAction {
}
get default() {
- return this._action.default === true
+ return this._action.default
}
get inline() {
@@ -151,7 +156,7 @@ export class FileAction {
throw new Error('Invalid order')
}
- if ('default' in action && typeof action.default !== 'boolean') {
+ if (action.default && !Object.values(DefaultType).includes(action.default)) {
throw new Error('Invalid default')
}