Ports the Fossa Plugin to the new plugin model

Towards #3424
This commit is contained in:
Oliver Sand
2021-02-01 12:19:04 +01:00
parent 7ee15d2c5b
commit 5ac9df8995
8 changed files with 119 additions and 75 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/plugin-fossa': minor
---
Port FOSSA plugin to new extension model.
If you are using the FOSSA plugin adjust the plugin import from `plugin` to
`fossaPlugin` and replace `<FossaCard entity={...} ...>` with `<EntityFossaCard />`.
+4 -4
View File
@@ -19,21 +19,21 @@ yarn add @backstage/plugin-fossa
```js
// packages/app/src/plugins.ts
export { plugin as Fossa } from '@backstage/plugin-fossa';
export { fossaPlugin } from '@backstage/plugin-fossa';
```
3. Add the `FossaCard` to the EntityPage:
3. Add the `EntityFossaCard` to the EntityPage:
```jsx
// packages/app/src/components/catalog/EntityPage.tsx
import { FossaCard } from '@backstage/plugin-fossa';
import { EntityFossaCard } from '@backstage/plugin-fossa';
const OverviewContent = ({ entity }: { entity: Entity }) => (
<Grid container spacing={3} alignItems="stretch">
// ...
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity} />
<EntityFossaCard />
</Grid>
// ...
</Grid>
+66 -66
View File
@@ -14,21 +14,28 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
import {
Content,
createPlugin,
createRouteRef,
Header,
Page,
} from '@backstage/core';
import React from 'react';
import { Grid } from '@material-ui/core';
import { FossaApi, fossaApiRef } from '../src/api';
import { FossaCard } from '../src';
import { Entity } from '@backstage/catalog-model';
import { Content, Header, Page } from '@backstage/core';
import { createDevApp } from '@backstage/dev-utils';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import { Grid } from '@material-ui/core';
import React from 'react';
import { EntityFossaCard } from '../src';
import { FossaApi, fossaApiRef } from '../src/api';
import { FOSSA_PROJECT_NAME_ANNOTATION } from '../src/components/useProjectName';
const entity = (name?: string) =>
({
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
annotations: {
[FOSSA_PROJECT_NAME_ANNOTATION]: name,
},
name: name,
},
} as Entity);
createDevApp()
.registerApi({
api: fossaApiRef,
@@ -76,58 +83,51 @@ createDevApp()
},
} as FossaApi),
})
.registerPlugin(
createPlugin({
id: 'fossa-demo',
register({ router }) {
const entity = (name?: string) =>
({
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
annotations: {
[FOSSA_PROJECT_NAME_ANNOTATION]: name,
},
name: name,
},
} as Entity);
const ExamplePage = () => (
<Page themeId="home">
<Header title="Fossa" />
<Content>
<Grid container>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('empty')} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('error')} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('never')} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('zero-deps')} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('issues')} />
</Grid>
<Grid item xs={12} sm={6} md={4}>
<FossaCard entity={entity('no-issues')} />
</Grid>
<Grid item xs={12}>
<FossaCard entity={entity(undefined)} />
</Grid>
</Grid>
</Content>
</Page>
);
router.addRoute(
createRouteRef({ path: '/', title: 'Fossa' }),
ExamplePage,
);
},
}),
)
.addPage({
title: 'Entity Content',
element: (
<Page themeId="home">
<Header title="Fossa" />
<Content>
<Grid container>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('empty')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('error')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('never')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('zero-deps')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('issues')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12} sm={6} md={4}>
<EntityProvider entity={entity('no-issues')}>
<EntityFossaCard />
</EntityProvider>
</Grid>
<Grid item xs={12}>
<EntityProvider entity={entity(undefined)}>
<EntityFossaCard />
</EntityProvider>
</Grid>
</Grid>
</Content>
</Page>
),
})
.render();
+1
View File
@@ -33,6 +33,7 @@
"dependencies": {
"@backstage/catalog-model": "^0.7.0",
"@backstage/core": "^0.5.0",
"@backstage/plugin-catalog-react": "^0.0.1",
"@backstage/theme": "^0.2.2",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createComponentExtension } from '@backstage/core';
import { useEntity } from '@backstage/plugin-catalog-react';
import React from 'react';
import { fossaPlugin } from './plugin';
export const EntityFossaCard = fossaPlugin.provide(
createComponentExtension({
component: {
lazy: () =>
import('./components/FossaCard').then(({ FossaCard }) => {
const EntityFossaCard = () => {
const { entity } = useEntity();
return <FossaCard entity={entity} />;
};
return EntityFossaCard;
}),
},
}),
);
+2 -2
View File
@@ -14,5 +14,5 @@
* limitations under the License.
*/
export { plugin } from './plugin';
export * from './components';
export { fossaPlugin } from './plugin';
export { EntityFossaCard } from './extensions';
+2 -2
View File
@@ -14,10 +14,10 @@
* limitations under the License.
*/
import { plugin } from './plugin';
import { fossaPlugin } from './plugin';
describe('fossa', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(fossaPlugin).toBeDefined();
});
});
+1 -1
View File
@@ -22,7 +22,7 @@ import {
} from '@backstage/core';
import { fossaApiRef, FossaClient } from './api';
export const plugin = createPlugin({
export const fossaPlugin = createPlugin({
id: 'fossa',
apis: [
createApiFactory({