From 06bead3f76bd2919d4dd3bddb17aa666f131e735 Mon Sep 17 00:00:00 2001 From: elizavetaRa Date: Mon, 5 Jun 2023 10:53:03 +0200 Subject: [PATCH] hasPriority instead of canBeDefault --- .../components/FilesList/ContextActions.vue | 2 +- .../actions/files/useFileActions.ts | 22 ++++++++++--------- .../files/useFileActionsCreateNewFile.ts | 2 -- .../files/useFileActionsCreateNewFolder.ts | 1 - .../files/useFileActionsDownloadArchive.ts | 1 - .../files/useFileActionsDownloadFile.ts | 1 - .../actions/files/useFileActionsNavigate.ts | 1 - .../actions/files/useFileActionsSetImage.ts | 1 - .../tests/__fixtures__/fileActions.ts | 2 +- packages/web-app-pdf-viewer/src/index.ts | 3 +-- packages/web-app-preview/src/index.ts | 1 - packages/web-app-text-editor/src/index.ts | 10 ++++----- .../actions/files/useFileActionsSetReadme.ts | 1 - .../web-pkg/src/composables/actions/types.ts | 2 +- packages/web-runtime/src/store/apps.ts | 5 ++++- 15 files changed, 25 insertions(+), 30 deletions(-) diff --git a/packages/web-app-files/src/components/FilesList/ContextActions.vue b/packages/web-app-files/src/components/FilesList/ContextActions.vue index 0e72e1ac978..2cba8d3fc05 100644 --- a/packages/web-app-files/src/components/FilesList/ContextActions.vue +++ b/packages/web-app-files/src/components/FilesList/ContextActions.vue @@ -96,7 +96,7 @@ export default defineComponent({ return [...fileHandlers] .filter((item) => item.isEnabled(unref(actionOptions))) - .sort((x, y) => Number(y.canBeDefault) - Number(x.canBeDefault)) + .sort((x, y) => Number(y.hasPriority) - Number(x.hasPriority)) }) const menuItemsShare = computed(() => { diff --git a/packages/web-app-files/src/composables/actions/files/useFileActions.ts b/packages/web-app-files/src/composables/actions/files/useFileActions.ts index ebc0a3fec40..221a0308bc6 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActions.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActions.ts @@ -128,14 +128,14 @@ export const useFileActions = ({ store }: { store?: Store } = {}) => { return false }, - canBeDefault: editor.canBeDefault, + hasPriority: editor.hasPriority, componentType: 'button', class: `oc-files-actions-${kebabCase(apps.meta[editor.app].name).toLowerCase()}-trigger` } }) .sort((first, second) => { // Ensure default are listed first - if (second.canBeDefault !== first.canBeDefault && second.canBeDefault) { + if (second.hasPriority !== first.hasPriority && second.hasPriority) { return 1 } return 0 @@ -216,23 +216,25 @@ export const useFileActions = ({ store }: { store?: Store } = {}) => { const getDefaultAction = (options: FileActionOptions): Action => { const filterCallback = (action) => - action.canBeDefault && action.isEnabled({ ...options, parent: store.getters['Files/currentFolder'] }) // first priority: handlers from config - const defaultEditorActions = unref(editorActions).filter(filterCallback) - if (defaultEditorActions.length) { - return defaultEditorActions[0] - } + const enabledEditorActions = unref(editorActions).filter(filterCallback) // second priority: `/app/open` endpoint of app provider if available // FIXME: files app should not know anything about the `external apps` app const externalAppsActions = loadExternalAppActions(options).filter(filterCallback) - if (externalAppsActions.length) { - return externalAppsActions[0] + + // prioritize apps that have hasPriority set + const appActions = [...enabledEditorActions, ...externalAppsActions].sort( + (a, b) => Number(b.hasPriority) - Number(a.hasPriority) + ) + + if (appActions.length) { + return appActions[0] } // fallback: system actions @@ -290,7 +292,7 @@ export const useFileActions = ({ store }: { store?: Store } = {}) => { componentType: 'button', class: `oc-files-actions-${app.name}-trigger`, isEnabled: () => true, - canBeDefault: defaultApplication === app.name, + hasPriority: defaultApplication === app.name, handler: () => openExternalApp(app.name, driveAliasAndItem, webDavPath, fileId, options.space.shareId), label: () => $gettextInterpolate(label, { appName: app.name }) diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts index 4a313abcc51..b733655239e 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFile.ts @@ -221,7 +221,6 @@ export const useFileActionsCreateNewFile = ({ isEnabled: () => { return unref(currentFolder)?.canUpload({ user: store.getters.user }) }, - canBeDefault: true, componentType: 'button', class: 'oc-files-actions-create-new-file', ext: newFileHandler.ext @@ -237,7 +236,6 @@ export const useFileActionsCreateNewFile = ({ isEnabled: () => { return unref(currentFolder)?.canUpload({ user: store.getters.user }) }, - canBeDefault: true, componentType: 'button', class: 'oc-files-actions-create-new-file', ext: mimeType.ext diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts index ae161a42360..40d826ec289 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsCreateNewFolder.ts @@ -123,7 +123,6 @@ export const useFileActionsCreateNewFolder = ({ isEnabled: () => { return unref(currentFolder)?.canCreate() }, - canBeDefault: true, componentType: 'button', class: 'oc-files-actions-create-new-folder' } diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadArchive.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadArchive.ts index b842f928b15..67ad2619dca 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadArchive.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadArchive.ts @@ -130,7 +130,6 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store } }) return !downloadDisabled }, - canBeDefault: true, componentType: 'button', class: 'oc-files-actions-download-archive-trigger' } diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadFile.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadFile.ts index be8a20a3a92..6233d0c578c 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadFile.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsDownloadFile.ts @@ -51,7 +51,6 @@ export const useFileActionsDownloadFile = () => { } return resources[0].canDownload() }, - canBeDefault: true, componentType: 'button', class: 'oc-files-actions-download-file-trigger' } diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsNavigate.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsNavigate.ts index 74e0d5e10ad..86cd8da0f1c 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsNavigate.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsNavigate.ts @@ -84,7 +84,6 @@ export const useFileActionsNavigate = ({ store }: { store?: Store } = {}) = return true }, - canBeDefault: true, componentType: 'router-link', route: ({ space, resources }) => { if ( diff --git a/packages/web-app-files/src/composables/actions/files/useFileActionsSetImage.ts b/packages/web-app-files/src/composables/actions/files/useFileActionsSetImage.ts index be682d36422..e2063100794 100644 --- a/packages/web-app-files/src/composables/actions/files/useFileActionsSetImage.ts +++ b/packages/web-app-files/src/composables/actions/files/useFileActionsSetImage.ts @@ -108,7 +108,6 @@ export const useFileActionsSetImage = ({ store }: { store?: Store } = {}) = return space.canEditImage({ user: store.getters.user }) }, - canBeDefault: false, componentType: 'button', class: 'oc-files-actions-set-space-image-trigger' } diff --git a/packages/web-app-files/tests/__fixtures__/fileActions.ts b/packages/web-app-files/tests/__fixtures__/fileActions.ts index 1c2837a4fb3..65fc5ea26f6 100644 --- a/packages/web-app-files/tests/__fixtures__/fileActions.ts +++ b/packages/web-app-files/tests/__fixtures__/fileActions.ts @@ -177,7 +177,7 @@ export const getActions = function (actions = []) { isEnabled: () => true, componentType: action.componentType || 'oc-button', class: action.class, - canBeDefault: defaultActions.indexOf(key) > -1, + hasPriority: defaultActions.indexOf(key) > -1, opensInNewWindow: action.opensInNewWindow || false } res.push(actionObj) diff --git a/packages/web-app-pdf-viewer/src/index.ts b/packages/web-app-pdf-viewer/src/index.ts index 396a836274c..121f864a9d7 100644 --- a/packages/web-app-pdf-viewer/src/index.ts +++ b/packages/web-app-pdf-viewer/src/index.ts @@ -27,8 +27,7 @@ const appInfo = { extensions: [ { extension: 'pdf', - routeName: 'pdf-viewer', - canBeDefault: true + routeName: 'pdf-viewer' } ] } diff --git a/packages/web-app-preview/src/index.ts b/packages/web-app-preview/src/index.ts index 03f57f5d1a0..319b1040982 100644 --- a/packages/web-app-preview/src/index.ts +++ b/packages/web-app-preview/src/index.ts @@ -27,7 +27,6 @@ const appInfo = { id: appId, icon: 'eye', extensions: mimeTypes().map((mimeType) => ({ - canBeDefault: true, mimeType, routeName, label: $gettext('Preview') diff --git a/packages/web-app-text-editor/src/index.ts b/packages/web-app-text-editor/src/index.ts index feed0917128..c9d4f85721b 100644 --- a/packages/web-app-text-editor/src/index.ts +++ b/packages/web-app-text-editor/src/index.ts @@ -25,7 +25,6 @@ const fileExtensions = () => { const extensions: { extension: string label: string - canBeDefault?: boolean newFileMenu?: any }[] = [ { @@ -62,14 +61,18 @@ const fileExtensions = () => { } ] + const config = (window as any).__$store.getters.extensionConfigByAppId(appId) let primaryExtensions = (window as any).__$store.getters.extensionConfigByAppId(appId) .primaryExtensions || ['txt', 'md'] + + let extraExtensions = config.extraExtensions || [] if (typeof primaryExtensions === 'string') { primaryExtensions = [primaryExtensions] } + + extensions.push(...extraExtensions.map((ext) => ({ extension: ext }))) return extensions.reduce((acc, extensionItem) => { const isPrimary = primaryExtensions.includes(extensionItem.extension) - extensionItem.canBeDefault = isPrimary if (isPrimary) { extensionItem.newFileMenu = { menuTitle($gettext) { @@ -92,9 +95,6 @@ const appInfo = { extension: extensionItem.extension, ...(Object.prototype.hasOwnProperty.call(extensionItem, 'newFileMenu') && { newFileMenu: extensionItem.newFileMenu - }), - ...(Object.prototype.hasOwnProperty.call(extensionItem, 'canBeDefault') && { - canBeDefault: extensionItem.canBeDefault }) } }) diff --git a/packages/web-pkg/src/composables/actions/files/useFileActionsSetReadme.ts b/packages/web-pkg/src/composables/actions/files/useFileActionsSetReadme.ts index e7713c8fb2e..4e8ff0fefb5 100644 --- a/packages/web-pkg/src/composables/actions/files/useFileActionsSetReadme.ts +++ b/packages/web-pkg/src/composables/actions/files/useFileActionsSetReadme.ts @@ -82,7 +82,6 @@ export const useFileActionsSetReadme = ({ store }: { store?: Store } = {}) return space.canEditReadme({ user: store.getters.user }) }, - canBeDefault: false, componentType: 'button', class: 'oc-files-actions-set-space-readme-trigger' } diff --git a/packages/web-pkg/src/composables/actions/types.ts b/packages/web-pkg/src/composables/actions/types.ts index 12ed230610f..a31b992a28b 100644 --- a/packages/web-pkg/src/composables/actions/types.ts +++ b/packages/web-pkg/src/composables/actions/types.ts @@ -11,7 +11,7 @@ export interface Action { img?: string componentType: 'button' | 'router-link' class: string - canBeDefault?: boolean + hasPriority?: boolean hideLabel?: boolean shortcut?: string keepOpen?: boolean diff --git a/packages/web-runtime/src/store/apps.ts b/packages/web-runtime/src/store/apps.ts index 362ce1e7cd4..efe2d08e6b1 100644 --- a/packages/web-runtime/src/store/apps.ts +++ b/packages/web-runtime/src/store/apps.ts @@ -28,7 +28,10 @@ const mutations = { extension: extension.extension, mimeType: extension.mimeType, handler: extension.handler, - canBeDefault: extension.canBeDefault !== false, + hasPriority: + extension.hasPriority || + state.fileEditorConfigs?.[app]?.priorityExtensions?.includes(extension.extension) || + false, config: (state.fileEditorConfigs || {})[app], ...(extension.label && { label: extension.label }) }