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

Add a Button to Reset Viewing Layer Zoom (#215) #290

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -62,3 +62,15 @@ limitations under the License.
top: 0;
user-select: none;
}

.viewRangeTimeResetButton {
everett980 marked this conversation as resolved.
Show resolved Hide resolved
display: none;
position: absolute;
right: 1%;
top: 10%;
z-index: 1;
}

.ViewingLayer:hover > .viewRangeTimeResetButton {
display: unset;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import * as React from 'react';
import cx from 'classnames';
import { Button } from 'antd';
everett980 marked this conversation as resolved.
Show resolved Hide resolved

import GraphTicks from './GraphTicks';
import Scrubber from './Scrubber';
Expand Down Expand Up @@ -224,7 +225,18 @@ export default class ViewingLayer extends React.PureComponent<ViewingLayerProps,
};

/**
* Randers the difference between where the drag started and the current
* Resets the zoom to fully zoomed out.
*
* @param {Syntheticevent<HTMLButtonElement>} event - Click event created by clicking on button.
*/
_resetTimeZoomClickHandler = (event: SyntheticEvent<HTMLButtonElement>) => {
event.stopPropagation();
everett980 marked this conversation as resolved.
Show resolved Hide resolved
event.preventDefault();
this.props.updateViewRangeTime(0, 1);
};

/**
* Renders the difference between where the drag started and the current
* position, e.g. the red or blue highlight.
*
* @returns React.Node[]
Expand Down Expand Up @@ -276,6 +288,11 @@ export default class ViewingLayer extends React.PureComponent<ViewingLayerProps,

return (
<div aria-hidden className="ViewingLayer" style={{ height }}>
{(viewStart !== 0 || viewEnd !== 1) && (
<Button onClick={this._resetTimeZoomClickHandler} className="viewRangeTimeResetButton">
Reset Selection
</Button>
)}
<svg
height={height}
className="ViewingLayer--graph"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,37 @@ describe('<SpanGraph>', () => {
});
});
});

describe('.viewRangeTimeResetButton', () => {
it('should render viewRangeResetButton if props.viewRange.time.current[0] !== 0', () => {
everett980 marked this conversation as resolved.
Show resolved Hide resolved
expect(wrapper.find('.viewRangeTimeResetButton').length).toBe(0);
wrapper.setProps({ viewRange: { time: { current: [0.1, 1] } } });
expect(wrapper.find('.viewRangeTimeResetButton').length).toBe(1);
});

it('should render viewRangeResetButton if props.viewRange.time.current[1] !== 1', () => {
expect(wrapper.find('.viewRangeTimeResetButton').length).toBe(0);
wrapper.setProps({ viewRange: { time: { current: [0, 0.9] } } });
expect(wrapper.find('.viewRangeTimeResetButton').length).toBe(1);
});

it('should call props.updateViewRangeTime and handle click event when clicked', () => {
wrapper.setProps({ viewRange: { time: { current: [0.1, 0.9] } } });
const viewRangeTimeResetButton = wrapper.find('.viewRangeTimeResetButton');
// If the test fails on the following expect statement, this may be a false negative caused
// by a regression to rendering.
expect(viewRangeTimeResetButton.length).toBe(1);

const mockEvent = {
preventDefault: jest.fn(),
stopPropagation: jest.fn(),
};
viewRangeTimeResetButton.simulate('click', mockEvent);
expect(mockEvent.preventDefault).toHaveBeenCalledTimes(1);
expect(mockEvent.stopPropagation).toHaveBeenCalledTimes(1);
expect(props.updateViewRangeTime).lastCalledWith(0, 1);
});
});
});

it('renders a <GraphTicks />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ describe('<TracePageHeaderEmbed>', () => {
wrapper.setProps({ enableDetails: true });
expect(wrapper.find(LabeledList).length).toBe(1);
});

});
6 changes: 4 additions & 2 deletions packages/jaeger-ui/src/components/TracePage/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ describe('mapStateToProps()', () => {
},
router: {
location: {
search: 'embed=v0&enableDetails&mapCollapsed&fromSearch=%2Fsearch%3Fend%3D1542902040794000%26limit%3D20%26lookback%3D1h%26maxDuration%26minDuration%26service%3Dproductpage%26start%3D1542898440794000',
search:
'embed=v0&enableDetails&mapCollapsed&fromSearch=%2Fsearch%3Fend%3D1542902040794000%26limit%3D20%26lookback%3D1h%26maxDuration%26minDuration%26service%3Dproductpage%26start%3D1542898440794000',
},
},
config: {
Expand All @@ -436,7 +437,8 @@ describe('mapStateToProps()', () => {
archiveEnabled: false,
embed: true,
enableDetails: true,
fromSearch: '/search?end=1542902040794000&limit=20&lookback=1h&maxDuration&minDuration&service=productpage&start=1542898440794000',
fromSearch:
'/search?end=1542902040794000&limit=20&lookback=1h&maxDuration&minDuration&service=productpage&start=1542898440794000',
mapCollapsed: true,
archiveTraceState: undefined,
trace: { data: {}, state: fetchedState.DONE },
Expand Down