From b284ecb010272dd725ad043e36cf39e1136e3793 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 7 Aug 2024 11:33:26 +0200 Subject: [PATCH] chore: reworking how to override the page component Signed-off-by: blam --- .../src/extensions/NavItemBlueprint.ts | 51 +++++++++++++++++++ .../src/extensions/PageBlueprint.test.tsx | 23 ++++----- 2 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 packages/frontend-plugin-api/src/extensions/NavItemBlueprint.ts diff --git a/packages/frontend-plugin-api/src/extensions/NavItemBlueprint.ts b/packages/frontend-plugin-api/src/extensions/NavItemBlueprint.ts new file mode 100644 index 0000000000..568431c0f5 --- /dev/null +++ b/packages/frontend-plugin-api/src/extensions/NavItemBlueprint.ts @@ -0,0 +1,51 @@ +/* + * Copyright 2024 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 { IconComponent } from '@backstage/core-plugin-api'; +import { RouteRef } from '../routing'; +import { createExtensionBlueprint } from '../wiring'; +import { createNavItemExtension } from './createNavItemExtension'; + +export const NavItemBlueprint = createExtensionBlueprint({ + kind: 'nav-item', + attachTo: { id: 'app/nav', input: 'items' }, + output: [createNavItemExtension.targetDataRef], + dataRefs: { + target: createNavItemExtension.targetDataRef, + }, + factory: ( + { + icon, + routeRef, + }: { + title: string; + icon: IconComponent; + routeRef: RouteRef; + }, + { config }, + ) => [ + createNavItemExtension.targetDataRef({ + title: config.title, + icon, + routeRef, + }), + ], + config: { + schema: ({ title }) => ({ + title: z => z.string().default(title), + }), + }, +}); diff --git a/packages/frontend-plugin-api/src/extensions/PageBlueprint.test.tsx b/packages/frontend-plugin-api/src/extensions/PageBlueprint.test.tsx index e020167f43..5e1d6b7601 100644 --- a/packages/frontend-plugin-api/src/extensions/PageBlueprint.test.tsx +++ b/packages/frontend-plugin-api/src/extensions/PageBlueprint.test.tsx @@ -107,24 +107,23 @@ describe('PageBlueprint', () => { it('should allow defining additional inputs to the extension', async () => { const myPage = PageBlueprint.make({ name: 'test-page', - params: { - loader: async ({ inputs }) => { - return ( -
- {inputs.cards.map(c => c.get(coreExtensionData.reactElement))} -
- ); - }, - defaultPath: '/test', - routeRef: mockRouteRef, - }, - /* todo(blam): need to fix the typescript here, as inputs is not the right type, wont let me merge without specifying parent opts */ inputs: { cards: createExtensionInput([coreExtensionData.reactElement], { optional: false, singleton: false, }), }, + factory(originalFactory, { inputs }) { + return originalFactory({ + loader: async () => ( +
+ {inputs.cards.map(c => c.get(coreExtensionData.reactElement))} +
+ ), + defaultPath: '/test', + routeRef: mockRouteRef, + }); + }, }); const CardBlueprint = createExtensionBlueprint({