Change regex for static legend label to include up to first period
parent
3c70128525
commit
8333286e06
|
@ -0,0 +1,19 @@
|
||||||
|
import {removeMeasurement} from 'src/shared/graphs/helpers'
|
||||||
|
|
||||||
|
describe('removeMeasurement', () => {
|
||||||
|
it('removes the measurement string from a simple label', () => {
|
||||||
|
const label = 'cpu.mean_usage_system'
|
||||||
|
const expected = 'mean_usage_system'
|
||||||
|
const actual = removeMeasurement(label)
|
||||||
|
|
||||||
|
expect(actual).toBe(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('removes the measurement string from a label with a period', () => {
|
||||||
|
const label = 'ping.average[url=www.google.com]'
|
||||||
|
const expected = 'average[url=www.google.com]'
|
||||||
|
const actual = removeMeasurement(label)
|
||||||
|
|
||||||
|
expect(actual).toBe(expected)
|
||||||
|
})
|
||||||
|
})
|
|
@ -167,9 +167,9 @@ export const makeLegendStyles = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// globally matches anything that ends in a '.'
|
// matches everything up to the first '.'
|
||||||
export const removeMeasurement = (label = '') => {
|
export const removeMeasurement = (label = '') => {
|
||||||
const [measurement] = label.match(/^(.*)[.]/g) || ['']
|
const [measurement] = label.match(/^([^.])+./g) || ['']
|
||||||
return label.replace(measurement, '')
|
return label.replace(measurement, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue