diff --git a/plugins/catalog/src/api/CatalogClient.ts b/plugins/catalog/src/api/CatalogClient.ts index d6d717a085..20720d34bd 100644 --- a/plugins/catalog/src/api/CatalogClient.ts +++ b/plugins/catalog/src/api/CatalogClient.ts @@ -16,7 +16,7 @@ import { CatalogApi } from './types'; import { DescriptorEnvelope } from '../types'; -import { Entity } from '@backstage/catalog-model'; +import { Entity, Location } from '@backstage/catalog-model'; export class CatalogClient implements CatalogApi { private apiOrigin: string; @@ -43,22 +43,19 @@ export class CatalogClient implements CatalogApi { if (entity) return entity; throw new Error(`'Entity not found: ${name}`); } - async getLocationByEntity(entity: Entity): Promise { - const findLocationIdInEntity = (e: Entity) => { - return e.metadata.annotations - ? e.metadata.annotations['backstage.io/managed-by-location'] - : null; - }; + async getLocationByEntity(entity: Entity): Promise { + const findLocationIdInEntity = (e: Entity) => + e.metadata.annotations?.['backstage.io/managed-by-location']; const locationId = findLocationIdInEntity(entity); - if (!locationId) return null; + if (!locationId) return undefined; const response = await fetch( `${this.apiOrigin}${this.basePath}/locations/${locationId}`, ); if (response.ok) { const location = await response.json(); - if (location) return location; + if (location) return location.data; } throw new Error(`'Location not found: ${locationId}`); } diff --git a/plugins/catalog/src/api/types.ts b/plugins/catalog/src/api/types.ts index 845dbe8e83..9e8dc5fbac 100644 --- a/plugins/catalog/src/api/types.ts +++ b/plugins/catalog/src/api/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { createApiRef } from '@backstage/core'; -import { Entity } from '@backstage/catalog-model'; +import { Entity, Location } from '@backstage/catalog-model'; export const catalogApiRef = createApiRef({ id: 'plugin.catalog.service', @@ -25,5 +25,5 @@ export const catalogApiRef = createApiRef({ export interface CatalogApi { getEntities(): Promise; getEntityByName(name: string): Promise; - getLocationByEntity(entity: Entity): Promise; + getLocationByEntity(entity: Entity): Promise; } diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx index 4242f89fe1..479b5fee42 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx @@ -35,7 +35,7 @@ import { import { Button, makeStyles, Typography, Link } from '@material-ui/core'; import { filterGroups, defaultFilter } from '../../data/filters'; import GitHub from '@material-ui/icons/GitHub'; -import { Entity } from '@backstage/catalog-model'; +import { Entity, Location } from '@backstage/catalog-model'; const useStyles = makeStyles(theme => ({ contentWrapper: { @@ -48,6 +48,7 @@ const useStyles = makeStyles(theme => ({ import { catalogApiRef } from '../..'; import { envelopeToComponent } from '../../data/utils'; +import { Component } from '../../data/component'; const CatalogPage: FC<{}> = () => { const catalogApi = useApi(catalogApiRef); @@ -71,14 +72,12 @@ const CatalogPage: FC<{}> = () => { }; if (value) { - getLocationDataForEntities(value) - .then(location => location.map(l => l.data)) - .then(setLocations); + getLocationDataForEntities(value).then(setLocations); } }, [value, catalogApi]); const actions = [ - (rowData: any) => ({ + (rowData: Component) => ({ icon: GitHub, tooltop: 'View on GitHub', onClick: () => { @@ -92,7 +91,10 @@ const CatalogPage: FC<{}> = () => { }), ]; - const findLocationForEntity = (entity: Entity, l: any) => { + const findLocationForEntity = ( + entity: Entity, + l: Location[], + ): Location | undefined => { const entityLocationId = entity.metadata.annotations?.['backstage.io/managed-by-location']; return l.find((location: any) => location.id === entityLocationId);