diff --git a/plugins/nomad/package.json b/plugins/nomad/package.json index 17231e7b24..e195a2fbe0 100644 --- a/plugins/nomad/package.json +++ b/plugins/nomad/package.json @@ -22,6 +22,7 @@ "postpack": "backstage-cli package postpack" }, "dependencies": { + "@backstage/catalog-model": "workspace:^", "@backstage/core-components": "workspace:^", "@backstage/core-plugin-api": "workspace:^", "@backstage/theme": "workspace:^", diff --git a/plugins/nomad/src/components/ExampleComponent/ExampleComponent.test.tsx b/plugins/nomad/src/components/NomadComponent/NomadComponent.test.tsx similarity index 89% rename from plugins/nomad/src/components/ExampleComponent/ExampleComponent.test.tsx rename to plugins/nomad/src/components/NomadComponent/NomadComponent.test.tsx index b0fb163116..31b7319fd6 100644 --- a/plugins/nomad/src/components/ExampleComponent/ExampleComponent.test.tsx +++ b/plugins/nomad/src/components/NomadComponent/NomadComponent.test.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ import React from 'react'; -import { ExampleComponent } from './ExampleComponent'; +import { NomadComponent } from './NomadComponent'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; import { screen } from '@testing-library/react'; @@ -23,7 +23,7 @@ import { renderInTestApp, } from '@backstage/test-utils'; -describe('ExampleComponent', () => { +describe('NomadComponent', () => { const server = setupServer(); // Enable sane handlers for network requests setupRequestMockHandlers(server); @@ -36,7 +36,7 @@ describe('ExampleComponent', () => { }); it('should render', async () => { - await renderInTestApp(); + await renderInTestApp(); expect(screen.getByText('Welcome to nomad!')).toBeInTheDocument(); }); }); diff --git a/plugins/nomad/src/components/ExampleComponent/ExampleComponent.tsx b/plugins/nomad/src/components/NomadComponent/NomadComponent.tsx similarity index 91% rename from plugins/nomad/src/components/ExampleComponent/ExampleComponent.tsx rename to plugins/nomad/src/components/NomadComponent/NomadComponent.tsx index 0a0d8809fc..cd7334d7eb 100644 --- a/plugins/nomad/src/components/ExampleComponent/ExampleComponent.tsx +++ b/plugins/nomad/src/components/NomadComponent/NomadComponent.tsx @@ -24,9 +24,9 @@ import { HeaderLabel, SupportButton, } from '@backstage/core-components'; -import { ExampleFetchComponent } from '../ExampleFetchComponent'; +import { NomadFetchComponent } from '../NomadFetchComponent'; -export const ExampleComponent = () => ( +export const NomadComponent = () => (
@@ -45,7 +45,7 @@ export const ExampleComponent = () => ( - + diff --git a/plugins/nomad/src/components/ExampleComponent/index.ts b/plugins/nomad/src/components/NomadComponent/index.ts similarity index 91% rename from plugins/nomad/src/components/ExampleComponent/index.ts rename to plugins/nomad/src/components/NomadComponent/index.ts index 7e520a7ab8..aeecd0d9e6 100644 --- a/plugins/nomad/src/components/ExampleComponent/index.ts +++ b/plugins/nomad/src/components/NomadComponent/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { ExampleComponent } from './ExampleComponent'; +export { NomadComponent } from './NomadComponent'; diff --git a/plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx b/plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.test.tsx similarity index 89% rename from plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx rename to plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.test.tsx index a714f640da..48c27dce05 100644 --- a/plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx +++ b/plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.test.tsx @@ -15,12 +15,12 @@ */ import React from 'react'; import { render, screen } from '@testing-library/react'; -import { ExampleFetchComponent } from './ExampleFetchComponent'; +import { NomadFetchComponent } from './NomadFetchComponent'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; import { setupRequestMockHandlers } from '@backstage/test-utils'; -describe('ExampleFetchComponent', () => { +describe('NomadFetchComponent', () => { const server = setupServer(); // Enable sane handlers for network requests setupRequestMockHandlers(server); @@ -34,7 +34,7 @@ describe('ExampleFetchComponent', () => { ); }); it('should render', async () => { - await render(); + await render(); expect(await screen.findByTestId('progress')).toBeInTheDocument(); }); }); diff --git a/plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx b/plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.tsx similarity index 98% rename from plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx rename to plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.tsx index c3403e1923..0cd3061a3e 100644 --- a/plugins/nomad/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx +++ b/plugins/nomad/src/components/NomadFetchComponent/NomadFetchComponent.tsx @@ -93,7 +93,7 @@ export const DenseTable = ({ users }: DenseTableProps) => { ); }; -export const ExampleFetchComponent = () => { +export const NomadFetchComponent = () => { const { fetch } = useApi(fetchApiRef); const { value, loading, error } = useAsync(async (): Promise => { const response = await fetch('https://randomuser.me/api/?results=20'); diff --git a/plugins/nomad/src/components/ExampleFetchComponent/index.ts b/plugins/nomad/src/components/NomadFetchComponent/index.ts similarity index 90% rename from plugins/nomad/src/components/ExampleFetchComponent/index.ts rename to plugins/nomad/src/components/NomadFetchComponent/index.ts index 9644c904ea..8e30a21fd1 100644 --- a/plugins/nomad/src/components/ExampleFetchComponent/index.ts +++ b/plugins/nomad/src/components/NomadFetchComponent/index.ts @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { ExampleFetchComponent } from './ExampleFetchComponent'; +export { NomadFetchComponent } from './NomadFetchComponent'; diff --git a/plugins/nomad/src/components/Router.tsx b/plugins/nomad/src/components/Router.tsx new file mode 100644 index 0000000000..c6b4ac47e8 --- /dev/null +++ b/plugins/nomad/src/components/Router.tsx @@ -0,0 +1,32 @@ +/* + * Copyright 2020 The Backstage Authors + * + * 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 { Entity } from '@backstage/catalog-model'; + +/** @public */ +export const NOMAD_JOB_ANNOTATION = 'nomad.io/job'; + +/** @public */ +export const NOMAD_GROUP_ANNOTATION = 'nomad.io/group'; + +/** @public */ +export const NOMAD_TASK_ANNOTATION = 'nomad.io/task'; + +/** @public */ +export const isNomadAvailable = (entity: Entity) => + Boolean(entity.metadata.annotations?.[NOMAD_JOB_ANNOTATION]) || + Boolean(entity.metadata.annotations?.[NOMAD_GROUP_ANNOTATION]) || + Boolean(entity.metadata.annotations?.[NOMAD_TASK_ANNOTATION]); diff --git a/plugins/nomad/src/plugin.ts b/plugins/nomad/src/plugin.ts index e200d2c5ac..c5c8f81aad 100644 --- a/plugins/nomad/src/plugin.ts +++ b/plugins/nomad/src/plugin.ts @@ -31,7 +31,7 @@ export const NomadPage = nomadPlugin.provide( createRoutableExtension({ name: 'NomadPage', component: () => - import('./components/ExampleComponent').then(m => m.ExampleComponent), + import('./components/NomadComponent').then(m => m.NomadComponent), mountPoint: rootRouteRef, }), ); diff --git a/yarn.lock b/yarn.lock index 29957c4f56..9417d52474 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7930,6 +7930,7 @@ __metadata: version: 0.0.0-use.local resolution: "@backstage/plugin-nomad@workspace:plugins/nomad" dependencies: + "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/core-app-api": "workspace:^" "@backstage/core-components": "workspace:^"