import React, { PureComponent } from 'react'; import metricToSeriesName from './MetricFormat'; interface SeriesNameProps { labels: { [key: string]: string } | null; format: boolean; } class SeriesName extends PureComponent { renderFormatted(): React.ReactNode { const labels = this.props.labels!; const labelNodes: React.ReactNode[] = []; let first = true; for (const label in labels) { if (label === '__name__') { continue; } labelNodes.push( {!first && ', '} {label}="{labels[label]}" ); if (first) { first = false; } } return ( <> {labels.__name__ || ''} {'{'} {labelNodes} {'}'} ); } renderPlain() { const labels = this.props.labels!; return metricToSeriesName(labels); } render() { if (this.props.labels === null) { return 'scalar'; } if (this.props.format) { return this.renderFormatted(); } // Return a simple text node. This is much faster to scroll through // for longer lists (hundreds of items). return this.renderPlain(); } } export default SeriesName;