Change regex for static legend label to include up to first period

pull/4643/head
Alirie Gray 2018-10-23 15:56:04 -07:00
parent 3c70128525
commit 8333286e06
2 changed files with 21 additions and 2 deletions

View File

@ -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)
})
})

View File

@ -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, '')
} }