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

Replace deprecated ant-design props from ReferenceButton and KeyValuesTable #1864

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import { Menu, Dropdown, Tooltip } from 'antd';
import { Dropdown, Tooltip } from 'antd';

import ReferencesButton from './ReferencesButton';
import transformTraceData from '../../../model/transform-trace-data';
Expand Down Expand Up @@ -66,14 +66,11 @@ describe(ReferencesButton, () => {
const wrapper = shallow(<ReferencesButton {...props} />);
const dropdown = wrapper.find(Dropdown);
expect(dropdown.length).toBe(1);
const menuInstance = shallow(dropdown.first().props().overlay).dive();
const submenuItems = menuInstance.find(Menu.Item);
const submenuItems = dropdown.prop('menu').items;
expect(submenuItems.length).toBe(3);
submenuItems.forEach((submenuItem, i) => {
expect(submenuItem.find(ReferenceLink).prop('reference')).toBe(moreReferences[i]);
expect(submenuItem.label.props.reference).toBe(moreReferences[i]);
});
expect(submenuItems.at(2).find(ReferenceLink).childAt(0).text()).toBe(
`(another trace) - ${moreReferences[2].spanID}`
);
expect(submenuItems[2].label.props.children[0]).toBe(`(another trace) - ${moreReferences[2].spanID}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import React from 'react';
import { Dropdown, Menu, Tooltip } from 'antd';
import { Dropdown, Tooltip } from 'antd';
import { TooltipPlacement } from 'antd/lib/tooltip';
import NewWindowIcon from '../../common/NewWindowIcon';
import { SpanReference } from '../../../types/trace';
Expand All @@ -28,28 +28,30 @@ type TReferencesButtonProps = {
focusSpan: (spanID: string) => void;
};

// ReferencesButton is displayed as a menu at the span level.
// Example: https://github.com/jaegertracing/jaeger-ui/assets/94157520/2b29921a-2225-4a01-9018-1a1952f186ef
Comment on lines +31 to +32
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example

(Used some dummy data to visualize this component)

export default class ReferencesButton extends React.PureComponent<TReferencesButtonProps> {
referencesList = (references: SpanReference[]) => (
<Menu>
{references.map(ref => {
const { span, spanID } = ref;
return (
<Menu.Item key={`${spanID}`}>
<ReferenceLink
reference={ref}
focusSpan={this.props.focusSpan}
className="ReferencesButton--TraceRefLink"
>
{span
? `${span.process.serviceName}:${span.operationName} - ${ref.spanID}`
: `(another trace) - ${ref.spanID}`}
{!span && <NewWindowIcon />}
</ReferenceLink>
</Menu.Item>
);
})}
</Menu>
);
referencesList = (references: SpanReference[]) => {
const dropdownItems = references.map(ref => {
const { span, spanID } = ref;
return {
key: `${spanID}`,
label: (
<ReferenceLink
reference={ref}
focusSpan={this.props.focusSpan}
className="ReferencesButton--TraceRefLink"
>
{span
? `${span.process.serviceName}:${span.operationName} - ${ref.spanID}`
: `(another trace) - ${ref.spanID}`}
{!span && <NewWindowIcon />}
</ReferenceLink>
),
};
});
return dropdownItems;
};

render() {
const { references, children, tooltipText, focusSpan } = this.props;
Expand All @@ -65,7 +67,11 @@ export default class ReferencesButton extends React.PureComponent<TReferencesBut
if (references.length > 1) {
return (
<Tooltip {...tooltipProps}>
<Dropdown overlay={this.referencesList(references)} placement="bottomRight" trigger={['click']}>
<Dropdown
menu={{ items: this.referencesList(references) }}
placement="bottomRight"
trigger={['click']}
>
<a className="ReferencesButton-MultiParent">{children}</a>
</Dropdown>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ describe('<KeyValuesTable>', () => {
]
: [],
});

const anchor = wrapper.find(LinkValue);
expect(anchor).toHaveLength(1);
expect(anchor.prop('href')).toBe('http://example.com/?kind=client');
Expand All @@ -136,15 +135,14 @@ describe('<KeyValuesTable>', () => {
: [],
});
const dropdown = wrapper.find(Dropdown);
const menu = shallow(dropdown.prop('overlay')).dive();
const anchors = menu.find(LinkValue);
const anchors = dropdown.prop('menu').items;
expect(anchors).toHaveLength(2);
const firstAnchor = anchors.first();
expect(firstAnchor.prop('href')).toBe('http://example.com/1?kind=client');
expect(firstAnchor.children().text()).toBe('Example 1');
const secondAnchor = anchors.last();
expect(secondAnchor.prop('href')).toBe('http://example.com/2?kind=client');
expect(secondAnchor.children().text()).toBe('Example 2');
const firstAnchor = anchors[0];
expect(firstAnchor.label.props.href).toBe('http://example.com/1?kind=client');
expect(firstAnchor.label.props.children).toBe('Example 1');
const secondAnchor = anchors[anchors.length - 1];
expect(secondAnchor.label.props.href).toBe('http://example.com/2?kind=client');
expect(secondAnchor.label.props.children).toBe('Example 2');
expect(dropdown.closest('tr').find('td').first().text()).toBe('span.kind');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import { Dropdown, Menu } from 'antd';
import { Dropdown } from 'antd';
import { IoOpenOutline, IoList, IoCopyOutline } from 'react-icons/io5';
import { JsonView, allExpanded, collapseAllNested, defaultStyles } from 'react-json-view-lite';

Expand Down Expand Up @@ -110,23 +110,21 @@ LinkValue.defaultProps = {
title: '',
};

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>
);
const linkValueList = (links: Link[]) => {
const dropdownItems = links.map(({ text, url }, index) => ({
label: <LinkValue href={url}>{text}</LinkValue>,
key: `${url}-${index}`,
}));
return dropdownItems;
};

type KeyValuesTableProps = {
data: KeyValuePair[];
linksGetter: ((pairs: KeyValuePair[], index: number) => Link[]) | TNil;
};

// KeyValuesTable is displayed as a menu at span level.
// Example: https://github.com/jaegertracing/jaeger-ui/assets/94157520/b518cad9-cb37-4775-a3d6-b667a1235f89
Comment on lines +126 to +127
Copy link
Member Author

@anshgoyalevil anshgoyalevil Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example

(Used some dummy data to visualize this component)

Copy link
Member

@yurishkuro yurishkuro Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if there's only one link, do we still show the sandwich menu or the outgoing link directly? The latter would be more usable (I think it's unusual to have >1 link on a tag)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there's one link only, the link is shown directly, instead of DropDown.

if (links?.length === 1) {
valueMarkup = (
<div>
<LinkValue href={links[0].url} title={links[0].text}>
{jsonTable}
</LinkValue>
</div>
);
} else if (links && links.length > 1) {

export default function KeyValuesTable(props: KeyValuesTableProps) {
const { data, linksGetter } = props;

Expand All @@ -149,7 +147,11 @@ export default function KeyValuesTable(props: KeyValuesTableProps) {
} else if (links && links.length > 1) {
valueMarkup = (
<div>
<Dropdown overlay={linkValueList(links)} placement="bottomRight" trigger={['click']}>
<Dropdown
menu={{ items: linkValueList(links) }}
placement="bottomRight"
trigger={['click']}
>
<a>
{jsonTable} <IoList className="KeyValueTable--linkIcon" />
</a>
Expand Down