[dashboard] Fix URLShortLinkButton position after click anchor link (#7812)

This commit is contained in:
Grace Guo 2019-07-03 15:05:51 -07:00 committed by GitHub
parent 9dac805e7e
commit 9b8996038e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 13 deletions

View File

@ -131,6 +131,17 @@ describe('Tabs', () => {
expect(onChangeTab.callCount).toBe(1);
});
it('should not call onChangeTab when anchor link is clicked', () => {
const onChangeTab = sinon.spy();
const wrapper = setup({ editMode: true, onChangeTab });
wrapper
.find('.dashboard-component-tabs .nav-tabs a .short-link-trigger')
.at(1) // will not call if it is already selected
.simulate('click');
expect(onChangeTab.callCount).toBe(0);
});
it('should render a HoverMenu in editMode', () => {
let wrapper = setup();
expect(wrapper.find(HoverMenu)).toHaveLength(0);

View File

@ -38,11 +38,6 @@ const defaultProps = {
class AnchorLink extends React.PureComponent {
constructor(props) {
super(props);
this.handleClickAnchorLink = this.handleClickAnchorLink.bind(this);
}
componentDidMount() {
const hash = this.getLocationHash();
@ -65,17 +60,12 @@ class AnchorLink extends React.PureComponent {
return (window.location.hash || '').substring(1);
}
handleClickAnchorLink(ev) {
ev.stopPropagation();
}
render() {
const { anchorLinkId, filters, showShortLinkButton, placement } = this.props;
return (
<span
className="anchor-link-container"
id={anchorLinkId}
onClick={this.handleClickAnchorLink}
>
{showShortLinkButton &&
<URLShortLinkButton

View File

@ -78,8 +78,8 @@ class URLShortLinkButton extends React.Component {
onEnter={this.getCopyUrl}
overlay={this.renderPopover()}
>
<span className="btn btn-default btn-sm" data-test="short-link-button">
<i className="fa fa-link" />&nbsp;
<span className="short-link-trigger btn btn-default btn-sm" data-test="short-link-button">
<i className="short-link-trigger fa fa-link" />&nbsp;
</span>
</OverlayTrigger>
);

View File

@ -100,7 +100,14 @@ class Tabs extends React.PureComponent {
}
}
handleClickTab(tabIndex) {
handleClickTab(tabIndex, ev) {
const target = ev.target;
// special handler for clicking on anchor link icon (or whitespace nearby):
// will show short link popover but do not change tab
if (target.classList.contains('short-link-trigger')) {
return;
}
const { component, createComponent } = this.props;
if (tabIndex === NEW_TAB_INDEX) {