From a6569f8dfb6bc6a2dffeabd2a85fb9556a47c26a Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Wed, 26 Aug 2020 01:08:17 -0700 Subject: [PATCH] navigation: fixes navigation expand and collapse --- components/core/ApplicationNavigation.js | 129 +++++++++-------------- 1 file changed, 49 insertions(+), 80 deletions(-) diff --git a/components/core/ApplicationNavigation.js b/components/core/ApplicationNavigation.js index 299ad3eb..78b2ed0f 100644 --- a/components/core/ApplicationNavigation.js +++ b/components/core/ApplicationNavigation.js @@ -143,61 +143,59 @@ const STYLES_ICON_ELEMENT = css` } `; -const Item = ({ - data, - id, - activeIds, - level, - children, - showActive, - decorator, - onToggleShow, - onNavigateTo, -}) => { +const Item = (props) => { return ( - + - {onToggleShow ? ( + {props.treeChildren && props.treeChildren.length ? ( ) : null} - onNavigateTo({ id }, data)}> + props.onNavigateTo({ id: props.id }, props.data)} + > - {IconMap[decorator]} - + /> onNavigateTo({ id }, data)} + children={props.children} + onClick={() => props.onNavigateTo({ id: props.id }, props.data)} style={{ - color: activeIds[id] ? Constants.system.brand : null, + color: props.activeIds[props.id] ? Constants.system.brand : null, }} - > - {children} - + /> ); }; class NodeReference extends React.Component { + static defaultProps = { + treeChildren: [], + }; + state = { showTreeChildren: false, }; @@ -207,65 +205,41 @@ class NodeReference extends React.Component { }; render() { - const { - id, - activeId, - activeIds, - level, - children, - treeChildren, - decorator, - onNavigateTo, - data, - } = this.props; - const { showTreeChildren } = this.state; - - let showActive = showTreeChildren || activeIds[id]; - let showChildren = showActive && treeChildren && treeChildren.length; - return ( - {children} - + id={this.props.id} + data={this.props.data} + activeId={this.props.activeId} + activeIds={this.props.activeIds} + level={this.props.level} + treeChildren={this.props.treeChildren} + onNavigateTo={this.props.onNavigateTo} + decorator={this.props.decorator} + onToggleShow={this._handleToggleShow} + expanded={this.state.showTreeChildren} + children={this.props.children} + /> - {showChildren - ? treeChildren.map((child) => { - if (!child) { - return null; - } - - if (child.ignore) { + {this.state.showTreeChildren + ? this.props.treeChildren.map((child) => { + if (!child || child.ignore) { return null; } return ( - {child.name} - + children={child.name} + /> ); }) : null} @@ -300,11 +274,7 @@ export default class ApplicationNavigation extends React.Component { /> {this.props.navigation.map((each) => { - if (!each) { - return null; - } - - if (each.ignore) { + if (!each || each.ignore) { return null; } @@ -319,9 +289,8 @@ export default class ApplicationNavigation extends React.Component { level={0} treeChildren={each.children} decorator={each.decorator} - > - {each.name} - + children={each.name} + /> ); })}