diff --git a/.changeset/sixty-lemons-agree.md b/.changeset/sixty-lemons-agree.md
new file mode 100644
index 0000000000..7fc438b433
--- /dev/null
+++ b/.changeset/sixty-lemons-agree.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-kafka': patch
+---
+
+Migrate to new composability API, exporting the plugin instance as `kafkaPlugin`, entity content as `EntityKafkaContent`, and entity conditional as `isKafkaAvailable`.
diff --git a/plugins/kafka/dev/index.tsx b/plugins/kafka/dev/index.tsx
index 264d6f801f..5506d47026 100644
--- a/plugins/kafka/dev/index.tsx
+++ b/plugins/kafka/dev/index.tsx
@@ -14,6 +14,6 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
-import { plugin } from '../src/plugin';
+import { kafkaPlugin } from '../src/plugin';
-createDevApp().registerPlugin(plugin).render();
+createDevApp().registerPlugin(kafkaPlugin).render();
diff --git a/plugins/kafka/src/Router.tsx b/plugins/kafka/src/Router.tsx
index b445f8f408..13503fefe8 100644
--- a/plugins/kafka/src/Router.tsx
+++ b/plugins/kafka/src/Router.tsx
@@ -17,7 +17,7 @@
import { Entity } from '@backstage/catalog-model';
import React from 'react';
import { Route, Routes } from 'react-router';
-
+import { useEntity } from '@backstage/plugin-catalog-react';
import { rootCatalogKafkaRouteRef } from './plugin';
import { KAFKA_CONSUMER_GROUP_ANNOTATION } from './constants';
import { KafkaTopicsForConsumer } from './components/ConsumerGroupOffsets/ConsumerGroupOffsets';
@@ -26,10 +26,23 @@ import { MissingAnnotationEmptyState } from '@backstage/core';
export const isPluginApplicableToEntity = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[KAFKA_CONSUMER_GROUP_ANNOTATION]);
-export const Router = ({ entity }: { entity: Entity }) => {
- return !isPluginApplicableToEntity(entity) ? (
-
- ) : (
+type Props = {
+ /** @deprecated The entity is now grabbed from context instead */
+ entity?: Entity;
+};
+
+export const Router = (_props: Props) => {
+ const { entity } = useEntity();
+
+ if (!isPluginApplicableToEntity(entity)) {
+ return (
+
+ );
+ }
+
+ return (
{
it('should export plugin', () => {
- expect(plugin).toBeDefined();
+ expect(kafkaPlugin).toBeDefined();
});
});
diff --git a/plugins/kafka/src/plugin.ts b/plugins/kafka/src/plugin.ts
index 878a7f56e9..832099a30c 100644
--- a/plugins/kafka/src/plugin.ts
+++ b/plugins/kafka/src/plugin.ts
@@ -16,6 +16,7 @@
import {
createApiFactory,
createPlugin,
+ createRoutableExtension,
createRouteRef,
discoveryApiRef,
} from '@backstage/core';
@@ -27,7 +28,7 @@ export const rootCatalogKafkaRouteRef = createRouteRef({
title: 'Kafka',
});
-export const plugin = createPlugin({
+export const kafkaPlugin = createPlugin({
id: 'kafka',
apis: [
createApiFactory({
@@ -36,4 +37,14 @@ export const plugin = createPlugin({
factory: ({ discoveryApi }) => new KafkaBackendClient({ discoveryApi }),
}),
],
+ routes: {
+ entityContent: rootCatalogKafkaRouteRef,
+ },
});
+
+export const EntityKafkaContent = kafkaPlugin.provide(
+ createRoutableExtension({
+ component: () => import('./Router').then(m => m.Router),
+ mountPoint: rootCatalogKafkaRouteRef,
+ }),
+);