Skip to content

Commit

Permalink
chore(#693): prevent errors with missing data in storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Sep 2, 2024
1 parent 42bd94f commit bcf0646
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions packages/breadcrumb/src/components/DruxtBreadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default {
crumbs: ({ model }) => model,
...mapState({
route: state => state.druxtRouter.route,
routes: state => state.druxtRouter.routes
route: state => state.druxtRouter?.route,
routes: state => state.druxtRouter?.routes
})
},
Expand All @@ -103,9 +103,9 @@ export default {
* Fetch Crumbs
*/
async fetchCrumbs() {
const path = this.path || this.$route.path
const path = this.path || this.$route?.path
let route = this.route
if (path && path !== route.path) {
if (path && path !== route?.path) {
route = await this.getRoute(path)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/druxt/src/components/DruxtModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export default {
// Return only wrapper if fetch state is still pending and Druxt hasn't set
// the available component options.
if (this.$fetchState.pending && !this.component.options?.length) {
if (this.$fetchState.pending && !this.component?.options?.length) {
return h(this.wrapper?.component || 'div', wrapperData)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/menu/src/components/DruxtMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
}),
...mapState({
entities: state => state.druxtMenu.entities
entities: state => state.druxtMenu?.entities
})
},
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/components/DruxtRouter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default {
*/
componentOptions: ({ module, route }) => [
// @TODO - Add Path options.
[module || 'error', route.isHomePath ? 'front' : 'not-front'],
[module || 'error', route?.isHomePath ? 'front' : 'not-front'],
['default']
],
Expand Down Expand Up @@ -259,7 +259,7 @@ export default {
const scopedSlots = {}
// Provide defualt error message.
if (this.model.error) {
if (this.model?.error) {
scopedSlots.default = () => h('div', [
h('h1', [`Error ${this.model.error.statusCode}`]),
h('p', [this.model.error.message]),
Expand Down
6 changes: 3 additions & 3 deletions packages/site/src/components/DruxtSite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
},
data: ({ $druxt }) => ({
defaultTheme: ($druxt.settings.site || {}).theme,
defaultTheme: $druxt?.settings?.site?.theme,
}),
/** */
Expand Down Expand Up @@ -129,7 +129,7 @@ export default {
.addFields(type, ['theme'])
.addFilter('plugin', 'system_main_block')
.addPageLimit(1)
}).then((resources) => resources.data[0].attributes.theme)
})?.then((resources) => resources.data[0].attributes.theme)
}
// Fetch all available regions.
Expand All @@ -139,7 +139,7 @@ export default {
query: new DrupalJsonApiParams()
.addFilter('theme', this.theme || this.defaultTheme)
.addFields(type, ['region']),
}).then((resources) => resources.data.map((resource) => resource.attributes.region).filter((v, i, s) => s.indexOf(v) === i))
})?.then((resources) => resources.data.map((resource) => resource.attributes.region).filter((v, i, s) => s.indexOf(v) === i))
}
},
Expand Down
16 changes: 8 additions & 8 deletions packages/views/src/components/DruxtView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default {
* @type {string[]}
*/
attachments_after() {
if (!((((this.view || {}).data || {}).attributes || {}).display)) return false
if (!this.view?.data?.attributes?.display) return false
const displays = this.view.data.attributes.display
return Object.keys(displays).filter(key => {
Expand All @@ -176,7 +176,7 @@ export default {
* @type {string[]}
*/
attachments_before() {
if (!((((this.view || {}).data || {}).attributes || {}).display)) return false
if (!this.view?.data?.attributes?.display) return false
const displays = this.view.data.attributes.display
return Object.keys(displays).filter(key => {
Expand All @@ -201,7 +201,7 @@ export default {
* @type {object}
*/
display() {
if (!(((this.view || {}).data || {}).attributes || {}).display) return {}
if (!this.view?.data?.attributes?.display) return {}
if (this.display_id === 'default') return this.view.data.attributes.display[this.display_id]
Expand Down Expand Up @@ -259,7 +259,7 @@ export default {
* @type {object[]}
*/
results() {
return (this.resource || {}).data || []
return this.resource?.data || []
},
/**
Expand Down Expand Up @@ -432,8 +432,8 @@ export default {
* @returns {ComponentOptions}
*/
componentOptions: ({ displayId, uuid, view, viewId }) => ([
[viewId || ((view.data || {}).attributes || {}).drupal_internal__id, displayId],
[uuid || (view.data || {}).id, displayId],
[viewId || view?.data?.attributes?.drupal_internal__id, displayId],
[uuid || view?.data?.id, displayId],
[displayId]
]),
Expand All @@ -454,7 +454,7 @@ export default {
type: this.type,
query: new DrupalJsonApiParams().addFilter('drupal_internal__id', this.viewId)
})
this.view = { data: collection.data[0] }
this.view = { data: collection?.data?.[0] }
}
}
},
Expand All @@ -463,7 +463,7 @@ export default {
* Fetch JSON:API Views results.
*/
async fetchData(settings) {
const viewId = this.viewId || (((this.view || {}).data || {}).attributes || {}).drupal_internal__id
const viewId = this.viewId || this.view?.data?.attributes?.drupal_internal__id
if (viewId) {
// Check if we need to bypass cache.
let bypassCache = false
Expand Down

0 comments on commit bcf0646

Please sign in to comment.