Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified renderButtons() in drawer/Menu.jsx (issue 1526) #1527

Merged
merged 6 commits into from
Mar 10, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions web/client/plugins/drawer/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,28 @@ var Menu = React.createClass({
);
},
renderButtons() {
return this.props.children.map((child) => (
<Button key={child.props.eventKey} bsSize="large" className={(child.props.buttonConfig && child.props.buttonConfig.buttonClassName) ? child.props.buttonConfig.buttonClassName : "square-button"} onClick={this.props.onChoose.bind(null, child.props.eventKey)} bsStyle={this.props.activeKey === child.props.eventKey ? 'default' : 'primary'}>
{child.props.glyph ? <Glyphicon glyph={child.props.glyph} /> : child.props.icon}
</Button>
));
let toReturn = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't do sideeffects, the map function on arrays returns an array, don't use it as a forEach.

Something more similar to this is preferrable:

return this.props.children.map((child) => {
    const button = (<Button key={child.props.eventKey} bsSize="large" className={(child.props.buttonConfig && child.props.buttonConfig.buttonClassName) ? child.props.buttonConfig.buttonClassName : "square-button"} onClick={this.props.onChoose.bind(null, child.props.eventKey)} bsStyle={this.props.activeKey === child.props.eventKey ? 'default' : 'primary'}>
                        {child.props.glyph ? <Glyphicon glyph={child.props.glyph} /> : child.props.icon}
                    </Button>);
    const tooltip = <Tooltip key={"tooltip." + child.props.eventKey} id={"tooltip." + child.props.eventKey}>{child.props.tooltip || ''}</Tooltip>;
    return child.props.tooltip ? (
        <OverlayTrigger placement={"top"} key={"overlay-trigger." + child.props.eventKey}
            overlay={tooltip}>
            {button}
        </OverlayTrigger>
    ) : button;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

this.props.children.map((child) => {
if (child && child.props.buttonConfig && child.props.buttonConfig.tooltip) {
let myTooltip = (<Tooltip key={"tooltip." + child.props.eventKey} id={"tooltip." + child.props.eventKey} >{child.props.buttonConfig.tooltip}</Tooltip>);
toReturn.push(myTooltip);
toReturn.push(
<OverlayTrigger placement={"top"} key={"overlay-trigger." + child.props.eventKey} overlay={myTooltip}>
<Button key={child.props.eventKey} bsSize="large" className={(child.props.buttonConfig && child.props.buttonConfig.buttonClassName) ? child.props.buttonConfig.buttonClassName : "square-button"} onClick={this.props.onChoose.bind(null, child.props.eventKey)} bsStyle={this.props.activeKey === child.props.eventKey ? 'default' : 'primary'}>
{child.props.glyph ? <Glyphicon glyph={child.props.glyph} /> : child.props.icon}
</Button>
</OverlayTrigger>
);
} else {
toReturn.push(
<Button key={child.props.eventKey} bsSize="large" className={(child.props.buttonConfig && child.props.buttonConfig.buttonClassName) ? child.props.buttonConfig.buttonClassName : "square-button"} onClick={this.props.onChoose.bind(null, child.props.eventKey)} bsStyle={this.props.activeKey === child.props.eventKey ? 'default' : 'primary'}>
{child.props.glyph ? <Glyphicon glyph={child.props.glyph} /> : child.props.icon}
</Button>
);
}
}
);
return toReturn;
},
renderContent() {
const header = this.props.single ? (
Expand Down