All files / modules/70-pipeline/components/execution/StepDetails/tabs/ServiceNowApprovalTab ServiceNowApprovalTab.tsx

100% Statements 16/16
77.53% Branches 69/89
100% Functions 1/1
100% Lines 16/16

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              2x   2x 2x 2x 2x 2x 2x 2x                         2x 4x 4x   4x 4x 4x 4x   4x                                                                                                                                                
/*
 * 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 type { ApprovalInstanceResponse, ServiceNowApprovalInstanceDetails } from 'services/pipeline-ng'
import { Duration } from '@common/exports'
import { ApprovalStatus } from '@pipeline/utils/approvalUtils'
import { String } from 'framework/strings'
import ExecutionStatusLabel from '@pipeline/components/ExecutionStatusLabel/ExecutionStatusLabel'
import { ServiceNowCriteria } from './ServiceNowCriteria/ServiceNowCriteria'
import headerCss from '@pipeline/pages/execution/ExecutionPipelineView/ExecutionGraphView/ExecutionStageDetailsHeader/ExecutionStageDetailsHeader.module.scss'
import css from './ServiceNowApprovalTab.module.scss'
 
export type ApprovalData =
  | (ApprovalInstanceResponse & {
      details: ServiceNowApprovalInstanceDetails
    })
  | null
 
export interface ServiceNowApprovalTabProps {
  approvalData: ApprovalData
  isWaiting: boolean
}
 
export function ServiceNowApprovalTab(props: ServiceNowApprovalTabProps): React.ReactElement {
  const { approvalData, isWaiting } = props
  const wasApproved = !isWaiting && approvalData?.status === ApprovalStatus.APPROVED
  const wasRejected =
    !isWaiting && (approvalData?.status === ApprovalStatus.REJECTED || approvalData?.status === ApprovalStatus.EXPIRED)
  const wasFailed = !isWaiting && approvalData?.status === ApprovalStatus.FAILED
  const serviceNowKey = approvalData?.details.ticket.key
  const serviceNowUrl = approvalData?.details.ticket.url
 
  return (
    <React.Fragment>
      {wasFailed ? (
        <div className={headerCss.errorMsgWrapper}>
          <ExecutionStatusLabel status={'Failed'} />
          <div className={headerCss.errorMsg}>
            <String className={headerCss.errorTitle} stringID="errorSummaryText" tagName="div" />
            <p>{approvalData?.errorMessage}</p>
          </div>
        </div>
      ) : (
        <div className={css.info} data-type="serviceNow">
          {isWaiting ? (
            <>
              <div className={css.timer}>
                <Duration
                  className={css.duration}
                  durationText=""
                  icon="hourglass"
                  startTime={approvalData?.deadline}
                  iconProps={{ size: 8 }}
                />
                <String stringID="pipeline.timeRemainingSuffix" />
              </div>
              {serviceNowKey && serviceNowUrl ? (
                <div className={css.serviceNowTicket}>
                  <String stringID="pipeline.serviceNowApprovalStep.execution.serviceNowTicket" />
 
                  <a href={serviceNowUrl} target="_blank" rel="noopener noreferrer">
                    {serviceNowKey}
                  </a>
                </div>
              ) : null}
            </>
          ) : null}
          {wasApproved && serviceNowUrl && serviceNowKey ? (
            <div className={css.serviceNowTicket}>
              <String stringID="pipeline.serviceNowApprovalStep.execution.wasApproved" />
 
              <a href={serviceNowUrl} target="_blank" rel="noopener noreferrer">
                {serviceNowKey}
              </a>
            </div>
          ) : null}
 
          {wasRejected && serviceNowUrl && serviceNowKey ? (
            <div className={css.serviceNowTicket}>
              {approvalData?.status === ApprovalStatus.REJECTED ? (
                <String stringID="pipeline.serviceNowApprovalStep.execution.wasRejected" />
              ) : null}
              {approvalData?.status === ApprovalStatus.EXPIRED ? (
                <String stringID="pipeline.serviceNowApprovalStep.execution.wasExpired" />
              ) : null}
              <a href={serviceNowUrl} target="_blank" rel="noopener noreferrer">
                {serviceNowKey}
              </a>
            </div>
          ) : null}
        </div>
      )}
 
      <div className={css.serviceNowApproval}>
        {approvalData?.details?.approvalCriteria ? (
          <ServiceNowCriteria type="approval" criteria={approvalData.details.approvalCriteria} />
        ) : null}
        {approvalData?.details?.rejectionCriteria ? (
          <ServiceNowCriteria type="rejection" criteria={approvalData.details.rejectionCriteria} />
        ) : null}
      </div>
    </React.Fragment>
  )
}