diff --git a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx index 0b6c451ff8..e7d13e609f 100644 --- a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx +++ b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx @@ -46,7 +46,7 @@ export const JobStatusModal = ({ const jobStatus = job?.status ?? ''; useEffect(() => { - if (jobStatus === 'COMPLETED') onComplete(job); + if (jobStatus === 'COMPLETED') onComplete(job!); }, [jobStatus, onComplete]); // eslint-disable-line react-hooks/exhaustive-deps return ( diff --git a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx index e68c795bd6..4ead44ab99 100644 --- a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx +++ b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.tsx @@ -27,7 +27,7 @@ import { import { catalogApiRef } from '@backstage/plugin-catalog'; import { LinearProgress } from '@material-ui/core'; import { IChangeEvent } from '@rjsf/core'; -import React, { useState } from 'react'; +import React, { useState, useCallback } from 'react'; import { useParams } from 'react-router-dom'; import useStaleWhileRevalidate from 'swr'; import { scaffolderApiRef } from '../../api'; @@ -108,27 +108,30 @@ export const TemplatePage = () => { null, ); - const handleCreateComplete = async (job: Job) => { - const componentYaml = job.metadata.remoteUrl?.replace( - /\.git$/, - '/blob/master/component-info.yaml', - ); - - if (!componentYaml) { - errorApi.post( - new Error( - `Failed to find component-info.yaml file in ${job.metadata.remoteUrl}.`, - ), + const handleCreateComplete = useCallback( + async (job: Job) => { + const componentYaml = job.metadata.remoteUrl?.replace( + /\.git$/, + '/blob/master/component-info.yaml', ); - return; - } - const { - entities: [createdEntity], - } = await catalogApi.addLocation('github', componentYaml); + if (!componentYaml) { + errorApi.post( + new Error( + `Failed to find component-info.yaml file in ${job.metadata.remoteUrl}.`, + ), + ); + return; + } - setEntity((createdEntity as any) as TemplateEntityV1alpha1); - }; + const { + entities: [createdEntity], + } = await catalogApi.addLocation('github', componentYaml); + + setEntity((createdEntity as any) as TemplateEntityV1alpha1); + }, + [catalogApi, setEntity, errorApi], + ); if (!loading && !template) { errorApi.post(new Error('Template was not found.'));