Tabs: handle null and array values

This commit is contained in:
cgfhtw
2023-12-21 15:10:30 +01:00
parent f479e7ff62
commit 4b5e784081
+31 -13
View File
@@ -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: `
<div class="fhc-tabs d-flex flex-column">
<div class="fhc-tabs d-flex flex-column" v-if="Object.keys(tabs).length">
<div class="nav nav-tabs">
<div
v-for="tab in tabs"