Skip to content

Commit

Permalink
feat: filter components from hide-component attribues (#215)
Browse files Browse the repository at this point in the history
* Create a new helper to filter the components array
* Adding an example page in the preview site

closes #214
  • Loading branch information
benjaminParisel authored Apr 3, 2024
1 parent 7b15c67 commit 97f6001
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
13 changes: 13 additions & 0 deletions preview-src/hide-components-entry.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
= Hide components
:page-hide-components: abc, bonita


== Header entry

In the header, the Bonita Theme and Project ABC should be hidden on this page. But if you go on another page, the both entry should be available.


== Navigation explore

In the navigation explore section (on the bottom-left of the page), the Bonita Theme and Project ABC should be hidden on this page. But if you go on another page, the both entry should be available.

3 changes: 3 additions & 0 deletions preview-src/ui-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ page:
- content: Not editable page
url: /bonita/dev/test-not-editable-page.html
urlType: internal
- content: Hide component entry
url: /bonita/dev/hide-components-entry.html
urlType: internal
- content: Message blocks
items:
- content: Out of support
Expand Down
25 changes: 25 additions & 0 deletions src/helpers/isComponentToHide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

module.exports = (components, page) => {
const componentsToHide = page.attributes?.['hide-components']
if (page.attributes?.['hide-components']) {
const arrayToHide = trimItems(componentsToHide.split(','))
const compos = transformAsAnArrayIfNeeded(components)
return compos.filter((component) => !arrayToHide.includes(component.name))
}
return components

function trimItems (componentsToHide) {
return componentsToHide.map((c) => c.trim())
}

/**
* Transform the components an array if needed
* @param components, could be an array of components or
* an object { component1 : {name: component1}, {name:component2, {...}}}
* @returns an array of component
*/
function transformAsAnArrayIfNeeded (components) {
return Array.isArray(components) ? components : Object.values(components)
}
}
2 changes: 1 addition & 1 deletion src/partials/header-content.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div id="topbar-nav" class="navbar-menu">
{{#unless site.keys.hideNavbarComponentsList}}
{{#each site.components}}
{{#each (isComponentToHide site.components page) }}
<div class="navbar-item is-hoverable">
<a class="navbar-link" href="{{{./latest.url}}}">{{{./title}}}</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/partials/nav-explore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
{{/if}}
<ul class="components">
{{#each site.components}}
{{#each (isComponentToHide site.components page) }}
<li class="component{{#if (eq this @root.page.component)}} is-current{{/if}}">
<span class="title">{{{./title}}}</span>
<ul class="versions">
Expand Down

0 comments on commit 97f6001

Please sign in to comment.