import { CoreStart , CoreSetup } from 'opensearch-dashboards/public' ; import { OpenSearchDashboardsLegacyStart } from 'src/plugins/opensearch_dashboards_legacy/public' ; import { Subscription } from 'rxjs' ; import { navigateToDefaultApp } from './navigate_to_default_app' ; import { createLegacyUrlForwardApp , createLegacyUrlForwardCurrentApp } from './forward_app' ; import { navigateToLegacyOpenSearchDashboardsUrl } from './forward_app/navigate_to_legacy_opensearch_dashboards_url' ; export interface ForwardDefinition { legacyAppId : string ; newAppId : string ; rewritePath : ( legacyPath : string ) => string ; } export class UrlForwardingPlugin { private forwardDefinitions : ForwardDefinition [ ] = [ ] ; private currentAppId : string | undefined ; private currentAppIdSubscription : Subscription | undefined ; public setup ( core ) { core . application . register ( createLegacyUrlForwardApp ( core , this . forwardDefinitions ) ) ; core . application . register ( createLegacyUrlForwardCurrentApp ( core , this . forwardDefinitions ) ) ; return { param legacyAppId param newAppId param rewritePath forwardApp : ( legacyAppId , newAppId , rewritePath ? ) => { this . forwardDefinitions . push ( { legacyAppId , newAppId , rewritePath : rewritePath || ( ( path ) => `#${ path . replace ( `/${ legacyAppId }` , '' ) || '/' }` ) , } ) ; } , } ; } public start ( { application , http : { basePath } , uiSettings } , { opensearchDashboardsLegacy } ) { this . currentAppIdSubscription = application . currentAppId$ . subscribe ( ( currentAppId ) => { this . currentAppId = currentAppId ; } ) ; return { /**
             * Navigates to the app defined as opensearch-dashboards.defaultAppId.
             * This takes redirects into account and uses the right mechanism to navigate.
             */ navigateToDefaultApp : ( { overwriteHash } = { overwriteHash : true } ) => { navigateToDefaultApp ( opensearchDashboardsLegacy . config . defaultAppId , this . forwardDefinitions , application , basePath , this . currentAppId , overwriteHash ) ; } , param hash navigateToLegacyOpenSearchDashboardsUrl : ( hash ) => { return navigateToLegacyOpenSearchDashboardsUrl ( hash , this . forwardDefinitions , basePath , application ) ; } , deprecated getForwards : ( ) => this . forwardDefinitions , } ; } public stop ( ) { if ( this . currentAppIdSubscription ) { this . currentAppIdSubscription . unsubscribe ( ) ; } } } export type UrlForwardingSetup = ReturnType < UrlForwardingPlugin [ 'setup' ] > ; export type UrlForwardingStart = ReturnType < UrlForwardingPlugin [ 'start' ] > ;