prometheus/web/ui/react-app/src/SeriesName.tsx
Julius Volz fffb5ca1e9
React UI: More conversions to Function Components (#6259)
* 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>
2019-11-02 21:45:22 +01:00

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;