All files / modules/45-dashboards/pages/home FilterTagsSideBar.tsx

100% Statements 20/20
81.25% Branches 26/32
100% Functions 5/5
100% Lines 20/20

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              1x 1x 1x 1x 1x 1x 1x 1x           1x 5x 5x   5x   5x               7x   6x               2x 2x 1x   1x                         1x  
/*
 * 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 cx from 'classnames'
import { useParams } from 'react-router-dom'
import { Button, Container, Layout, Text } from '@wings-software/uicore'
import { FontVariation } from '@harness/design-system'
import { useStrings } from 'framework/strings'
import { useGetTags } from '@dashboards/services/CustomDashboardsService'
import css from './HomePage.module.scss'
 
export interface FilterTagsSideBarProps {
  setFilteredTags: (cb: (prevState: string[]) => string[]) => void
}
 
const FilterTagsSideBar: React.FC<FilterTagsSideBarProps> = ({ setFilteredTags }) => {
  const { getString } = useStrings()
  const { accountId, folderId } = useParams<{ accountId: string; folderId: string }>()
 
  const { data: tagsList, loading: fetchingTags } = useGetTags(accountId, folderId)
 
  return (
    <Layout.Vertical className={css.filterPanel} padding="medium" spacing="medium">
      <Text font={{ variation: FontVariation.FORM_SUB_SECTION }}>{getString('dashboards.homePage.filterByTags')}</Text>
      <Container className={css.predefinedTags}>
        {fetchingTags && <span>{getString('loading')} </span>}
        {!fetchingTags &&
          tagsList?.resource?.tags
            ?.split(',')
            .filter((tag: string) => !!tag)
            .map((tag: string, index: number) => {
              return (
                <Button
                  text={tag}
                  inline
                  minimal
                  className={cx(css.customTag, css.customTagButton)}
                  key={tag + index}
                  onClick={() => {
                    setFilteredTags(prevState => {
                      if (!prevState.includes(tag)) {
                        return [...prevState, tag]
                      }
                      return prevState
                    })
                  }}
                />
              )
            })}
 
        {tagsList?.resource?.tags?.length === 0 && <span>{getString('dashboards.homePage.noTags')}</span>}
      </Container>
    </Layout.Vertical>
  )
}
 
export default FilterTagsSideBar