All files / modules/72-triggers/pages/trigger-details TriggerDetails.tsx

100% Statements 29/29
72.95% Branches 89/122
100% Functions 3/3
100% Lines 28/28

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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189              3x 3x 3x 3x 3x 3x 3x 3x 3x   3x 3x 3x   3x         2x                 2x   2x   2x                                                       3x 1x                   1x 1x                                                                                                                     3x             1x                 1x 1x   1x                     1x         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 { Container, Layout, TabNavigation } from '@wings-software/uicore'
import { useParams } from 'react-router-dom'
import cx from 'classnames'
import { Page } from '@common/exports'
import routes from '@common/RouteDefinitions'
import { useGetPipelineSummary, ResponsePMSPipelineSummaryResponse } from 'services/pipeline-ng'
import { useDocumentTitle } from '@common/hooks/useDocumentTitle'
import { useStrings } from 'framework/strings'
import type { GitQueryParams, PipelineType } from '@common/interfaces/RouteInterfaces'
import { useQueryParams } from '@common/hooks'
import { NGBreadcrumbs } from '@common/components/NGBreadcrumbs/NGBreadcrumbs'
import css from './TriggerDetails.module.scss'
 
export const TriggerBreadcrumbs = ({
  pipelineResponse
}: {
  pipelineResponse: ResponsePMSPipelineSummaryResponse | null
}): JSX.Element => {
  const { orgIdentifier, projectIdentifier, pipelineIdentifier, accountId, module } = useParams<
    PipelineType<{
      projectIdentifier: string
      orgIdentifier: string
      accountId: string
      pipelineIdentifier: string
      triggerIdentifier: string
    }>
  >()
  const { repoIdentifier, branch } = useQueryParams<GitQueryParams>()
 
  const { getString } = useStrings()
 
  return (
    <NGBreadcrumbs
      links={[
        {
          url: routes.toPipelines({
            orgIdentifier,
            projectIdentifier,
            accountId,
            module
          }),
          label: getString('pipelines')
        },
        {
          url: routes.toTriggersPage({
            orgIdentifier,
            projectIdentifier,
            accountId,
            pipelineIdentifier,
            module,
            repoIdentifier,
            branch
          }),
          label: pipelineResponse?.data?.name || ''
        }
      ]}
    />
  )
}
const GetTriggerRightNav = (pipelineResponse: ResponsePMSPipelineSummaryResponse | null): JSX.Element => {
  const { orgIdentifier, projectIdentifier, pipelineIdentifier, accountId, module } = useParams<
    PipelineType<{
      projectIdentifier: string
      orgIdentifier: string
      accountId: string
      pipelineIdentifier: string
      triggerIdentifier: string
    }>
  >()
 
  const { getString } = useStrings()
  return (
    <Container>
      <TabNavigation
        size={'small'}
        links={[
          {
            label: getString('pipelineStudio'),
            to: routes.toPipelineStudio({
              orgIdentifier,
              projectIdentifier,
              pipelineIdentifier,
              accountId,
              module,
              branch: pipelineResponse?.data?.gitDetails?.branch,
              repoIdentifier: pipelineResponse?.data?.gitDetails?.repoIdentifier
            })
          },
          {
            label: getString('inputSetsText'),
            to: routes.toInputSetList({
              orgIdentifier,
              projectIdentifier,
              pipelineIdentifier,
              accountId,
              module,
              branch: pipelineResponse?.data?.gitDetails?.branch,
              repoIdentifier: pipelineResponse?.data?.gitDetails?.repoIdentifier
            })
          },
          {
            label: getString('common.triggersLabel'),
            to: routes.toTriggersPage({
              orgIdentifier,
              projectIdentifier,
              pipelineIdentifier,
              accountId,
              module,
              branch: pipelineResponse?.data?.gitDetails?.branch,
              repoIdentifier: pipelineResponse?.data?.gitDetails?.repoIdentifier
            })
          },
          {
            label: getString('executionHeaderText'),
            to: routes.toPipelineDeploymentList({
              orgIdentifier,
              projectIdentifier,
              pipelineIdentifier,
              accountId,
              module,
              branch: pipelineResponse?.data?.gitDetails?.branch,
              repoIdentifier: pipelineResponse?.data?.gitDetails?.repoIdentifier
            })
          }
        ]}
      />
    </Container>
  )
}
 
export default function TriggerDetails({
  children,
  wizard
}: {
  children: React.ReactElement
  wizard?: boolean
}): React.ReactElement {
  const { orgIdentifier, projectIdentifier, pipelineIdentifier, accountId } = useParams<
    PipelineType<{
      projectIdentifier: string
      orgIdentifier: string
      accountId: string
      pipelineIdentifier: string
      triggerIdentifier: string
    }>
  >()
  const { getString } = useStrings()
  const { repoIdentifier, branch } = useQueryParams<GitQueryParams>()
 
  const { data: pipeline } = useGetPipelineSummary({
    pipelineIdentifier,
    queryParams: {
      accountIdentifier: accountId,
      orgIdentifier,
      projectIdentifier,
      repoIdentifier,
      branch
    }
  })
 
  useDocumentTitle([
    pipeline?.data?.name || getString('pipelines'),
    getString('triggers.newTriggerWithoutPlus') || getString('common.triggersLabel')
  ])
 
  return (
    <>
      <Page.Header
        className={cx(wizard && css.wizard)}
        toolbar={GetTriggerRightNav(pipeline)}
        title={
          <Layout.Vertical spacing="xsmall">
            <TriggerBreadcrumbs pipelineResponse={pipeline} />
          </Layout.Vertical>
        }
      />
      <Page.Body className={cx(wizard && css.wizardBody)}>{children}</Page.Body>
    </>
  )
}