Skip to content

Commit

Permalink
Hide popover when clicking the Manage Spaces button (elastic#24166)
Browse files Browse the repository at this point in the history
Fixes elastic#24135 

This PR closes the space selector popover after clicking the Manage Spaces button. Previously, the popover would stay open, which is confusing and annoying
  • Loading branch information
legrego authored Oct 18, 2018
1 parent 6458e48 commit 016034e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
size?: 's' | 'l';
style?: CSSProperties;
userProfile: UserProfile;
onClick?: () => void;
}

export class ManageSpacesButton extends Component<Props, {}> {
Expand All @@ -36,6 +37,9 @@ export class ManageSpacesButton extends Component<Props, {}> {
}

private navigateToManageSpaces = () => {
if (this.props.onClick) {
this.props.onClick();
}
window.location.replace(MANAGE_SPACES_URL);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exports[`NavControlPopover renders without crashing 1`] = `
repositionOnScroll={true}
>
<Component
onManageSpacesClick={[Function]}
userProfile={
Object {
"hasCapability": [Function],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports[`SpacesDescription renders without crashing 1`] = `
key="manageSpacesButton"
>
<ManageSpacesButton
onClick={[MockFunction]}
size="s"
style={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { SpacesDescription } from './spaces_description';
describe('SpacesDescription', () => {
it('renders without crashing', () => {
expect(
shallow(<SpacesDescription userProfile={{ hasCapability: () => true }} />)
shallow(
<SpacesDescription
userProfile={{ hasCapability: () => true }}
onManageSpacesClick={jest.fn()}
/>
)
).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './spaces_description.less';

interface Props {
userProfile: UserProfile;
onManageSpacesClick: () => void;
}

export const SpacesDescription: SFC<Props> = (props: Props) => {
Expand All @@ -27,7 +28,12 @@ export const SpacesDescription: SFC<Props> = (props: Props) => {
<p>{SPACES_FEATURE_DESCRIPTION}</p>
</EuiText>
<div key="manageSpacesButton" className="spacesDescription__manageButtonWrapper">
<ManageSpacesButton size="s" style={{ width: `100%` }} userProfile={props.userProfile} />
<ManageSpacesButton
size="s"
style={{ width: `100%` }}
userProfile={props.userProfile}
onClick={props.onManageSpacesClick}
/>
</div>
</EuiContextMenuPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import './spaces_menu.less';
interface Props {
spaces: Space[];
onSelectSpace: (space: Space) => void;
onManageSpacesClick: () => void;
userProfile: UserProfile;
}

Expand Down Expand Up @@ -139,6 +140,7 @@ export class SpacesMenu extends Component<Props, State> {
size="s"
style={{ width: `100%` }}
userProfile={this.props.userProfile}
onClick={this.props.onManageSpacesClick}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ export class NavControlPopover extends Component<Props, State> {

let element: React.ReactNode;
if (this.state.spaces.length < 2) {
element = <SpacesDescription userProfile={this.props.userProfile} />;
element = (
<SpacesDescription
userProfile={this.props.userProfile}
onManageSpacesClick={this.toggleSpaceSelector}
/>
);
} else {
element = (
<SpacesMenu
spaces={this.state.spaces}
onSelectSpace={this.onSelectSpace}
userProfile={this.props.userProfile}
onManageSpacesClick={this.toggleSpaceSelector}
/>
);
}
Expand Down

0 comments on commit 016034e

Please sign in to comment.