# All files / utils normalizeConfig.ts

92.3% Statements 12/13
100% Branches 17/17
100% Functions 3/3
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    1x
    11x
    6x
    6x
    6x
    4x

    6x
    4x

    6x

    9x

     import {Config, LayerConfig} from '../types'

    // TODO: move all layer defaults here, see: https://github.com/influxdata/giraffe/issues/447
    export const normalizeLayers = (layers: LayerConfig[]): LayerConfig[] =>
      layers?.map(layerConfig => {
        if (layerConfig.type === 'band') {
          let {upperColumnName, lowerColumnName} = layerConfig
          if (!upperColumnName || upperColumnName === layerConfig.mainColumnName) {
            upperColumnName = ''
          }
          if (!lowerColumnName || lowerColumnName === layerConfig.mainColumnName) {
            lowerColumnName = ''
          }
          return {...layerConfig, upperColumnName, lowerColumnName}
        }
        return layerConfig
      }) || []

    export const normalizeConfig = (config: Config): Config => ({
      ...config,
      layers: normalizeLayers(config?.layers),
    })