From 8b21788e96ea5744b1ffd5c2394e144452e96d87 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 21 Oct 2021 14:11:42 +0200 Subject: [PATCH] chore: added some more deprecation fixes for the routeRefs Signed-off-by: blam --- packages/core-plugin-api/src/routing/RouteRef.ts | 5 +++++ .../components/BuildsPage/lib/CITable/CITable.tsx | 7 +++++-- plugins/jenkins/src/components/Router.tsx | 4 ++-- plugins/jenkins/src/plugin.ts | 6 ++++-- plugins/kafka/src/Router.tsx | 6 +----- plugins/kubernetes/src/Router.tsx | 6 +----- plugins/rollbar/src/components/Router.tsx | 6 +----- plugins/user-settings/src/components/Settings.tsx | 6 +++--- .../XcmetricsLayout/XcmetricsLayout.tsx | 15 +++++---------- 9 files changed, 27 insertions(+), 34 deletions(-) diff --git a/packages/core-plugin-api/src/routing/RouteRef.ts b/packages/core-plugin-api/src/routing/RouteRef.ts index 22ad2ee5bf..d62504615a 100644 --- a/packages/core-plugin-api/src/routing/RouteRef.ts +++ b/packages/core-plugin-api/src/routing/RouteRef.ts @@ -78,6 +78,11 @@ export class RouteRefImpl } } + // /** @deprecated use `useRouteRef` instead */ + // get path() { + // return thuis + // } + get icon() { return this.config.icon; } diff --git a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx index ee17df8533..7a7b77f5dc 100644 --- a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx +++ b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx @@ -17,12 +17,13 @@ import React from 'react'; import { Box, IconButton, Link, Typography, Tooltip } from '@material-ui/core'; import RetryIcon from '@material-ui/icons/Replay'; import JenkinsLogo from '../../../../assets/JenkinsLogo.svg'; -import { generatePath, Link as RouterLink } from 'react-router-dom'; +import { Link as RouterLink } from 'react-router-dom'; import { JenkinsRunStatus } from '../Status'; import { useBuilds } from '../../../useBuilds'; import { buildRouteRef } from '../../../../plugin'; import { Table, TableColumn } from '@backstage/core-components'; import { Project } from '../../../../api/JenkinsApi'; +import { useRouteRef } from '@backstage/core-plugin-api'; const FailCount = ({ count }: { count: number }): JSX.Element | null => { if (count !== 0) { @@ -91,6 +92,8 @@ const generatedColumns: TableColumn[] = [ field: 'fullName', highlight: true, render: (row: Partial) => { + // eslint-disable-next-line react-hooks/rules-of-hooks + const routeLink = useRouteRef(buildRouteRef); if (!row.fullName || !row.lastBuild?.number) { return ( <> @@ -105,7 +108,7 @@ const generatedColumns: TableColumn[] = [ return ( { return ( - } /> + } /> } /> ); diff --git a/plugins/jenkins/src/plugin.ts b/plugins/jenkins/src/plugin.ts index b255ed9fd1..e38cf55f54 100644 --- a/plugins/jenkins/src/plugin.ts +++ b/plugins/jenkins/src/plugin.ts @@ -20,6 +20,7 @@ import { createPlugin, createRoutableExtension, createRouteRef, + createSubRouteRef, discoveryApiRef, identityApiRef, } from '@backstage/core-plugin-api'; @@ -29,9 +30,10 @@ export const rootRouteRef = createRouteRef({ id: 'jenkins', }); -export const buildRouteRef = createRouteRef({ +export const buildRouteRef = createSubRouteRef({ id: 'jenkins/build', - params: ['jobFullName', 'buildNumber'], + path: '/builds/:jobFullName/:buildNumber', + parent: rootRouteRef, }); export const jenkinsPlugin = createPlugin({ diff --git a/plugins/kafka/src/Router.tsx b/plugins/kafka/src/Router.tsx index 977c71712e..c63019253b 100644 --- a/plugins/kafka/src/Router.tsx +++ b/plugins/kafka/src/Router.tsx @@ -18,7 +18,6 @@ import { Entity } from '@backstage/catalog-model'; import React from 'react'; import { Route, Routes } from 'react-router'; import { useEntity } from '@backstage/plugin-catalog-react'; -import { rootCatalogKafkaRouteRef } from './plugin'; import { KAFKA_CONSUMER_GROUP_ANNOTATION } from './constants'; import { KafkaTopicsForConsumer } from './components/ConsumerGroupOffsets/ConsumerGroupOffsets'; import { MissingAnnotationEmptyState } from '@backstage/core-components'; @@ -44,10 +43,7 @@ export const Router = (_props: Props) => { return ( - } - /> + } /> ); }; diff --git a/plugins/kubernetes/src/Router.tsx b/plugins/kubernetes/src/Router.tsx index f98d3ca45e..873bf128e4 100644 --- a/plugins/kubernetes/src/Router.tsx +++ b/plugins/kubernetes/src/Router.tsx @@ -18,7 +18,6 @@ import React from 'react'; import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; import { Route, Routes } from 'react-router-dom'; -import { rootCatalogKubernetesRouteRef } from './plugin'; import { KubernetesContent } from './components/KubernetesContent'; import { Button } from '@material-ui/core'; import { MissingAnnotationEmptyState } from '@backstage/core-components'; @@ -53,10 +52,7 @@ export const Router = (_props: Props) => { ) { return ( - } - /> + } /> ); } diff --git a/plugins/rollbar/src/components/Router.tsx b/plugins/rollbar/src/components/Router.tsx index 845da22a20..032bf0166e 100644 --- a/plugins/rollbar/src/components/Router.tsx +++ b/plugins/rollbar/src/components/Router.tsx @@ -19,7 +19,6 @@ import { useEntity } from '@backstage/plugin-catalog-react'; import React from 'react'; import { Route, Routes } from 'react-router'; import { ROLLBAR_ANNOTATION } from '../constants'; -import { rootRouteRef } from '../plugin'; import { EntityPageRollbar } from './EntityPageRollbar/EntityPageRollbar'; import { MissingAnnotationEmptyState } from '@backstage/core-components'; @@ -40,10 +39,7 @@ export const Router = (_props: Props) => { return ( - } - /> + } /> ); }; diff --git a/plugins/user-settings/src/components/Settings.tsx b/plugins/user-settings/src/components/Settings.tsx index 43a00ee9cc..e9b3ae7d0a 100644 --- a/plugins/user-settings/src/components/Settings.tsx +++ b/plugins/user-settings/src/components/Settings.tsx @@ -18,14 +18,14 @@ import React from 'react'; import SettingsIcon from '@material-ui/icons/Settings'; import { settingsRouteRef } from '../plugin'; import { SidebarItem } from '@backstage/core-components'; -import { IconComponent } from '@backstage/core-plugin-api'; +import { useRouteRef, IconComponent } from '@backstage/core-plugin-api'; type SettingsProps = { icon?: IconComponent; }; export const Settings = (props: SettingsProps) => { + const routePath = useRouteRef(settingsRouteRef); const Icon = props.icon ? props.icon : SettingsIcon; - - return ; + return ; }; diff --git a/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.tsx b/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.tsx index 53545890a4..a21918e322 100644 --- a/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.tsx +++ b/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.tsx @@ -22,24 +22,23 @@ import { TabbedLayout, } from '@backstage/core-components'; import { Overview } from '../Overview'; -import { buildsRouteRef, rootRouteRef } from '../../routes'; -import { RouteRef, SubRouteRef } from '@backstage/core-plugin-api'; +import { buildsRouteRef } from '../../routes'; import { BuildsPage } from '../BuildsPage'; export interface TabConfig { - routeRef: RouteRef | SubRouteRef; + path: string; title: string; component: ReactChild; } const TABS: TabConfig[] = [ { - routeRef: rootRouteRef, + path: '/', title: 'Overview', component: , }, { - routeRef: buildsRouteRef, + path: buildsRouteRef.path, title: 'Builds', component: , }, @@ -53,11 +52,7 @@ export const XcmetricsLayout = () => ( {TABS.map(tab => ( - + {tab.component} ))}