Skip to content

Commit

Permalink
Merge pull request #13046 from lokanandaprabhu/feature/OCPBUGS-16693
Browse files Browse the repository at this point in the history
OCPBUGS-16693, OCPBUGS-13387: Import page create button is disabled due to PAC validation
  • Loading branch information
openshift-merge-robot committed Aug 4, 2023
2 parents 60eca68 + dc780bd commit bd06053
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Expand Up @@ -710,7 +710,7 @@ export const createOrUpdateResources = async (
return createDevfileResources(formData, dryRun, appResources, generatedImageStreamName);
}

if (pipeline.type === PipelineType.PAC) {
if (pipeline.type === PipelineType.PAC && formData?.pipeline?.enabled) {
const pacRepository = formData?.pac?.repository;
const labels = formData?.labels;
const repo = await createRepositoryResources(pacRepository, namespace, labels, dryRun);
Expand Down
Expand Up @@ -64,14 +64,15 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis

const {
values: {
import: { recommendedStrategy },
import: { recommendedStrategy, selectedStrategy },
git: { url, type, ref, dir, secretResource },
pipeline,
image,
build,
resources,
},
setFieldValue,
setFieldTouched,
} = useFormikContext<FormikValues>();

const isDockerStrategy = build.strategy === 'Docker';
Expand All @@ -93,14 +94,30 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis
setFieldValue('pipeline.enabled', true);
setFieldValue('pipeline.type', PipelineType.PAC);
setFieldValue('pac.repository.gitUrl', url);
setFieldValue('pac.pipelineType', PipelineType.PAC);
setFieldValue('pac.pipelineEnabled', true);
} else {
setFieldValue('pipeline.enabled', false);
setFieldValue('pipeline.type', PipelineType.PIPELINE);
setFieldValue('pac.repository.gitUrl', '');
setFieldValue('pac.pipelineType', PipelineType.PIPELINE);
setFieldValue('pac.pipelineEnabled', false);
}
setIsPipelineTypeChanged(true);
}, [url, type, ref, dir, secretResource, isRepositoryEnabled, setFieldValue]);

React.useEffect(() => {
pipelineStorageRef.current = {};
}, [selectedStrategy]);

React.useEffect(() => {
setFieldValue('pac.pipelineEnabled', !!pipeline.enabled);
// Added setTimeout to re-validate yup validation after onchange event
setTimeout(() => {
setFieldTouched('pipeline.enabled', true);
}, 0);
}, [pipeline.enabled, setFieldValue, setFieldTouched]);

React.useEffect(() => {
let ignore = false;

Expand All @@ -118,7 +135,10 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis
}
const fetchPipelineTemplate = async () => {
let fetchedPipelines: PipelineKind[] = null;
if (!pipelineStorageRef.current[image.selected]) {
if (
!pipelineStorageRef.current[image.selected] ||
!pipelineStorageRef.current[image.selected]?.length
) {
fetchedPipelines = (await k8sList(PipelineModel, {
ns: CLUSTER_PIPELINE_NS,
labelSelector,
Expand Down Expand Up @@ -164,6 +184,7 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis
} else {
setFieldValue('pipeline.template', null);
setFieldValue('pipeline.templateSelected', '');
setFieldValue('pipeline.enabled', false);
setNoTemplateForRuntime(true);
}
};
Expand Down Expand Up @@ -215,6 +236,15 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis
);
}

const onChangePipelineType = (value: PipelineType) => {
setFieldValue('pac.pipelineType', value);
setFieldValue('pipeline.type', value);
// Added setTimeout to re-validate yup validation after onchange event
setTimeout(() => {
setFieldTouched('pipeline.type', true);
}, 0);
};

return pipeline.template ? (
<>
<CheckboxField
Expand All @@ -226,6 +256,7 @@ const PipelineTemplate: React.FC<PipelineTemplateProps> = ({ builderImages, exis
<RadioGroupField
className="odc-pipeline-section-pac__radio-intent"
name={'pipeline.type'}
onChange={(val: string) => onChangePipelineType(val as PipelineType)}
options={[
{
value: PipelineType.PAC,
Expand Down
Expand Up @@ -17,6 +17,7 @@ import { ConfigMapModel, SecretModel } from '@console/internal/models';
import { ConfigMapKind, SecretKind, K8sResourceKind } from '@console/internal/module/k8s';
import { nameRegex } from '@console/shared/src';
import { RepositoryModel } from '../../models';
import { PipelineType } from '../import/import-types';
import { PAC_TEMPLATE_DEFAULT } from '../pac/const';
import { PIPELINERUN_TEMPLATE_NAMESPACE } from '../pipelines/const';
import { RepositoryRuntimes, gitProviderTypesHosts } from './consts';
Expand Down Expand Up @@ -106,7 +107,10 @@ export const pipelinesAccessTokenValidationSchema = (t: TFunction) =>

export const importFlowRepositoryValidationSchema = (t: TFunction) => {
return yup.object().shape({
repository: pipelinesAccessTokenValidationSchema(t),
repository: yup.object().when(['pipelineType', 'pipelineEnabled'], {
is: (pipelineType, pipelineEnabled) => pipelineType === PipelineType.PAC && pipelineEnabled,
then: pipelinesAccessTokenValidationSchema(t),
}),
});
};

Expand Down

0 comments on commit bd06053

Please sign in to comment.