prometheus/web/ui/react-app/src/pages/graph/SeriesName.tsx
Boyko 1c321ed047
React-UI: flex-wrap the content (#6796)
* flex-wrap the content

Signed-off-by: blalov <boiskila@gmail.com>

* wrap formatted series in a div

Signed-off-by: blalov <boiskila@gmail.com>
2020-02-11 15:25:39 +01:00

53 lines
1.3 KiB
TypeScript

import React, { FC } from 'react';
import { metricToSeriesName } from '../../utils';
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 (
<div>
<span className="legend-metric-name">{labels!.__name__ || ''}</span>
<span className="legend-label-brace">{'{'}</span>
{labelNodes}
<span className="legend-label-brace">{'}'}</span>
</div>
);
};
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;