From f4efd3d30a9cce49d1cafc7816ffb6cb0d861998 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Oct 2023 14:29:50 +0200 Subject: [PATCH] frontend-plugin-api: updates to use new routing API Signed-off-by: Patrik Oldsberg --- .../src/extensions/createNavItemExtension.tsx | 5 +++-- .../src/extensions/createPageExtension.tsx | 2 +- packages/frontend-plugin-api/src/routing/types.ts | 12 ------------ .../src/routing/useRouteRef.test.tsx | 10 +++++----- .../src/routing/useRouteRefParams.test.tsx | 1 - .../src/wiring/coreExtensionData.ts | 4 ++-- .../frontend-plugin-api/src/wiring/createPlugin.ts | 12 +++++++++--- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx b/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx index f208c975b7..ee38dda016 100644 --- a/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx +++ b/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx @@ -14,9 +14,10 @@ * limitations under the License. */ -import { IconComponent, RouteRef } from '@backstage/core-plugin-api'; +import { IconComponent } from '@backstage/core-plugin-api'; import { createSchemaFromZod } from '../schema/createSchemaFromZod'; import { coreExtensionData, createExtension } from '../wiring'; +import { RouteRef } from '../routing'; /** * Helper for creating extensions for a nav item. @@ -24,7 +25,7 @@ import { coreExtensionData, createExtension } from '../wiring'; */ export function createNavItemExtension(options: { id: string; - routeRef: RouteRef; + routeRef: RouteRef; title: string; icon: IconComponent; }) { diff --git a/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx b/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx index 43edfaa36d..217fb33ce5 100644 --- a/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx +++ b/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx @@ -14,7 +14,6 @@ * limitations under the License. */ -import { RouteRef } from '@backstage/core-plugin-api'; import React from 'react'; import { ExtensionBoundary } from '../components'; import { createSchemaFromZod, PortableSchema } from '../schema'; @@ -26,6 +25,7 @@ import { } from '../wiring'; import { AnyExtensionInputMap } from '../wiring/createExtension'; import { Expand } from '../types'; +import { RouteRef } from '../routing'; /** * Helper for creating extensions for a routable React page component. diff --git a/packages/frontend-plugin-api/src/routing/types.ts b/packages/frontend-plugin-api/src/routing/types.ts index 583bc4f815..8fe0d7e8a4 100644 --- a/packages/frontend-plugin-api/src/routing/types.ts +++ b/packages/frontend-plugin-api/src/routing/types.ts @@ -20,15 +20,3 @@ * @public */ export type AnyRouteParams = { [param in string]: string } | undefined; - -/** - * A duplicate of the react-router RouteObject, but with routeRef added - * @internal - */ -export interface BackstageRouteObject { - caseSensitive: boolean; - children?: BackstageRouteObject[]; - element: React.ReactNode; - path: string; - routeRefs: Set; -} diff --git a/packages/frontend-plugin-api/src/routing/useRouteRef.test.tsx b/packages/frontend-plugin-api/src/routing/useRouteRef.test.tsx index 7a03a1cdc4..c786cd71fa 100644 --- a/packages/frontend-plugin-api/src/routing/useRouteRef.test.tsx +++ b/packages/frontend-plugin-api/src/routing/useRouteRef.test.tsx @@ -33,7 +33,7 @@ describe('v1 consumer', () => { const resolve = jest.fn(() => () => '/hello'); context.set({ 1: { resolve } }); - const routeRef = createRouteRef({ id: 'ref1' }); + const routeRef = createRouteRef(); const renderedHook = renderHook(() => useRouteRef(routeRef), { wrapper: ({ children }: React.PropsWithChildren<{}>) => ( @@ -55,7 +55,7 @@ describe('v1 consumer', () => { const resolve = jest.fn(() => () => '/hello'); context.set({ 1: { resolve } }); - const routeRef = createRouteRef({ id: 'ref1' }); + const routeRef = createRouteRef(); const history = createBrowserHistory(); history.push('/my-page'); @@ -81,7 +81,7 @@ describe('v1 consumer', () => { const resolve = jest.fn(() => () => '/hello'); context.set({ 1: { resolve } }); - const routeRef = createRouteRef({ id: 'ref1' }); + const routeRef = createRouteRef(); const history = createBrowserHistory(); history.push('/my-page'); @@ -107,7 +107,7 @@ describe('v1 consumer', () => { const resolve = jest.fn(() => () => '/hello'); context.set({ 1: { resolve } }); - const routeRef = createRouteRef({ id: 'ref1' }); + const routeRef = createRouteRef(); const history = createBrowserHistory(); history.push('/my-page'); @@ -133,7 +133,7 @@ describe('v1 consumer', () => { const resolve = jest.fn(() => () => '/hello'); context.set({ 1: { resolve } }); - const routeRef = createRouteRef({ id: 'ref1' }); + const routeRef = createRouteRef(); const history = createBrowserHistory(); history.push('/my-page'); diff --git a/packages/frontend-plugin-api/src/routing/useRouteRefParams.test.tsx b/packages/frontend-plugin-api/src/routing/useRouteRefParams.test.tsx index 40ee7219c2..37432b294e 100644 --- a/packages/frontend-plugin-api/src/routing/useRouteRefParams.test.tsx +++ b/packages/frontend-plugin-api/src/routing/useRouteRefParams.test.tsx @@ -23,7 +23,6 @@ import { createRouteRef } from './RouteRef'; describe('useRouteRefParams', () => { it('should provide types params', () => { const routeRef = createRouteRef({ - id: 'ref1', params: ['a', 'b'], }); diff --git a/packages/frontend-plugin-api/src/wiring/coreExtensionData.ts b/packages/frontend-plugin-api/src/wiring/coreExtensionData.ts index 6913501907..023eab57e1 100644 --- a/packages/frontend-plugin-api/src/wiring/coreExtensionData.ts +++ b/packages/frontend-plugin-api/src/wiring/coreExtensionData.ts @@ -19,15 +19,15 @@ import { AnyApiFactory, AppTheme, IconComponent, - RouteRef, } from '@backstage/core-plugin-api'; import { createExtensionDataRef } from './createExtensionDataRef'; +import { RouteRef } from '../routing'; /** @public */ export type NavTarget = { title: string; icon: IconComponent; - routeRef: RouteRef<{}>; + routeRef: RouteRef; }; /** @public */ diff --git a/packages/frontend-plugin-api/src/wiring/createPlugin.ts b/packages/frontend-plugin-api/src/wiring/createPlugin.ts index 3afb5cedff..782e5134ec 100644 --- a/packages/frontend-plugin-api/src/wiring/createPlugin.ts +++ b/packages/frontend-plugin-api/src/wiring/createPlugin.ts @@ -14,8 +14,14 @@ * limitations under the License. */ -import { AnyExternalRoutes, AnyRoutes } from '@backstage/core-plugin-api'; import { Extension } from './createExtension'; +import { ExternalRouteRef, RouteRef } from '../routing'; + +/** @internal */ +export type AnyRoutes = { [name in string]: RouteRef }; + +/** @internal */ +export type AnyExternalRoutes = { [name in string]: ExternalRouteRef }; /** @public */ export interface PluginOptions< @@ -42,8 +48,8 @@ export interface BackstagePlugin< /** @public */ export function createPlugin< - Routes extends AnyRoutes = AnyRoutes, - ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes, + Routes extends AnyRoutes, + ExternalRoutes extends AnyExternalRoutes, >( options: PluginOptions, ): BackstagePlugin {