All files / modules/75-cf/pages/feature-flags-detail/targeting-rules-tab/components/default-rules DefaultRules.tsx

100% Statements 13/13
100% Branches 5/5
100% Functions 2/2
100% Lines 12/12

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 51 52 53 54 55 56 57 58              4x 4x   4x 4x 4x   4x                 4x 142x   142x 284x           142x                                             4x  
/*
 * Copyright 2022 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, { ReactElement } from 'react'
import { FontVariation, FormInput, Heading, SelectOption } from '@harness/uicore'
import type { Variation } from 'services/cf'
import { CFVariationColors } from '@cf/constants'
import { useStrings } from 'framework/strings'
import StringWithTooltip from '@common/components/StringWithTooltip/StringWithTooltip'
import type { StringsMap } from 'framework/strings/StringsContext'
import DisabledFeatureTooltip from '../disabled-feature-tooltip/DisabledFeatureTooltip'
 
export interface DefaultRulesProps {
  featureFlagVariations: Variation[]
  hideSubheading?: boolean
  titleStringId: keyof StringsMap
  inputName: string
}
 
const DefaultRules = (props: DefaultRulesProps): ReactElement => {
  const { featureFlagVariations, titleStringId, inputName, hideSubheading = false } = props
 
  const { getString } = useStrings()
  const variationItems = featureFlagVariations.map<SelectOption>((variation, index) => ({
    label: variation.name || variation.identifier,
    value: variation.identifier,
    icon: { name: 'full-circle', style: { color: CFVariationColors[index] } }
  }))
 
  return (
    <>
      <Heading level={3} font={{ variation: FontVariation.H6 }} margin={{ bottom: 'medium' }}>
        <StringWithTooltip stringId={titleStringId} tooltipId="ff_ffDefaultRules_heading" />
      </Heading>
      {!hideSubheading && (
        <Heading level={4} font={{ variation: FontVariation.BODY2 }} margin={{ bottom: 'small' }}>
          {getString('cf.featureFlags.rules.defaultRule')}
        </Heading>
      )}
      <DisabledFeatureTooltip>
        <FormInput.Select
          style={{ marginBottom: '0' }}
          label={getString('cf.featureFlags.serve')}
          inline
          name={inputName}
          items={variationItems}
        />
      </DisabledFeatureTooltip>
    </>
  )
}
 
export default DefaultRules