diff --git a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.test.ts b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.test.ts index 6de0aa90a5..30b480f348 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.test.ts +++ b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.test.ts @@ -28,7 +28,7 @@ describe('DatabaseEntitiesCatalog', () => { updateEntity: jest.fn(), entities: jest.fn(), entity: jest.fn(), - entityById: jest.fn(), + entityByUid: jest.fn(), removeEntity: jest.fn(), addLocation: jest.fn(), removeLocation: jest.fn(), diff --git a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts index 9c3f87055b..578ae40daa 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts @@ -81,7 +81,7 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { async removeEntityByUid(uid: string): Promise { return await this.database.transaction(async tx => { - const currentEntity = await this.database.entityById(tx, uid); + const currentEntity = await this.database.entityByUid(tx, uid); if (!currentEntity) { throw new NotFoundError(`Entity with ID ${uid} was not found`); } diff --git a/plugins/catalog-backend/src/database/CommonDatabase.ts b/plugins/catalog-backend/src/database/CommonDatabase.ts index 75d1bfb64f..2a1b33bbbe 100644 --- a/plugins/catalog-backend/src/database/CommonDatabase.ts +++ b/plugins/catalog-backend/src/database/CommonDatabase.ts @@ -319,7 +319,7 @@ export class CommonDatabase implements Database { return toEntityResponse(rows[0]); } - async entityById( + async entityByUid( txOpaque: unknown, id: string, ): Promise { diff --git a/plugins/catalog-backend/src/database/types.ts b/plugins/catalog-backend/src/database/types.ts index 078319d9cb..fc81e124ba 100644 --- a/plugins/catalog-backend/src/database/types.ts +++ b/plugins/catalog-backend/src/database/types.ts @@ -130,7 +130,7 @@ export type Database = { namespace?: string, ): Promise; - entityById(tx: unknown, id: string): Promise; + entityByUid(tx: unknown, uid: string): Promise; removeEntity(tx: unknown, uid: string): Promise; diff --git a/plugins/catalog/src/components/CatalogFilter/CatalogFilter.test.tsx b/plugins/catalog/src/components/CatalogFilter/CatalogFilter.test.tsx index 6246726fab..b78450d549 100644 --- a/plugins/catalog/src/components/CatalogFilter/CatalogFilter.test.tsx +++ b/plugins/catalog/src/components/CatalogFilter/CatalogFilter.test.tsx @@ -18,7 +18,7 @@ import React from 'react'; import { render, fireEvent } from '@testing-library/react'; import { wrapInTestApp } from '@backstage/test-utils'; import { CatalogFilter, CatalogFilterGroup } from './CatalogFilter'; -import { FilterGroupItem } from '../../types'; +import { EntityFilterType } from '../../data/filters'; describe('Catalog Filter', () => { it('should render the different groups', async () => { @@ -41,11 +41,11 @@ describe('Catalog Filter', () => { name: 'Test Group 1', items: [ { - id: FilterGroupItem.ALL, + id: EntityFilterType.ALL, label: 'First Label', }, { - id: FilterGroupItem.STARRED, + id: EntityFilterType.STARRED, label: 'Second Label', }, ], @@ -68,12 +68,12 @@ describe('Catalog Filter', () => { name: 'Test Group 1', items: [ { - id: FilterGroupItem.ALL, + id: EntityFilterType.ALL, label: 'First Label', count: 100, }, { - id: FilterGroupItem.STARRED, + id: EntityFilterType.STARRED, label: 'Second Label', count: 400, }, @@ -97,12 +97,12 @@ describe('Catalog Filter', () => { name: 'Test Group 1', items: [ { - id: FilterGroupItem.ALL, + id: EntityFilterType.ALL, label: 'First Label', count: 100, }, { - id: FilterGroupItem.STARRED, + id: EntityFilterType.STARRED, label: 'Second Label', count: 400, }, @@ -136,12 +136,12 @@ describe('Catalog Filter', () => { name: 'Test Group 1', items: [ { - id: FilterGroupItem.ALL, + id: EntityFilterType.ALL, label: 'First Label', count: () => BACKSTAGE!, }, { - id: FilterGroupItem.STARRED, + id: EntityFilterType.STARRED, label: 'Second Label', count: 400, }, diff --git a/plugins/catalog/src/components/CatalogFilter/CatalogFilter.tsx b/plugins/catalog/src/components/CatalogFilter/CatalogFilter.tsx index 6541a4df8d..2551ebd4d1 100644 --- a/plugins/catalog/src/components/CatalogFilter/CatalogFilter.tsx +++ b/plugins/catalog/src/components/CatalogFilter/CatalogFilter.tsx @@ -25,9 +25,9 @@ import { makeStyles, } from '@material-ui/core'; import type { IconComponent } from '@backstage/core'; -import { FilterGroupItem } from '../../types'; +import { EntityFilterType } from '../../data/filters'; export type CatalogFilterItem = { - id: FilterGroupItem; + id: EntityFilterType; label: string; icon?: IconComponent; count?: number | React.FC; diff --git a/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx b/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx index 0c2bd2d8dd..6ad507a603 100644 --- a/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx +++ b/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx @@ -15,7 +15,7 @@ */ import { Entity, LOCATION_ANNOTATION } from '@backstage/catalog-model'; -import { Progress, useApi } from '@backstage/core'; +import { Progress, useApi, alertApiRef } from '@backstage/core'; import { Button, Dialog, @@ -32,7 +32,6 @@ import React, { FC } from 'react'; import { useAsync } from 'react-use'; import { AsyncState } from 'react-use/lib/useAsync'; import { catalogApiRef } from '../../api/types'; -import { alertApiRef } from '../../../../../packages/core-api/src/apis/definitions/AlertApi'; type ComponentRemovalDialogProps = { open: boolean; @@ -63,6 +62,17 @@ export const ComponentRemovalDialog: FC = ({ const catalogApi = useApi(catalogApiRef); const alertApi = useApi(alertApiRef); + const removeEntity = async () => { + const uid = entity.metadata.uid; + try { + await catalogApi.removeEntityByUid(uid!); + } catch (err) { + alertApi.post({ message: err.message }); + } + + onConfirm(); + }; + return ( @@ -93,7 +103,7 @@ export const ComponentRemovalDialog: FC = ({
  • - {entities[0]?.metadata?.annotations?.[LOCATION_ANNOTATION]} + {entities[0]?.metadata.annotations?.[LOCATION_ANNOTATION]}
@@ -109,20 +119,7 @@ export const ComponentRemovalDialog: FC = ({