2019-10-28 07:02:42 -07:00
|
|
|
import React, { PureComponent } from 'react';
|
2019-10-28 10:09:48 -07:00
|
|
|
import metricToSeriesName from './MetricFormat';
|
2019-10-17 05:38:09 -07:00
|
|
|
|
|
|
|
interface SeriesNameProps {
|
2019-10-28 07:02:42 -07:00
|
|
|
labels: { [key: string]: string } | null;
|
2019-10-17 05:38:09 -07:00
|
|
|
format: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SeriesName extends PureComponent<SeriesNameProps> {
|
|
|
|
renderFormatted(): React.ReactNode {
|
|
|
|
const labels = this.props.labels!;
|
|
|
|
|
2019-10-28 07:02:42 -07:00
|
|
|
const labelNodes: React.ReactNode[] = [];
|
2019-10-17 05:38:09 -07:00
|
|
|
let first = true;
|
2019-10-28 07:02:42 -07:00
|
|
|
for (const label in labels) {
|
2019-10-17 05:38:09 -07:00
|
|
|
if (label === '__name__') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
labelNodes.push(
|
|
|
|
<span key={label}>
|
|
|
|
{!first && ', '}
|
2019-10-28 07:02:42 -07:00
|
|
|
<span className="legend-label-name">{label}</span>=<span className="legend-label-value">"{labels[label]}"</span>
|
2019-10-17 05:38:09 -07:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span className="legend-metric-name">{labels.__name__ || ''}</span>
|
|
|
|
<span className="legend-label-brace">{'{'}</span>
|
2019-10-28 07:02:42 -07:00
|
|
|
{labelNodes}
|
2019-10-17 05:38:09 -07:00
|
|
|
<span className="legend-label-brace">{'}'}</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPlain() {
|
|
|
|
const labels = this.props.labels!;
|
2019-10-28 10:09:48 -07:00
|
|
|
return metricToSeriesName(labels);
|
2019-10-17 05:38:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|