Skip to content

Commit b8986b3

Browse files
[AccordianKeyValues]: replace defaultProps with destructuring (jaegertracing#2667)
## Which problem is this PR solving? - Part of jaegertracing#2596 ## Description of the changes - removed defaultProps from AccordianKeyValues ## How was this change tested? - npm ci - npm test ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Abhishek <[email protected]>
1 parent 655f2b7 commit b8986b3

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

Diff for: packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanDetail/AccordianKeyValues.test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ describe('<KeyValuesSummary>', () => {
5555

5656
describe('<AccordianKeyValues>', () => {
5757
let wrapper;
58+
const mockToggle = jest.fn();
5859

5960
const props = {
6061
compact: false,
6162
data: tags,
6263
highContrast: false,
6364
isOpen: false,
6465
label: 'le-label',
65-
onToggle: jest.fn(),
66+
onToggle: mockToggle,
6667
};
6768

6869
beforeEach(() => {
@@ -74,6 +75,28 @@ describe('<AccordianKeyValues>', () => {
7475
expect(wrapper.exists()).toBe(true);
7576
});
7677

78+
it('calls onToggle when clicked', () => {
79+
wrapper.find('.AccordianKeyValues--header').simulate('click');
80+
expect(mockToggle).toHaveBeenCalled();
81+
});
82+
83+
it('does not call onToggle if interactive is false', () => {
84+
mockToggle.mockClear();
85+
wrapper.setProps({ interactive: false });
86+
wrapper.update();
87+
wrapper.find('.AccordianKeyValues--header').simulate('click');
88+
expect(mockToggle).not.toHaveBeenCalled();
89+
});
90+
91+
it('does not apply high contrast styles by default', () => {
92+
expect(wrapper.find('.AccordianKeyValues--header').hasClass('is-high-contrast')).toBe(false);
93+
});
94+
95+
it('applies high contrast styles when highContrast is true', () => {
96+
wrapper.setProps({ highContrast: true });
97+
expect(wrapper.find('.AccordianKeyValues--header').hasClass('is-high-contrast')).toBe(true);
98+
});
99+
77100
it('renders the label', () => {
78101
const header = wrapper.find(`[data-test="${markers.LABEL}"]`);
79102
expect(header.length).toBe(1);

Diff for: packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/SpanDetail/AccordianKeyValues.tsx

+20-26
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,8 @@ import { KeyValuePair, Link } from '../../../../types/trace';
2323

2424
import './AccordianKeyValues.css';
2525

26-
type AccordianKeyValuesProps = {
27-
className?: string | TNil;
28-
data: KeyValuePair[];
29-
highContrast?: boolean;
30-
interactive?: boolean;
31-
isOpen: boolean;
32-
label: string;
33-
linksGetter: ((pairs: KeyValuePair[], index: number) => Link[]) | TNil;
34-
onToggle?: null | (() => void);
35-
};
36-
3726
// export for tests
38-
export function KeyValuesSummary(props: { data?: KeyValuePair[] }) {
39-
const { data } = props;
27+
export function KeyValuesSummary({ data }: { data: KeyValuePair[] }) {
4028
if (!Array.isArray(data) || !data.length) {
4129
return null;
4230
}
@@ -55,12 +43,25 @@ export function KeyValuesSummary(props: { data?: KeyValuePair[] }) {
5543
);
5644
}
5745

58-
KeyValuesSummary.defaultProps = {
59-
data: null,
60-
};
61-
62-
export default function AccordianKeyValues(props: AccordianKeyValuesProps) {
63-
const { className, data, highContrast, interactive, isOpen, label, linksGetter, onToggle } = props;
46+
export default function AccordianKeyValues({
47+
className = null,
48+
data,
49+
highContrast = false,
50+
interactive = true,
51+
isOpen,
52+
label,
53+
linksGetter,
54+
onToggle = null,
55+
}: {
56+
className?: string | TNil;
57+
data: KeyValuePair[];
58+
highContrast?: boolean;
59+
interactive?: boolean;
60+
isOpen: boolean;
61+
label: string;
62+
linksGetter: ((pairs: KeyValuePair[], index: number) => Link[]) | TNil;
63+
onToggle?: null | (() => void);
64+
}) {
6465
const isEmpty = !Array.isArray(data) || !data.length;
6566
const iconCls = cx('u-align-icon', { 'AccordianKeyValues--emptyIcon': isEmpty });
6667
let arrow: React.ReactNode | null = null;
@@ -94,10 +95,3 @@ export default function AccordianKeyValues(props: AccordianKeyValuesProps) {
9495
</div>
9596
);
9697
}
97-
98-
AccordianKeyValues.defaultProps = {
99-
className: null,
100-
highContrast: false,
101-
interactive: true,
102-
onToggle: null,
103-
};

0 commit comments

Comments
 (0)