Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graphiql link in main nav #998

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions web/src/shared/components/Header/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Link } from 'react-router-dom'
import { Link, LinkProps } from 'react-router-dom'
import { Dropdown, Menu, Popup } from 'semantic-ui-react'

import { BillingApi } from '../../../sm-api'
Expand Down Expand Up @@ -55,24 +55,34 @@ interface MenuItem {
url: string
icon: JSX.Element
submenu?: MenuItem[]
reloadDocument?: boolean
}
interface MenuItemProps {
index: number
item: MenuItem
}

// A link component that reloads the document when clicked
// This is used for the graphiql link which doesn't render
// properly without a reload
const ReloadingLink = (props: LinkProps) => {
return <Link reloadDocument={true} {...props} />
}

const MenuItem: React.FC<MenuItemProps> = ({ index, item }) => {
const theme = React.useContext(ThemeContext)
const isDarkMode = theme.theme === 'dark-mode'

const MenuLinkComponent = item.reloadDocument ? ReloadingLink : Link

const dropdown = (item: MenuItem) => (
<Dropdown id="navDrop" text={item.title} key={index} inverted={isDarkMode}>
<Dropdown.Menu id="navDropMenu">
{item.submenu &&
item.submenu.map((subitem, subindex) => (
<Dropdown.Item
id="navDropMenuItem"
as={Link}
as={MenuLinkComponent}
to={subitem.url}
key={subindex}
>
Expand Down Expand Up @@ -105,7 +115,7 @@ const MenuItem: React.FC<MenuItemProps> = ({ index, item }) => {
return item.submenu ? (
<Menu.Item className="headerMenuItem">{popup(dropdown(item), item.icon)}</Menu.Item>
) : (
<Menu.Item className="headerMenuItem" as={Link} to={item.url} key={index}>
<Menu.Item className="headerMenuItem" as={MenuLinkComponent} to={item.url} key={index}>
{popup(item.title, item.icon)}
</Menu.Item>
)
Expand Down Expand Up @@ -141,6 +151,7 @@ const NavBar = () => {
{
title: 'GraphQL',
url: '/graphql',
reloadDocument: true,
icon: <TroubleshootIcon />,
},
InsightsPages,
Expand Down