Merge pull request #4361 from backstage/rugvip/ports

plugins: migrate lighthouse, catalog-import, and org to new composability API
This commit is contained in:
Patrik Oldsberg
2021-02-02 21:55:31 +01:00
committed by GitHub
19 changed files with 142 additions and 51 deletions
+2 -2
View File
@@ -15,6 +15,6 @@
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src/plugin';
import { catalogImportPlugin } from '../src/plugin';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(catalogImportPlugin).render();
+5 -1
View File
@@ -14,6 +14,10 @@
* limitations under the License.
*/
export { plugin } from './plugin';
export {
catalogImportPlugin,
catalogImportPlugin as plugin,
CatalogImportPage,
} from './plugin';
export { Router } from './components/Router';
export * from './api';
+2 -2
View File
@@ -14,10 +14,10 @@
* limitations under the License.
*/
import { plugin } from './plugin';
import { catalogImportPlugin } from './plugin';
describe('catalog-import', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(catalogImportPlugin).toBeDefined();
});
});
+12 -1
View File
@@ -21,6 +21,7 @@ import {
discoveryApiRef,
githubAuthApiRef,
configApiRef,
createRoutableExtension,
} from '@backstage/core';
import { catalogImportApiRef } from './api/CatalogImportApi';
import { CatalogImportClient } from './api/CatalogImportClient';
@@ -30,7 +31,7 @@ export const rootRouteRef = createRouteRef({
title: 'catalog-import',
});
export const plugin = createPlugin({
export const catalogImportPlugin = createPlugin({
id: 'catalog-import',
apis: [
createApiFactory({
@@ -44,4 +45,14 @@ export const plugin = createPlugin({
new CatalogImportClient({ discoveryApi, githubAuthApi, configApi }),
}),
],
routes: {
importPage: rootRouteRef,
},
});
export const CatalogImportPage = catalogImportPlugin.provide(
createRoutableExtension({
component: () => import('./components/Router').then(m => m.Router),
mountPoint: rootRouteRef,
}),
);
+2 -2
View File
@@ -15,11 +15,11 @@
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src/plugin';
import { lighthousePlugin } from '../src/plugin';
import { lighthouseApiRef, LighthouseRestApi } from '../src';
createDevApp()
.registerPlugin(plugin)
.registerPlugin(lighthousePlugin)
.registerApi({
api: lighthouseApiRef,
deps: {},
+8 -15
View File
@@ -16,7 +16,6 @@
import React from 'react';
import { Route, Routes } from 'react-router-dom';
import { createAuditRouteRef, rootRouteRef, viewAuditRouteRef } from './plugin';
import AuditList from './components/AuditList';
import AuditView, { AuditViewContent } from './components/AuditView';
import CreateAudit, { CreateAuditContent } from './components/CreateAudit';
@@ -25,32 +24,26 @@ import { LIGHTHOUSE_WEBSITE_URL_ANNOTATION } from '../constants';
import { AuditListForEntity } from './components/AuditList/AuditListForEntity';
import { MissingAnnotationEmptyState } from '@backstage/core';
export const isPluginApplicableToEntity = (entity: Entity) =>
export const isLighthouseAvailable = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[LIGHTHOUSE_WEBSITE_URL_ANNOTATION]);
export const Router = () => (
<Routes>
<Route path={`/${rootRouteRef.path}`} element={<AuditList />} />
<Route path={`/${viewAuditRouteRef.path}`} element={<AuditView />} />
<Route path={`/${createAuditRouteRef.path}`} element={<CreateAudit />} />
<Route path="/" element={<AuditList />} />
<Route path="/audit/:id" element={<AuditView />} />
<Route path="/create-audit" element={<CreateAudit />} />
</Routes>
);
export const EmbeddedRouter = ({ entity }: { entity: Entity }) =>
!isPluginApplicableToEntity(entity) ? (
!isLighthouseAvailable(entity) ? (
<MissingAnnotationEmptyState
annotation={LIGHTHOUSE_WEBSITE_URL_ANNOTATION}
/>
) : (
<Routes>
<Route path={`/${rootRouteRef.path}`} element={<AuditListForEntity />} />
<Route
path={`/${viewAuditRouteRef.path}`}
element={<AuditViewContent />}
/>
<Route
path={`/${createAuditRouteRef.path}`}
element={<CreateAuditContent />}
/>
<Route path="/" element={<AuditListForEntity />} />
<Route path="/audit/:id" element={<AuditViewContent />} />
<Route path="/create-audit" element={<CreateAuditContent />} />
</Routes>
);
@@ -25,7 +25,6 @@ import {
} from '../../utils';
import { Link, generatePath } from 'react-router-dom';
import AuditStatusIcon from '../AuditStatusIcon';
import { viewAuditRouteRef } from '../../plugin';
const columns: TableColumn[] = [
{
@@ -99,11 +98,7 @@ export const AuditListTable = ({ items }: { items: Website[] }) => {
return {
websiteUrl: (
<Link
to={generatePath(viewAuditRouteRef.path, {
id: website.lastAudit.id,
})}
>
<Link to={generatePath('audit/:id', { id: website.lastAudit.id })}>
{website.url}
</Link>
),
@@ -35,7 +35,6 @@ import { useQuery } from '../../utils';
import LighthouseSupportButton from '../SupportButton';
import LighthouseIntro, { LIGHTHOUSE_INTRO_LOCAL_STORAGE } from '../Intro';
import AuditListTable from './AuditListTable';
import { createAuditRouteRef } from '../../plugin';
export const LIMIT = 10;
@@ -110,7 +109,7 @@ const AuditList = () => {
<Button
variant="contained"
color="primary"
onClick={() => navigate(createAuditRouteRef.path)}
onClick={() => navigate('create-audit')}
>
Create Audit
</Button>
@@ -47,7 +47,6 @@ import { lighthouseApiRef, Website, Audit } from '../../api';
import AuditStatusIcon from '../AuditStatusIcon';
import LighthouseSupportButton from '../SupportButton';
import { formatTime } from '../../utils';
import { viewAuditRouteRef, createAuditRouteRef } from '../../plugin';
const useStyles = makeStyles({
contentGrid: {
@@ -78,12 +77,7 @@ const AuditLinkList = ({ audits = [], selectedId }: AuditLinkListProps) => (
button
component={Link}
replace
to={resolvePath(
generatePath(viewAuditRouteRef.path, {
id: audit.id,
}),
'../../',
)}
to={resolvePath(generatePath('audit/:id', { id: audit.id }), '../../')}
>
<ListItemIcon>
<AuditStatusIcon audit={audit} />
@@ -163,7 +157,7 @@ export const AuditViewContent = () => {
);
}
let createAuditButtonUrl = createAuditRouteRef.path;
let createAuditButtonUrl = 'create-audit';
if (value?.url) {
createAuditButtonUrl += `?url=${encodeURIComponent(value.url)}`;
}
+13 -2
View File
@@ -14,7 +14,18 @@
* limitations under the License.
*/
export { plugin } from './plugin';
export { Router, isPluginApplicableToEntity, EmbeddedRouter } from './Router';
export {
lighthousePlugin,
lighthousePlugin as plugin,
LighthousePage,
EntityLighthouseContent,
EntityLastLighthouseAuditCard,
} from './plugin';
export {
Router,
isLighthouseAvailable as isPluginApplicableToEntity,
isLighthouseAvailable,
EmbeddedRouter,
} from './Router';
export * from './api';
export * from './components/Cards';
+2 -2
View File
@@ -14,10 +14,10 @@
* limitations under the License.
*/
import { plugin } from './plugin';
import { lighthousePlugin } from './plugin';
describe('lighthouse', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(lighthousePlugin).toBeDefined();
});
});
+34 -1
View File
@@ -19,6 +19,8 @@ import {
createRouteRef,
createApiFactory,
configApiRef,
createRoutableExtension,
createComponentExtension,
} from '@backstage/core';
import { lighthouseApiRef, LighthouseRestApi } from './api';
@@ -37,7 +39,11 @@ export const createAuditRouteRef = createRouteRef({
title: 'Create Lighthouse Audit',
});
export const plugin = createPlugin({
export const entityContentRouteRef = createRouteRef({
title: 'Lighthouse Entity Content',
});
export const lighthousePlugin = createPlugin({
id: 'lighthouse',
apis: [
createApiFactory({
@@ -46,4 +52,31 @@ export const plugin = createPlugin({
factory: ({ configApi }) => LighthouseRestApi.fromConfig(configApi),
}),
],
routes: {
root: createAuditRouteRef,
entityContent: entityContentRouteRef,
},
});
export const LighthousePage = lighthousePlugin.provide(
createRoutableExtension({
component: () => import('./Router').then(m => m.Router),
mountPoint: rootRouteRef,
}),
);
export const EntityLighthouseContent = lighthousePlugin.provide(
createRoutableExtension({
component: () => import('./Router').then(m => m.EmbeddedRouter),
mountPoint: entityContentRouteRef,
}),
);
export const EntityLastLighthouseAuditCard = lighthousePlugin.provide(
createComponentExtension({
component: {
lazy: () =>
import('./components/Cards').then(m => m.LastLighthouseAuditCard),
},
}),
);
+2 -2
View File
@@ -14,6 +14,6 @@
* limitations under the License.
*/
import { createDevApp } from '@backstage/dev-utils';
import { plugin } from '../src/plugin';
import { orgPlugin } from '../src/plugin';
createDevApp().registerPlugin(plugin).render();
createDevApp().registerPlugin(orgPlugin).render();
+8 -1
View File
@@ -13,5 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { plugin } from './plugin';
export {
orgPlugin,
orgPlugin as plugin,
EntityGroupProfileCard,
EntityMembersListCard,
EntityOwnershipCard,
EntityUserProfileCard,
} from './plugin';
export * from './components';
+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 { orgPlugin } from './plugin';
describe('groups', () => {
it('should export plugin', () => {
expect(plugin).toBeDefined();
expect(orgPlugin).toBeDefined();
});
});
+31 -2
View File
@@ -13,8 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createPlugin } from '@backstage/core';
import { createComponentExtension, createPlugin } from '@backstage/core';
export const plugin = createPlugin({
export const orgPlugin = createPlugin({
id: 'org',
});
export const EntityGroupProfileCard = orgPlugin.provide(
createComponentExtension({
component: {
lazy: () => import('./components').then(m => m.GroupProfileCard),
},
}),
);
export const EntityMembersListCard = orgPlugin.provide(
createComponentExtension({
component: {
lazy: () => import('./components').then(m => m.MembersListCard),
},
}),
);
export const EntityOwnershipCard = orgPlugin.provide(
createComponentExtension({
component: {
lazy: () => import('./components').then(m => m.OwnershipCard),
},
}),
);
export const EntityUserProfileCard = orgPlugin.provide(
createComponentExtension({
component: {
lazy: () => import('./components').then(m => m.UserProfileCard),
},
}),
);