-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter components from hide-component attribues (#215)
* Create a new helper to filter the components array * Adding an example page in the preview site closes #214
- Loading branch information
1 parent
7b15c67
commit 97f6001
Showing
5 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters