All files / modules/75-cf/components/PipelineSteps/FlagConfigurationStep FlagConfigurationStepVariablesView.tsx

45.45% Statements 5/11
0% Branches 0/12
0% Functions 0/2
45.45% Lines 5/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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50              2x 2x   2x       2x               2x                                                      
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React from 'react'
import { pick } from 'lodash-es'
 
import { VariablesListTable } from '@pipeline/components/VariablesListTable/VariablesListTable'
import type { VariableResponseMapValue } from 'services/pipeline-ng'
import type { FlagConfigurationStepData } from './types'
 
import css from './FlagConfiguration.module.scss'
 
export interface FlagConfigurationStepVariablesViewProps {
  metadataMap: Record<string, VariableResponseMapValue>
  variablesData: FlagConfigurationStepData
  originalData: FlagConfigurationStepData
}
 
export function FlagConfigurationStepVariablesView(props: FlagConfigurationStepVariablesViewProps): React.ReactElement {
  const {
    variablesData = {} as FlagConfigurationStepData,
    originalData = {} as FlagConfigurationStepData,
    metadataMap
  } = props
 
  const data: Record<string, string> = pick(variablesData.spec, ['feature', 'environment']) as unknown as Record<
    string,
    string
  >
 
  if (Array.isArray(variablesData.spec?.instructions)) {
    variablesData.spec.instructions.forEach((row, i) => {
      data[`instructions[${i}].value`] = row.type as string // TODO: Correct this
    })
  }
 
  return (
    <VariablesListTable
      className={css.variablesList}
      metadataMap={metadataMap}
      data={data}
      originalData={originalData?.spec as unknown as Record<string, string>} // TODO: Correct this
    />
  )
}