From 9a23ea8bdab9ec70523eeec6d14b1f648f49fab3 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Fri, 24 Jul 2020 11:54:46 +0200 Subject: [PATCH] feat(catalog): add trivial tab implementation and add a tab to display all implemented apis --- plugins/catalog/package.json | 1 + .../EntityPageApi/EntityPageApi.tsx | 72 +++++++++++++++++++ .../EntityPageOverview/EntityPageOverview.tsx | 61 ++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 plugins/catalog/src/components/EntityPageApi/EntityPageApi.tsx create mode 100644 plugins/catalog/src/components/EntityPageOverview/EntityPageOverview.tsx diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index 4f0e5df322..d91b8c03cc 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -23,6 +23,7 @@ "dependencies": { "@backstage/catalog-model": "^0.1.1-alpha.18", "@backstage/core": "^0.1.1-alpha.18", + "@backstage/plugin-api-docs": "^0.1.1-alpha.18", "@backstage/plugin-github-actions": "^0.1.1-alpha.18", "@backstage/plugin-jenkins": "^0.1.1-alpha.18", "@backstage/plugin-scaffolder": "^0.1.1-alpha.18", diff --git a/plugins/catalog/src/components/EntityPageApi/EntityPageApi.tsx b/plugins/catalog/src/components/EntityPageApi/EntityPageApi.tsx new file mode 100644 index 0000000000..b115539366 --- /dev/null +++ b/plugins/catalog/src/components/EntityPageApi/EntityPageApi.tsx @@ -0,0 +1,72 @@ +/* + * 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 { ApiEntityV1alpha1, Entity } from '@backstage/catalog-model'; +import { Content, Progress, useApi } from '@backstage/core'; +import { ApiDefinitionCard } from '@backstage/plugin-api-docs'; +import { Grid } from '@material-ui/core'; +import { Alert } from '@material-ui/lab'; +import React, { FC } from 'react'; +import { useAsync } from 'react-use'; +import { catalogApiRef } from '../..'; + +export const EntityPageApi: FC<{ entity: Entity }> = ({ entity }) => { + const catalogApi = useApi(catalogApiRef); + + const { value: apiEntities, loading } = useAsync(async () => { + const a = await Promise.all( + ((entity?.spec?.implementedApis as string[]) || []).map(api => + catalogApi.getEntityByName({ + kind: 'API', + name: api, + }), + ), + ); + const b = new Map(); + + a.filter(api => !!api).forEach(api => { + b.set(api?.metadata?.name!, api as ApiEntityV1alpha1); + }); + return b; + }, [catalogApi, entity]); + + return ( + + {loading && } + {!loading && ( + + {((entity?.spec?.implementedApis as string[]) || []).map(api => { + const apiEntity = apiEntities && apiEntities.get(api); + + return ( + + {!apiEntity && ( + + Error on fetching the API: {api} + + )} + + {apiEntity && ( + + )} + + ); + })} + + )} + + ); +}; diff --git a/plugins/catalog/src/components/EntityPageOverview/EntityPageOverview.tsx b/plugins/catalog/src/components/EntityPageOverview/EntityPageOverview.tsx new file mode 100644 index 0000000000..f4faa8c574 --- /dev/null +++ b/plugins/catalog/src/components/EntityPageOverview/EntityPageOverview.tsx @@ -0,0 +1,61 @@ +/* + * 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 { Entity } from '@backstage/catalog-model'; +import { Content } from '@backstage/core'; +import { SentryIssuesWidget } from '@backstage/plugin-sentry'; +import { Widget as GithubActionsWidget } from '@backstage/plugin-github-actions'; +import { JenkinsBuildsWidget, JenkinsLastBuildWidget, } from '@backstage/plugin-jenkins'; +import { Grid } from '@material-ui/core'; +import React, { FC } from 'react'; +import { EntityMetadataCard } from '../EntityMetadataCard/EntityMetadataCard'; + +export const EntityPageOverview: FC<{ entity: Entity }> = ({ entity }) => { + return ( + + + + + + {entity.metadata?.annotations?.[ + 'backstage.io/jenkins-github-folder' + ] && ( + + + + )} + {entity.metadata?.annotations?.[ + 'backstage.io/jenkins-github-folder' + ] && ( + + + + )} + {entity.metadata?.annotations?.['backstage.io/github-actions-id'] && ( + + + + )} + + + + + + ); +};