Skip to content

Commit 5b13d66

Browse files
committed
Use default app from app provider and early returns in fileActions
1 parent 1f639f6 commit 5b13d66

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

packages/web-app-external/src/App.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ export default {
101101
headers.append('X-Requested-With', 'XMLHttpRequest')
102102
103103
const configUrl = this.configuration.server
104-
const appOpenUrl = this.capabilities.files.app_providers[0].open_url.replace('/app', 'app')
105-
const url = configUrl + appOpenUrl + '?file_id=' + this.fileId + '&app_name=' + this.appName
104+
const appOpenUrl = this.capabilities.files.app_providers[0].open_url.replace(/^\/+/, '')
105+
const url =
106+
configUrl +
107+
appOpenUrl +
108+
`?file_id=${this.fileId}` +
109+
(this.appName ? `&app_name=${this.appName}` : '')
106110
107111
const response = await fetch(url, {
108112
method: 'POST',

packages/web-app-external/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const appInfo = {
1515
const routes = [
1616
{
1717
name: 'apps',
18-
path: '/:app/:file_id',
18+
path: '/:file_id/:app?',
1919
components: {
2020
app: App
2121
},

packages/web-app-files/src/mixins/fileActions.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,32 @@ export default {
143143
// returns the _first_ action from actions array which we now construct from
144144
// available mime-types coming from the app-provider and existing actions
145145
$_fileActions_triggerDefaultAction(resource) {
146-
const actions = this.$_fileActions_getAllAvailableActions(resource).filter(
147-
(action) => action.canBeDefault
148-
)
149-
actions[0].handler(resource, actions[0].handlerData)
146+
const action = this.$_fileActions_getDefaultAction(resource)
147+
action.handler(resource, action.handlerData)
148+
},
149+
150+
$_fileActions_getDefaultAction(resource) {
151+
const filterCallback = (action) =>
152+
action.canBeDefault && action.isEnabled({ resource, parent: this.currentFolder })
153+
154+
// first priority: handlers from config
155+
const defaultEditorActions = this.$_fileActions_editorActions.filter(filterCallback)
156+
if (defaultEditorActions.length) {
157+
return defaultEditorActions[0]
158+
}
159+
160+
// second priority: `/app/open` endpoint of app provider if available
161+
// FIXME: files app should not know anything about the `external apps` app
162+
const externalAppsActions =
163+
this.$_fileActions_loadExternalAppActions(resource).filter(filterCallback)
164+
if (externalAppsActions.length) {
165+
return {
166+
handler: () => this.$_fileActions_openLink(undefined, resource.fileId)
167+
}
168+
}
169+
170+
// fallback: system actions
171+
return this.$_fileActions_systemActions.filter(filterCallback)
150172
},
151173

152174
$_fileActions_getAllAvailableActions(resource) {
@@ -195,9 +217,11 @@ export default {
195217
},
196218

197219
$_fileActions_openLink(appName, resourceId) {
220+
const params = { file_id: resourceId }
221+
if (appName) params.app = appName
198222
const routeData = this.$router.resolve({
199223
name: 'external-apps',
200-
params: { app: appName, file_id: resourceId }
224+
params
201225
})
202226
// TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
203227
window.open(routeData.href, '_blank')

0 commit comments

Comments
 (0)