Skip to content

Commit

Permalink
Ability to open additional menu links in same tab (jaegertracing#275)
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Zabolotskyy <zablvit@gmail.com>
  • Loading branch information
zablvit authored and Vitaliy Zabolotskyy committed Nov 17, 2018
1 parent feeaccd commit 48ad897
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/jaeger-ui/src/components/App/TopNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ function CustomNavDropdown({ label, items }: ConfigMenuGroup) {
const menuItems = (
<Menu>
{items.map(item => {
const { label: itemLabel, url } = item;
return (
const { label: itemLabel, url, openInSameTab } = item;
const target = openInSameTab ? "_self" : "_blank";
return (
<Menu.Item key={itemLabel}>
<a href={url} target="_blank" rel="noopener noreferrer">
<a href={url} target={target} rel="noopener noreferrer">
{itemLabel}
</a>
</Menu.Item>
Expand Down Expand Up @@ -93,9 +94,10 @@ export function TopNavImpl(props: Props) {
);
}
const item = ((m: any): ConfigMenuItem);
const target = item.openInSameTab ? "_self" : "_blank";
return (
<Menu.Item key={item.label}>
<a href={item.url} target="_blank" rel="noopener noreferrer">
<a href={item.url} target={target} rel="noopener noreferrer">
{item.label}
</a>
</Menu.Item>
Expand Down
8 changes: 8 additions & 0 deletions packages/jaeger-ui/src/components/App/TopNav.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('<TopNav>', () => {
{
label: 'Twitter',
url: 'https://twitter.com/JaegerTracing',
openInSameTab: true,
},
];

Expand All @@ -39,6 +40,7 @@ describe('<TopNav>', () => {
{
label: labelGitHub,
url: githubUrl,
openInSameTab: true,
},
{
label: labelAbout,
Expand Down Expand Up @@ -87,5 +89,11 @@ describe('<TopNav>', () => {
expect(item.prop('label')).toBe(labelAbout);
expect(item.prop('items')).toBe(dropdownItems);
});

it('adds target=_self to top-level item', () => {
const item = wrapper.find(`[href="${githubUrl}"]`);
expect(item.length).toBe(1);
expect(item.find(`[target="_self"]`).length).toBe(1);
});
});
});
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/types/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export type ConfigMenuItem = {
label: string,
url: string,
openInSameTab: boolean,
};

export type ConfigMenuGroup = {
Expand Down

0 comments on commit 48ad897

Please sign in to comment.