-
Notifications
You must be signed in to change notification settings - Fork 483
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
Span Search - Add result count, navigation and clear buttons #234
Conversation
Screen shots please |
bonus points if you screen shot your IDE with the code instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davit-y Great work! Definitely a huge improvement! 🎉
Regarding the aesthetics, right now the disabled state has quite a bit of visual weight. I would say it would be preferable to lighten it up, if possible?
I left a number of small comments in the code. What do you think?
@@ -30,14 +29,18 @@ import { formatDatetime, formatDuration } from '../../utils/date'; | |||
import prefixUrl from '../../utils/prefix-url'; | |||
|
|||
import './TracePageHeader.css'; | |||
import TracePageSearchBar from './TracePageSearchBar'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this import to fall after TracePageHeader.track.
Imports are sorted alphabetically with more dots under less dots and css files that are imported for the side effect go below the other imports. Also, external packages go above local resources, separated by a blank line, with react going above others.
import * as React from 'react';
import extA from 'a';
import extB from 'b';
import a from './a';
import z from './z';
import b from '../b';
import 'a.css';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, forgot to push my commit
onChange={event => updateTextFilter(event.target.value)} | ||
defaultValue={textFilter} | ||
data-test={markers.IN_TRACE_SEARCH} | ||
<div className="ub-flex-auto ub-mr2 TracePageHeader--search"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this wrapping <div>
into the TracePageSearchBar
component.
resultCount: number, | ||
}; | ||
|
||
type TracePageSearchBarState = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need state? this.props.textFilter
should be all you need.
|
||
return ( | ||
<Input.Group compact style={{ display: 'flex' }}> | ||
<Input // ^ inline because compact overwrites the display |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the comment above the line it refers to.
render() { | ||
const { prevResult, nextResult, resultCount } = this.props; | ||
|
||
const count = this.state.textFilter ? <span>{resultCount.toString()}</span> : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the .toString()
call here is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's preferable for the suffix to have less contrast than the input text:
const count = ... ? <span className="u-tx-muted">{resultCount}</span> : null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the .toString()
makes sure that "0" shows up, otherwise it's interpreted as null
I had wrapped with a span to add formatting, but forgot. u-tx-muted
didn't seem to work so I created a style that drops the opacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good to know. But, looks like 0
is working ok with the suffix?
}; | ||
} | ||
|
||
updateTextFilter = (textFilter: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change this to take the event as the parameter you do not need to create a function as the handler on every render.
/> | ||
<Button disabled={!this.state.textFilter} icon="up" onClick={prevResult} /> | ||
<Button disabled={!this.state.textFilter} icon="down" onClick={nextResult} /> | ||
<Button disabled={!this.state.textFilter} icon="close" onClick={() => this.updateTextFilter('')} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend creating a method clearFilter = () => { ... }
instead of creating a function on every render.
@@ -45,6 +45,7 @@ import type { Config } from '../../types/config'; | |||
import prefixUrl from '../../utils/prefix-url'; | |||
|
|||
import './index.css'; | |||
import getFilteredSpans from './TraceTimelineViewer/get-filtered-spans'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this file needs to be in the ./TraceTimelineViewer/
folder anymore?
@@ -278,6 +291,9 @@ export default class TracePage extends React.PureComponent<TracePageProps, Trace | |||
traceID={traceID} | |||
onSlimViewClicked={this.toggleSlimView} | |||
textFilter={textFilter} | |||
prevResult={this.prevResult} | |||
nextResult={this.nextResult} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the use of methods is needed for the scroll props, e.g.
prevResult={this._scrollManager.scrollToPrevVisibleSpan}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially did this to set up the next PR where the buttons move one result at a time, but that will probably just live in the scrollManager too so I'll get rid of the methods.
trackFilter(textFilter); | ||
this.setState({ textFilter }); | ||
const findMatchesIDs = getFilteredSpans(this.props.trace, textFilter.trim()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend setting findMatchesIDs
to null
if !textFilter.trim()
...
nextResult: () => {}, | ||
resultCount: 0, | ||
}; | ||
wrapper = shallow(<TracePageSearchBar {...searchBarProps} />); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should be in TracePageSearchBar.test.js
?
max-width: 20rem; | ||
} | ||
|
||
.TracePageSearchBar--count { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the u-tx-muted
CSS utility class too dark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm
transition: 0.5s; | ||
} | ||
|
||
.TracePageSearchBar--btn-hide { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, please change the selector to something like .TracePageSearchBar--btn.is-*
where *
describes the state, e.g. .DiffNode--labelCell.is-added
.
render() { | ||
const { prevResult, nextResult, resultCount } = this.props; | ||
|
||
const count = this.state.textFilter ? <span>{resultCount.toString()}</span> : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good to know. But, looks like 0
is working ok with the suffix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adjusting the contrast on the buttons!
Left a couple of comments. What do you think?
max-width: 20rem; | ||
} | ||
|
||
.TracePageSearchBar--count { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm
trackFilter(textFilter); | ||
this.setState({ textFilter }); | ||
this.setState({ findMatchesIDs }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These setState calls should be grouped into one call: this.setState({ a, b });
@@ -61,7 +62,8 @@ type TracePageProps = { | |||
type TracePageState = { | |||
headerHeight: ?number, | |||
slimView: boolean, | |||
textFilter: ?string, | |||
textFilter: string, | |||
findMatchesIDs: ?Set<string>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment about this component, the filter needs to be updated when the traceID changes, similar to the time range:
if (!(trace instanceof Error) && (!prevTrace || prevTrace.traceID !== trace.traceID)) {
this.updateViewRangeTime(0, 1);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -278,6 +292,9 @@ export default class TracePage extends React.PureComponent<TracePageProps, Trace | |||
traceID={traceID} | |||
onSlimViewClicked={this.toggleSlimView} | |||
textFilter={textFilter} | |||
prevResult={this._scrollManager.scrollToPrevVisibleSpan} | |||
nextResult={this._scrollManager.scrollToNextVisibleSpan} | |||
resultCount={this.state.findMatchesIDs ? this.state.findMatchesIDs.size : 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend destructing findMatchesIDs
, similar to the other state value:
const { slimView, headerHeight, textFilter, viewRange } = this.state;
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
Signed-off-by: Davit Yeghshatyan <[email protected]>
70c2f60
to
cc48630
Compare
Signed-off-by: Davit Yeghshatyan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress. A couple of small notes.
Also, there are 17 failing tests. Please take a look:
https://travis-ci.org/jaegertracing/jaeger-ui/builds/417057052#L2833
@@ -86,7 +90,7 @@ export const HEADER_ITEMS = [ | |||
}, | |||
]; | |||
|
|||
export default function TracePageHeader(props: TracePageHeaderProps) { | |||
function TracePageHeader(props: TracePageHeaderProps, ref: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend using the following type instead of any
:
import { Input } from 'antd';
// ...
ref: { current: Input | null }
const { prevResult, nextResult, clearSearch, resultCount, updateTextFilter, textFilter } = props; | ||
|
||
const count = textFilter ? ( | ||
<span className="TracePageSearchBar--count">{resultCount.toString()}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get a chance to try this without the .toString()
? React should render the zero.
}); | ||
|
||
it('calls updateTextFilter() function for onChange of the input', () => { | ||
const updateTextFilter = sinon.spy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use jest.fn()
instead of sinon.spy()
.
@@ -36,8 +36,8 @@ type TraceTimelineViewerProps = { | |||
collapseOne: (Span[]) => void, | |||
expandAll: () => void, | |||
expandOne: (Span[]) => void, | |||
findMatchesIDs: Set<string>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this value can be null, then the type should be Set<string> | null
@@ -99,6 +101,7 @@ export class TracePageImpl extends React.PureComponent<TracePageProps, TracePage | |||
state: TracePageState; | |||
|
|||
_headerElm: ?Element; | |||
_searchBar: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend using the following type instead of any
:
import { Input } from 'antd';
// ...
ref: { current: Input | null }
@@ -64,6 +67,8 @@ export const kbdMappings = { | |||
expandAll: '[', | |||
collapseOne: 'p', | |||
expandOne: 'o', | |||
searchSpans: 'ctrl+b', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, why not use meta
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keyboard handler adds the inputted character to the input. Meta+b outputs a character, while ctrl+b does not.
A work around to use meta is to remove all instances of the '∫' char from the input string, but I didn't want to clutter the code. I tried having the textFilter shortened by 1 char after the event goes off, but unfortunately the input box receives the char after the completion of the event.
Signed-off-by: Davit Yeghshatyan <[email protected]>
cbba4ee
to
98ca290
Compare
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
=========================================
- Coverage 78.61% 77.6% -1.01%
=========================================
Files 135 135
Lines 2927 2934 +7
Branches 607 608 +1
=========================================
- Hits 2301 2277 -24
- Misses 495 520 +25
- Partials 131 137 +6
Continue to review full report at Codecov.
|
Signed-off-by: Davit Yeghshatyan <[email protected]>
534ab63
to
e23f6a1
Compare
Looks great. Thanks for the hard work! |
@yurishkuro, can you merge this PR? I'll take care of the test coverage when I address test coverage in trace comparison. |
…racing#234) * Add result count, navigation and clear buttons Signed-off-by: Davit Yeghshatyan <[email protected]> * Correct imports Signed-off-by: Davit Yeghshatyan <[email protected]> * Move and delete files Signed-off-by: Davit Yeghshatyan <[email protected]> * Review fixes Signed-off-by: Davit Yeghshatyan <[email protected]> * Fix TracePageHeader test Signed-off-by: Davit Yeghshatyan <[email protected]> * Lighten buttons when disabled Signed-off-by: Davit Yeghshatyan <[email protected]> * Review fixes Signed-off-by: Davit Yeghshatyan <[email protected]> * Fix tests Signed-off-by: Davit Yeghshatyan <[email protected]> * Add shortcuts Signed-off-by: Davit Yeghshatyan <[email protected]> * Fix merge changes Signed-off-by: Davit Yeghshatyan <[email protected]> * Fix TracePageHeader and TracePageSearchBar tests Signed-off-by: Davit Yeghshatyan <[email protected]> * Delay TracePageHeader testing until release of Enzyme v3.5.0 Signed-off-by: Davit Yeghshatyan <[email protected]> Signed-off-by: vvvprabhakar <[email protected]>
Which problem is this PR solving?
Short description of the changes
TODO: