From 4b5e784081c87f9cd74802b9738106ec5998a83d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 21 Dec 2023 15:10:30 +0100 Subject: [PATCH] Tabs: handle null and array values --- public/js/components/Tabs.js | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 84104b812..80f59e646 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -40,19 +40,37 @@ export default { .get(this.configUrl) .then(result => CoreRESTClient.getData(result.data)) .then(result => { - const tabs = {}; - // TODO(chris): check if result is array - Object.entries(result).forEach(([key, config]) => { - if (!config.component) - return console.error('Component missing for ' + key); + if (!result) + return; - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(config.component))), - title: config.title || key, - config: config.config, - key - } - }); + const tabs = {}; + + if (Array.isArray(result)) { + result.forEach((config, key) => { + if (!config.component) + return console.error('Component missing for ' + key); + + tabs[key] = { + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(config.component))), + title: config.title || key, + config: config.config, + key + } + }); + + } else { + Object.entries(result).forEach(([key, config]) => { + if (!config.component) + return console.error('Component missing for ' + key); + + tabs[key] = { + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(config.component))), + title: config.title || key, + config: config.config, + key + } + }); + } if (tabs[this.default]) this.current = this.default; else @@ -62,7 +80,7 @@ export default { .catch(this.$fhcAlert.handleSystemError); }, template: ` -
+