diff --git a/plugins/newrelic-dashboard/src/components/NewRelicDashboard/DashboardEntityList.tsx b/plugins/newrelic-dashboard/src/components/NewRelicDashboard/DashboardEntityList.tsx index 823055c284..005bc42151 100644 --- a/plugins/newrelic-dashboard/src/components/NewRelicDashboard/DashboardEntityList.tsx +++ b/plugins/newrelic-dashboard/src/components/NewRelicDashboard/DashboardEntityList.tsx @@ -25,9 +25,10 @@ import { ErrorPanel, } from '@backstage/core-components'; import DesktopMac from '@material-ui/icons/DesktopMac'; -import { useNewRelicDashboardEntity } from '../../hooks'; import { DashboardEntitySummary } from '../../api/NewRelicDashboardApi'; import { ResultEntity } from '../../types/DashboardEntity'; +import { useEntity } from '@backstage/plugin-catalog-react'; +import { NEWRELIC_GUID_ANNOTATION } from './../../constants'; const useStyles = makeStyles({ svgIcon: { @@ -40,7 +41,7 @@ const useStyles = makeStyles({ }, }); export const DashboardEntityList = () => { - const DashboardEntity = useNewRelicDashboardEntity(); + const { entity } = useEntity(); const classes = useStyles(); const newRelicDashboardAPI = useApi(newRelicDashboardApiRef); const { value, loading, error } = useAsync(async (): Promise< @@ -48,10 +49,10 @@ export const DashboardEntityList = () => { > => { const dashboardObject: Promise = newRelicDashboardAPI.getDashboardEntity( - String(DashboardEntity?.integrationKey), + String(entity.metadata.annotations?.[NEWRELIC_GUID_ANNOTATION]), ); return dashboardObject; - }, [DashboardEntity?.integrationKey]); + }, [entity.metadata.annotations?.[NEWRELIC_GUID_ANNOTATION]]); if (loading) { return ; } @@ -68,7 +69,7 @@ export const DashboardEntityList = () => { <>No Dashboard Pages found with the specified Dashboard GUID )} {value?.getDashboardEntity?.data.actor.entitySearch.results.entities?.map( - (entity: ResultEntity) => { + (entityResult: ResultEntity) => { return ( @@ -77,7 +78,7 @@ export const DashboardEntityList = () => { - {entity.name} + {entityResult.name} ); diff --git a/plugins/newrelic-dashboard/src/components/NewRelicDashboard/NewRelicDashboard.tsx b/plugins/newrelic-dashboard/src/components/NewRelicDashboard/NewRelicDashboard.tsx index 11feff1cab..c9cc9bf611 100644 --- a/plugins/newrelic-dashboard/src/components/NewRelicDashboard/NewRelicDashboard.tsx +++ b/plugins/newrelic-dashboard/src/components/NewRelicDashboard/NewRelicDashboard.tsx @@ -16,12 +16,13 @@ import React from 'react'; import { Grid } from '@material-ui/core'; import { Page, Content } from '@backstage/core-components'; -import { useNewRelicDashboardEntity } from '../../hooks'; import { DashboardEntityList } from './DashboardEntityList'; import { DashboardSnapshotList } from './DashboardSnapshotList'; +import { useEntity } from '@backstage/plugin-catalog-react'; +import { NEWRELIC_GUID_ANNOTATION } from '../../constants'; export const NewRelicDashboard = () => { - const entity = useNewRelicDashboardEntity(); + const { entity } = useEntity(); return ( @@ -30,7 +31,11 @@ export const NewRelicDashboard = () => { - + diff --git a/plugins/newrelic-dashboard/src/hooks/index.ts b/plugins/newrelic-dashboard/src/hooks/index.ts deleted file mode 100644 index a170bd10f8..0000000000 --- a/plugins/newrelic-dashboard/src/hooks/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 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 { useEntity } from '@backstage/plugin-catalog-react'; - -import { NEWRELIC_GUID_ANNOTATION } from '../constants'; - -export function useNewRelicDashboardEntity() { - const { entity } = useEntity(); - const integrationKey: string | undefined = - entity?.metadata?.annotations?.[NEWRELIC_GUID_ANNOTATION]; - const name: string | undefined = entity?.metadata?.name; - - return { integrationKey, name }; -}