All files / modules/45-dashboards/components/ModuleTagsFilter ModuleTagsFilter.tsx

100% Statements 13/13
100% Branches 3/3
100% Functions 3/3
100% Lines 13/13

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              1x 1x 1x 1x 1x             1x 4x 4x   4x 24x           1x                 4x                       1x  
/*
 * 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 { Checkbox, Layout } from '@wings-software/uicore'
import { useStrings, StringKeys } from 'framework/strings'
import { useFeatureFlags } from '@common/hooks/useFeatureFlag'
import moduleTagCss from '@dashboards/common/ModuleTags.module.scss'
 
export interface ModuleTagsFilterProps {
  selectedFilter: Record<string, boolean>
  setPredefinedFilter: (moduleName: string, checked: boolean) => void
}
 
const ModuleTagsFilter: React.FC<ModuleTagsFilterProps> = ({ selectedFilter, setPredefinedFilter }) => {
  const { getString } = useStrings()
  const { CENG_ENABLED, CING_ENABLED, CDNG_ENABLED, CFNG_ENABLED, CUSTOM_DASHBOARD_V2 } = useFeatureFlags()
 
  const renderTagsFilter = (moduleName: string, cssClass: string, text: StringKeys, isEnabled = false) => {
    return (
      isEnabled && (
        <Layout.Horizontal flex={{ alignItems: 'center' }}>
          <Checkbox
            checked={selectedFilter[moduleName]}
            onChange={e => {
              setPredefinedFilter(moduleName, e.currentTarget.checked)
            }}
          />
          <div className={`${cssClass} ${moduleTagCss.moduleTag}`}>{getString(text)}</div>
        </Layout.Horizontal>
      )
    )
  }
 
  return (
    <>
      {renderTagsFilter('HARNESS', moduleTagCss.harnessTag, 'dashboards.modules.harness', true)}
      {renderTagsFilter('CE', moduleTagCss.ceTag, 'common.purpose.ce.cloudCost', CENG_ENABLED)}
      {renderTagsFilter('CI', moduleTagCss.ciTag, 'buildsText', CING_ENABLED)}
      {renderTagsFilter('CD', moduleTagCss.cdTag, 'deploymentsText', CDNG_ENABLED)}
      {renderTagsFilter('CF', moduleTagCss.cfTag, 'common.purpose.cf.continuous', CFNG_ENABLED)}
      {renderTagsFilter('CG_CD', moduleTagCss.cgCdTag, 'dashboards.modules.cgDeployments', CUSTOM_DASHBOARD_V2)}
    </>
  )
}
 
export default ModuleTagsFilter