Merge pull request #515 from YunoHost/fix-cp-args

Fix config panel apply with empty `args` + fix config panel init error preventing AppInfo from being displayed
This commit is contained in:
Alexandre Aubin 2023-03-24 14:11:39 +01:00 committed by GitHub
commit b8229a6cf3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 13 deletions

View file

@ -28,6 +28,7 @@ export default {
computed: { computed: {
_icon () { _icon () {
if (this.icon) return this.icon
return DEFAULT_STATUS_ICON[this.variant] return DEFAULT_STATUS_ICON[this.variant]
} }
} }

View file

@ -75,7 +75,9 @@
}, },
"info": { "info": {
"forum": "Search or ask the forum!", "forum": "Search or ask the forum!",
"problem": "A problem with this app?" "problem": "A problem with this app?",
"config_panel_error": "An error prevents the configuration panel from being displayed:",
"config_panel_error_please_report": "Please report this error to the YunoHost team to get it fixed!"
}, },
"install": { "install": {
"license": "License: {license}", "license": "License: {license}",

View file

@ -1,5 +1,8 @@
<template> <template>
<view-base :queries="queries" @queries-response="onQueriesResponse" ref="view"> <view-base
:queries="queries" @queries-response="onQueriesResponse" :loading="loading"
ref="view"
>
<yuno-alert v-if="app && app.doc && app.doc.notifications && app.doc.notifications.postInstall.length" variant="info" class="my-4"> <yuno-alert v-if="app && app.doc && app.doc.notifications && app.doc.notifications.postInstall.length" variant="info" class="my-4">
<div class="d-md-flex align-items-center mb-3"> <div class="d-md-flex align-items-center mb-3">
<h2 v-t="'app.doc.notifications.post_install'" class="md-m-0" /> <h2 v-t="'app.doc.notifications.post_install'" class="md-m-0" />
@ -89,6 +92,15 @@
<vue-showdown :markdown="app.description" flavor="github" /> <vue-showdown :markdown="app.description" flavor="github" />
</section> </section>
<yuno-alert
v-if="config_panel_err"
class="mb-4" variant="danger" icon="bug"
>
<p>{{ $t('app.info.config_panel_error') }}</p>
<p>{{ config_panel_err }}</p>
<p>{{ $t('app.info.config_panel_error_please_report') }}</p>
</yuno-alert>
<!-- BASIC INFOS --> <!-- BASIC INFOS -->
<config-panels v-bind="config" @submit="onConfigSubmit"> <config-panels v-bind="config" @submit="onConfigSubmit">
<!-- OPERATIONS TAB --> <!-- OPERATIONS TAB -->
@ -265,6 +277,7 @@ import api, { objectToParams } from '@/api'
import { readableDate } from '@/helpers/filters/date' import { readableDate } from '@/helpers/filters/date'
import { humanPermissionName } from '@/helpers/filters/human' import { humanPermissionName } from '@/helpers/filters/human'
import { required } from '@/helpers/validators' import { required } from '@/helpers/validators'
import { isEmptyValue } from '@/helpers/commons'
import { import {
formatFormData, formatFormData,
formatI18nField, formatI18nField,
@ -288,11 +301,12 @@ export default {
queries: [ queries: [
['GET', `apps/${this.id}?full`], ['GET', `apps/${this.id}?full`],
['GET', { uri: 'users/permissions?full', storeKey: 'permissions' }], ['GET', { uri: 'users/permissions?full', storeKey: 'permissions' }],
['GET', { uri: 'domains' }], ['GET', { uri: 'domains' }]
['GET', `apps/${this.id}/config?full`]
], ],
loading: true,
app: undefined, app: undefined,
form: undefined, form: undefined,
config_panel_err: null,
config: { config: {
panels: [ panels: [
// Fake integration of operations in config panels // Fake integration of operations in config panels
@ -345,14 +359,8 @@ export default {
} }
return linksIcons[linkType] return linksIcons[linkType]
}, },
onQueriesResponse (app, _, __, config) {
if (app.supports_config_panel) {
const config_ = formatYunoHostConfigPanels(config)
// reinject 'operations' fake config tab
config_.panels.unshift(this.config.panels[0])
this.config = config_
}
async onQueriesResponse (app) {
const form = { labels: [] } const form = { labels: [] }
const mainPermission = app.permissions[this.id + '.main'] const mainPermission = app.permissions[this.id + '.main']
@ -429,6 +437,18 @@ export default {
if (!Object.values(this.app.doc.notifications).some((notif) => notif.length)) { if (!Object.values(this.app.doc.notifications).some((notif) => notif.length)) {
this.app.doc.notifications = null this.app.doc.notifications = null
} }
if (app.supports_config_panel) {
await api.get(`apps/${this.id}/config?full`).then((config) => {
const config_ = formatYunoHostConfigPanels(config)
// reinject 'operations' fake config tab
config_.panels.unshift(this.config.panels[0])
this.config = config_
}).catch((err) => {
this.config_panel_err = err.message
})
}
this.loading = false
}, },
async onConfigSubmit ({ id, form, action, name }) { async onConfigSubmit ({ id, form, action, name }) {
@ -438,10 +458,11 @@ export default {
action action
? `apps/${this.id}/actions/${action}` ? `apps/${this.id}/actions/${action}`
: `apps/${this.id}/config/${id}`, : `apps/${this.id}/config/${id}`,
{ args: objectToParams(args) }, isEmptyValue(args) ? {} : { args: objectToParams(args) },
{ key: `apps.${action ? 'action' : 'update'}_config`, id, name: this.id } { key: `apps.${action ? 'action' : 'update'}_config`, id, name: this.id }
).then(() => { ).then(() => {
this.$refs.view.fetchQueries({ triggerLoading: true }) this.loading = true
this.$refs.view.fetchQueries()
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err
const panel = this.config.panels.find(panel => panel.id === id) const panel = this.config.panels.find(panel => panel.id === id)