Skip to content

Commit

Permalink
Merge pull request #420 from nextcloud/enhancement/sidebar/tab-valida…
Browse files Browse the repository at this point in the history
…tion-warn

Properly validate sidebar tabs and warn
  • Loading branch information
ChristophWurst authored May 31, 2019
2 parents f659fa6 + 48d11ea commit f06101b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/components/AppSidebar/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@
</template>

<script>
import Vue from 'vue'
import Actions from 'Components/Actions'

const IsValidString = function(value) {
return value && typeof value === 'string' && value.trim() !== '' && value.indexOf(' ') === -1
}

export default {
name: 'AppSidebar',
components: {
Expand Down Expand Up @@ -162,11 +167,19 @@ export default {
mounted() {
// Init tabs from $children
this.tabs = this.$children.reduce((tabs, tab) => {
if (tab.name && typeof tab.name === 'string'
&& tab.id && typeof tab.id === 'string' && tab.id.indexOf(' ') === -1
&& tab.icon && typeof tab.icon === 'string' && tab.icon.indexOf(' ') === -1) {
tabs.push(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
}, [])

Expand Down

0 comments on commit f06101b

Please sign in to comment.