import { ManagementAppMountParams } from '../../../../../../../src/plugins/management/public' ; import { textService } from '../text' ; import { linkToHome , linkToSnapshots , linkToRepositories , linkToPolicies , linkToRestoreStatus , } from './' ; type SetBreadcrumbs = ManagementAppMountParams [ 'setBreadcrumbs' ] ; class BreadcrumbService { private breadcrumbs : { [ key ] : Array < { text : string ; href ? : string ; } > ; } = { management : [ ] , home : [ ] , snapshots : [ ] , repositories : [ ] , policies : [ ] , restore_status : [ ] , repositoryAdd : [ ] , repositoryEdit : [ ] , restoreSnapshot : [ ] , policyAdd : [ ] , policyEdit : [ ] , } ; private setBreadcrumbsHandler ? : SetBreadcrumbs ; public setup ( setBreadcrumbsHandler ) { this . setBreadcrumbsHandler = setBreadcrumbsHandler ; this . breadcrumbs . home = [ { text : textService . breadcrumbs . home , href : linkToHome ( ) , } , ] ; this . breadcrumbs . snapshots = [ ... this . breadcrumbs . home , { text : textService . breadcrumbs . snapshots , href : linkToSnapshots ( ) , } , ] ; this . breadcrumbs . repositories = [ ... this . breadcrumbs . home , { text : textService . breadcrumbs . repositories , href : linkToRepositories ( ) , } , ] ; this . breadcrumbs . policies = [ ... this . breadcrumbs . home , { text : textService . breadcrumbs . policies , href : linkToPolicies ( ) , } , ] ; this . breadcrumbs . restore_status = [ ... this . breadcrumbs . home , { text : textService . breadcrumbs . restore_status , href : linkToRestoreStatus ( ) , } , ] ; this . breadcrumbs . repositoryAdd = [ ... this . breadcrumbs . repositories , { text : textService . breadcrumbs . repositoryAdd , } , ] ; this . breadcrumbs . repositoryEdit = [ ... this . breadcrumbs . repositories , { text : textService . breadcrumbs . repositoryEdit , } , ] ; this . breadcrumbs . restoreSnapshot = [ ... this . breadcrumbs . snapshots , { text : textService . breadcrumbs . restoreSnapshot , } , ] ; this . breadcrumbs . policyAdd = [ ... this . breadcrumbs . policies , { text : textService . breadcrumbs . policyAdd , } , ] ; this . breadcrumbs . policyEdit = [ ... this . breadcrumbs . policies , { text : textService . breadcrumbs . policyEdit , } , ] ; } 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 ) ; } } export const breadcrumbService = new BreadcrumbService ( ) ;