Merge pull request #4368 from backstage/rugvip/moreports

plugins: migrate kafka, kubernetes, newrelic to new composability API
This commit is contained in:
Patrik Oldsberg
2021-02-04 21:02:48 +01:00
committed by GitHub
18 changed files with 112 additions and 26 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-newrelic': patch
---
Migrate to new composability API, exporting the plugin instance as `newRelicPlugin`, and the root page as `NewRelicPage`.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes': patch
---
Migrate to new composability API, exporting the plugin instance as `kubernetesPlugin` and entity content as `EntityKubernetesContent`.
+5
View File
@@ -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`.
+2 -2
View File
@@ -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();
+18 -5
View File
@@ -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) ? (
<MissingAnnotationEmptyState annotation={KAFKA_CONSUMER_GROUP_ANNOTATION} />
) : (
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 (
<MissingAnnotationEmptyState
annotation={KAFKA_CONSUMER_GROUP_ANNOTATION}
/>
);
}
return (
<Routes>
<Route
path={`${rootCatalogKafkaRouteRef.path}`}
+10 -2
View File
@@ -13,6 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { plugin } from './plugin';
export {
kafkaPlugin,
kafkaPlugin as plugin,
EntityKafkaContent,
} from './plugin';
export { KAFKA_CONSUMER_GROUP_ANNOTATION } from './constants';
export { Router, isPluginApplicableToEntity } from './Router';
export {
Router,
isPluginApplicableToEntity,
isPluginApplicableToEntity as isKafkaAvailable,
} from './Router';
+2 -2
View File
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { plugin } from './plugin';
import { kafkaPlugin } from './plugin';
describe('kafka', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(kafkaPlugin).toBeDefined();
});
});
+12 -1
View File
@@ -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,
}),
);
+2 -2
View File
@@ -14,6 +14,6 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src';
import { kubernetesPlugin } from '../src';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(kubernetesPlugin).render();
+1
View File
@@ -32,6 +32,7 @@
},
"dependencies": {
"@backstage/catalog-model": "^0.7.1",
"@backstage/plugin-catalog-react": "^0.0.2",
"@backstage/config": "^0.1.2",
"@backstage/core": "^0.6.0",
"@backstage/plugin-kubernetes-backend": "^0.2.6",
+9 -2
View File
@@ -16,15 +16,22 @@
import React from 'react';
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { Route, Routes } from 'react-router-dom';
import { rootCatalogKubernetesRouteRef } from './plugin';
import { KubernetesContent } from './components/KubernetesContent';
import { MissingAnnotationEmptyState } from '@backstage/core';
const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id';
export const Router = ({ entity }: { entity: Entity }) => {
type Props = {
/** @deprecated The entity is now grabbed from context instead */
entity?: Entity;
};
export const Router = (_props: Props) => {
const { entity } = useEntity();
const kubernetesAnnotationValue =
entity.metadata.annotations?.[KUBERNETES_ANNOTATION];
+5 -1
View File
@@ -13,5 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { plugin } from './plugin';
export {
kubernetesPlugin,
kubernetesPlugin as plugin,
EntityKubernetesContent,
} from './plugin';
export { Router } from './Router';
+2 -2
View File
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { plugin } from './plugin';
import { kubernetesPlugin } from './plugin';
describe('kubernetes', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(kubernetesPlugin).toBeDefined();
});
});
+12 -1
View File
@@ -19,6 +19,7 @@ import {
createRouteRef,
discoveryApiRef,
googleAuthApiRef,
createRoutableExtension,
} from '@backstage/core';
import { KubernetesBackendClient } from './api/KubernetesBackendClient';
import { kubernetesApiRef } from './api/types';
@@ -30,7 +31,7 @@ export const rootCatalogKubernetesRouteRef = createRouteRef({
title: 'Kubernetes',
});
export const plugin = createPlugin({
export const kubernetesPlugin = createPlugin({
id: 'kubernetes',
apis: [
createApiFactory({
@@ -47,4 +48,14 @@ export const plugin = createPlugin({
},
}),
],
routes: {
entityContent: rootCatalogKubernetesRouteRef,
},
});
export const EntityKubernetesContent = kubernetesPlugin.provide(
createRoutableExtension({
component: () => import('./Router').then(m => m.Router),
mountPoint: rootCatalogKubernetesRouteRef,
}),
);
+2 -2
View File
@@ -15,6 +15,6 @@
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src/plugin';
import { newRelicPlugin } from '../src/plugin';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(newRelicPlugin).render();
+5 -1
View File
@@ -14,4 +14,8 @@
* limitations under the License.
*/
export { plugin } from './plugin';
export {
newRelicPlugin,
newRelicPlugin as plugin,
NewRelicPage,
} from './plugin';
+2 -2
View File
@@ -14,10 +14,10 @@
* limitations under the License.
*/
import { plugin } from './plugin';
import { newRelicPlugin } from './plugin';
describe('newrelic', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(newRelicPlugin).toBeDefined();
});
});
+13 -1
View File
@@ -19,6 +19,7 @@ import {
createPlugin,
createRouteRef,
discoveryApiRef,
createRoutableExtension,
} from '@backstage/core';
import { NewRelicClient, newRelicApiRef } from './api';
import NewRelicComponent from './components/NewRelicComponent';
@@ -28,7 +29,7 @@ export const rootRouteRef = createRouteRef({
title: 'newrelic',
});
export const plugin = createPlugin({
export const newRelicPlugin = createPlugin({
id: 'newrelic',
apis: [
createApiFactory({
@@ -40,4 +41,15 @@ export const plugin = createPlugin({
register({ router }) {
router.addRoute(rootRouteRef, NewRelicComponent);
},
routes: {
root: rootRouteRef,
},
});
export const NewRelicPage = newRelicPlugin.provide(
createRoutableExtension({
component: () =>
import('./components/NewRelicComponent').then(m => m.default),
mountPoint: rootRouteRef,
}),
);