From 40ef5b4c269f9d85a94d1b2d6275292239280bef Mon Sep 17 00:00:00 2001 From: axolotle Date: Sat, 17 Apr 2021 19:23:20 +0200 Subject: [PATCH] fix several user errors when no users created --- app/src/helpers/yunohostArguments.js | 6 +++++- app/src/store/data.js | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/helpers/yunohostArguments.js b/app/src/helpers/yunohostArguments.js index 42bd3c53..77636bde 100644 --- a/app/src/helpers/yunohostArguments.js +++ b/app/src/helpers/yunohostArguments.js @@ -98,7 +98,11 @@ export function formatYunoHostArgument (arg) { field.component = 'SelectItem' field.link = { name: arg.type + '-list', text: i18n.t(`manage_${arg.type}s`) } field.props.choices = store.getters[arg.type + 'sAsChoices'] - value = arg.type === 'domain' ? store.getters.mainDomain : field.props.choices[0].value + if (arg.type === 'domain') { + value = store.getters.mainDomain + } else { + value = field.props.choices.length ? field.props.choices[0].value : null + } // Unknown from the specs, try to display it as an input[text] // FIXME throw an error instead ? diff --git a/app/src/store/data.js b/app/src/store/data.js index 7ac1b88a..0dc940d0 100644 --- a/app/src/store/data.js +++ b/app/src/store/data.js @@ -36,7 +36,7 @@ export default { }, 'SET_USERS' (state, [users]) { - state.users = Object.keys(users).length === 0 ? null : users + state.users = users || null }, 'ADD_USERS' (state, [user]) { @@ -161,9 +161,12 @@ export default { }, usersAsChoices: state => { - return Object.values(state.users).map(({ username, fullname, mail }) => { - return { text: `${fullname} (${mail})`, value: username } - }) + if (state.users) { + return Object.values(state.users).map(({ username, fullname, mail }) => { + return { text: `${fullname} (${mail})`, value: username } + }) + } + return [] }, user: state => name => state.users_details[name], // not cached