generated from openmcp-project/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: rework breadcrumbs #291
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const Routes = { | ||
Home: '/', | ||
Project: '/mcp/projects/:projectName', | ||
Mcp: '/mcp/projects/:projectName/workspaces/:workspaceName/mcps/:controlPlaneName', | ||
} as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Button, FlexBox, FlexBoxAlignItems, Menu, MenuItem } from '@ui5/webcomponents-react'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { FeedbackButton } from './FeedbackButton.tsx'; | ||
import { BetaButton } from './BetaButton.tsx'; | ||
import { useRef, useState } from 'react'; | ||
import { useAuthOnboarding } from '../../spaces/onboarding/auth/AuthContextOnboarding.tsx'; | ||
import { SearchParamToggleVisibility } from '../Helper/FeatureToggleExistance.tsx'; | ||
import { PathAwareBreadcrumbs } from './PathAwareBreadcrumbs/PathAwareBreadcrumbs.tsx'; | ||
|
||
export function BreadcrumbFeedbackHeader() { | ||
return ( | ||
<FlexBox alignItems={FlexBoxAlignItems.Center}> | ||
<PathAwareBreadcrumbs /> | ||
<BetaButton /> | ||
<FeedbackButton /> | ||
<SearchParamToggleVisibility | ||
shouldBeVisible={(params) => { | ||
if (params === undefined) return false; | ||
if (params.get('showHeaderBar') === null) return false; | ||
return params?.get('showHeaderBar') === 'false'; | ||
}} | ||
> | ||
<LogoutMenu /> | ||
</SearchParamToggleVisibility> | ||
</FlexBox> | ||
); | ||
} | ||
|
||
function LogoutMenu() { | ||
const auth = useAuthOnboarding(); | ||
const { t } = useTranslation(); | ||
|
||
const buttonRef = useRef(null); | ||
const [menuIsOpen, setMenuIsOpen] = useState(false); | ||
return ( | ||
<> | ||
<Button | ||
ref={buttonRef} | ||
icon="menu2" | ||
onClick={() => { | ||
setMenuIsOpen(true); | ||
}} | ||
/> | ||
<Menu | ||
opener={buttonRef.current} | ||
open={menuIsOpen} | ||
onClose={() => { | ||
setMenuIsOpen(false); | ||
}} | ||
> | ||
<MenuItem | ||
icon="log" | ||
text={t('ShellBar.signOutButton')} | ||
onClick={async () => { | ||
setMenuIsOpen(false); | ||
await auth.logout(); | ||
}} | ||
/> | ||
</Menu> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/components/Core/PathAwareBreadcrumbs/PathAwareBreadcrumbs.cy.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { PathAwareBreadcrumbs } from './PathAwareBreadcrumbs'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
|
||
describe('PathAwareBreadcrumbs', () => { | ||
let lastNavigatedPath = ''; | ||
const fakeUseNavigate = (() => (path: string) => { | ||
lastNavigatedPath = path; | ||
}) as typeof useNavigate; | ||
const fakeUseParams = (() => ({ | ||
projectName: 'my-project', | ||
workspaceName: 'my-workspace', | ||
controlPlaneName: 'my-control-plane', | ||
})) as typeof useParams; | ||
|
||
beforeEach(() => { | ||
lastNavigatedPath = ''; | ||
}); | ||
|
||
it('renders breadcrumbs for all path parameters', () => { | ||
cy.mount(<PathAwareBreadcrumbs useNavigate={fakeUseNavigate} useParams={fakeUseParams} />); | ||
|
||
// Check that all breadcrumbs are rendered | ||
cy.get("[data-testid='breadcrumb-item']").should('have.length', 3); | ||
cy.get("[data-testid='breadcrumb-item']").eq(0).should('contain', '[LOCAL] Projects'); | ||
cy.get("[data-testid='breadcrumb-item']").eq(1).should('contain', 'my-project'); | ||
cy.get("[data-testid='breadcrumb-item']").eq(2).should('contain', 'my-workspace'); | ||
}); | ||
|
||
it('navigates when clicking breadcrumbs for all path parameters', () => { | ||
cy.mount(<PathAwareBreadcrumbs useNavigate={fakeUseNavigate} useParams={fakeUseParams} />); | ||
|
||
// Navigate to '/' | ||
cy.contains('[LOCAL] Projects').click(); | ||
cy.wrap(null).then(() => { | ||
expect(lastNavigatedPath).to.equal('/'); | ||
}); | ||
|
||
// Click on 'my-project' > Navigate to 'my-project' | ||
cy.contains('my-project').click(); | ||
cy.wrap(null).then(() => { | ||
expect(lastNavigatedPath).to.equal('/mcp/projects/my-project'); | ||
}); | ||
|
||
// Click on 'my-workspace' > Navigate to 'my-project' since workspaces don’t expose a direct path | ||
cy.contains('my-workspace').click(); | ||
cy.wrap(null).then(() => { | ||
expect(lastNavigatedPath).to.equal('/mcp/projects/my-project'); | ||
}); | ||
}); | ||
|
||
it('renders only home breadcrumb when there are no path parameters', () => { | ||
const fakeUseParams = (() => ({})) as typeof useParams; | ||
|
||
cy.mount(<PathAwareBreadcrumbs useNavigate={fakeUseNavigate} useParams={fakeUseParams} />); | ||
|
||
cy.get("[data-testid='breadcrumb-item']").should('have.length', 1); | ||
}); | ||
|
||
it('handles partial route parameters', () => { | ||
const fakeUseParams = (() => ({ | ||
projectName: 'my-project', | ||
// No workspaceName | ||
// No controlPlaneName | ||
})) as typeof useParams; | ||
|
||
cy.mount(<PathAwareBreadcrumbs useNavigate={fakeUseNavigate} useParams={fakeUseParams} />); | ||
|
||
// Should show 3 breadcrumbs | ||
cy.get("[data-testid='breadcrumb-item']").should('have.length', 2); | ||
|
||
// Verify data-target attributes | ||
cy.get("[data-testid='breadcrumb-item']").eq(0).should('contain', '[LOCAL] Projects'); | ||
cy.get("[data-testid='breadcrumb-item']").eq(1).should('contain', 'my-project'); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
src/components/Core/PathAwareBreadcrumbs/PathAwareBreadcrumbs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Breadcrumbs } from '@ui5/webcomponents-react'; | ||
import { BreadcrumbsItem } from '@ui5/webcomponents-react/wrappers'; | ||
import { generatePath, useNavigate as _useNavigate, useParams as _useParams } from 'react-router-dom'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { useFrontendConfig } from '../../../context/FrontendConfigContext.tsx'; | ||
import { Routes } from '../../../Routes.ts'; | ||
|
||
export interface PathAwareBreadcrumbsProps { | ||
useNavigate?: typeof _useNavigate; | ||
useParams?: typeof _useParams; | ||
} | ||
export function PathAwareBreadcrumbs({ | ||
useNavigate = _useNavigate, | ||
useParams = _useParams, | ||
}: PathAwareBreadcrumbsProps) { | ||
const { projectName, workspaceName } = useParams(); | ||
const { t } = useTranslation(); | ||
const frontendConfig = useFrontendConfig(); | ||
const navigate = useNavigate(); | ||
|
||
const breadcrumbItems: { label: string; path: string }[] = [ | ||
{ | ||
label: `[${frontendConfig.landscape}] ${t('PathAwareBreadcrumbs.projectsLabel')}`, | ||
path: Routes.Home, | ||
}, | ||
]; | ||
|
||
if (projectName) { | ||
breadcrumbItems.push({ | ||
label: projectName, | ||
path: generatePath(Routes.Project, { | ||
projectName, | ||
}), | ||
}); | ||
|
||
if (workspaceName) { | ||
breadcrumbItems.push({ | ||
label: workspaceName, | ||
// Navigate to the project route since workspaces don't provide a direct path | ||
path: generatePath(Routes.Project, { | ||
projectName, | ||
}), | ||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<Breadcrumbs | ||
design="NoCurrentPage" | ||
onItemClick={(event) => { | ||
event.preventDefault(); | ||
const target = event.detail.item.dataset.target; | ||
|
||
if (target) { | ||
navigate(target); | ||
} | ||
}} | ||
> | ||
{breadcrumbItems.map((item) => ( | ||
<BreadcrumbsItem key={item.path} data-target={item.path} data-testid="breadcrumb-item"> | ||
{item.label} | ||
</BreadcrumbsItem> | ||
))} | ||
</Breadcrumbs> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.