chore: migrate to new backend in local development

additionally allow defining custom sidebar item for dev app page.

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-03-01 10:27:11 +02:00
parent 794883b10d
commit 9a41a7bfa8
15 changed files with 212 additions and 347 deletions
+30 -10
View File
@@ -44,7 +44,7 @@ import {
} from '@backstage/integration-react';
import Box from '@material-ui/core/Box';
import BookmarkIcon from '@material-ui/icons/Bookmark';
import React, { ComponentType, ReactNode, PropsWithChildren } from 'react';
import React, { ComponentType, PropsWithChildren, ReactNode } from 'react';
import { createRoutesFromChildren, Route } from 'react-router-dom';
import { SidebarThemeSwitcher } from './SidebarThemeSwitcher';
import 'react-dom';
@@ -80,6 +80,9 @@ export type DevAppPageOptions = {
children?: JSX.Element;
title?: string;
icon?: IconComponent;
sideBarItem?: JSX.Element;
routeRef?: RouteRef;
};
/**
@@ -141,7 +144,9 @@ export class DevAppBuilder {
this.defaultPage = path;
}
if (opts.title) {
if (opts.sideBarItem) {
this.sidebarItems.push(opts.sideBarItem);
} else if (opts.title) {
this.sidebarItems.push(
<SidebarItem
key={path}
@@ -151,14 +156,29 @@ export class DevAppBuilder {
/>,
);
}
this.routes.push(
<MaybeGatheringRoute
key={path}
path={path}
element={opts.element}
children={opts.children}
/>,
);
if (opts.routeRef) {
const Elem = () => <>{opts.element}</>;
attachComponentData(Elem, 'core.mountPoint', opts.routeRef);
this.routes.push(
<MaybeGatheringRoute
key={path}
path={path}
element={<Elem />}
children={opts.children}
/>,
);
} else {
this.routes.push(
<MaybeGatheringRoute
key={path}
path={path}
element={opts.element}
children={opts.children}
/>,
);
}
return this;
}