mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-03 18:07:27 -08:00
fffb5ca1e9
* React UI: More conversions to Function Components Signed-off-by: Julius Volz <julius.volz@gmail.com> * Address chat feedback over Riot Signed-off-by: Julius Volz <julius.volz@gmail.com>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import React, { FC } from 'react';
|
|
import metricToSeriesName from './MetricFormat';
|
|
|
|
interface SeriesNameProps {
|
|
labels: { [key: string]: string } | null;
|
|
format: boolean;
|
|
}
|
|
|
|
const SeriesName: FC<SeriesNameProps> = ({ labels, format }) => {
|
|
const renderFormatted = (): React.ReactElement => {
|
|
const labelNodes: React.ReactElement[] = [];
|
|
let first = true;
|
|
for (const label in labels) {
|
|
if (label === '__name__') {
|
|
continue;
|
|
}
|
|
|
|
labelNodes.push(
|
|
<span key={label}>
|
|
{!first && ', '}
|
|
<span className="legend-label-name">{label}</span>=<span className="legend-label-value">"{labels[label]}"</span>
|
|
</span>
|
|
);
|
|
|
|
if (first) {
|
|
first = false;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<span className="legend-metric-name">{labels!.__name__ || ''}</span>
|
|
<span className="legend-label-brace">{'{'}</span>
|
|
{labelNodes}
|
|
<span className="legend-label-brace">{'}'}</span>
|
|
</>
|
|
);
|
|
};
|
|
|
|
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;
|