All files / modules/75-cf/pages/target-group-detail TargetGroupDetailPage.tsx

100% Statements 30/30
88.46% Branches 23/26
100% Functions 2/2
100% Lines 30/30

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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116              1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x 10x 10x             10x             10x                             10x                 10x   10x 2x     8x 3x       1x           5x                                                               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, { FC } from 'react'
import { useParams } from 'react-router-dom'
import { Page, Tab, Tabs } from '@harness/uicore'
import { useStrings } from 'framework/strings'
import { Feature, Segment, useGetSegment } from 'services/cf'
import { useGetEnvironment } from 'services/cd-ng'
import { ContainerSpinner } from '@common/components/ContainerSpinner/ContainerSpinner'
import StringWithTooltip from '@common/components/StringWithTooltip/StringWithTooltip'
import { AuditLogObjectType } from '@cf/utils/CFUtils'
import useActiveEnvironment from '@cf/hooks/useActiveEnvironment'
import { AuditLogs } from '@cf/components/AuditLogs/AuditLogs'
import TargetManagementDetailPageTemplate from '@cf/components/TargetManagementDetailPageTemplate/TargetManagementDetailPageTemplate'
import TargetGroupCriteria from './components/TargetGroupCriteria'
import FlagSettingsPanel from './components/FlagSettingsPanel/FlagSettingsPanel'
import useDeleteTargetGroupDialog from './hooks/useDeleteTargetGroupDialog'
 
import css from './TargetGroupDetailPage.module.scss'
 
const TargetGroupDetailPage: FC = () => {
  const { getString } = useStrings()
  const { activeEnvironment: environmentIdentifier } = useActiveEnvironment()
 
  const {
    accountId: accountIdentifier,
    orgIdentifier,
    projectIdentifier,
    segmentIdentifier
  } = useParams<Record<string, string>>()
 
  const {
    data: targetGroup,
    loading: targetGroupLoading,
    error: targetGroupError,
    refetch: refetchTargetGroup
  } = useGetSegment({
    identifier: segmentIdentifier,
    queryParams: {
      accountIdentifier,
      orgIdentifier,
      projectIdentifier,
      environmentIdentifier
    }
  })
 
  const {
    data: envData,
    loading: envLoading,
    error: envError,
    refetch: refetchEnv
  } = useGetEnvironment({
    environmentIdentifier,
    queryParams: {
      accountId: accountIdentifier,
      orgIdentifier,
      projectIdentifier
    }
  })
 
  const deleteTargetGroupDialog = useDeleteTargetGroupDialog(targetGroup as Segment)
 
  if (targetGroupLoading || envLoading) {
    return <ContainerSpinner flex={{ align: 'center-center' }} />
  }
 
  if (targetGroupError || envError) {
    return (
      <Page.Error
        message={targetGroupError?.message || envError?.message}
        onClick={async () => {
          await Promise.all([refetchTargetGroup(), refetchEnv()])
        }}
      />
    )
  }
 
  return (
    <TargetManagementDetailPageTemplate
      item={targetGroup as Segment}
      openDeleteDialog={deleteTargetGroupDialog}
      metaData={{ environment: envData?.data?.name as string }}
      leftBar={<TargetGroupCriteria targetGroup={targetGroup as Segment} reloadTargetGroup={refetchTargetGroup} />}
    >
      <div className={css.tabs}>
        <Tabs id="TargetGroupDetailPageTabs">
          <Tab
            id="FlagSettingsTab"
            title={
              <StringWithTooltip
                stringId="cf.targetDetail.flagSetting"
                tooltipId="ff_targetGroupDetail_flagSettings_heading"
              />
            }
            panel={<FlagSettingsPanel targetGroup={targetGroup as Segment} />}
            panelClassName={css.panel}
          />
          <Tab
            id="AuditLogsTab"
            title={getString('activityLog')}
            panel={<AuditLogs flagData={targetGroup as Feature} objectType={AuditLogObjectType.Segment} />}
            panelClassName={css.panel}
          />
        </Tabs>
      </div>
    </TargetManagementDetailPageTemplate>
  )
}
 
export default TargetGroupDetailPage