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 | 2x 2x 2x 2x 2x 2x 2x 23x 23x 23x 1x 22x 1x 21x 23x | /*
 * 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 { Icon, Layout, Text } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import cx from 'classnames'
import { useStrings } from 'framework/strings'
import styles from '@gitsync/components/GitSyncErrorMessage/GitSyncErrorMessage.module.scss'
 
export interface GitSyncErrorMessageProps {
  mode: 'COMMIT' | 'FILE' | 'CONNECTIVITY'
  title: string
  count?: number
  repo?: string
  branch?: string
  commitId?: string
  timestamp?: number
  items: {
    title?: string
    reason: string
    showDetails?: () => void
    fixCommit?: string
  }[]
}
 
export const GitSyncErrorMessageItem: React.FC<GitSyncErrorMessageProps['items'][number]> = ({
  title,
  reason,
  showDetails,
  fixCommit
}) => {
  const { getString } = useStrings()
  const CustomComponent: React.ReactElement = React.useMemo(() => {
    if (showDetails) {
      return (
        <Text
          font={{ size: 'small', weight: 'semi-bold' }}
          color={Color.PRIMARY_7}
          className={styles.errorItemViewContent}
          onClick={() => showDetails()}
        >
          {getString('common.viewContent')}
        </Text>
      )
    }
    if (fixCommit) {
      return (
        <Layout.Horizontal
          className={styles.errorItemErrorFixed}
          background={Color.GREY_100}
          padding={{ left: 'small', right: 'small', top: 'small', bottom: 'small' }}
        >
          <Layout.Horizontal margin={{ right: 'medium' }}>
            <Icon name="command-artifact-check" color={Color.GREEN_500} size={14} margin={{ right: 'small' }} />
            <Text font={{ size: 'small', weight: 'semi-bold' }} color={Color.BLACK}>
              {getString('gitsync.errorFixed')}
            </Text>
          </Layout.Horizontal>
          <Layout.Horizontal>
            <Icon name="git-commit" color={Color.PRIMARY_7} margin={{ right: 'small' }} />
            <Text
              font={{ size: 'small', weight: 'semi-bold' }}
              color={Color.PRIMARY_7}
              data-testid="gitSyncErrorMessageItemFixCommit"
            >
              {fixCommit?.slice(0, 7)}
            </Text>
          </Layout.Horizontal>
        </Layout.Horizontal>
      )
    }
    return <></>
  }, [showDetails, fixCommit, getString])
  return (
    <Layout.Horizontal
      className={styles.section}
      flex={{ justifyContent: 'space-between' }}
      data-testid="gitSyncErrorMessageItem"
    >
      <Layout.Vertical
        className={cx({
          [styles.fixedError]: fixCommit,
          [styles.hasDetails]: showDetails,
          [styles.defaultErrorText]: !(fixCommit || showDetails)
        })}
      >
        {title ? (
          <Text
            font={{ size: 'small', weight: 'semi-bold' }}
            className={styles.errorItemTitle}
            lineClamp={2}
            data-testid="gitSyncErrorMessageItemTitle"
          >
            {title}
          </Text>
        ) : null}
        <Layout.Horizontal>
          <Text font={{ size: 'small' }} color={Color.RED_600} margin={{ right: 'large' }}>
            {getString('failed')}
          </Text>
          <Text
            font={{ size: 'small' }}
            color={Color.GREY_900}
            lineClamp={2}
            data-testid="gitSyncErrorMessageItemReason"
          >
            {reason}
          </Text>
        </Layout.Horizontal>
      </Layout.Vertical>
      {CustomComponent}
    </Layout.Horizontal>
  )
}
  |