fix(scaffolder): sturdier fix for the catalog posting after success

This commit is contained in:
Ivan Shmidt
2020-09-22 13:50:54 +02:00
parent e8c60104df
commit 248f615148
2 changed files with 23 additions and 20 deletions
@@ -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 (
@@ -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.'));