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

AppSidebar: fix tab validation: tabs are optional #445

Merged
merged 1 commit into from
Jun 24, 2019
Merged
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
35 changes: 20 additions & 15 deletions src/components/AppSidebar/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,27 @@ export default {
},
mounted() {
// Init tabs from $children
this.tabs = this.$children.reduce((tabs, tab) => {
if (!tab.name || typeof tab.name !== 'string') {
Vue.util.warn(`This tab is missing a valid name: ${tab.name}`, tab)
return tabs
}
if (!IsValidString(tab.id)) {
Vue.util.warn(`This tab is missing a valid id: ${tab.id}`, tab)
return tabs
}
if (!IsValidString(tab.icon)) {
Vue.util.warn(`This tab is missing a valid icon: ${tab.icon}`, tab)
const tabs = this.$children.filter(comp => comp.$options.name === 'AppSidebarTab')
if (tabs.length === 0 || tabs.length === this.$children.length) {
this.tabs = tabs.reduce((tabs, tab) => {
if (!tab.name || typeof tab.name !== 'string') {
Vue.util.warn(`This tab is missing a valid name: ${tab.name}`, tab)
return tabs
}
if (!IsValidString(tab.id)) {
Vue.util.warn(`This tab is missing a valid id: ${tab.id}`, tab)
return tabs
}
if (!IsValidString(tab.icon)) {
Vue.util.warn(`This tab is missing a valid icon: ${tab.icon}`, tab)
return tabs
}
tabs.push(tab)
return tabs
}
tabs.push(tab)
return tabs
}, [])
}, [])
} else {
Vue.util.warn('You must use either AppSideTab\'s or custom elements.')
}

// init active tab if exists
if (this.tabs.length > 0) {
Expand Down