import React from 'react' ; import { MissingAnnotationEmptyState } from '@backstage/core-components' ; import { PrometheusGraph } from './PrometheusGraph' ; import { useEntity } from '@backstage/plugin-catalog-react' ; import { isPrometheusGraphAvailable , PROMETHEUS_RULE_ANNOTATION , } from '../util' ; export const PrometheusGraphEntityWrapper = ( { step = 14 , range = { hours : 1 } , graphType , } ) => { const { entity } = useEntity ( ) ; const graphContent = isPrometheusGraphAvailable ( entity ) ; if ( ! graphContent ) { return ( < MissingAnnotationEmptyState annotation = { PROMETHEUS_RULE_ANNOTATION } / > ) ; } const ruleTuples = graphContent ? entity . metadata . annotations ! ! [ PROMETHEUS_RULE_ANNOTATION ] . split ( ',' ) . map ( it => it . split ( '|' ) ) : [ ] ; if ( ruleTuples . length > 0 ) { const [ query , dimension ] = ruleTuples [ 0 ] ; return ( < PrometheusGraph dimension = { dimension } query = { query } range = { range } step = { step } graphType = { graphType } / > ) ; } return < > < />; } ;