Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
ActionMenuItem,
useExtensionRegistry,
useFileActions,
useIsAppActive
useIsAppActive,
useFileActionsDelete,
useFileActionsDownloadFile,
useFileActionsRestore
} from '@opencloud-eu/web-pkg'
import { computed, inject, Ref, unref } from 'vue'
import { Resource, SpaceResource } from '@opencloud-eu/web-client'
Expand All @@ -32,6 +35,11 @@ const { getAllOpenWithActions } = useFileActions()
const extensionActions = computed(() =>
requestExtensions<ActionExtension>(fileSideBarActionsExtensionPoint).map((e) => e.action)
)

const { actions: downloadFileActions } = useFileActionsDownloadFile()
const { actions: deleteActions } = useFileActionsDelete()
const { actions: restoreActions } = useFileActionsRestore()

const actions = computed(() => {
const options = {
space: unref(space),
Expand All @@ -41,9 +49,12 @@ const actions = computed(() => {
}

return [
// FIXME: as soon as all actions are migrated to web-app-files
// and registered as extension point, omit ...getAllOpenWithActions(options),
// FIXME: remove as soon as actions are announced in extension system
...getAllOpenWithActions(options),
...[...unref(downloadFileActions), ...unref(deleteActions), ...unref(restoreActions)].filter(
(action) => action.isVisible(options)
),

...unref(extensionActions).filter((action) => action.isVisible(options))
]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const menuItemsPrimary = computed(() => {
})

const menuItemsPrimaryDrop = computed(() => {
return getAllOpenWithActions({ ...unref(actionOptions), omitSystemActions: true })
return getAllOpenWithActions(unref(actionOptions))
.filter((item) => item.isVisible(unref(actionOptions)))
.sort((x, y) => Number(y.hasPriority) - Number(x.hasPriority))
})
Expand Down
44 changes: 10 additions & 34 deletions packages/web-pkg/src/composables/actions/files/useFileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import {
useWindowOpen
} from '../../actions'

import {
useFileActionsDelete,
useFileActionsDownloadFile,
useFileActionsNavigate,
useFileActionsRestore
} from './index'
import { useFileActionsNavigate } from './index'
import {
ActionExtension,
useAppsStore,
Expand All @@ -33,9 +28,7 @@ import { storeToRefs } from 'pinia'
import { useEmbedMode } from '../../embedMode'
import { RouteRecordName } from 'vue-router'

export interface GetFileActionsOptions extends FileActionOptions {
omitSystemActions?: boolean
}
export interface GetFileActionsOptions extends FileActionOptions {}

export interface FileActionOptionsWithEvent extends FileActionOptions<Resource> {
event?: MouseEvent
Expand All @@ -52,17 +45,8 @@ export const useFileActions = () => {
const configStore = useConfigStore()
const { options } = storeToRefs(configStore)

const { actions: deleteActions } = useFileActionsDelete()
const { actions: downloadFileActions } = useFileActionsDownloadFile()
const { actions: fallbackToDownloadAction } = useFileActionFallbackToDownload()
const { actions: fallbackToDownloadActions } = useFileActionFallbackToDownload()
const { actions: navigateActions } = useFileActionsNavigate()
const { actions: restoreActions } = useFileActionsRestore()

const systemActions = computed<FileAction<any>[]>(() => [
...unref(downloadFileActions),
...unref(deleteActions),
...unref(restoreActions)
])

const extensionsContextActions = computed(() => {
return (
Expand Down Expand Up @@ -257,33 +241,25 @@ export const useFileActions = () => {

const getDefaultAction = (options: GetFileActionsOptions): Action | undefined => {
const actions = getAllOpenWithActions(options)

if (actions.length) {
return actions[0].name === unref(downloadFileActions)[0].name
? unref(fallbackToDownloadAction)[0]
: actions[0]
return actions[0]
}
return undefined

return unref(fallbackToDownloadActions)[0].isVisible(options)
? unref(fallbackToDownloadActions)[0]
: undefined
}

const getAllOpenWithActions = (
options: GetFileActionsOptions & { omitEditorActions?: boolean }
) => {
const filterCallback = (action: FileAction) => action.isVisible(options)

const primaryActions = [
return [
...unref(extensionsContextActions),
...(options.omitEditorActions ? [] : unref(editorActions)),
...unref(navigateActions)
]
.filter(filterCallback)
.filter((action: FileAction) => action.isVisible(options))
.sort((a, b) => Number(b.hasPriority) - Number(a.hasPriority))

const secondaryActions = options.omitSystemActions
? []
: unref(systemActions).filter(filterCallback)

return [...primaryActions, ...secondaryActions]
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,29 @@ import { useFileActions } from './useFileActions'
export const useFileActionsOpenWithDefault = () => {
const { $gettext } = useGettext()

const { getDefaultAction } = useFileActions()
const { getDefaultAction, getAllOpenWithActions } = useFileActions()

const actions = computed((): FileAction[] => [
{
name: 'open',
icon: 'eye',
label: () => $gettext('Open'),
handler: (options) => {
const defaultAction = getDefaultAction({ ...options, omitSystemActions: true })
const defaultAction = getDefaultAction(options)
if (!defaultAction || !Object.hasOwn(defaultAction, 'handler')) {
return
}
defaultAction.handler(options)
},
route: (options) => {
const defaultAction = getDefaultAction({ ...options, omitSystemActions: true })
const defaultAction = getDefaultAction(options)
if (!defaultAction || !Object.hasOwn(defaultAction, 'route')) {
return
}
return defaultAction.route(options)
},
isVisible: (options) => {
const defaultAction = getDefaultAction({ ...options, omitSystemActions: true })
if (!defaultAction) {
return false
}
return defaultAction.isVisible(options)
return getAllOpenWithActions(options).length > 0
},
class: 'oc-files-actions-default-editor-trigger'
}
Expand Down
1 change: 0 additions & 1 deletion packages/web-pkg/src/composables/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from './types'

export * from './useActionsShowDetails'
export * from './useOpenEmptyEditor'
export * from './useOpenWithDefaultApp'
export * from './useWindowOpen'
29 changes: 0 additions & 29 deletions packages/web-pkg/src/composables/actions/useOpenWithDefaultApp.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const actionOptions: GetFileActionsOptions = {
extension: 'txt'
})
],
space: null,
omitSystemActions: true
space: null
}

describe('fileActions', () => {
Expand Down