All files / modules/70-pipeline/components/PipelineStudio/PipelineVariables/VariablesHeader VariablesHeader.tsx

100% Statements 11/11
86.67% Branches 13/15
100% Functions 1/1
100% Lines 11/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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80              26x 26x 26x 26x 26x   26x               26x 21x             21x   21x 21x                                                                                              
/*
 * 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 from 'react'
import { Button, ButtonSize, ButtonVariation, ExpandingSearchInput, Icon, Layout, Text } from '@harness/uicore'
import { FontVariation, Color } from '@harness/design-system'
import { useStrings } from 'framework/strings'
import { usePipelineVariables } from '@pipeline/components/PipelineVariablesContext/PipelineVariablesContext'
 
import css from '../PipelineVariables.module.scss'
 
export interface VariablesHeaderProps {
  enableSearch?: boolean
  applyChanges(): void
  discardChanges(): void
}
 
export function VariablesHeader(props: VariablesHeaderProps): JSX.Element {
  const { enableSearch = true, applyChanges, discardChanges } = props
  const {
    onSearchInputChange,
    searchIndex = 0,
    searchResults = [],
    goToNextSearchResult,
    goToPrevSearchResult
  } = usePipelineVariables()
 
  const { getString } = useStrings()
  return (
    <>
      <div className={css.variablePanelHeader}>
        <div className={css.variableTitle}>
          <Layout.Horizontal>
            <Icon name="pipeline-variables" size={24} color={Color.PRIMARY_7} />
            <Text font={{ variation: FontVariation.H4 }} tooltipProps={{ dataTooltipId: 'pipelineVariables' }}>
              {getString('variablesText')}
            </Text>
          </Layout.Horizontal>
        </div>
        <div>
          {enableSearch && (
            <ExpandingSearchInput
              alwaysExpanded
              width={420}
              onChange={onSearchInputChange}
              showPrevNextButtons
              fixedText={`${Math.min((searchIndex || 0) + 1, searchResults?.length)} / ${searchResults?.length}`}
              onNext={goToNextSearchResult}
              onPrev={goToPrevSearchResult}
              onEnter={goToNextSearchResult}
              placeholder={getString('search')}
            />
          )}
        </div>
        <div className={css.mainActions}>
          <Button
            variation={ButtonVariation.SECONDARY}
            size={ButtonSize.SMALL}
            text={getString('applyChanges')}
            onClick={applyChanges}
          />
          <Button minimal size={ButtonSize.SMALL} text={getString('pipeline.discard')} onClick={discardChanges} />
        </div>
      </div>
      <div className={css.variableListHeader}>
        <Text font={{ variation: FontVariation.SMALL_BOLD }} color={Color.GREY_600}>
          {getString('variableLabel')}
        </Text>
        <Text font={{ variation: FontVariation.SMALL_BOLD }} color={Color.GREY_600}>
          {getString('common.input')}
        </Text>
      </div>
    </>
  )
}