feat: Pass entity unique id to POST body of /v1/jobs instead of entire entity

This commit is contained in:
Marvin9
2020-10-13 19:16:22 +05:30
parent a24b657721
commit 91e425fdab
2 changed files with 4 additions and 8 deletions
+3 -7
View File
@@ -15,7 +15,6 @@
*/
import { createApiRef, DiscoveryApi } from '@backstage/core';
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
export const scaffolderApiRef = createApiRef<ScaffolderApi>({
id: 'plugin.scaffolder.service',
@@ -33,20 +32,17 @@ export class ScaffolderApi {
* Executes the scaffolding of a component, given a template and its
* parameter values.
*
* @param template Template entity for the scaffolder to use. New project is going to be created out of this template.
* @param templateName Template name for the scaffolder to use. New project is going to be created out of this template.
* @param values Parameters for the template, e.g. name, description
*/
async scaffold(
template: TemplateEntityV1alpha1,
values: Record<string, any>,
) {
async scaffold(templateName: string, values: Record<string, any>) {
const url = `${await this.discoveryApi.getBaseUrl('scaffolder')}/v1/jobs`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ template, values: { ...values } }),
body: JSON.stringify({ templateName, values: { ...values } }),
});
if (response.status !== 201) {
@@ -97,7 +97,7 @@ export const TemplatePage = () => {
const handleCreate = async () => {
try {
const job = await scaffolderApi.scaffold(template!, formState);
const job = await scaffolderApi.scaffold(templateName, formState);
setJobId(job);
} catch (e) {
errorApi.post(e);