From 304c544af51a746b52391a3bdf94da3098620177 Mon Sep 17 00:00:00 2001 From: Ivan Shmidt Date: Fri, 29 May 2020 14:59:59 +0200 Subject: [PATCH] Posting addLocation --- plugins/catalog/src/api/CatalogClient.ts | 2 +- .../RegisterComponentPage.tsx | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/catalog/src/api/CatalogClient.ts b/plugins/catalog/src/api/CatalogClient.ts index 7449ce2f2c..94ee9aa4b3 100644 --- a/plugins/catalog/src/api/CatalogClient.ts +++ b/plugins/catalog/src/api/CatalogClient.ts @@ -16,7 +16,6 @@ import { CatalogApi } from './types'; import { DescriptorEnvelope } from '../types'; -import {} from '@backstage/catalog-model'; export class CatalogClient implements CatalogApi { private apiOrigin: string; @@ -44,6 +43,7 @@ export class CatalogClient implements CatalogApi { throw new Error(`'Entity not found: ${name}`); } + // TODO: Types for the type param async addLocation(type: string, target: string): Promise<{}> { const response = await fetch( `${this.apiOrigin}${this.basePath}/locations`, diff --git a/plugins/register-component/src/components/RegisterComponentPage/RegisterComponentPage.tsx b/plugins/register-component/src/components/RegisterComponentPage/RegisterComponentPage.tsx index 114c37fe4c..33029a012d 100644 --- a/plugins/register-component/src/components/RegisterComponentPage/RegisterComponentPage.tsx +++ b/plugins/register-component/src/components/RegisterComponentPage/RegisterComponentPage.tsx @@ -23,22 +23,23 @@ import { Content, ContentHeader, SupportButton, + useApi, } from '@backstage/core'; import RegisterComponentForm from '../RegisterComponentForm'; +import { catalogApiRef } from '@backstage/plugin-catalog'; const RegisterComponentPage: FC<{}> = () => { + const catalogApi = useApi(catalogApiRef); const [isSubmitting, setIsSubmitting] = useState(false); - useEffect(() => { - if (isSubmitting) { - setTimeout(() => { - setIsSubmitting(false); - }, 4000); - } - }, [isSubmitting]); - - const onSubmit = () => { + const onSubmit = async (formData: { componentIdInput: string }) => { setIsSubmitting(true); + + const { componentIdInput: target } = formData; + + const location = await catalogApi.addLocation('github', target); + + setIsSubmitting(false); }; return (