import { i18n } from '@kbn/i18n' ; import { ManagementAppMountParams } from '../../../../../src/plugins/management/public' ; type SetBreadcrumbs = ManagementAppMountParams [ 'setBreadcrumbs' ] ; export class BreadcrumbService { private breadcrumbs : { [ key ] : Array < { text : string ; href ? : string ; } > ; } = { dashboard : [ ] , upload : [ ] , } ; private setBreadcrumbsHandler ? : SetBreadcrumbs ; public setup ( setBreadcrumbsHandler ) { this . setBreadcrumbsHandler = setBreadcrumbsHandler ; this . breadcrumbs . dashboard = [ { text : i18n . translate ( 'xpack.licenseMgmt.dashboard.breadcrumb' , { defaultMessage : 'License management' , } ) , href : `/` , } , ] ; this . breadcrumbs . upload = [ ... this . breadcrumbs . dashboard , { text : i18n . translate ( 'xpack.licenseMgmt.upload.breadcrumb' , { defaultMessage : 'Upload' , } ) , } , ] ; } public setBreadcrumbs ( type ) { if ( ! this . setBreadcrumbsHandler ) { throw new Error ( `BreadcrumbService#setup() must be called first!` ) ; } const newBreadcrumbs = this . breadcrumbs [ type ] ? [ ... this . breadcrumbs [ type ] ] : [ ... this . breadcrumbs . home ] ; const lastBreadcrumb = newBreadcrumbs . pop ( ) as { text : string ; href ? : string ; } ; newBreadcrumbs . push ( { ... lastBreadcrumb , href : undefined , } ) ; this . setBreadcrumbsHandler ( newBreadcrumbs ) ; } }