From 48b2289c3ed78ce00d34f988f454976ecbe727b8 Mon Sep 17 00:00:00 2001 From: mufaddalWh Date: Fri, 19 Nov 2021 11:48:56 +0530 Subject: [PATCH] Added duration variable in API query Signed-off-by: mufaddal motiwala --- packages/app/package.json | 1 + .../app/src/components/catalog/EntityPage.tsx | 30 +++++++- plugins/new-relic-dashboard/src/Router.tsx | 7 +- .../src/api/NewRelicDashboardApi.ts | 2 +- .../src/api/NewRelicDashboardClient.ts | 2 +- .../DashboardSnapshot/DashboardSnapshot.tsx | 43 ++++++----- .../DashboardSnapshotList.tsx | 73 ++++++++++--------- .../src/queries/getDashboardSnapshotQuery.ts | 2 +- 8 files changed, 95 insertions(+), 65 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 833e146d45..9b443ff67e 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -30,6 +30,7 @@ "@backstage/plugin-kafka": "^0.2.19", "@backstage/plugin-kubernetes": "^0.4.17", "@backstage/plugin-lighthouse": "^0.2.29", + "@backstage/plugin-new-relic-dashboard": "^0.1.0", "@backstage/plugin-newrelic": "^0.3.8", "@backstage/plugin-org": "^0.3.27", "@backstage/plugin-pagerduty": "0.3.17", diff --git a/packages/app/src/components/catalog/EntityPage.tsx b/packages/app/src/components/catalog/EntityPage.tsx index 3fe027ddad..3ce0ffb30f 100644 --- a/packages/app/src/components/catalog/EntityPage.tsx +++ b/packages/app/src/components/catalog/EntityPage.tsx @@ -126,6 +126,12 @@ import { EntityTravisCIOverviewCard, isTravisciAvailable, } from '@roadiehq/backstage-plugin-travis-ci'; +import { + isNewRelicDashboardAvailable, + EntityNewRelicDashboard, + EntityPageNewRelicDashboard, +} from '@backstage/plugin-new-relic-dashboard'; + import React, { ReactNode, useMemo, useState } from 'react'; const EntityLayoutWrapper = (props: { children?: ReactNode }) => { @@ -283,6 +289,14 @@ const overviewContent = ( + + + + + + + + @@ -363,6 +377,14 @@ const serviceEntityPage = ( + + + + @@ -421,7 +443,13 @@ const websiteEntityPage = ( - + + + diff --git a/plugins/new-relic-dashboard/src/Router.tsx b/plugins/new-relic-dashboard/src/Router.tsx index 6d8340505b..67fe12f146 100644 --- a/plugins/new-relic-dashboard/src/Router.tsx +++ b/plugins/new-relic-dashboard/src/Router.tsx @@ -14,7 +14,6 @@ * limitations under the License. */ import { Entity } from '@backstage/catalog-model'; -import { Route, Routes } from 'react-router-dom'; import React from 'react'; import { MissingAnnotationEmptyState } from '@backstage/core-components'; import { Button } from '@material-ui/core'; @@ -34,11 +33,7 @@ export const Router = (_props: Props) => { const { entity } = useEntity(); if (isNewRelicDashboardAvailable(entity)) { - return ( - - } /> - - ); + return ; } return ( diff --git a/plugins/new-relic-dashboard/src/api/NewRelicDashboardApi.ts b/plugins/new-relic-dashboard/src/api/NewRelicDashboardApi.ts index 7ec0c5623a..0d27c7a85e 100644 --- a/plugins/new-relic-dashboard/src/api/NewRelicDashboardApi.ts +++ b/plugins/new-relic-dashboard/src/api/NewRelicDashboardApi.ts @@ -38,6 +38,6 @@ export type NewRelicDashboardApi = { getDashboardEntity(guid: String): Promise; getDashboardSnapshot( guid: String, - duration: String, + duration: Number, ): Promise; }; diff --git a/plugins/new-relic-dashboard/src/api/NewRelicDashboardClient.ts b/plugins/new-relic-dashboard/src/api/NewRelicDashboardClient.ts index 20ff3962af..1d18d3950e 100644 --- a/plugins/new-relic-dashboard/src/api/NewRelicDashboardClient.ts +++ b/plugins/new-relic-dashboard/src/api/NewRelicDashboardClient.ts @@ -83,7 +83,7 @@ export class NewRelicDashboardClient implements NewRelicDashboardApi { async getDashboardSnapshot( guid: String, - duration: String, + duration: Number, ): Promise { const DashboardSnapshotValue = await this.callApi( getDashboardSnapshotQuery, diff --git a/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshot.tsx b/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshot.tsx index dd2f4622c6..306789a6f8 100644 --- a/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshot.tsx +++ b/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshot.tsx @@ -14,18 +14,19 @@ * limitations under the License. */ import React from 'react'; -import { Grid, Typography } from '@material-ui/core'; +import { Grid, Paper, Typography } from '@material-ui/core'; import { useApi } from '@backstage/core-plugin-api'; import { useAsync } from 'react-use'; import { Progress } from '@backstage/core-components'; import { NewRelicDashboardApiRef } from '../../../api'; import Alert from '@material-ui/lab/Alert'; +import Link from '@material-ui/core/Link'; type Props = { guid: String; name: String; permalink: string; - duration: String; + duration: Number; }; export const DashboardSnapshot = ({ @@ -49,29 +50,33 @@ export const DashboardSnapshot = ({ return {error.message}; } return ( - - - {name} - + + + + + {name} + + - - - {`${name} - - {/* {JSON.stringify( + + + {`${name} + + {/* {JSON.stringify( value.getDashboardSnapshot.data.dashboardCreateSnapshotUrl.replace( /...$/, 'png', ), )} */} + - + ); }; diff --git a/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshotList.tsx b/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshotList.tsx index 78684f7a55..1946d4016b 100644 --- a/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshotList.tsx +++ b/plugins/new-relic-dashboard/src/components/NewRelicDashboard/DashboardSnapshot/DashboardSnapshotList.tsx @@ -27,6 +27,7 @@ interface TabPanelProps { index: number; value1: number; } + function TabPanel(props: TabPanelProps) { const { children, value1, index, ...other } = props; @@ -38,7 +39,7 @@ function TabPanel(props: TabPanelProps) { aria-labelledby={`simple-tab-${index}`} {...other} > - {value1 === index && children} + {children} ); } @@ -111,47 +112,47 @@ export const DashboardSnapshotList = ({ guid }: Props) => { }, )} */} - - + + {value.getDashboardEntity.data.actor.entitySearch.results.entities?.map( + (Entity: any, index: any) => { + return ( + + ); + }, + )} + {value.getDashboardEntity.data.actor.entitySearch.results.entities?.map( (Entity: any, index: any) => { return ( - + + + ); }, )} - - {value.getDashboardEntity.data.actor.entitySearch.results.entities?.map( - (Entity: any, index: any) => { - return ( - - - - ); - }, - )} + ); }; diff --git a/plugins/new-relic-dashboard/src/queries/getDashboardSnapshotQuery.ts b/plugins/new-relic-dashboard/src/queries/getDashboardSnapshotQuery.ts index 7f96bf46ad..be683ecd7b 100644 --- a/plugins/new-relic-dashboard/src/queries/getDashboardSnapshotQuery.ts +++ b/plugins/new-relic-dashboard/src/queries/getDashboardSnapshotQuery.ts @@ -14,4 +14,4 @@ * limitations under the License. */ export const getDashboardSnapshotQuery = - 'mutation($guid: EntityGuid!) {\n dashboardCreateSnapshotUrl(guid: $guid , params: {timeWindow: {duration: $duration}})\n}'; + 'mutation($guid: EntityGuid! , ,$duration: Milliseconds) {\n dashboardCreateSnapshotUrl(guid: $guid , params: {timeWindow: {duration: $duration}})\n}';