From 8333286e06b63e3b6ca2310edeeb37ecec57db49 Mon Sep 17 00:00:00 2001 From: Alirie Gray Date: Tue, 23 Oct 2018 15:56:04 -0700 Subject: [PATCH] Change regex for static legend label to include up to first period --- ui/src/shared/graphs/helpers.test.ts | 19 +++++++++++++++++++ ui/src/shared/graphs/helpers.ts | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 ui/src/shared/graphs/helpers.test.ts diff --git a/ui/src/shared/graphs/helpers.test.ts b/ui/src/shared/graphs/helpers.test.ts new file mode 100644 index 000000000..11b5c1c29 --- /dev/null +++ b/ui/src/shared/graphs/helpers.test.ts @@ -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) + }) +}) diff --git a/ui/src/shared/graphs/helpers.ts b/ui/src/shared/graphs/helpers.ts index c16e176e7..b06e73dca 100644 --- a/ui/src/shared/graphs/helpers.ts +++ b/ui/src/shared/graphs/helpers.ts @@ -167,9 +167,9 @@ export const makeLegendStyles = ( } } -// globally matches anything that ends in a '.' +// matches everything up to the first '.' export const removeMeasurement = (label = '') => { - const [measurement] = label.match(/^(.*)[.]/g) || [''] + const [measurement] = label.match(/^([^.])+./g) || [''] return label.replace(measurement, '') }