Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load extension config #4380

Merged
merged 1 commit into from
Nov 24, 2020
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
7 changes: 6 additions & 1 deletion apps/files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export default {

$_fileActions_openEditor(editor, filePath, fileId) {
if (editor.handler) {
return editor.handler(this.configuration, filePath, fileId)
return editor.handler({
config: this.configuration,
extensionConfig: editor.config,
filePath,
fileId
})
}

// TODO: Refactor in the store
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/editor-handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Load extensions config

We've started loading the config of extensions which can now be defined as an object in the `external_apps` in the config.json.

https://github.com/owncloud/phoenix/pull/4380
3 changes: 0 additions & 3 deletions src/phoenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ async function loadApps () {
}

store.dispatch('registerApp', app.appInfo)
if (config.external_apps) {
store.dispatch('loadExternalAppConfig', { app: app.appInfo, config })
}
}
router.addRoutes(routes.flat())
sync(store, router)
Expand Down
42 changes: 12 additions & 30 deletions src/store/apps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const merge = require('deepmerge')

const state = {
file: {
path: '',
Expand Down Expand Up @@ -42,34 +40,6 @@ const actions = {
},
addFileAction({ commit }, action) {
commit('ADD_FILE_ACTION', action)
},

/**
* Load config for external app
* @param {Object} app AppInfo containing information about app and local config
* @param {Object} config Config from config.json which can overwrite local config from AppInfo
*/
loadExternalAppConfig({ dispatch }, { app, config }) {
config.external_apps.forEach(extension => {
// Check if app is loaded from external server
// Extension id = id from external apps array
// App id = id specified in AppInfo
if (extension.id === app.id && (app.config || extension.config)) {
if (app.config && extension.config) {
dispatch(`${app.name}/loadConfig`, merge(app.config, extension.config), { root: true })
return
}

if (app.config) {
dispatch(`${app.name}/loadConfig`, app.config, { root: true })
return
}

if (extension.config) {
dispatch(`${app.name}/loadConfig`, extension.config, { root: true })
}
}
})
}
}

Expand Down Expand Up @@ -125,6 +95,18 @@ const mutations = {
},
FETCH_FILE(state, filePath) {
state.file.path = filePath
},

LOAD_EXTENSION_CONFIG(state, { id, config }) {
const editors = state.fileEditors

for (const editor of editors) {
if (editor.app === id) {
editor.config = config
}
}

state.fileEditors = editors
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/store/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ const state = {
}

const actions = {
loadConfig(context, config) {
context.commit('LOAD_CONFIG', config)
loadConfig({ commit }, config) {
commit('LOAD_CONFIG', config)

if (config.external_apps) {
config.external_apps.forEach(externalApp => {
if (externalApp.config !== undefined) {
commit(
'LOAD_EXTENSION_CONFIG',
{ id: externalApp.id, config: externalApp.config },
{ root: true }
)
}
})
}
},
loadTheme(context, { theme, name }) {
theme.name = name
Expand Down