diff --git a/x-pack/legacy/plugins/spaces/public/lib/spaces_manager.ts b/x-pack/legacy/plugins/spaces/public/lib/spaces_manager.ts index cd2939f83e20b..288fc665dead1 100644 --- a/x-pack/legacy/plugins/spaces/public/lib/spaces_manager.ts +++ b/x-pack/legacy/plugins/spaces/public/lib/spaces_manager.ts @@ -51,14 +51,16 @@ export class SpacesManager extends EventEmitter { }); } - public async changeSelectedSpace(space: Space) { - await kfetch({ + public async changeSelectedSpace(space: Space, waitUntil = Promise.resolve()) { + const getSpaceLocation = await kfetch({ pathname: `/api/spaces/v1/space/${encodeURIComponent(space.id)}/select`, method: 'POST', - }) - .then(response => { - if (response.location) { - window.location = response.location; + }); + + Promise.all([getSpaceLocation, waitUntil]) + .then(([{ location }]) => { + if (location) { + window.location = location; } else { this._displayError(); } diff --git a/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_header_nav_button.tsx b/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_header_nav_button.tsx index 45bb79ee749ee..e75a04d0409e5 100644 --- a/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_header_nav_button.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_header_nav_button.tsx @@ -13,16 +13,17 @@ import { ButtonProps } from '../types'; export class SpacesHeaderNavButton extends Component { public render() { + const { spaceSelectorShown, linkTitle, linkIcon, toggleSpaceSelector } = this.props; return ( - {this.props.linkIcon} + {linkIcon} ); } diff --git a/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_menu.tsx b/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_menu.tsx index 76a47ca738627..b91053dc9fa6a 100644 --- a/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_menu.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/nav_control/components/spaces_menu.tsx @@ -6,6 +6,7 @@ import { EuiContextMenuItem, EuiContextMenuPanel, EuiFieldSearch, EuiText } from '@elastic/eui'; import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import React, { Component } from 'react'; import { SPACE_SEARCH_COUNT_THRESHOLD } from '../../../../common/constants'; import { Space } from '../../../../common/model/space'; @@ -163,6 +164,15 @@ class SpacesMenuUI extends Component { private renderSpaceMenuItem = (space: Space): JSX.Element => { const icon = ; + const itemAriaLabel = i18n.translate( + 'xpack.spaces.navControl.spacesMenu.headerNavigationSwitchAriaLabel', + { + defaultMessage: '; Switch to {spaceName} space', + values: { + spaceName: space.name, + }, + } + ); return ( { onClick={this.props.onSelectSpace.bind(this, space)} toolTipTitle={space.description && space.name} toolTipContent={space.description} + aria-label={itemAriaLabel} > {space.name} diff --git a/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx b/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx index 4669bd3608e4f..869ae23ed8d3b 100644 --- a/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx +++ b/x-pack/legacy/plugins/spaces/public/views/nav_control/nav_control_popover.tsx @@ -4,8 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EuiAvatar, EuiPopover, PopoverAnchorPosition } from '@elastic/eui'; import React, { Component, ComponentClass } from 'react'; +import { EuiAvatar, EuiPopover, PopoverAnchorPosition } from '@elastic/eui'; +import { toastNotifications } from 'ui/notify'; +import { i18n } from '@kbn/i18n'; import { Space } from '../../../common/model/space'; import { SpaceAvatar } from '../../components'; import { SpacesManager } from '../../lib/spaces_manager'; @@ -159,6 +161,22 @@ export class NavControlPopover extends Component { }; private onSelectSpace = (space: Space) => { - this.props.spacesManager.changeSelectedSpace(space); + toastNotifications.add({ + title: i18n.translate( + 'xpack.spaces.navControl.spacesMenu.jobCreationFailedNotificationTitle', + { + defaultMessage: 'Switching to {spaceName} space', + values: { + spaceName: space.name, + }, + } + ), + invisible: true, + onClose: () => this.props.spacesManager.changeSelectedSpace(space), + }); + + const timeoutPromise = new Promise(resolve => setTimeout(resolve, 2000)); + this.props.spacesManager.changeSelectedSpace(space, timeoutPromise); + return true; }; }