From 3438bdeb7d2210ddc79887777ae4b512ba60b16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 31 Aug 2023 14:32:45 +0200 Subject: [PATCH] add a skeleton for route test pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Patrik Oldsberg Co-authored-by: Johan Haals Signed-off-by: Fredrik Adelöw --- packages/app-next/src/App.tsx | 3 +- .../app-next/src/examples/pagesPlugin.tsx | 62 +++++++++++++++++++ packages/frontend-app-api/src/createApp.tsx | 6 +- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 packages/app-next/src/examples/pagesPlugin.tsx diff --git a/packages/app-next/src/App.tsx b/packages/app-next/src/App.tsx index b875fb3927..82b0c927e9 100644 --- a/packages/app-next/src/App.tsx +++ b/packages/app-next/src/App.tsx @@ -17,6 +17,7 @@ import { graphiqlPlugin as legacyGraphiqlPlugin } from '@backstage/plugin-graphiql'; import { createApp as createLegacyApp } from '@backstage/app-defaults'; import { createApp } from '@backstage/frontend-app-api'; +import { pagesPlugin } from './examples/pagesPlugin'; import { graphiqlPlugin } from './examples/graphiqlPlugin'; /* @@ -49,7 +50,7 @@ TODO: /* app.tsx */ const app = createApp({ - plugins: [graphiqlPlugin], + plugins: [graphiqlPlugin, pagesPlugin], // bindRoutes({ bind }) { // bind(catalogPlugin.externalRoutes, { // createComponent: scaffolderPlugin.routes.root, diff --git a/packages/app-next/src/examples/pagesPlugin.tsx b/packages/app-next/src/examples/pagesPlugin.tsx new file mode 100644 index 0000000000..4bb0b76ad7 --- /dev/null +++ b/packages/app-next/src/examples/pagesPlugin.tsx @@ -0,0 +1,62 @@ +/* + * Copyright 2023 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 React from 'react'; +import { Link } from '@backstage/core-components'; +import { + createPageExtension, + createPlugin, +} from '@backstage/frontend-plugin-api'; + +const IndexPage = createPageExtension({ + id: 'index', + defaultPath: '/', + component: async () => { + const Component = () => { + // const page1 = useRouteRef(); + return ( +
+ op +
+ Page 1 +
+
+ GraphiQL +
+
+ ); + }; + return ; + }, +}); + +const Page1 = createPageExtension({ + id: 'page1', + defaultPath: '/page1', + component: async () => { + const Component = () => ( +
+

This is page 1

+
+ ); + return ; + }, +}); + +export const pagesPlugin = createPlugin({ + id: 'pages', + extensions: [IndexPage, Page1], +}); diff --git a/packages/frontend-app-api/src/createApp.tsx b/packages/frontend-app-api/src/createApp.tsx index e8b429f440..b3704fea4f 100644 --- a/packages/frontend-app-api/src/createApp.tsx +++ b/packages/frontend-app-api/src/createApp.tsx @@ -92,12 +92,16 @@ export function createApp(options: { plugins: BackstagePlugin[] }): { ]), ); - return createExtensionInstance({ + const newInstance = createExtensionInstance({ extension: instanceParams.extension, source: instanceParams.source, config: instanceParams.config, attachments, }); + + instances.set(instanceParams.extension.id, newInstance); + + return newInstance; } const rootConfigs = attachmentMap.get('root')?.get('default') ?? [];