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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 13x 14x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 13x 13x 13x 2x 13x 1x 1x 15x 15x 15x 15x 1x 45x 45x 97x 97x 110x 110x 110x 110x 110x 110x 110x 110x 13x 13x 13x 13x 2x 2x 1x 13x 13x 2x 11x 1x 10x 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, { useState } from 'react' import { Accordion, Button, ButtonVariation, Formik, FormInput, getMultiTypeFromValue, HarnessDocTooltip, IconName, Icon, Label, Layout, MultiTypeInputType, Text, StepWizard } from '@wings-software/uicore' import { Color } from '@harness/design-system' import { Classes, Dialog, IOptionProps, IDialogProps } from '@blueprintjs/core' import * as Yup from 'yup' import { v4 as uuid } from 'uuid' import { useParams } from 'react-router-dom' import cx from 'classnames' import { cloneDeep, isEmpty, set, unset, isString } from 'lodash-es' import { FormikErrors, FormikProps, yupToFormErrors } from 'formik' import { PipelineStep, StepProps } from '@pipeline/components/PipelineSteps/PipelineStep' import { StepType } from '@pipeline/components/PipelineSteps/PipelineStepInterface' import { FormMultiTypeDurationField, getDurationValidationSchema } from '@common/components/MultiTypeDuration/MultiTypeDuration' // import { StepViewType } from '@pipeline/components/AbstractSteps/Step' import { setFormikRef, StepFormikFowardRef, StepViewType, ValidateInputSetProps } from '@pipeline/components/AbstractSteps/Step' import { useVariablesExpression } from '@pipeline/components/PipelineStudio/PiplineHooks/useVariablesExpression' import { useStrings } from 'framework/strings' import { ConfigureOptions } from '@common/components/ConfigureOptions/ConfigureOptions' import { FormMultiTypeConnectorField } from '@connectors/components/ConnectorReferenceField/FormMultiTypeConnectorField' import MultiTypeList from '@common/components/MultiTypeList/MultiTypeList' import MultiTypeMap from '@common/components/MultiTypeMap/MultiTypeMap' import MultiTypeFieldSelector from '@common/components/MultiTypeFieldSelector/MultiTypeFieldSelector' import { useQueryParams } from '@common/hooks' import type { GitQueryParams } from '@common/interfaces/RouteInterfaces' import type { StringNGVariable } from 'services/cd-ng' import type { StringsMap } from 'stringTypes' import { getNameAndIdentifierSchema } from '@pipeline/components/PipelineSteps/Steps/StepsValidateUtils' import GitDetailsStep from '@connectors/components/CreateConnector/commonSteps/GitDetailsStep' import ConnectorDetailsStep from '@connectors/components/CreateConnector/commonSteps/ConnectorDetailsStep' import VerifyOutOfClusterDelegate from '@connectors/common/VerifyOutOfClusterDelegate/VerifyOutOfClusterDelegate' import StepGitAuthentication from '@connectors/components/CreateConnector/GitConnector/StepAuth/StepGitAuthentication' import StepGitlabAuthentication from '@connectors/components/CreateConnector/GitlabConnector/StepAuth/StepGitlabAuthentication' import StepGithubAuthentication from '@connectors/components/CreateConnector/GithubConnector/StepAuth/StepGithubAuthentication' import StepBitbucketAuthentication from '@connectors/components/CreateConnector/BitbucketConnector/StepAuth/StepBitbucketAuthentication' import DelegateSelectorStep from '@connectors/components/CreateConnector/commonSteps/DelegateSelectorStep/DelegateSelectorStep' import StepArtifactoryAuthentication from '@connectors/components/CreateConnector/ArtifactoryConnector/StepAuth/StepArtifactoryAuthentication' import { Connectors, CONNECTOR_CREDENTIALS_STEP_IDENTIFIER } from '@connectors/constants' import { CommandTypes, onSubmitTFPlanData, TerraformPlanProps, TerraformPlanVariableStepProps, TFPlanFormData } from '../Common/Terraform/TerraformInterfaces' import TfVarFileList from './TfPlanVarFileList' import TerraformInputStep from './TfPlanInputStep' import { TerraformVariableStep } from './TfPlanVariableView' import { TerraformConfigStepOne } from '../Common/Terraform/Editview/TerraformConfigFormStepOne' import { TerraformConfigStepTwo } from '../Common/Terraform/Editview/TerraformConfigFormStepTwo' import { ConnectorMap, ConnectorTypes, getBuildPayload } from '../Common/Terraform/Editview/TerraformConfigFormHelper' import { TFArtifactoryForm } from '../Common/Terraform/Editview/TerraformArtifactoryForm' import { formatArtifactoryData } from '../Common/Terraform/Editview/TerraformArtifactoryFormHelper' import { TFMonaco } from '../Common/Terraform/Editview/TFMonacoEditor' import stepCss from '@pipeline/components/PipelineSteps/Steps/Steps.module.scss' import css from '../Common/Terraform/Editview/TerraformVarfile.module.scss' const setInitialValues = (data: TFPlanFormData): TFPlanFormData => { return data } interface StepChangeData<SharedObject> { prevStep?: number nextStep?: number prevStepData: SharedObject } function TerraformPlanWidget( props: TerraformPlanProps, formikRef: StepFormikFowardRef<TFPlanFormData> ): React.ReactElement { const { initialValues, onUpdate, onChange, allowableTypes, isNewStep, readonly = false, stepViewType } = props const { getString } = useStrings() const { expressions } = useVariablesExpression() const [connectorView, setConnectorView] = useState(false) const [selectedConnector, setSelectedConnector] = useState<ConnectorTypes | ''>('') const commandTypeOptions: IOptionProps[] = [ { label: getString('filters.apply'), value: CommandTypes.Apply }, { label: getString('pipelineSteps.destroy'), value: CommandTypes.Destroy } ] const { accountId, projectIdentifier, orgIdentifier } = useParams<{ projectIdentifier: string orgIdentifier: string accountId: string }>() const { repoIdentifier, branch } = useQueryParams<GitQueryParams>() const query = useQueryParams() const sectionId = (query as any).sectionId || '' const [showRemoteWizard, setShowRemoteWizard] = useState(false) const [isEditMode, setIsEditMode] = useState(false) const DIALOG_PROPS: IDialogProps = { isOpen: true, usePortal: true, autoFocus: true, canEscapeKeyClose: true, canOutsideClickClose: true, enforceFocus: false, style: { width: 1175, minHeight: 640, borderLeft: 0, paddingBottom: 0, position: 'relative', overflow: 'hidden' } } const onCloseOfRemoteWizard = () => { setConnectorView(false) setShowRemoteWizard(false) setIsEditMode(false) } const getNewConnectorSteps = () => { const connectorType = ConnectorMap[selectedConnector] const buildPayload = getBuildPayload(connectorType) return ( <StepWizard title={getString('connectors.createNewConnector')}> <ConnectorDetailsStep type={connectorType} name={getString('overview')} isEditMode={isEditMode} gitDetails={{ repoIdentifier, branch, getDefaultFromOtherRepo: true }} /> {connectorType !== Connectors.ARTIFACTORY ? ( <GitDetailsStep type={connectorType} name={getString('details')} isEditMode={isEditMode} connectorInfo={undefined} /> ) : null} {connectorType === Connectors.GIT ? ( <StepGitAuthentication name={getString('credentials')} onConnectorCreated={() => { // Handle on success }} isEditMode={isEditMode} setIsEditMode={setIsEditMode} connectorInfo={undefined} accountId={accountId} orgIdentifier={orgIdentifier} projectIdentifier={projectIdentifier} /> ) : null} {connectorType === Connectors.GITHUB ? ( <StepGithubAuthentication name={getString('credentials')} onConnectorCreated={() => { // Handle on success }} isEditMode={isEditMode} setIsEditMode={setIsEditMode} connectorInfo={undefined} accountId={accountId} orgIdentifier={orgIdentifier} projectIdentifier={projectIdentifier} /> ) : null} {connectorType === Connectors.BITBUCKET ? ( <StepBitbucketAuthentication name={getString('credentials')} onConnectorCreated={() => { // Handle on success }} isEditMode={isEditMode} setIsEditMode={setIsEditMode} connectorInfo={undefined} accountId={accountId} orgIdentifier={orgIdentifier} projectIdentifier={projectIdentifier} /> ) : null} {connectorType === Connectors.GITLAB ? ( <StepGitlabAuthentication name={getString('credentials')} identifier={CONNECTOR_CREDENTIALS_STEP_IDENTIFIER} onConnectorCreated={() => { // Handle on success }} isEditMode={isEditMode} setIsEditMode={setIsEditMode} connectorInfo={undefined} accountId={accountId} orgIdentifier={orgIdentifier} projectIdentifier={projectIdentifier} /> ) : null} {connectorType === Connectors.ARTIFACTORY ? ( <StepArtifactoryAuthentication name={getString('details')} identifier={CONNECTOR_CREDENTIALS_STEP_IDENTIFIER} isEditMode={isEditMode} setIsEditMode={setIsEditMode} connectorInfo={undefined} accountId={accountId} orgIdentifier={orgIdentifier} projectIdentifier={projectIdentifier} /> ) : null} <DelegateSelectorStep name={getString('delegate.DelegateselectionLabel')} isEditMode={isEditMode} setIsEditMode={setIsEditMode} buildPayload={buildPayload} connectorInfo={undefined} /> <VerifyOutOfClusterDelegate name={getString('connectors.stepThreeName')} connectorInfo={undefined} isStep={true} isLastStep={false} type={connectorType} /> </StepWizard> ) } const onStepChange = (arg: StepChangeData<any>): void => { if (arg?.prevStep && arg?.nextStep && arg.prevStep > arg.nextStep && arg.nextStep <= 2) { setConnectorView(false) } } const getTitle = () => ( <Layout.Vertical flex style={{ justifyContent: 'center', alignItems: 'center' }} margin={{ bottom: 'xlarge' }}> <Icon name="service-terraform" className={css.remoteIcon} size={50} padding={{ bottom: 'large' }} /> <Text color={Color.WHITE}>{getString('cd.configFileStoreTitle')}</Text> </Layout.Vertical> ) return ( <Formik<TFPlanFormData> onSubmit={values => { onUpdate?.(values) }} validate={values => { onChange?.(values) }} initialValues={setInitialValues(initialValues)} validationSchema={Yup.object().shape({ ...getNameAndIdentifierSchema(getString, stepViewType), timeout: getDurationValidationSchema({ minimum: '10s' }).required(getString('validation.timeout10SecMinimum')), spec: Yup.object().shape({ provisionerIdentifier: Yup.string() .required(getString('pipelineSteps.provisionerIdentifierRequired')) .nullable(), configuration: Yup.object().shape({ command: Yup.string().required(getString('pipelineSteps.commandRequired')), secretManagerRef: Yup.string().required(getString('cd.secretManagerRequired')).nullable() }) }) })} formName={`terraformPlanEditView-tfPlan-${sectionId}`} > {(formik: FormikProps<TFPlanFormData>) => { const { values, setFieldValue } = formik setFormikRef(formikRef, formik) const configFile = values?.spec?.configuration?.configFiles return ( <> <> {stepViewType !== StepViewType.Template && ( <div className={cx(stepCss.formGroup, stepCss.md)}> <FormInput.InputWithIdentifier inputLabel={getString('name')} isIdentifierEditable={isNewStep} inputGroupProps={{ placeholder: getString('pipeline.stepNamePlaceholder'), disabled: readonly }} /> </div> )} <div className={cx(stepCss.formGroup, stepCss.sm)}> <FormMultiTypeDurationField name="timeout" label={getString('pipelineSteps.timeoutLabel')} multiTypeDurationProps={{ enableConfigureOptions: false, expressions, allowableTypes }} disabled={readonly} /> {getMultiTypeFromValue(values.timeout) === MultiTypeInputType.RUNTIME && ( <ConfigureOptions value={values.timeout as string} type="String" variableName="step.timeout" showRequiredField={false} showDefaultField={false} showAdvanced={true} onChange={value => { /* istanbul ignore next */ setFieldValue('timeout', value) }} isReadonly={readonly} /> )} </div> <div className={css.divider} /> <div className={cx(stepCss.formGroup, stepCss.md)}> <FormInput.RadioGroup name="spec.configuration.command" label={getString('commandLabel')} radioGroup={{ inline: true }} items={commandTypeOptions} className={css.radioBtns} disabled={readonly} /> </div> <div className={cx(stepCss.formGroup, stepCss.md)}> <FormInput.MultiTextInput name="spec.provisionerIdentifier" placeholder={getString('pipeline.terraformStep.provisionerIdentifier')} label={getString('pipelineSteps.provisionerIdentifier')} multiTextInputProps={{ expressions, allowableTypes }} disabled={readonly} /> {getMultiTypeFromValue(values.spec?.provisionerIdentifier) === MultiTypeInputType.RUNTIME && ( <ConfigureOptions value={values.spec?.provisionerIdentifier as string} type="String" variableName="spec.provisionerIdentifier" showRequiredField={false} showDefaultField={false} showAdvanced={true} onChange={value => { setFieldValue('spec.provisionerIdentifier', value) }} isReadonly={readonly} /> )} </div> <div className={cx(stepCss.formGroup, stepCss.md)}> <FormMultiTypeConnectorField label={getString('connectors.title.secretManager')} category={'SECRET_MANAGER'} setRefValue width={280} name="spec.configuration.secretManagerRef" placeholder={getString('select')} accountIdentifier={accountId} projectIdentifier={projectIdentifier} orgIdentifier={orgIdentifier} style={{ marginBottom: 10 }} multiTypeProps={{ expressions, allowableTypes }} gitScope={{ repo: repoIdentifier || '', branch, getDefaultFromOtherRepo: true }} disabled={readonly} /> </div> <Layout.Vertical> <Label style={{ color: Color.GREY_900 }} className={css.configLabel} data-tooltip-id="tfConfigurationFile" > {getString('cd.configurationFile')} <HarnessDocTooltip useStandAlone={true} tooltipId="tfConfigurationFile" /> </Label> <div className={cx(css.configFile, css.addMarginBottom)}> <div className={css.configField}> {!configFile?.store?.spec?.folderPath && !configFile?.store?.spec?.artifactPaths && ( <a className={css.configPlaceHolder} onClick={() => setShowRemoteWizard(true)}> {getString('cd.configFilePlaceHolder')} </a> )} {(configFile?.store?.spec?.folderPath || configFile?.store?.spec?.artifactPaths) && ( <Text font="normal" lineClamp={1} width={200} data-testid={configFile?.store?.spec?.folderPath}> / {configFile?.store?.spec?.folderPath ? configFile?.store?.spec?.folderPath : isString(configFile?.store.spec.artifactPaths) ? configFile?.store.spec.artifactPaths : configFile?.store.spec.artifactPaths[0]} </Text> )} {configFile?.store?.spec?.folderPath || configFile?.store?.spec?.artifactPaths ? ( <Button minimal icon="Edit" withoutBoxShadow iconProps={{ size: 16 }} onClick={() => setShowRemoteWizard(true)} data-name="config-edit" withoutCurrentColor={true} className={css.editBtn} /> ) : null} </div> </div> </Layout.Vertical> <Accordion className={stepCss.accordion}> <Accordion.Panel id="step-1" summary={getString('common.optionalConfig')} details={ <> <div className={cx(stepCss.formGroup, stepCss.md)}> <FormInput.MultiTextInput name="spec.configuration.workspace" placeholder={getString('pipeline.terraformStep.workspace')} label={getString('pipelineSteps.workspace')} multiTextInputProps={{ expressions, allowableTypes }} isOptional={true} disabled={readonly} /> {getMultiTypeFromValue(formik.values.spec?.configuration?.workspace) === MultiTypeInputType.RUNTIME && ( <ConfigureOptions value={formik.values?.spec?.configuration?.workspace as string} type="String" variableName="spec.configuration.workspace" showRequiredField={false} showDefaultField={false} showAdvanced={true} onChange={value => { /* istanbul ignore else */ formik.setFieldValue('spec.configuration.workspace', value) }} isReadonly={readonly} /> )} </div> <div className={css.divider} /> <TfVarFileList formik={formik} isReadonly={readonly} allowableTypes={allowableTypes} selectedConnector={selectedConnector} setSelectedConnector={setSelectedConnector} getNewConnectorSteps={getNewConnectorSteps} /> <div className={css.divider} /> <div className={cx(stepCss.formGroup, css.addMarginTop, css.addMarginBottom)}> <MultiTypeFieldSelector name="spec.configuration.backendConfig.spec.content" label={ <Text style={{ color: 'rgb(11, 11, 13)' }}> {' '} {getString('optionalField', { name: getString('cd.backEndConfig') })} </Text> } defaultValueToReset="" allowedTypes={allowableTypes} disabled={readonly} expressionRender={() => { return ( <TFMonaco name="spec.configuration.backendConfig.spec.content" formik={formik} expressions={expressions} title={getString('cd.backEndConfig')} /> ) }} skipRenderValueInExpressionLabel > <TFMonaco name="spec.configuration.backendConfig.spec.content" formik={formik} expressions={expressions} title={getString('cd.backEndConfig')} /> </MultiTypeFieldSelector> {getMultiTypeFromValue(formik.values.spec?.configuration?.backendConfig?.spec?.content) === MultiTypeInputType.RUNTIME && ( <ConfigureOptions style={{ marginTop: 3 }} value={formik.values.spec?.configuration?.backendConfig?.spec?.content as string} type="String" variableName="spec.configuration.backendConfig.spec.content" showRequiredField={false} showDefaultField={false} showAdvanced={true} onChange={value => setFieldValue('spec.configuration.backendConfig.spec.content', value)} isReadonly={readonly} /> )} </div> <div className={cx(stepCss.formGroup, css.addMarginTop, css.addMarginBottom)}> <MultiTypeList name="spec.configuration.targets" placeholder={getString('cd.enterTragets')} multiTextInputProps={{ expressions, allowableTypes: allowableTypes.filter(item => item !== MultiTypeInputType.RUNTIME) }} multiTypeFieldSelectorProps={{ label: ( <Text style={{ display: 'flex', alignItems: 'center', color: 'rgb(11, 11, 13)' }}> {getString('optionalField', { name: getString('pipeline.targets.title') })} </Text> ) }} style={{ marginTop: 'var(--spacing-small)', marginBottom: 'var(--spacing-small)' }} disabled={readonly} /> </div> <div className={css.divider} /> <div className={cx(stepCss.formGroup, css.addMarginTop, css.addMarginBottom)}> <MultiTypeMap name="spec.configuration.environmentVariables" valueMultiTextInputProps={{ expressions, allowableTypes: allowableTypes.filter(item => item !== MultiTypeInputType.RUNTIME) }} multiTypeFieldSelectorProps={{ disableTypeSelection: true, label: ( <Text style={{ display: 'flex', alignItems: 'center', color: 'rgb(11, 11, 13)' }}> {getString('optionalField', { name: getString('environmentVariables') })} </Text> ) }} disabled={readonly} /> </div> </> } /> </Accordion> </> {showRemoteWizard && ( <Dialog {...DIALOG_PROPS} isOpen={true} isCloseButtonShown onClose={() => { setConnectorView(false) setShowRemoteWizard(false) }} className={cx(css.modal, Classes.DIALOG)} > <div className={css.createTfWizard}> <StepWizard title={getTitle()} className={css.configWizard} onStepChange={onStepChange}> <TerraformConfigStepOne name={getString('cd.configFileStepOne')} data={formik.values} isTerraformPlan isReadonly={readonly} isEditMode={isEditMode} allowableTypes={allowableTypes} setConnectorView={setConnectorView} selectedConnector={selectedConnector} setSelectedConnector={setSelectedConnector} /> {connectorView ? getNewConnectorSteps() : null} {selectedConnector === Connectors.ARTIFACTORY ? ( <TFArtifactoryForm isConfig isTerraformPlan allowableTypes={allowableTypes} name={getString('cd.configFileDetails')} onSubmitCallBack={(data: any, prevStepData: any) => { const configObject = { ...prevStepData?.formValues?.spec?.configuration?.configFiles } const valObj = formatArtifactoryData(prevStepData, data, configObject, formik) set(valObj, 'spec.configuration.configFiles', { ...configObject }) formik.setValues(valObj) setConnectorView(false) setShowRemoteWizard(false) }} /> ) : ( <TerraformConfigStepTwo name={getString('cd.configFileDetails')} isTerraformPlan isReadonly={readonly} allowableTypes={allowableTypes} onSubmitCallBack={(data: any, prevStepData: any) => { const configObject = { ...data.spec?.configuration?.configFiles } if (prevStepData.identifier && prevStepData.identifier !== data?.identifier) { configObject.store.spec.connectorRef = prevStepData?.identifier } if (configObject?.store.spec.gitFetchType === 'Branch') { unset(configObject.store.spec, 'commitId') } else if (configObject?.store.spec.gitFetchType === 'Commit') { unset(configObject.store.spec, 'branch') } if (configObject?.store?.spec?.artifactPaths) { unset(configObject?.store.spec, 'artifactPaths') unset(configObject?.store.spec, 'repositoryName') } const valObj = cloneDeep(formik.values) configObject.store.type = prevStepData?.selectedType set(valObj, 'spec.configuration.configFiles', { ...configObject }) formik.setValues(valObj) setConnectorView(false) setShowRemoteWizard(false) }} /> )} </StepWizard> </div> <Button variation={ButtonVariation.ICON} icon="cross" iconProps={{ size: 18 }} onClick={onCloseOfRemoteWizard} data-testid={'close-wizard'} className={css.crossIcon} /> </Dialog> )} </> ) }} </Formik> ) } const TerraformPlanWidgetWithRef = React.forwardRef(TerraformPlanWidget) export class TerraformPlan extends PipelineStep<TFPlanFormData> { constructor() { super() this._hasStepVariables = true this._hasDelegateSelectionVisible = true } protected type = StepType.TerraformPlan protected defaultValues: TFPlanFormData = { identifier: '', timeout: '10m', name: '', type: StepType.TerraformPlan, spec: { configuration: { command: 'Apply', configFiles: { store: { type: 'Git', spec: { gitFetchType: 'Branch' } } }, secretManagerRef: '' }, provisionerIdentifier: '' } } protected stepIcon: IconName = 'terraform-plan' protected stepName = 'Terraform Plan' protected stepDescription: keyof StringsMap = 'pipeline.stepDescription.TerraformPlan' /* istanbul ignore next */ validateInputSet({ data, template, getString, viewType }: ValidateInputSetProps<TFPlanFormData>): FormikErrors<TFPlanFormData> { /* istanbul ignore next */ const errors = {} as any /* istanbul ignore next */ const isRequired = viewType === StepViewType.DeploymentForm || viewType === StepViewType.TriggerForm /* istanbul ignore next */ if (getMultiTypeFromValue(template?.timeout) === MultiTypeInputType.RUNTIME) { let timeoutSchema = getDurationValidationSchema({ minimum: '10s' }) /* istanbul ignore next */ if (isRequired) { timeoutSchema = timeoutSchema.required(getString?.('validation.timeout10SecMinimum')) } const timeout = Yup.object().shape({ timeout: timeoutSchema }) /* istanbul ignore next */ try { timeout.validateSync(data) } catch (e) { /* istanbul ignore else */ if (e instanceof Yup.ValidationError) { const err = yupToFormErrors(e) Object.assign(errors, err) } } } /* istanbul ignore else */ if (isEmpty(errors.spec)) { delete errors.spec } return errors } private getInitialValues(data: TFPlanFormData): TFPlanFormData { const envVars = data.spec?.configuration?.environmentVariables as StringNGVariable[] const isEnvRunTime = getMultiTypeFromValue(data.spec?.configuration?.environmentVariables as any) === MultiTypeInputType.RUNTIME const isTargetRunTime = getMultiTypeFromValue(data.spec?.configuration?.targets as any) === MultiTypeInputType.RUNTIME return { ...data, spec: { ...data.spec, configuration: { ...data.spec?.configuration, secretManagerRef: data.spec?.configuration?.secretManagerRef || '', configFiles: data.spec?.configuration?.configFiles || ({} as any), command: data.spec?.configuration?.command || 'Apply', targets: !isTargetRunTime ? Array.isArray(data.spec?.configuration?.targets) ? (data.spec?.configuration?.targets as string[]).map((target: string) => ({ value: target, id: uuid() })) : [{ value: '', id: uuid() }] : data?.spec?.configuration?.targets, environmentVariables: !isEnvRunTime ? Array.isArray(envVars) ? envVars.map(variable => ({ key: variable.name || '', value: variable?.value, id: uuid() })) : [{ key: '', value: '', id: uuid() }] : data?.spec?.configuration?.environmentVariables } } } } processFormData(data: any): TFPlanFormData { return onSubmitTFPlanData(data) } renderStep(props: StepProps<TFPlanFormData, TerraformPlanVariableStepProps>): JSX.Element { const { initialValues, onUpdate, onChange, allowableTypes, stepViewType, inputSetData, customStepProps, formikRef, isNewStep } = props if (stepViewType === StepViewType.InputSet || stepViewType === StepViewType.DeploymentForm) { return ( <TerraformInputStep initialValues={this.getInitialValues(initialValues)} onUpdate={data => onUpdate?.(this.processFormData(data))} onChange={data => onChange?.(this.processFormData(data))} allowableTypes={allowableTypes} stepViewType={stepViewType} allValues={inputSetData?.allValues} readonly={inputSetData?.readonly} inputSetData={inputSetData} path={inputSetData?.path} /> ) } else if (stepViewType === StepViewType.InputVariable) { return ( <TerraformVariableStep {...(customStepProps as TerraformPlanVariableStepProps)} initialValues={this.getInitialValues(initialValues)} onUpdate={(data: any) => onUpdate?.(this.processFormData(data))} /> ) } return ( <TerraformPlanWidgetWithRef initialValues={this.getInitialValues(initialValues)} onUpdate={data => onUpdate?.(this.processFormData(data))} onChange={data => onChange?.(this.processFormData(data))} allowableTypes={allowableTypes} isNewStep={isNewStep} stepViewType={stepViewType} ref={formikRef} stepType={StepType.TerraformPlan} readonly={props.readonly} /> ) } } |