From 523af24224d12893c4c8f374cd92669b69affa3f Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 4 Jun 2023 15:30:32 -0400 Subject: [PATCH] Fix registration of component Signed-off-by: josh --- .../app/src/components/catalog/EntityPage.tsx | 15 ++++--- plugins/nomad-backend/src/run.ts | 4 +- .../EntityNomadJobVersionListCard.tsx | 6 ++- plugins/nomad/src/components/index.ts | 3 +- plugins/nomad/src/index.ts | 7 +++- plugins/nomad/src/plugin.ts | 42 ++++++++++++++++++- 6 files changed, 65 insertions(+), 12 deletions(-) diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx index 043a9fc3aa..be5ae3e3bf 100644 --- a/packages/app/src/components/catalog/EntityPage.tsx +++ b/packages/app/src/components/catalog/EntityPage.tsx @@ -113,8 +113,10 @@ import { EntityUserProfileCard, } from '@backstage/plugin-org'; import { - EntityNomadContent, + EntityNomadAllocationListTable, EntityNomadJobVersionListCard, + isNomadAllocationsAvailable, + isNomadJobIDAvailable, } from '@backstage/plugin-nomad'; import { EntityPagerDutyCard, @@ -176,7 +178,6 @@ import { isLinguistAvailable, EntityLinguistCard, } from '@backstage/plugin-linguist'; -import { isNomadJobIDAvailable } from '@backstage/plugin-nomad'; const customEntityFilterKind = ['Component', 'API', 'System']; @@ -450,7 +451,7 @@ const overviewContent = ( - + @@ -514,8 +515,12 @@ const serviceEntityPage = ( - - + + diff --git a/plugins/nomad-backend/src/run.ts b/plugins/nomad-backend/src/run.ts index d299ed23e9..711bdcc46c 100644 --- a/plugins/nomad-backend/src/run.ts +++ b/plugins/nomad-backend/src/run.ts @@ -16,12 +16,14 @@ import { getRootLogger } from '@backstage/backend-common'; import yn from 'yn'; import { startStandaloneServer } from './service/standaloneServer'; +import { ConfigReader } from '@backstage/config'; +const config = new ConfigReader({}); const port = process.env.PLUGIN_PORT ? Number(process.env.PLUGIN_PORT) : 7007; const enableCors = yn(process.env.PLUGIN_CORS, { default: false }); const logger = getRootLogger(); -startStandaloneServer({ port, enableCors, logger }).catch(err => { +startStandaloneServer({ config, port, enableCors, logger }).catch(err => { logger.error(err); process.exit(1); }); diff --git a/plugins/nomad/src/components/EntityNomadJobVersionListCard/EntityNomadJobVersionListCard.tsx b/plugins/nomad/src/components/EntityNomadJobVersionListCard/EntityNomadJobVersionListCard.tsx index 909fd7a236..c4dad1f455 100644 --- a/plugins/nomad/src/components/EntityNomadJobVersionListCard/EntityNomadJobVersionListCard.tsx +++ b/plugins/nomad/src/components/EntityNomadJobVersionListCard/EntityNomadJobVersionListCard.tsx @@ -110,6 +110,8 @@ export const EntityNomadJobVersionListCard = () => { return ; } + if (!entity) return <>; + // Check that job ID is set if (!isNomadJobIDAvailable(entity)) { return ( @@ -121,11 +123,11 @@ export const EntityNomadJobVersionListCard = () => { return ( - title="Job Versions" + title="Job versions" actions={[ { icon: () => , - tooltip: 'Open Job Versions Tab in Nomad', + tooltip: 'Open in Nomad UI', isFreeAction: true, onClick: () => window.open(`${nomadAddr}/ui/jobs/${jobID}/versions`), }, diff --git a/plugins/nomad/src/components/index.ts b/plugins/nomad/src/components/index.ts index d113bf73d9..3951061b23 100644 --- a/plugins/nomad/src/components/index.ts +++ b/plugins/nomad/src/components/index.ts @@ -14,5 +14,6 @@ * limitations under the License. */ import { EntityNomadJobVersionListCard } from './EntityNomadJobVersionListCard/EntityNomadJobVersionListCard'; +import { EntityNomadAllocationListTable } from './EntityNomadAllocationListTable/EntityNomadAllocationListTable'; -export { EntityNomadJobVersionListCard }; +export { EntityNomadJobVersionListCard, EntityNomadAllocationListTable }; diff --git a/plugins/nomad/src/index.ts b/plugins/nomad/src/index.ts index 601c133b52..2b95af217a 100644 --- a/plugins/nomad/src/index.ts +++ b/plugins/nomad/src/index.ts @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { nomadPlugin } from './plugin'; +export { + nomadPlugin, + EntityNomadJobVersionListCard, + EntityNomadAllocationListTable, +} from './plugin'; export { isNomadAllocationsAvailable, isNomadJobIDAvailable, EmbeddedRouter, } from './Router'; -export { EntityNomadJobVersionListCard } from './components'; diff --git a/plugins/nomad/src/plugin.ts b/plugins/nomad/src/plugin.ts index 65181724d5..d8367d97df 100644 --- a/plugins/nomad/src/plugin.ts +++ b/plugins/nomad/src/plugin.ts @@ -18,8 +18,9 @@ import { fetchApiRef, createApiFactory, createPlugin, - createRoutableExtension, createRouteRef, + createRoutableExtension, + createComponentExtension, } from '@backstage/core-plugin-api'; import { rootRouteRef } from './routes'; @@ -44,3 +45,42 @@ export const nomadPlugin = createPlugin({ entityContent: entityContentRouteRef, }, }); + +/** @public */ +export const EntityNomadContent = nomadPlugin.provide( + createRoutableExtension({ + name: 'EntityNomadContent', + component: () => import('./Router').then(m => m.EmbeddedRouter), + mountPoint: entityContentRouteRef, + }), +); + +/** + * Card used to show the list of Nomad job versions. + * + * @public + */ +export const EntityNomadJobVersionListCard = nomadPlugin.provide( + createComponentExtension({ + name: 'EntityNomadJobVersionListCard', + component: { + lazy: () => + import('./components').then(m => m.EntityNomadJobVersionListCard), + }, + }), +); + +/** + * Table used to show the list of Nomad allocations for a job and/or task-group. + * + * @public + */ +export const EntityNomadAllocationListTable = nomadPlugin.provide( + createComponentExtension({ + name: 'EntityNomadAllocationListTable', + component: { + lazy: () => + import('./components').then(m => m.EntityNomadAllocationListTable), + }, + }), +);