Skip to content

Commit

Permalink
fix(artifacts): fix uncaught undefined exception with artifacts (#7362)
Browse files Browse the repository at this point in the history
* fix(artifacts): fix uncaught undefined exception with artifacts

* remove the usage of promises
  • Loading branch information
Jammy Louie authored and maggieneterval committed Aug 29, 2019
1 parent dc16166 commit b889857
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function TriggerForm(triggerFormProps: ITriggerProps & { formik: FormikProps<ITr
triggerExpectedArtifactIds.push(expectedArtifact.id);
}

updateTriggerFields({ expectedArtifactIds: triggerExpectedArtifactIds });
updateExpectedArtifacts(pipelineExpectedArtifacts);
updateTriggerFields({ expectedArtifactIds: triggerExpectedArtifactIds });
};

const showRunAsUser = SETTINGS.feature.fiatEnabled && !SETTINGS.feature.managedServiceAccounts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface ITriggersPageContentProps {
export function TriggersPageContent(props: ITriggersPageContentProps) {
const showProperties = SETTINGS.feature.quietPeriod || SETTINGS.feature.managedServiceAccounts;
const { pipeline, application, updatePipelineConfig } = props;
// must keep track of state to avoid race condition -- Remove once PipelineConfigurer is converted over to React
const [expectedArtifacts, setExpectedArtifacts] = React.useState<IExpectedArtifact[]>(
props.pipeline.expectedArtifacts ? props.pipeline.expectedArtifacts : [],
);

function updateRoles(roles: any[]): void {
updatePipelineConfig({ roles });
Expand Down Expand Up @@ -53,22 +57,24 @@ export function TriggersPageContent(props: ITriggersPageContentProps) {
}

// Expected Artifacts
function updateExpectedArtifacts(expectedArtifacts: IExpectedArtifact[]) {
function updateExpectedArtifacts(e: IExpectedArtifact[]) {
setExpectedArtifacts(e);
updatePipelineConfig({ expectedArtifacts });
}

function removeUnusedExpectedArtifacts(pipelineParam: IPipeline) {
// remove unused expected artifacts from the pipeline
const newExpectedArtifacts: IExpectedArtifact[] = pipelineParam.expectedArtifacts.slice(0);
pipelineParam.expectedArtifacts.forEach(expectedArtifact => {
const newExpectedArtifacts: IExpectedArtifact[] = expectedArtifacts;
newExpectedArtifacts.forEach(expectedArtifact => {
if (
!pipelineParam.triggers.find(t => t.expectedArtifactIds && t.expectedArtifactIds.includes(expectedArtifact.id))
) {
newExpectedArtifacts.splice(findIndex(newExpectedArtifacts, e => e.id === expectedArtifact.id), 1);
}
ArtifactReferenceService.removeReferenceFromStages(expectedArtifact.id, pipelineParam.stages);
});
updatePipelineConfig({ expectedArtifacts: newExpectedArtifacts });
setExpectedArtifacts(newExpectedArtifacts);
updatePipelineConfig({ expectedArtifacts });
}

return (
Expand Down

0 comments on commit b889857

Please sign in to comment.