Skip to content

Commit

Permalink
hasPriority instead of canBeDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
elizavetaRa committed Jun 5, 2023
1 parent bfa6cf2 commit 06bead3
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {

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
Expand Down Expand Up @@ -216,23 +216,25 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {

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
Expand Down Expand Up @@ -290,7 +292,7 @@ export const useFileActions = ({ store }: { store?: Store<any> } = {}) => {
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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export const useFileActionsCreateNewFolder = ({
isEnabled: () => {
return unref(currentFolder)?.canCreate()
},
canBeDefault: true,
componentType: 'button',
class: 'oc-files-actions-create-new-folder'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const useFileActionsDownloadArchive = ({ store }: { store?: Store<any> }
})
return !downloadDisabled
},
canBeDefault: true,
componentType: 'button',
class: 'oc-files-actions-download-archive-trigger'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const useFileActionsDownloadFile = () => {
}
return resources[0].canDownload()
},
canBeDefault: true,
componentType: 'button',
class: 'oc-files-actions-download-file-trigger'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const useFileActionsNavigate = ({ store }: { store?: Store<any> } = {}) =

return true
},
canBeDefault: true,
componentType: 'router-link',
route: ({ space, resources }) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export const useFileActionsSetImage = ({ store }: { store?: Store<any> } = {}) =

return space.canEditImage({ user: store.getters.user })
},
canBeDefault: false,
componentType: 'button',
class: 'oc-files-actions-set-space-image-trigger'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/tests/__fixtures__/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions packages/web-app-pdf-viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const appInfo = {
extensions: [
{
extension: 'pdf',
routeName: 'pdf-viewer',
canBeDefault: true
routeName: 'pdf-viewer'
}
]
}
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-preview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const appInfo = {
id: appId,
icon: 'eye',
extensions: mimeTypes().map((mimeType) => ({
canBeDefault: true,
mimeType,
routeName,
label: $gettext('Preview')
Expand Down
10 changes: 5 additions & 5 deletions packages/web-app-text-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const fileExtensions = () => {
const extensions: {
extension: string
label: string
canBeDefault?: boolean
newFileMenu?: any
}[] = [
{
Expand Down Expand Up @@ -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) {
Expand All @@ -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
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export const useFileActionsSetReadme = ({ store }: { store?: Store<any> } = {})

return space.canEditReadme({ user: store.getters.user })
},
canBeDefault: false,
componentType: 'button',
class: 'oc-files-actions-set-space-readme-trigger'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/composables/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Action<T = ActionOptions> {
img?: string
componentType: 'button' | 'router-link'
class: string
canBeDefault?: boolean
hasPriority?: boolean
hideLabel?: boolean
shortcut?: string
keepOpen?: boolean
Expand Down
5 changes: 4 additions & 1 deletion packages/web-runtime/src/store/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down

0 comments on commit 06bead3

Please sign in to comment.