diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
index 6d38319fe9..c04e4c95a8 100644
--- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
+++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import { Entity } from '@backstage/catalog-model';
import { wrapInTestApp } from '@backstage/test-utils';
import { render } from '@testing-library/react';
@@ -50,12 +51,12 @@ describe('CatalogTable component', () => {
),
);
const errorMessage = await rendered.findByText(
- /Error encountered while fetching components./,
+ /Error encountered while fetching catalog entities./,
);
expect(errorMessage).toBeInTheDocument();
});
- it('should display component names when loading has finished and no error occurred', async () => {
+ it('should display entity names when loading has finished and no error occurred', async () => {
const rendered = render(
wrapInTestApp(
= ({
return (
- Error encountered while fetching components. {error.toString()}
+ Error encountered while fetching catalog entities. {error.toString()}
);
diff --git a/plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.test.tsx b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.test.tsx
similarity index 72%
rename from plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.test.tsx
rename to plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.test.tsx
index 8a1f513f67..68306944a3 100644
--- a/plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.test.tsx
+++ b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.test.tsx
@@ -13,21 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { ComponentContextMenu } from './ComponentContextMenu';
-import { render } from '@testing-library/react';
+
+import { render, fireEvent } from '@testing-library/react';
import * as React from 'react';
import { act } from 'react-dom/test-utils';
+import { EntityContextMenu } from './EntityContextMenu';
describe('ComponentContextMenu', () => {
- it('should call onUnregisterComponent on button click', async () => {
+ it('should call onUnregisterEntity on button click', async () => {
await act(async () => {
const mockCallback = jest.fn();
const menu = render(
- ,
+ ,
);
const button = await menu.findByTestId('menu-button');
- button.click();
- const unregister = await menu.findByText('Unregister component');
+ fireEvent.click(button);
+ const unregister = await menu.findByText('Unregister entity');
expect(unregister).toBeInTheDocument();
});
});
diff --git a/plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.tsx b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx
similarity index 88%
rename from plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.tsx
rename to plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx
index 14c68ec7f9..fd52b97cb1 100644
--- a/plugins/catalog/src/components/ComponentContextMenu/ComponentContextMenu.tsx
+++ b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import {
IconButton,
ListItemIcon,
@@ -34,13 +35,11 @@ const useStyles = makeStyles({
},
});
-type ComponentContextMenuProps = {
- onUnregisterComponent: () => void;
+type Props = {
+ onUnregisterEntity: () => void;
};
-export const ComponentContextMenu: FC = ({
- onUnregisterComponent,
-}) => {
+export const EntityContextMenu: FC = ({ onUnregisterEntity }) => {
const [anchorEl, setAnchorEl] = useState();
const classes = useStyles();
@@ -53,7 +52,7 @@ export const ComponentContextMenu: FC = ({
};
return (
-
+ <>
= ({
-
+ >
);
};
diff --git a/plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.test.tsx b/plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.test.tsx
similarity index 77%
rename from plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.test.tsx
rename to plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.test.tsx
index ef12e52363..e0027431ff 100644
--- a/plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.test.tsx
+++ b/plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.test.tsx
@@ -13,21 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import { Entity } from '@backstage/catalog-model';
import { render } from '@testing-library/react';
import React from 'react';
-import { ComponentMetadataCard } from './ComponentMetadataCard';
+import { EntityMetadataCard } from './EntityMetadataCard';
-describe('ComponentMetadataCard component', () => {
- it('should display component name if provided', async () => {
+describe('EntityMetadataCard component', () => {
+ it('should display entity name if provided', async () => {
const testEntity: Entity = {
apiVersion: 'backstage.io/v1beta1',
kind: 'Component',
metadata: { name: 'test' },
};
- const rendered = await render(
- ,
- );
+ const rendered = await render();
expect(await rendered.findByText('test')).toBeInTheDocument();
});
});
diff --git a/plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.tsx b/plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.tsx
similarity index 93%
rename from plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.tsx
rename to plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.tsx
index 60c9284121..d7a3bc81f6 100644
--- a/plugins/catalog/src/components/ComponentMetadataCard/ComponentMetadataCard.tsx
+++ b/plugins/catalog/src/components/EntityMetadataCard/EntityMetadataCard.tsx
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import { Entity } from '@backstage/catalog-model';
import { InfoCard, StructuredMetadataTable } from '@backstage/core';
import React, { FC } from 'react';
@@ -21,7 +22,7 @@ type Props = {
entity: Entity;
};
-export const ComponentMetadataCard: FC = ({ entity }) => (
+export const EntityMetadataCard: FC = ({ entity }) => (
diff --git a/plugins/catalog/src/components/ComponentPage/ComponentPage.test.tsx b/plugins/catalog/src/components/EntityPage/EntityPage.test.tsx
similarity index 85%
rename from plugins/catalog/src/components/ComponentPage/ComponentPage.test.tsx
rename to plugins/catalog/src/components/EntityPage/EntityPage.test.tsx
index 75393bd10e..22a47c192e 100644
--- a/plugins/catalog/src/components/ComponentPage/ComponentPage.test.tsx
+++ b/plugins/catalog/src/components/EntityPage/EntityPage.test.tsx
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { ComponentPage } from './ComponentPage';
+
+import { ApiProvider, ApiRegistry, errorApiRef } from '@backstage/core';
+import { wrapInTestApp } from '@backstage/test-utils';
import { render, wait } from '@testing-library/react';
import * as React from 'react';
-import { wrapInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry, errorApiRef } from '@backstage/core';
-import { catalogApiRef, CatalogApi } from '../../api/types';
+import { CatalogApi, catalogApiRef } from '../../api/types';
+import { EntityPage } from './EntityPage';
const getTestProps = (name: string) => {
return {
@@ -36,8 +37,8 @@ const getTestProps = (name: string) => {
const errorApi = { post: () => {} };
-describe('ComponentPage', () => {
- it('should redirect to component table page when name is not provided', async () => {
+describe('EntityPage', () => {
+ it('should redirect to catalog page when name is not provided', async () => {
const props = getTestProps('');
render(
wrapInTestApp(
@@ -52,7 +53,7 @@ describe('ComponentPage', () => {
],
])}
>
-
+
,
),
);
diff --git a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx b/plugins/catalog/src/components/EntityPage/EntityPage.tsx
similarity index 82%
rename from plugins/catalog/src/components/ComponentPage/ComponentPage.tsx
rename to plugins/catalog/src/components/EntityPage/EntityPage.tsx
index 17ad2d880d..96132819e8 100644
--- a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx
+++ b/plugins/catalog/src/components/EntityPage/EntityPage.tsx
@@ -31,13 +31,13 @@ import { Alert } from '@material-ui/lab';
import React, { FC, useEffect, useState } from 'react';
import { useAsync } from 'react-use';
import { catalogApiRef } from '../..';
-import { ComponentContextMenu } from '../ComponentContextMenu/ComponentContextMenu';
-import { ComponentMetadataCard } from '../ComponentMetadataCard/ComponentMetadataCard';
-import { ComponentRemovalDialog } from '../ComponentRemovalDialog/ComponentRemovalDialog';
+import { EntityContextMenu } from '../EntityContextMenu/EntityContextMenu';
+import { EntityMetadataCard } from '../EntityMetadataCard/EntityMetadataCard';
+import { UnregisterEntityDialog } from '../UnregisterEntityDialog/UnregisterEntityDialog';
const REDIRECT_DELAY = 1000;
-type ComponentPageProps = {
+type Props = {
match: {
params: {
optionalNamespaceAndName: string;
@@ -68,7 +68,7 @@ function headerProps(
};
}
-export const ComponentPage: FC = ({ match, history }) => {
+export const EntityPage: FC = ({ match, history }) => {
const { optionalNamespaceAndName, kind } = match.params;
const [name, namespace] = optionalNamespaceAndName.split(':').reverse();
@@ -83,7 +83,7 @@ export const ComponentPage: FC = ({ match, history }) => {
useEffect(() => {
if (!error && !loading && !entity) {
- errorApi.post(new Error('Component not found!'));
+ errorApi.post(new Error('Entity not found!'));
setTimeout(() => {
history.push('/');
}, REDIRECT_DELAY);
@@ -95,14 +95,12 @@ export const ComponentPage: FC = ({ match, history }) => {
return null;
}
- const removeComponent = async () => {
+ const cleanUpAfterRemoval = async () => {
setConfirmationDialogOpen(false);
- // await componentFactory.removeComponentByName(componentName);
history.push('/');
};
const showRemovalDialog = () => setConfirmationDialogOpen(true);
- const hideRemovalDialog = () => setConfirmationDialogOpen(false);
// TODO - Replace with proper tabs implementation
const tabs = [
@@ -143,9 +141,7 @@ export const ComponentPage: FC = ({ match, history }) => {
// TODO: Switch theme and type props based on component type (website, library, ...)
- {entity && (
-
- )}
+ {entity && }
{loading && }
@@ -163,7 +159,7 @@ export const ComponentPage: FC = ({ match, history }) => {
-
+
= ({ match, history }) => {
- setConfirmationDialogOpen(false)}
/>
>
)}
diff --git a/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx b/plugins/catalog/src/components/UnregisterEntityDialog/UnregisterEntityDialog.tsx
similarity index 80%
rename from plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx
rename to plugins/catalog/src/components/UnregisterEntityDialog/UnregisterEntityDialog.tsx
index aa8f99e01e..e4eec3c21f 100644
--- a/plugins/catalog/src/components/ComponentRemovalDialog/ComponentRemovalDialog.tsx
+++ b/plugins/catalog/src/components/UnregisterEntityDialog/UnregisterEntityDialog.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,
@@ -33,7 +33,7 @@ import { useAsync } from 'react-use';
import { AsyncState } from 'react-use/lib/useAsync';
import { catalogApiRef } from '../../api/types';
-type ComponentRemovalDialogProps = {
+type Props = {
open: boolean;
onConfirm: () => any;
onClose: () => any;
@@ -50,7 +50,7 @@ function useColocatedEntities(entity: Entity): AsyncState {
}, [catalogApi, entity]);
}
-export const ComponentRemovalDialog: FC = ({
+export const UnregisterEntityDialog: FC = ({
open,
onConfirm,
onClose,
@@ -59,11 +59,24 @@ export const ComponentRemovalDialog: FC = ({
const { value: entities, loading, error } = useColocatedEntities(entity);
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
+ 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 (