forked from jaegertracing/jaeger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Issue-467
- Loading branch information
Showing
10 changed files
with
340 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
packages/jaeger-ui/src/components/common/ExternalLinks.test.js
This file contains 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,54 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Menu, Dropdown } from 'antd'; | ||
|
||
import ExternalLinks from './ExternalLinks'; | ||
|
||
describe('<ExternalLinks>', () => { | ||
describe('render links links', () => { | ||
it('renders dropdown with multiple links', () => { | ||
const links = [ | ||
{ url: 'http://nowhere/', text: 'some text' }, | ||
{ url: 'http://other/', text: 'other text' }, | ||
{ url: 'http://link/', text: 'link text' }, | ||
]; | ||
|
||
const wrapper = shallow(<ExternalLinks links={links} />); | ||
const dropdown = wrapper.find(Dropdown); | ||
expect(dropdown.length).toBe(1); | ||
const linkValues = shallow(dropdown.first().props().overlay); | ||
const submenuItems = linkValues.find(Menu.Item); | ||
expect(submenuItems.length).toBe(links.length); | ||
submenuItems.forEach((subMenu, i) => { | ||
const linkValue = subMenu.find('LinkValue'); | ||
expect(linkValue.props().href).toBe(links[i].url); | ||
expect(linkValue.props().children).toBe(links[i].text); | ||
}); | ||
}); | ||
|
||
it('renders one link', () => { | ||
const links = [{ url: 'http://nowhere/', text: 'some text' }]; | ||
const wrapper = shallow(<ExternalLinks links={links} />); | ||
const dropdown = wrapper.find(Dropdown); | ||
expect(dropdown.length).toBe(0); | ||
const linkValues = wrapper.find('LinkValue'); | ||
expect(linkValues.length).toBe(1); | ||
expect(linkValues.prop('href')).toBe(links[0].url); | ||
expect(linkValues.prop('title')).toBe(links[0].text); | ||
}); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/jaeger-ui/src/components/common/ExternalLinks.tsx
This file contains 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,66 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Dropdown, Menu } from 'antd'; | ||
import * as React from 'react'; | ||
import { Link } from '../../types/trace'; | ||
import NewWindowIcon from './NewWindowIcon'; | ||
|
||
type ExternalLinksProps = { | ||
links: Link[]; | ||
}; | ||
|
||
const LinkValue = (props: { | ||
href: string; | ||
title?: string; | ||
children?: React.ReactNode; | ||
className?: string; | ||
}) => ( | ||
<a | ||
href={props.href} | ||
title={props.title} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className={props.className} | ||
> | ||
{props.children} <NewWindowIcon /> | ||
</a> | ||
); | ||
|
||
// export for testing | ||
export const linkValueList = (links: Link[]) => ( | ||
<Menu> | ||
{links.map(({ text, url }, index) => ( | ||
// `index` is necessary in the key because url can repeat | ||
// eslint-disable-next-line react/no-array-index-key | ||
<Menu.Item key={`${url}-${index}`}> | ||
<LinkValue href={url}>{text}</LinkValue> | ||
</Menu.Item> | ||
))} | ||
</Menu> | ||
); | ||
|
||
export default function ExternalLinks(props: ExternalLinksProps) { | ||
const { links } = props; | ||
if (links.length === 1) { | ||
return <LinkValue href={links[0].url} title={links[0].text} className="TracePageHeader--back" />; | ||
} | ||
return ( | ||
<Dropdown overlay={linkValueList(links)} placement="bottomRight" trigger={['click']}> | ||
<a className="TracePageHeader--back"> | ||
<NewWindowIcon isLarge /> | ||
</a> | ||
</Dropdown> | ||
); | ||
} |
This file contains 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 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 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,55 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { orderTags, deduplicateTags } from './transform-trace-data'; | ||
|
||
describe('orderTags()', () => { | ||
it('correctly orders tags', () => { | ||
const orderedTags = orderTags( | ||
[ | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'http.Status_code', value: '200' }, | ||
{ key: 'z.ip', value: '8.8.8.16' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
{ key: 'http.message', value: 'ok' }, | ||
], | ||
['z.', 'a.', 'HTTP.'] | ||
); | ||
expect(orderedTags).toEqual([ | ||
{ key: 'z.ip', value: '8.8.8.16' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
{ key: 'http.message', value: 'ok' }, | ||
{ key: 'http.Status_code', value: '200' }, | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('deduplicateTags()', () => { | ||
it('deduplicates tags', () => { | ||
const tagsInfo = deduplicateTags([ | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'b.ip', value: '8.8.8.8' }, | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
]); | ||
|
||
expect(tagsInfo.tags).toEqual([ | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'b.ip', value: '8.8.8.8' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
]); | ||
expect(tagsInfo.warnings).toEqual(['Duplicate tag "b.ip:8.8.4.4"']); | ||
}); | ||
}); |
This file contains 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.