fix(files): hidden default actions

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ 2023-06-22 14:57:25 +02:00
parent fa50f6ce14
commit 97d69c356f
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
12 changed files with 39 additions and 47 deletions

View file

@ -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)
})

View file

@ -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)
})
})

View file

@ -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,

View file

@ -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,
})

View file

@ -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)
})

View file

@ -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)
})
})

View file

@ -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,
})

View file

@ -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)
})
})

View file

@ -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)
})
})

View file

@ -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,
})

View file

@ -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() {

View file

@ -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')
}