Skip to content

Commit 351d260

Browse files
authored
feat(quickstart): add quickstart menu item to header (#2898)
Signed-off-by: Rohit Rai <rohitkrai03@gmail.com>
1 parent 328508c commit 351d260

22 files changed

Lines changed: 435 additions & 170 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-app-react': patch
3+
---
4+
5+
Removed the header specific style overrides for drawer

workspaces/app-defaults/packages/app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"@red-hat-developer-hub/backstage-plugin-app-auth": "workspace:^",
5151
"@red-hat-developer-hub/backstage-plugin-app-integrations": "workspace:^",
5252
"@red-hat-developer-hub/backstage-plugin-app-react": "workspace:^",
53+
"@red-hat-developer-hub/backstage-plugin-global-header": "^1.21.0",
54+
"material-icons": "^1.13.14",
5355
"react": "^18.0.2",
5456
"react-dom": "^18.0.2",
5557
"react-router": "^6.30.2",

workspaces/app-defaults/packages/app/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import catalogPlugin from '@backstage/plugin-catalog/alpha';
1919
import { appAuthModule } from '@red-hat-developer-hub/backstage-plugin-app-auth/alpha';
2020
import { appIntegrationsModule } from '@red-hat-developer-hub/backstage-plugin-app-integrations/alpha';
2121
import { appDrawerModule } from '@red-hat-developer-hub/backstage-plugin-app-react/alpha';
22+
import {
23+
globalHeaderModule,
24+
globalHeaderTranslationsModule,
25+
} from '@red-hat-developer-hub/backstage-plugin-global-header/alpha';
2226
import { navModule } from './modules/nav';
2327
import { drawerDemoModule } from './modules/drawer-demo';
2428

@@ -30,5 +34,7 @@ export default createApp({
3034
appIntegrationsModule,
3135
appDrawerModule,
3236
drawerDemoModule,
37+
globalHeaderModule,
38+
globalHeaderTranslationsModule,
3339
],
3440
});

workspaces/app-defaults/packages/app/src/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,23 @@
1515
*/
1616

1717
import '@backstage/cli/asset-types';
18+
import 'material-icons/iconfont/outlined.css';
1819
import ReactDOM from 'react-dom/client';
1920
import App from './App';
2021
import '@backstage/ui/css/styles.css';
2122

23+
// TODO: Remove once @red-hat-developer-hub/backstage-plugin-global-header
24+
// publishes a version with built-in drawer support (width: auto + margin-right
25+
// on the AppBar). Tracked by the GlobalHeader.tsx change in the global-header
26+
// workspace.
27+
const style = document.createElement('style');
28+
style.textContent = `
29+
#global-header {
30+
width: auto;
31+
margin-right: var(--docked-drawer-width, 0px);
32+
transition: margin-right 225ms cubic-bezier(0, 0, 0.2, 1);
33+
}
34+
`;
35+
document.head.appendChild(style);
36+
2237
ReactDOM.createRoot(document.getElementById('root')!).render(App.createRoot());

workspaces/app-defaults/packages/app/src/modules/drawer-demo/DrawerDemoContent.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { useAppDrawer } from '@red-hat-developer-hub/backstage-plugin-app-react';
18+
import { GlobalHeaderMenuItem } from '@red-hat-developer-hub/backstage-plugin-global-header/alpha';
1819
import Box from '@mui/material/Box';
1920
import Divider from '@mui/material/Divider';
2021
import IconButton from '@mui/material/IconButton';
@@ -121,3 +122,24 @@ export const HelpDrawerContent = () => {
121122
</Box>
122123
);
123124
};
125+
126+
export const HelpDrawerMenuItem = ({
127+
handleClose,
128+
}: {
129+
handleClose?: () => void;
130+
}) => {
131+
const { toggleDrawer } = useAppDrawer();
132+
133+
const handleClick = () => {
134+
toggleDrawer('demo-help');
135+
handleClose?.();
136+
};
137+
138+
return (
139+
<GlobalHeaderMenuItem
140+
title="Help"
141+
icon="help_outline"
142+
onClick={handleClick}
143+
/>
144+
);
145+
};

workspaces/app-defaults/packages/app/src/modules/drawer-demo/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616

1717
import { createFrontendModule } from '@backstage/frontend-plugin-api';
1818
import { AppDrawerContentBlueprint } from '@red-hat-developer-hub/backstage-plugin-app-react/alpha';
19-
import { ChatDrawerContent, HelpDrawerContent } from './DrawerDemoContent';
19+
import { GlobalHeaderMenuItemBlueprint } from '@red-hat-developer-hub/backstage-plugin-global-header/alpha';
20+
import {
21+
ChatDrawerContent,
22+
HelpDrawerContent,
23+
HelpDrawerMenuItem,
24+
} from './DrawerDemoContent';
2025

2126
const chatDrawer = AppDrawerContentBlueprint.make({
2227
name: 'demo-chat',
@@ -37,7 +42,16 @@ const helpDrawer = AppDrawerContentBlueprint.make({
3742
},
3843
});
3944

45+
const helpMenuItem = GlobalHeaderMenuItemBlueprint.make({
46+
name: 'demo-help',
47+
params: {
48+
target: 'help',
49+
component: HelpDrawerMenuItem,
50+
priority: 50,
51+
},
52+
});
53+
4054
export const drawerDemoModule = createFrontendModule({
4155
pluginId: 'app',
42-
extensions: [chatDrawer, helpDrawer],
56+
extensions: [chatDrawer, helpDrawer, helpMenuItem],
4357
});

workspaces/app-defaults/packages/app/src/modules/nav/Sidebar.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,18 @@ import { useAppDrawer } from '@red-hat-developer-hub/backstage-plugin-app-react'
2727
import MenuIcon from '@material-ui/icons/Menu';
2828
import SearchIcon from '@material-ui/icons/Search';
2929
import ChatIcon from '@material-ui/icons/Chat';
30-
import HelpIcon from '@material-ui/icons/Help';
3130
import { SidebarSearchModal } from '@backstage/plugin-search';
3231
import { UserSettingsSignInAvatar } from '@backstage/plugin-user-settings';
3332
import { NotificationsSidebarItem } from '@backstage/plugin-notifications';
3433

35-
const DrawerDemoItems = () => {
34+
const ChatDrawerItem = () => {
3635
const { toggleDrawer } = useAppDrawer();
3736
return (
38-
<>
39-
<SidebarItem
40-
icon={() => <ChatIcon />}
41-
text="Chat"
42-
onClick={() => toggleDrawer('demo-chat')}
43-
/>
44-
<SidebarItem
45-
icon={() => <HelpIcon />}
46-
text="Help"
47-
onClick={() => toggleDrawer('demo-help')}
48-
/>
49-
</>
37+
<SidebarItem
38+
icon={() => <ChatIcon />}
39+
text="Chat"
40+
onClick={() => toggleDrawer('demo-chat')}
41+
/>
5042
);
5143
};
5244

@@ -76,7 +68,7 @@ export const SidebarContent = NavContentBlueprint.make({
7668
</SidebarGroup>
7769
<SidebarSpace />
7870
<SidebarDivider />
79-
<DrawerDemoItems />
71+
<ChatDrawerItem />
8072
<NotificationsSidebarItem />
8173
<SidebarDivider />
8274
<SidebarGroup

workspaces/app-defaults/plugins/app-react/src/drawer/components/DrawerPanel.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,9 @@ export const DrawerPanel = (props: DrawerPanelProps) => {
110110
open={isDrawerOpen}
111111
PaperProps={{
112112
style: { width: drawerWidth },
113-
}}
114-
sx={{
115-
'& .MuiDrawer-paper': {
113+
sx: {
116114
boxSizing: 'border-box',
117-
backgroundColor: theme => {
115+
backgroundColor: (theme: Record<string, any>) => {
118116
const palette = theme.palette as Record<string, any>;
119117
return (
120118
palette?.rhdh?.general?.sidebarBackgroundColor ||
@@ -123,12 +121,6 @@ export const DrawerPanel = (props: DrawerPanelProps) => {
123121
},
124122
justifyContent: 'space-between',
125123
},
126-
'body:has(#global-header) &': {
127-
'& .MuiDrawer-paper': {
128-
top: '64px !important',
129-
height: 'calc(100vh - 64px) !important',
130-
},
131-
},
132124
}}
133125
>
134126
{isResizable && (

0 commit comments

Comments
 (0)