diff --git a/plugins/api-docs/dev/index.tsx b/plugins/api-docs/dev/index.tsx
index d7bc61073e..4bf0215f32 100644
--- a/plugins/api-docs/dev/index.tsx
+++ b/plugins/api-docs/dev/index.tsx
@@ -16,8 +16,8 @@
import React from 'react';
import { createDevApp } from '@backstage/dev-utils';
-import { ApiExplorerPage, plugin } from '../src/plugin';
-import { catalogApiRef } from '@backstage/plugin-catalog';
+import { ApiExplorerPage, apiDocsPlugin } from '../src/plugin';
+import { catalogApiRef } from '@backstage/plugin-catalog-react';
import petstoreApiEntity from './example-api.yaml';
createDevApp()
@@ -31,6 +31,6 @@ createDevApp()
},
} as unknown) as typeof catalogApiRef.T),
})
- .registerPlugin(plugin)
+ .registerPlugin(apiDocsPlugin)
.addPage({ element: })
.render();
diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
index d59699ab9a..0d2648ab5f 100644
--- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
+++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
@@ -16,6 +16,7 @@
import { ApiEntity } from '@backstage/catalog-model';
import { ApiProvider, ApiRegistry } from '@backstage/core';
+import { EntityProvider } from '@backstage/plugin-catalog-react';
import { renderInTestApp } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
@@ -54,7 +55,7 @@ paths:
get:
summary: List all artists
responses:
- "200":
+ "200":
description: Success
`;
const apiEntity: ApiEntity = {
@@ -81,7 +82,9 @@ paths:
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
@@ -110,7 +113,9 @@ paths:
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx
index 19370bfc18..0a4386e275 100644
--- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx
+++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx
@@ -15,6 +15,7 @@
*/
import { ApiEntity } from '@backstage/catalog-model';
+import { useEntity } from '@backstage/plugin-catalog-react';
import { CardTab, TabbedCard, useApi } from '@backstage/core';
import { Alert } from '@material-ui/lab';
import React from 'react';
@@ -22,29 +23,31 @@ import { apiDocsConfigRef } from '../../config';
import { PlainApiDefinitionWidget } from '../PlainApiDefinitionWidget';
type Props = {
+ /** @deprecated The entity is now grabbed from context instead */
apiEntity?: ApiEntity;
};
-export const ApiDefinitionCard = ({ apiEntity }: Props) => {
+export const ApiDefinitionCard = (_: Props) => {
+ const entity = useEntity().entity as ApiEntity;
const config = useApi(apiDocsConfigRef);
const { getApiDefinitionWidget } = config;
- if (!apiEntity) {
+ if (!entity) {
return Could not fetch the API;
}
- const definitionWidget = getApiDefinitionWidget(apiEntity);
+ const definitionWidget = getApiDefinitionWidget(entity);
if (definitionWidget) {
return (
-
+
- {definitionWidget.component(apiEntity.spec.definition)}
+ {definitionWidget.component(entity.spec.definition)}
@@ -53,13 +56,13 @@ export const ApiDefinitionCard = ({ apiEntity }: Props) => {
return (
+
,
]}
diff --git a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
index d406e160fc..7e9973c25f 100644
--- a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
@@ -16,7 +16,11 @@
import { Entity, RELATION_CONSUMES_API } from '@backstage/catalog-model';
import { ApiProvider, ApiRegistry } from '@backstage/core';
-import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
+import {
+ CatalogApi,
+ catalogApiRef,
+ EntityProvider,
+} from '@backstage/plugin-catalog-react';
import { renderInTestApp } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
@@ -63,7 +67,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
@@ -112,7 +118,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
diff --git a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.tsx b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.tsx
index 0bd4919554..8a808a6488 100644
--- a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.tsx
@@ -19,6 +19,7 @@ import {
Entity,
RELATION_CONSUMES_API,
} from '@backstage/catalog-model';
+import { useEntity } from '@backstage/plugin-catalog-react';
import { EmptyState, InfoCard, Progress } from '@backstage/core';
import React, { PropsWithChildren } from 'react';
import { ApisTable } from './ApisTable';
@@ -37,11 +38,13 @@ const ApisCard = ({
};
type Props = {
- entity: Entity;
+ /** @deprecated The entity is now grabbed from context instead */
+ entity?: Entity;
variant?: string;
};
-export const ConsumedApisCard = ({ entity, variant = 'gridItem' }: Props) => {
+export const ConsumedApisCard = ({ variant = 'gridItem' }: Props) => {
+ const { entity } = useEntity();
const { entities, loading, error } = useRelatedEntities(
entity,
RELATION_CONSUMES_API,
diff --git a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
index 7b6ce6e18a..2fc5763461 100644
--- a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
@@ -16,7 +16,11 @@
import { Entity, RELATION_PROVIDES_API } from '@backstage/catalog-model';
import { ApiProvider, ApiRegistry } from '@backstage/core';
-import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
+import {
+ CatalogApi,
+ catalogApiRef,
+ EntityProvider,
+} from '@backstage/plugin-catalog-react';
import { renderInTestApp } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
@@ -63,7 +67,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
@@ -112,7 +118,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
diff --git a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.tsx b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.tsx
index 618f2dc1f6..ed6e893a03 100644
--- a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.tsx
@@ -19,6 +19,7 @@ import {
Entity,
RELATION_PROVIDES_API,
} from '@backstage/catalog-model';
+import { useEntity } from '@backstage/plugin-catalog-react';
import { EmptyState, InfoCard, Progress } from '@backstage/core';
import React, { PropsWithChildren } from 'react';
import { ApisTable } from './ApisTable';
@@ -37,11 +38,13 @@ const ApisCard = ({
};
type Props = {
- entity: Entity;
+ /** @deprecated The entity is now grabbed from context instead */
+ entity?: Entity;
variant?: string;
};
-export const ProvidedApisCard = ({ entity, variant = 'gridItem' }: Props) => {
+export const ProvidedApisCard = ({ variant = 'gridItem' }: Props) => {
+ const { entity } = useEntity();
const { entities, loading, error } = useRelatedEntities(
entity,
RELATION_PROVIDES_API,
diff --git a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
index 99a8c0dc28..78080e8318 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
@@ -16,7 +16,11 @@
import { Entity, RELATION_API_CONSUMED_BY } from '@backstage/catalog-model';
import { ApiProvider, ApiRegistry } from '@backstage/core';
-import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
+import {
+ CatalogApi,
+ catalogApiRef,
+ EntityProvider,
+} from '@backstage/plugin-catalog-react';
import { renderInTestApp } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
@@ -62,7 +66,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
@@ -111,7 +117,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
diff --git a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.tsx b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.tsx
index 0431367aa2..56d2fb977d 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.tsx
@@ -19,6 +19,7 @@ import {
Entity,
RELATION_API_CONSUMED_BY,
} from '@backstage/catalog-model';
+import { useEntity } from '@backstage/plugin-catalog-react';
import { EmptyState, InfoCard, Progress } from '@backstage/core';
import React, { PropsWithChildren } from 'react';
import { MissingConsumesApisEmptyState } from '../EmptyState';
@@ -37,14 +38,13 @@ const ComponentsCard = ({
};
type Props = {
- entity: Entity;
+ /** @deprecated The entity is now grabbed from context instead */
+ entity?: Entity;
variant?: string;
};
-export const ConsumingComponentsCard = ({
- entity,
- variant = 'gridItem',
-}: Props) => {
+export const ConsumingComponentsCard = ({ variant = 'gridItem' }: Props) => {
+ const { entity } = useEntity();
const { entities, loading, error } = useRelatedEntities(
entity,
RELATION_API_CONSUMED_BY,
diff --git a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
index a3341ad8d0..5edd2efa14 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
@@ -16,7 +16,11 @@
import { Entity, RELATION_API_PROVIDED_BY } from '@backstage/catalog-model';
import { ApiProvider, ApiRegistry } from '@backstage/core';
-import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
+import {
+ CatalogApi,
+ catalogApiRef,
+ EntityProvider,
+} from '@backstage/plugin-catalog-react';
import { renderInTestApp } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
@@ -62,7 +66,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
@@ -111,7 +117,9 @@ describe('', () => {
const { getByText } = await renderInTestApp(
-
+
+
+
,
);
diff --git a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.tsx b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.tsx
index 9e405a3af3..959ff3feed 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.tsx
@@ -19,6 +19,7 @@ import {
Entity,
RELATION_API_PROVIDED_BY,
} from '@backstage/catalog-model';
+import { useEntity } from '@backstage/plugin-catalog-react';
import { EmptyState, InfoCard, Progress } from '@backstage/core';
import React, { PropsWithChildren } from 'react';
import { MissingProvidesApisEmptyState } from '../EmptyState';
@@ -37,14 +38,13 @@ const ComponentsCard = ({
};
type Props = {
- entity: Entity;
+ /** @deprecated The entity is now grabbed from context instead */
+ entity?: Entity;
variant?: string;
};
-export const ProvidingComponentsCard = ({
- entity,
- variant = 'gridItem',
-}: Props) => {
+export const ProvidingComponentsCard = ({ variant = 'gridItem' }: Props) => {
+ const { entity } = useEntity();
const { entities, loading, error } = useRelatedEntities(
entity,
RELATION_API_PROVIDED_BY,
diff --git a/plugins/api-docs/src/index.ts b/plugins/api-docs/src/index.ts
index e85c693864..dd231d6cb4 100644
--- a/plugins/api-docs/src/index.ts
+++ b/plugins/api-docs/src/index.ts
@@ -15,4 +15,8 @@
*/
export * from './components';
-export { plugin, ApiExplorerPage } from './plugin';
+export {
+ apiDocsPlugin,
+ apiDocsPlugin as plugin,
+ ApiExplorerPage,
+} from './plugin';
diff --git a/plugins/api-docs/src/plugin.test.ts b/plugins/api-docs/src/plugin.test.ts
index 054e804382..eaafd36b3d 100644
--- a/plugins/api-docs/src/plugin.test.ts
+++ b/plugins/api-docs/src/plugin.test.ts
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-import { plugin } from './plugin';
+import { apiDocsPlugin } from './plugin';
describe('api-docs', () => {
it('should export plugin', () => {
- expect(plugin).toBeDefined();
+ expect(apiDocsPlugin).toBeDefined();
});
});
diff --git a/plugins/api-docs/src/plugin.ts b/plugins/api-docs/src/plugin.ts
index 8faf5412fc..429fd60095 100644
--- a/plugins/api-docs/src/plugin.ts
+++ b/plugins/api-docs/src/plugin.ts
@@ -19,13 +19,14 @@ import {
createApiFactory,
createPlugin,
createRoutableExtension,
+ createComponentExtension,
} from '@backstage/core';
import { ApiExplorerPage as Page } from './components/ApiExplorerPage/ApiExplorerPage';
import { defaultDefinitionWidgets } from './components/ApiDefinitionCard';
import { rootRoute } from './routes';
import { apiDocsConfigRef } from './config';
-export const plugin = createPlugin({
+export const apiDocsPlugin = createPlugin({
id: 'api-docs',
routes: {
root: rootRoute,
@@ -49,10 +50,59 @@ export const plugin = createPlugin({
},
});
-export const ApiExplorerPage = plugin.provide(
+export const ApiExplorerPage = apiDocsPlugin.provide(
createRoutableExtension({
component: () =>
import('./components/ApiExplorerPage').then(m => m.ApiExplorerPage),
mountPoint: rootRoute,
}),
);
+
+export const EntityApiDefinitionCard = apiDocsPlugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () =>
+ import('./components/ApiDefinitionCard').then(m => m.ApiDefinitionCard),
+ },
+ }),
+);
+
+export const EntityConsumedApisCard = apiDocsPlugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () =>
+ import('./components/ApisCards').then(m => m.ConsumedApisCard),
+ },
+ }),
+);
+
+export const EntityConsumingComponentsCard = apiDocsPlugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () =>
+ import('./components/ComponentsCards').then(
+ m => m.ConsumingComponentsCard,
+ ),
+ },
+ }),
+);
+
+export const EntityProvidedApisCard = apiDocsPlugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () =>
+ import('./components/ApisCards').then(m => m.ProvidedApisCard),
+ },
+ }),
+);
+
+export const EntityProvidingComponentsCard = apiDocsPlugin.provide(
+ createComponentExtension({
+ component: {
+ lazy: () =>
+ import('./components/ComponentsCards').then(
+ m => m.ProvidingComponentsCard,
+ ),
+ },
+ }),
+);