All files / modules/75-cd/components/PipelineSteps/K8sDelete K8sDeleteStep.tsx

96.85% Statements 123/127
70.83% Branches 442/624
87.1% Functions 27/31
96.85% Lines 123/127

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 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864              97x 97x                         97x 97x 97x 97x   97x 97x 97x                   97x 97x 97x 97x 97x       97x 97x 97x 97x   97x 97x   97x 97x   97x                                                                                                                                                   7x 6x   6x   6x                           6x       6x 3x 3x 1x                     2x 1x                     1x 1x                         3x     6x   6x       1x     17x                                                                                         32x 32x 32x                                                                                                         3x   3x 3x                             5x         3x                     9x                                                                                                                   12x           10x                   30x                   1x                       1x                                                                                                                                                                                   97x 1x     97x   97x   116x 116x 116x                                   12x                       7x 1x                                                             5x   5x 5x 3x 3x 3x   3x     3x 3x     3x 3x 3x       5x       1x                 1x 1x                         1x 1x     1x 1x   1x       5x       1x                 1x 1x                         1x 1x     1x 1x   1x         5x 3x   5x       6x 1x                       2x                 5x 1x                       2x                 4x 2x                           2x                                                 5x     2x 2x                   2x         3x     2x 2x                   2x                 1x 1x                           116x 116x 116x 116x 116x   116x                          
/*
 * 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 {
  Button,
  ButtonVariation,
  Container,
  Formik,
  FormInput,
  getMultiTypeFromValue,
  IconName,
  Layout,
  MultiTypeInputType,
  Text,
  Icon
} from '@wings-software/uicore'
import { Intent, FontVariation } from '@harness/design-system'
import cx from 'classnames'
import { FieldArray, FormikErrors, FormikProps, yupToFormErrors } from 'formik'
import { v4 as uuid } from 'uuid'
import type { IOptionProps } from '@blueprintjs/core'
import * as Yup from 'yup'
import { defaultTo, isEmpty, unset } from 'lodash-es'
import {
  StepFormikFowardRef,
  setFormikRef,
  StepProps,
  StepViewType,
  ValidateInputSetProps
} from '@pipeline/components/AbstractSteps/Step'
import type { StepElementConfig } from 'services/cd-ng'
 
import type { VariableMergeServiceResponse } from 'services/pipeline-ng'
import { VariablesListTable } from '@pipeline/components/VariablesListTable/VariablesListTable'
import { FormMultiTypeCheckboxField } from '@common/components'
import { ConfigureOptions } from '@common/components/ConfigureOptions/ConfigureOptions'
import { useStrings } from 'framework/strings'
import {
  FormMultiTypeDurationField,
  getDurationValidationSchema
} from '@common/components/MultiTypeDuration/MultiTypeDuration'
import { useVariablesExpression } from '@pipeline/components/PipelineStudio/PiplineHooks/useVariablesExpression'
import { StepType } from '@pipeline/components/PipelineSteps/PipelineStepInterface'
import { PipelineStep } from '@pipeline/components/PipelineSteps/PipelineStep'
import { getNameAndIdentifierSchema } from '@pipeline/components/PipelineSteps/Steps/StepsValidateUtils'
 
import MultiTypeFieldSelector from '@common/components/MultiTypeFieldSelector/MultiTypeFieldSelector'
import List from '@common/components/List/List'
import type { StringsMap } from 'stringTypes'
import stepCss from '@pipeline/components/PipelineSteps/Steps/Steps.module.scss'
import css from './K8sDelete.module.scss'
 
const DeleteSpecConstant = {
  ResourceName: 'ResourceName',
  ReleaseName: 'ReleaseName',
  ManifestPath: 'ManifestPath'
}
 
interface K8sDeleteFormSpec {
  resourceNames?: string[] | K8sDeleteConfigHeader[]
  deleteNamespace?: boolean
  manifestPaths?: string[] | K8sDeleteConfigHeader[]
  skipDryRun?: boolean
}
interface K8sDeleteSpec {
  resourceNames?: K8sDeleteConfigHeader[] | string
  deleteNamespace?: boolean
  manifestPaths?: K8sDeleteConfigHeader[] | string
  skipDryRun?: boolean
}
 
interface K8sDeleteConfigHeader {
  id: string
  value: string
}
 
export interface K8sDeleteData extends StepElementConfig {
  spec: {
    deleteResources: {
      type?: string
      spec: K8sDeleteSpec
    }
  }
}
 
export interface K8sDeleteFormData extends StepElementConfig {
  spec: {
    deleteResources: {
      type?: string
      spec: K8sDeleteFormSpec
    }
  }
}
 
export interface K8sDeleteVariableStepProps {
  initialValues: K8sDeleteData
  stageIdentifier: string
  onUpdate?: (data: K8sDeleteData) => void
  metadataMap: Required<VariableMergeServiceResponse>['metadataMap']
  variablesData: K8sDeleteData
}
 
interface K8sDeleteProps {
  initialValues: K8sDeleteData
  onUpdate?: (data: K8sDeleteData) => void
  onChange?: (data: K8sDeleteData) => void
  allowableTypes: MultiTypeInputType[]
  isDisabled?: boolean
  stepViewType?: StepViewType
  isNewStep?: boolean
  inputSetData?: {
    template?: K8sDeleteData
    path?: string
  }
  readonly?: boolean
}
 
function K8sDeleteDeployWidget(props: K8sDeleteProps, formikRef: StepFormikFowardRef): React.ReactElement {
  const {
    initialValues,
    onUpdate,
    isNewStep = true,
    isDisabled,
    allowableTypes,
    onChange: onFormChange,
    stepViewType
  } = props
  const { getString } = useStrings()
 
  const accessTypeOptions = React.useMemo(() => {
    // eslint-disable-next-line @typescript-eslint/no-shadow
    const options: IOptionProps[] = [
      {
        label: getString('auditTrail.resourceNameLabel'),
        value: getString('pipelineSteps.resourceNameValue')
      },
      {
        label: getString('pipelineSteps.manifestPathLabel'),
        value: getString('pipelineSteps.manifestPathValue')
      },
      {
        label: getString('pipelineSteps.releaseNameLabel'),
        value: getString('pipelineSteps.releaseNameValue')
      }
    ]
    return options
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
 
  const onChange = (values: K8sDeleteData, value: string): K8sDeleteData => {
    let obj = values
    if (value === getString('pipelineSteps.manifestPathValue')) {
      obj = {
        ...values,
        spec: {
          deleteResources: {
            type: value,
            spec: {
              manifestPaths: [{ value: '', id: uuid() }]
            }
          }
        }
      }
    } else if (value === getString('pipelineSteps.resourceNameValue')) {
      obj = {
        ...values,
        spec: {
          deleteResources: {
            type: value,
            spec: {
              resourceNames: [{ value: '', id: uuid() }]
            }
          }
        }
      }
    } else Eif (value === getString('pipelineSteps.releaseNameValue')) {
      obj = {
        ...values,
        spec: {
          deleteResources: {
            type: value,
            spec: {
              deleteNamespace: false
            }
          }
        }
      }
    }
 
    return obj
  }
 
  const { expressions } = useVariablesExpression()
 
  return (
    <>
      <Formik<K8sDeleteData>
        onSubmit={values => {
          onUpdate?.(values)
        }}
        validate={values => {
          onFormChange?.(values)
        }}
        formName="k8DeleteData"
        initialValues={initialValues}
        validationSchema={Yup.object().shape({
          ...getNameAndIdentifierSchema(getString, stepViewType),
          timeout: getDurationValidationSchema({ minimum: '10s' }).required(
            getString('validation.timeout10SecMinimum')
          ),
          spec: Yup.object().shape({
            deleteResources: Yup.object().shape({
              spec: Yup.object()
                .when('type', {
                  is: DeleteSpecConstant.ResourceName,
                  then: Yup.object().shape({
                    resourceNames: Yup.lazy(value =>
                      getMultiTypeFromValue(value as boolean) === MultiTypeInputType.FIXED
                        ? Yup.array(
                            Yup.object().shape({
                              value: Yup.string().required(getString('cd.resourceCannotBeEmpty'))
                            })
                          ).required(getString('cd.resourceCannotBeEmpty'))
                        : Yup.string()
                    )
                  })
                })
                .when('type', {
                  is: DeleteSpecConstant.ManifestPath,
                  then: Yup.object().shape({
                    manifestPaths: Yup.lazy(value =>
                      getMultiTypeFromValue(value as boolean) === MultiTypeInputType.FIXED
                        ? Yup.array(
                            Yup.object().shape({
                              value: Yup.string().required(getString('cd.manifestPathsCannotBeEmpty'))
                            })
                          ).required(getString('cd.manifestPathsCannotBeEmpty'))
                        : Yup.string()
                    )
                  })
                })
            })
          })
        })}
      >
        {(formikProps: FormikProps<K8sDeleteData>) => {
          setFormikRef(formikRef, formikProps)
          const values = formikProps.values
          return (
            <>
              {stepViewType === StepViewType.Template ? null : (
                <div className={cx(stepCss.formGroup, stepCss.lg)}>
                  <FormInput.InputWithIdentifier
                    inputLabel={getString('name')}
                    isIdentifierEditable={isNewStep}
                    inputGroupProps={{
                      placeholder: getString('pipeline.stepNamePlaceholder'),
                      disabled: isDisabled
                    }}
                  />
                </div>
              )}
              <div className={cx(stepCss.formGroup, stepCss.sm)}>
                <Layout.Horizontal spacing="medium" style={{ alignItems: 'center' }}>
                  <FormMultiTypeDurationField
                    name="timeout"
                    disabled={isDisabled}
                    label={getString('pipelineSteps.timeoutLabel')}
                    multiTypeDurationProps={{
                      enableConfigureOptions: false,
                      expressions,
                      disabled: isDisabled,
                      allowableTypes
                    }}
                  />
                  {getMultiTypeFromValue(formikProps.values.timeout) === MultiTypeInputType.RUNTIME && (
                    <ConfigureOptions
                      style={{ marginBottom: 4 }}
                      value={values.timeout as string}
                      type="String"
                      variableName="step.timeout"
                      showRequiredField={false}
                      showDefaultField={false}
                      showAdvanced={true}
                      onChange={value => {
                        formikProps.setFieldValue('timeout', value)
                      }}
                      isReadonly={isDisabled}
                    />
                  )}
                </Layout.Horizontal>
              </div>
              <div className={stepCss.divider} />
              <div className={stepCss.formGroup}>
                <FormInput.RadioGroup
                  label={getString('pipelineSteps.deleteResourcesBy')}
                  name="spec.deleteResources.type"
                  items={accessTypeOptions}
                  disabled={isDisabled}
                  radioGroup={{ inline: true, disabled: isDisabled }}
                  onChange={e => {
                    const currentValue = e.currentTarget?.value
 
                    const valuesObj = onChange(values, currentValue)
                    formikProps?.setValues({ ...valuesObj })
                  }}
                />
              </div>
 
              {values?.spec?.deleteResources?.type === getString('pipelineSteps.resourceNameValue') && (
                <div className={stepCss.formGroup}>
                  <MultiTypeFieldSelector
                    defaultValueToReset={[{ value: '', id: uuid() }]}
                    name={'spec.deleteResources.spec.resourceNames'}
                    label={getString('auditTrail.resourceNameLabel')}
                    allowedTypes={allowableTypes}
                  >
                    <FieldArray
                      name="spec.deleteResources.spec.resourceNames"
                      render={arrayHelpers => (
                        <Layout.Vertical>
                          {(
                            (formikProps.values?.spec?.deleteResources?.spec?.resourceNames ||
                              []) as K8sDeleteConfigHeader[]
                          )?.map((_path: K8sDeleteConfigHeader, index: number) => (
                            <Layout.Horizontal key={_path.id}>
                              <FormInput.MultiTextInput
                                label=""
                                placeholder={getString('pipelineSteps.deleteResourcesPlaceHolder')}
                                name={`spec.deleteResources.spec.resourceNames[${index}].value`}
                                style={{ width: '430px' }}
                                disabled={isDisabled}
                                multiTextInputProps={{
                                  expressions,
                                  textProps: { disabled: isDisabled },
                                  allowableTypes: allowableTypes.filter(item => item !== MultiTypeInputType.RUNTIME)
                                }}
                              />
                              {/* istanbul ignore next */}
                              {formikProps.values?.spec?.deleteResources?.spec?.resourceNames && (
                                <Button
                                  variation={ButtonVariation.ICON}
                                  icon="main-trash"
                                  onClick={() => {
                                    /* istanbul ignore next */
                                    arrayHelpers.remove(index)
                                  }}
                                  disabled={isDisabled}
                                />
                              )}
                            </Layout.Horizontal>
                          ))}
                          <span>
                            <Button
                              variation={ButtonVariation.PRIMARY}
                              text={getString('plusAdd')}
                              className={css.addBtn}
                              onClick={() => {
                                /* istanbul ignore next */
                                arrayHelpers.push({ value: '', id: uuid() })
                              }}
                              disabled={isDisabled}
                            />
                          </span>
                        </Layout.Vertical>
                      )}
                    />
                  </MultiTypeFieldSelector>
                </div>
              )}
 
              {values?.spec?.deleteResources?.type === getString('pipelineSteps.releaseNameValue') && (
                <div className={cx(stepCss.formGroup, stepCss.md)}>
                  <FormMultiTypeCheckboxField
                    name="spec.deleteResources.spec.deleteNamespace"
                    label={getString('pipelineSteps.deleteNamespace')}
                    style={{ paddingLeft: 'var(--spacing-small)', fontSize: 'var(--font-size-small)' }}
                    multiTypeTextbox={{ expressions, disabled: isDisabled, allowableTypes }}
                    disabled={isDisabled}
                  />
                </div>
              )}
 
              {values?.spec?.deleteResources?.type === getString('pipelineSteps.manifestPathValue') && (
                <div className={stepCss.formGroup}>
                  <MultiTypeFieldSelector
                    defaultValueToReset={[{ value: '', id: uuid() }]}
                    name={'spec.deleteResources.spec.manifestPaths'}
                    label={getString('pipelineSteps.manifestPathLabel')}
                    allowedTypes={allowableTypes}
                  >
                    <FieldArray
                      name="spec.deleteResources.spec.manifestPaths"
                      render={arrayHelpers => (
                        <Layout.Vertical>
                          {/* istanbul ignore next */}
                          {(
                            (formikProps.values?.spec?.deleteResources?.spec?.manifestPaths ||
                              []) as K8sDeleteConfigHeader[]
                          )?.map((_path: K8sDeleteConfigHeader, index: number) => (
                            <Layout.Horizontal key={_path.id}>
                              <FormInput.MultiTextInput
                                label=""
                                placeholder={getString('pipelineSteps.manifestPathsPlaceHolder')}
                                name={`spec.deleteResources.spec.manifestPaths[${index}].value`}
                                style={{ width: '430px' }}
                                disabled={isDisabled}
                                multiTextInputProps={{
                                  expressions,
                                  allowableTypes: allowableTypes.filter(item => item !== MultiTypeInputType.RUNTIME),
                                  disabled: isDisabled
                                }}
                              />
 
                              {/* istanbul ignore next */}
                              {formikProps.values?.spec?.deleteResources?.spec?.manifestPaths && (
                                <Button
                                  variation={ButtonVariation.ICON}
                                  icon="main-trash"
                                  onClick={() => arrayHelpers.remove(index)}
                                  disabled={isDisabled}
                                />
                              )}
                            </Layout.Horizontal>
                          ))}
                          <span>
                            <Button
                              variation={ButtonVariation.PRIMARY}
                              text={getString('addFileText')}
                              className={css.addBtn}
                              disabled={isDisabled}
                              onClick={() => arrayHelpers.push({ value: '', id: uuid() })}
                            />
                          </span>
                        </Layout.Vertical>
                      )}
                    />
                  </MultiTypeFieldSelector>
                </div>
              )}
 
              {formikProps?.values?.spec?.deleteResources?.type === DeleteSpecConstant.ReleaseName &&
                formikProps?.values?.spec?.deleteResources?.spec?.deleteNamespace && (
                  <Container
                    id="warning-deletenamespace"
                    intent="warning"
                    padding={{ left: 'small' }}
                    font={{
                      align: 'center'
                    }}
                    flex={{ justifyContent: 'flex-start' }}
                  >
                    <Icon name="warning-icon" intent={Intent.DANGER} margin={{ right: 'small' }} />
                    <Text font={{ variation: FontVariation.FORM_MESSAGE_WARNING }}>
                      {getString('pipelineSteps.deleteNamespaceWarning')}
                    </Text>
                  </Container>
                )}
            </>
          )
        }}
      </Formik>
    </>
  )
}
 
/* istanbul ignore next */
const K8sDeleteInputStep: React.FC<K8sDeleteProps> = ({ inputSetData, readonly, allowableTypes }) => {
  const { getString } = useStrings()
  const { expressions } = useVariablesExpression()
  return (
    <>
      {getMultiTypeFromValue(inputSetData?.template?.timeout) === MultiTypeInputType.RUNTIME && (
        <div className={cx(stepCss.formGroup, stepCss.sm)}>
          <FormMultiTypeDurationField
            multiTypeDurationProps={{
              enableConfigureOptions: false,
              allowableTypes,
              expressions,
              disabled: readonly
            }}
            label={getString('pipelineSteps.timeoutLabel')}
            name={`${isEmpty(inputSetData?.path) ? '' : `${inputSetData?.path}.`}timeout`}
            disabled={readonly}
          />
        </div>
      )}
      {getMultiTypeFromValue(inputSetData?.template?.spec?.deleteResources?.spec?.manifestPaths as string) ===
        MultiTypeInputType.RUNTIME && (
        <div className={cx(stepCss.formGroup, stepCss.md)}>
          <List
            label={getString('filePaths')}
            name={`${
              isEmpty(inputSetData?.path) ? '' : `${inputSetData?.path}.`
            }spec.deleteResources.spec.manifestPaths`}
            disabled={readonly}
            expressions={expressions}
            style={{ marginBottom: 'var(--spacing-small)' }}
            isNameOfArrayType
          />
        </div>
      )}
      {getMultiTypeFromValue(inputSetData?.template?.spec?.deleteResources?.spec?.resourceNames as string) ===
        MultiTypeInputType.RUNTIME && (
        <div className={cx(stepCss.formGroup, stepCss.md)}>
          <List
            label={getString('filePaths')}
            name={`${
              isEmpty(inputSetData?.path) ? '' : `${inputSetData?.path}.`
            }spec.deleteResources.spec.resourceNames`}
            disabled={readonly}
            expressions={expressions}
            style={{ marginBottom: 'var(--spacing-small)' }}
            isNameOfArrayType
          />
        </div>
      )}
    </>
  )
}
 
const K8sDeleteVariableStep: React.FC<K8sDeleteVariableStepProps> = ({ variablesData, metadataMap, initialValues }) => {
  return <VariablesListTable data={variablesData.spec} originalData={initialValues.spec} metadataMap={metadataMap} />
}
 
const K8sDeleteDeployWidgetWithRef = React.forwardRef(K8sDeleteDeployWidget)
 
export class K8sDeleteStep extends PipelineStep<K8sDeleteFormData> {
  constructor() {
    super()
    this._hasStepVariables = true
    this._hasDelegateSelectionVisible = true
  }
  renderStep(props: StepProps<any>): JSX.Element {
    /* istanbul ignore next */
 
    const {
      initialValues,
      onUpdate,
      stepViewType,
      inputSetData,
      formikRef,
      customStepProps,
      isNewStep,
      readonly,
      allowableTypes,
      onChange
    } = props
 
    if (stepViewType === StepViewType.InputSet || stepViewType === StepViewType.DeploymentForm) {
      /* istanbul ignore next */
      return (
        <K8sDeleteInputStep
          initialValues={initialValues}
          stepViewType={stepViewType}
          inputSetData={inputSetData}
          readonly={!!inputSetData?.readonly}
          onUpdate={onUpdate}
          allowableTypes={allowableTypes}
        />
      )
    } else if (stepViewType === StepViewType.InputVariable) {
      return (
        <K8sDeleteVariableStep
          {...(customStepProps as K8sDeleteVariableStepProps)}
          initialValues={initialValues}
          onUpdate={onUpdate}
        />
      )
    }
    /* istanbul ignore next */
 
    return (
      <K8sDeleteDeployWidgetWithRef
        initialValues={this.getInitialValues(initialValues)}
        stepViewType={defaultTo(stepViewType, StepViewType.Edit)}
        isNewStep={isNewStep}
        readonly={!!inputSetData?.readonly}
        ref={formikRef}
        isDisabled={readonly}
        allowableTypes={allowableTypes}
        onChange={data => onChange?.(this.processFormData(data))}
        onUpdate={data => onUpdate?.(this.processFormData(data))}
      />
    )
  }
 
  validateInputSet({
    data,
    template,
    getString,
    viewType
  }: ValidateInputSetProps<K8sDeleteFormData>): FormikErrors<K8sDeleteFormData> {
    const isRequired = viewType === StepViewType.DeploymentForm || viewType === StepViewType.TriggerForm
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const errors: FormikErrors<K8sDeleteFormData> = {}
    if (getMultiTypeFromValue(template?.timeout) === MultiTypeInputType.RUNTIME) {
      let timeoutSchema = getDurationValidationSchema({ minimum: '10s' })
      Eif (isRequired) {
        timeoutSchema = timeoutSchema.required(getString?.('validation.timeout10SecMinimum'))
      }
      const timeout = Yup.object().shape({
        timeout: timeoutSchema
      })
      try {
        timeout.validateSync(data)
      } catch (e) {
        /* istanbul ignore else */
        if (e instanceof Yup.ValidationError) {
          const err = yupToFormErrors(e)
          Object.assign(errors, err)
        }
      }
    }
    if (
      getMultiTypeFromValue(template?.spec?.deleteResources?.spec?.manifestPaths as unknown as string) ===
      MultiTypeInputType.RUNTIME
    ) {
      let manifestPathsSchema = Yup.object().shape({
        spec: Yup.object().shape({
          deleteResources: Yup.object().shape({
            spec: Yup.object().shape({
              manifestPaths: Yup.array(Yup.string().trim()).ensure().nullable()
            })
          })
        })
      })
      Eif (isRequired) {
        manifestPathsSchema = Yup.object().shape({
          spec: Yup.object().shape({
            deleteResources: Yup.object().shape({
              spec: Yup.object().shape({
                manifestPaths: Yup.array(Yup.string().trim().required(getString?.('cd.manifestPathsCannotBeEmpty')))
                  .required(getString?.('cd.manifestPathsCannotBeEmpty'))
                  .min(1, getString?.('cd.manifestPathsCannotBeEmpty'))
                  .ensure()
              })
            })
          })
        })
      }
      try {
        manifestPathsSchema.validateSync(data)
      } catch (e) {
        /* istanbul ignore else */
        if (e instanceof Yup.ValidationError) {
          const err = yupToFormErrors(e)
 
          Object.assign(errors, err)
        }
      }
    }
    if (
      getMultiTypeFromValue(template?.spec?.deleteResources?.spec?.resourceNames as unknown as string) ===
      MultiTypeInputType.RUNTIME
    ) {
      let resourceNamesSchema = Yup.object().shape({
        spec: Yup.object().shape({
          deleteResources: Yup.object().shape({
            spec: Yup.object().shape({
              resourceNames: Yup.array(Yup.string().trim()).ensure().nullable()
            })
          })
        })
      })
      Eif (isRequired) {
        resourceNamesSchema = Yup.object().shape({
          spec: Yup.object().shape({
            deleteResources: Yup.object().shape({
              spec: Yup.object().shape({
                resourceNames: Yup.array(Yup.string().trim().required(getString?.('cd.resourceCannotBeEmpty')))
                  .required(getString?.('cd.resourceCannotBeEmpty'))
                  .min(1, getString?.('cd.resourceCannotBeEmpty'))
                  .ensure()
              })
            })
          })
        })
      }
      try {
        resourceNamesSchema.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
  }
  //TODO : to remove any
  private getInitialValues(initialValues: any): K8sDeleteData {
    if (initialValues.spec?.deleteResources?.type === DeleteSpecConstant.ResourceName) {
      return {
        ...initialValues,
        spec: {
          ...initialValues.spec,
          deleteResources: {
            type: DeleteSpecConstant.ResourceName,
            spec: {
              resourceNames:
                getMultiTypeFromValue(initialValues.spec?.deleteResources?.spec?.resourceNames) ===
                MultiTypeInputType.RUNTIME
                  ? initialValues.spec?.deleteResources?.spec?.resourceNames
                  : initialValues.spec?.deleteResources?.spec?.resourceNames?.length
                  ? defaultTo(initialValues.spec?.deleteResources?.spec?.resourceNames, []).map((item: string) => ({
                      value: item,
                      id: uuid()
                    }))
                  : [{ value: '', id: uuid() }]
            }
          }
        }
      }
    } else if (initialValues.spec?.deleteResources?.type === DeleteSpecConstant.ManifestPath) {
      return {
        ...initialValues,
        spec: {
          ...initialValues.spec,
          deleteResources: {
            type: DeleteSpecConstant.ManifestPath,
            spec: {
              manifestPaths:
                getMultiTypeFromValue(initialValues.spec?.deleteResources?.spec?.manifestPaths) ===
                MultiTypeInputType.RUNTIME
                  ? initialValues.spec?.deleteResources?.spec?.manifestPaths
                  : initialValues.spec?.deleteResources?.spec?.manifestPaths?.length
                  ? defaultTo(initialValues.spec?.deleteResources?.spec?.manifestPaths, []).map((item: string) => ({
                      value: item,
                      id: uuid()
                    }))
                  : [{ value: '', id: uuid() }]
            }
          }
        }
      }
    } else if (initialValues.spec?.deleteResources?.type === DeleteSpecConstant.ReleaseName) {
      return {
        ...initialValues,
        spec: {
          ...initialValues.spec,
          deleteResources: {
            type: DeleteSpecConstant.ReleaseName,
            spec: {
              deleteNamespace: initialValues.spec?.deleteResources?.spec?.deleteNamespace || false
            }
          }
        }
      }
    }
 
    return {
      ...initialValues,
      spec: {
        ...initialValues.spec,
        deleteResources: {
          type: DeleteSpecConstant.ResourceName,
          spec: {
            resourceNames:
              getMultiTypeFromValue(initialValues.spec?.deleteResources?.spec?.resourceNames) ===
              MultiTypeInputType.RUNTIME
                ? initialValues.spec?.deleteResources?.spec?.resourceNames
                : initialValues.spec?.deleteResources?.spec?.resourceNames?.length
                ? (initialValues.spec?.deleteResources?.spec?.resourceNames).map((item: string) => ({
                    value: item,
                    id: uuid()
                  }))
                : [{ value: '', id: uuid() }]
          }
        }
      }
    }
  }
  // TODO: remove any
  processFormData(data: any): K8sDeleteFormData {
    /* making sure to remove other entities */
    if (data.spec?.deleteResources?.type === DeleteSpecConstant.ResourceName) {
      /* istanbul ignore next */
      unset(data.spec?.deleteResources?.spec, 'deleteNamespace')
      unset(data.spec?.deleteResources?.spec, 'manifestPaths')
      return {
        ...data,
        spec: {
          ...data.spec,
          deleteResources: {
            type: DeleteSpecConstant.ResourceName,
            spec: {
              resourceNames:
                getMultiTypeFromValue(data.spec?.deleteResources?.spec?.resourceNames) === MultiTypeInputType.RUNTIME
                  ? data.spec?.deleteResources?.spec?.resourceNames
                  : defaultTo(data.spec?.deleteResources?.spec?.resourceNames, []).map((item: any) => item.value)
            }
          }
        }
      }
    } else if (data.spec?.deleteResources?.type === DeleteSpecConstant.ManifestPath) {
      /* istanbul ignore next */
      unset(data.spec?.deleteResources?.spec, 'deleteNamespace')
      unset(data.spec?.deleteResources?.spec, 'resourceNames')
      return {
        ...data,
        spec: {
          ...data.spec,
          deleteResources: {
            type: DeleteSpecConstant.ManifestPath,
            spec: {
              manifestPaths:
                getMultiTypeFromValue(data.spec?.deleteResources?.spec?.manifestPaths) === MultiTypeInputType.RUNTIME
                  ? data.spec?.deleteResources?.spec?.manifestPaths
                  : defaultTo(data.spec?.deleteResources?.spec?.manifestPaths, []).map((item: any) => item.value)
            }
          }
        }
      }
    }
 
    /* istanbul ignore next */
    unset(data.spec?.deleteResources?.spec, 'resourceNames')
    unset(data.spec?.deleteResources?.spec, 'manifestPaths')
    return {
      ...data,
      spec: {
        ...data.spec,
        deleteResources: {
          type: DeleteSpecConstant.ReleaseName,
          spec: {
            deleteNamespace: data.spec?.deleteResources?.spec?.deleteNamespace as boolean
          }
        }
      }
    }
  }
 
  protected type = StepType.K8sDelete
  protected stepName = 'K8s Delete'
  protected stepIcon: IconName = 'delete'
  protected stepDescription: keyof StringsMap = 'pipeline.stepDescription.K8sDelete'
  protected isHarnessSpecific = true
 
  protected defaultValues: K8sDeleteFormData = {
    identifier: '',
    timeout: '10m',
    name: '',
    type: StepType.K8sDelete,
    spec: {
      deleteResources: {
        type: '',
        spec: {}
      }
    }
  }
}