From ed0b4cd0190b6a20733712285415740fab50553e Mon Sep 17 00:00:00 2001 From: Timmy Luong Date: Thu, 10 Feb 2022 15:46:29 -0800 Subject: [PATCH] fix: fix typo to check against mainColumnName correctly (#735) --- giraffe/package.json | 2 +- giraffe/src/utils/normalizeConfig.test.ts | 86 ++++++++++++++++++++++- giraffe/src/utils/normalizeConfig.ts | 2 +- stories/package.json | 2 +- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/giraffe/package.json b/giraffe/package.json index e8ed92c0..c17f2622 100644 --- a/giraffe/package.json +++ b/giraffe/package.json @@ -1,6 +1,6 @@ { "name": "@influxdata/giraffe", - "version": "2.24.2", + "version": "2.24.3", "main": "dist/index.js", "module": "dist/index.js", "license": "MIT", diff --git a/giraffe/src/utils/normalizeConfig.test.ts b/giraffe/src/utils/normalizeConfig.test.ts index 71a84f7f..bed8b6d5 100644 --- a/giraffe/src/utils/normalizeConfig.test.ts +++ b/giraffe/src/utils/normalizeConfig.test.ts @@ -35,7 +35,61 @@ describe('normalizeConfig', () => { }) }) - it('overrides the "lowerColumnName" and "upperColumnName" when they match "mainColumnName"', () => { + it('overrides the "lowerColumnName" when it matches "mainColumnName"', () => { + const mainColumnName = 'mean' + const config = { + layers: [ + { + type: 'band', + x: '_time', + y: '_value', + fill: ['result', '_field', '_measurement', 'cpu', 'host'], + mainColumnName, + lowerColumnName: mainColumnName, + }, + ], + } as Config + expect(normalizeConfig(config)).toEqual({ + ...config, + layers: [ + { + ...config.layers[0], + upperColumnName: '', + mainColumnName, + lowerColumnName: '', + }, + ], + }) + }) + + it('overrides the "upperColumnName" when it matches "mainColumnName"', () => { + const mainColumnName = 'mean' + const config = { + layers: [ + { + type: 'band', + x: '_time', + y: '_value', + fill: ['result', '_field', '_measurement', 'cpu', 'host'], + upperColumnName: mainColumnName, + mainColumnName, + }, + ], + } as Config + expect(normalizeConfig(config)).toEqual({ + ...config, + layers: [ + { + ...config.layers[0], + upperColumnName: '', + mainColumnName, + lowerColumnName: '', + }, + ], + }) + }) + + it('overrides the "lowerColumnName" and "upperColumnName" when they both match "mainColumnName"', () => { const mainColumnName = 'mean' const config = { layers: [ @@ -92,6 +146,36 @@ describe('normalizeConfig', () => { ], }) }) + + it('allows lowerColumnName and upperColumnName to match if they do not match mainColumnName', () => { + const upperColumnName = 'upperandlower' + const mainColumnName = 'mean' + const lowerColumnName = upperColumnName + const config = { + layers: [ + { + type: 'band', + x: '_time', + y: '_value', + fill: ['result', '_field', '_measurement', 'cpu', 'host'], + upperColumnName, + mainColumnName, + lowerColumnName, + }, + ], + } as Config + expect(normalizeConfig(config)).toEqual({ + ...config, + layers: [ + { + ...config.layers[0], + upperColumnName, + mainColumnName, + lowerColumnName, + }, + ], + }) + }) }) /* diff --git a/giraffe/src/utils/normalizeConfig.ts b/giraffe/src/utils/normalizeConfig.ts index 9e382169..b1948f1d 100644 --- a/giraffe/src/utils/normalizeConfig.ts +++ b/giraffe/src/utils/normalizeConfig.ts @@ -8,7 +8,7 @@ export const normalizeLayers = (layers: LayerConfig[]): LayerConfig[] => if (!upperColumnName || upperColumnName === layerConfig.mainColumnName) { upperColumnName = '' } - if (!lowerColumnName || lowerColumnName === layerConfig.upperColumnName) { + if (!lowerColumnName || lowerColumnName === layerConfig.mainColumnName) { lowerColumnName = '' } return {...layerConfig, upperColumnName, lowerColumnName} diff --git a/stories/package.json b/stories/package.json index 81722328..30e43c0c 100644 --- a/stories/package.json +++ b/stories/package.json @@ -1,6 +1,6 @@ { "name": "@influxdata/giraffe-stories", - "version": "2.24.2", + "version": "2.24.3", "license": "MIT", "repository": { "type": "git",