import { first } from 'rxjs/operators' ; import { i18n } from '@kbn/i18n' ; import type { StartServicesAccessor } from 'src/core/public' ; import { DEFAULT_OBJECT_NOUN } from '../constants' ; import type { PluginsStart } from '../plugin' ; import type { SpacesApiUi } from '../ui_api' ; export function createRedirectLegacyUrl ( getStartServices ) { return async function ( path , objectNoun = DEFAULT_OBJECT_NOUN ) { const [ { notifications , application } ] = await getStartServices ( ) ; const { currentAppId$ , navigateToApp } = application ; const appId = await currentAppId$ . pipe ( first ( ) ) . toPromise ( ) ; const title = i18n . translate ( 'xpack.spaces.redirectLegacyUrlToast.title' , { defaultMessage : `We redirected you to a new URL` , } ) ; const text = i18n . translate ( 'xpack.spaces.redirectLegacyUrlToast.text' , { defaultMessage : `The {objectNoun} you're looking for has a new location. Use this URL from now on.` , values : { objectNoun } , } ) ; notifications . toasts . addInfo ( { title , text } ) ; await navigateToApp ( appId ! , { replace : true , path } ) ; } ; }