mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-18 19:44:06 -08:00
e0443e6fa3
* Add MetricFormat unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add App unit tests; Add debug script Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Checkbox unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add SeriesName unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add QueryStatsView unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Legend unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Remove unused utils/func Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add utils/urlParams unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add utils/timeFormat unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add ExpressionInput unit tests Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add GraphControls unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add TimeInput unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add DataTable unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add SanitizeHTML unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Graph unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Extract utils/html Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add PanelList unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add Panel unit test Signed-off-by: Dustin Hooten <dhooten@splunk.com> * Add react-ui test coverage report to CI Signed-off-by: Dustin Hooten <dhooten@splunk.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import metricToSeriesName from './MetricFormat';
|
|
|
|
interface SeriesNameProps {
|
|
labels: { [key: string]: string } | null;
|
|
format: boolean;
|
|
}
|
|
|
|
class SeriesName extends PureComponent<SeriesNameProps> {
|
|
renderFormatted(): React.ReactNode {
|
|
const labels = this.props.labels!;
|
|
|
|
const labelNodes: React.ReactNode[] = [];
|
|
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>
|
|
</>
|
|
);
|
|
}
|
|
|
|
renderPlain() {
|
|
const labels = this.props.labels!;
|
|
return metricToSeriesName(labels);
|
|
}
|
|
|
|
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;
|