import React, { FC } from 'react'; import metricToSeriesName from './MetricFormat'; interface SeriesNameProps { labels: { [key: string]: string } | null; format: boolean; } const SeriesName: FC = ({ labels, format }) => { const renderFormatted = (): React.ReactElement => { const labelNodes: React.ReactElement[] = []; 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} {'}'} ); }; if (labels === null) { return <>scalar; } if (format) { return renderFormatted(); } // Return a simple text node. This is much faster to scroll through // for longer lists (hundreds of items). return <>{metricToSeriesName(labels!)}; }; export default SeriesName;