All files / modules/70-pipeline/components/PipelineStudio PipelineStudio.tsx

87.5% Statements 21/24
47.83% Branches 11/23
60% Functions 3/5
87.5% Lines 21/24

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              6x 6x 6x                 6x   6x 6x 6x 6x 6x                                                 6x 1x   6x     1x 1x     1x       2x       2x 2x 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 cx from 'classnames'
import { Button, ButtonVariation, Container, Layout, Text } from '@wings-software/uicore'
import type {
  PipelinePathProps,
  ProjectPathProps,
  PathFn,
  PipelineType,
  PipelineStudioQueryParams
} from '@common/interfaces/RouteInterfaces'
 
import { String } from 'framework/strings'
import type { PipelineInfoConfig } from 'services/cd-ng'
import { GitSyncStoreProvider } from 'framework/GitRepoStore/GitSyncStoreContext'
import { PipelineCanvas } from './PipelineCanvas/PipelineCanvas'
import { PipelineContext } from './PipelineContext/PipelineContext'
import { PipelineSchemaContextProvider } from './PipelineSchema/PipelineSchemaContext'
import css from './PipelineStudio.module.scss'
 
export interface PipelineStudioProps {
  className?: string
  title?: string
  onClose?: () => void
  routePipelineStudio: PathFn<PipelineType<PipelinePathProps> & PipelineStudioQueryParams>
  routePipelineDetail: PathFn<PipelineType<PipelinePathProps>>
  routePipelineList: PathFn<PipelineType<ProjectPathProps>>
  routePipelineProject: PathFn<PipelineType<ProjectPathProps>>
  getOtherModal?: (
    onSubmit: (values: PipelineInfoConfig) => void,
    onClose: () => void
  ) => React.ReactElement<OtherModalProps>
}
 
interface PipelineStudioState {
  error?: Error
}
 
interface OtherModalProps {
  onSubmit?: (values: PipelineInfoConfig) => void
  initialValues?: PipelineInfoConfig
  onClose?: () => void
}
export class PipelineStudio extends React.Component<PipelineStudioProps, PipelineStudioState> {
  state: PipelineStudioState = { error: undefined }
  context!: React.ContextType<typeof PipelineContext>
  static contextType = PipelineContext
 
  componentDidCatch(error: Error): boolean {
    this.setState({ error })
    Iif (window?.bugsnagClient?.notify) {
      window?.bugsnagClient?.notify(error)
    }
    return false
  }
 
  render(): JSX.Element {
    const { error } = this.state
    const {
      deletePipelineCache,
      state: { gitDetails }
    } = this.context
    if (error) {
      return (
        <Layout.Vertical spacing="medium" padding="large">
          <Text>
            <String stringID="errorTitle" />
          </Text>
          <Text>
            <String stringID="errorSubtitle" />
          </Text>
          <Layout.Horizontal style={{ alignItems: 'baseline' }}>
            <Text>
              <String stringID="please" />
            </Text>
            <Button
              variation={ButtonVariation.SECONDARY}
              onClick={() => {
                return deletePipelineCache(gitDetails).then(() => {
                  window.location.reload()
                })
              }}
              minimal
            >
              <String stringID="clickHere" />
            </Button>
            <Text>
              <String stringID="errorHelp" />
            </Text>
          </Layout.Horizontal>
          {__DEV__ && (
            <React.Fragment>
              <Text font="small">Error Message</Text>
              <Container>
                <details>
                  <summary>Stacktrace</summary>
                  <pre>{error.stack}</pre>
                </details>
              </Container>
            </React.Fragment>
          )}
        </Layout.Vertical>
      )
    }
    const {
      className = '',
      routePipelineStudio,
      routePipelineDetail,
      routePipelineList,
      routePipelineProject,
      getOtherModal
    } = this.props
    return (
      <PipelineSchemaContextProvider>
        <GitSyncStoreProvider>
          <div className={cx(css.container, className)}>
            <PipelineCanvas
              toPipelineStudio={routePipelineStudio}
              toPipelineDetail={routePipelineDetail}
              toPipelineList={routePipelineList}
              toPipelineProject={routePipelineProject}
              getOtherModal={getOtherModal}
            />
          </div>
        </GitSyncStoreProvider>
      </PipelineSchemaContextProvider>
    )
  }
}