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

Span Search - Add result count, navigation and clear buttons #234

Merged
merged 12 commits into from
Sep 26, 2018

Conversation

davit-y
Copy link
Contributor

@davit-y davit-y commented Aug 13, 2018

Which problem is this PR solving?

Short description of the changes

  • Add result count
  • Add up/down arrows (call current nextVisibleSpan method)
  • Add clear button

TODO:

  • Improve aesthetics of disabled state
  • Tests
  • Add shortcuts

@black-adder
Copy link
Contributor

Screen shots please

@black-adder
Copy link
Contributor

bonus points if you screen shot your IDE with the code instead

@davit-y davit-y mentioned this pull request Aug 13, 2018
3 tasks
@davit-y davit-y changed the title Add result count, navigation and clear buttons Span Search - Add result count, navigation and clear buttons Aug 13, 2018
@davit-y
Copy link
Contributor Author

davit-y commented Aug 13, 2018

Without text filter:

screen shot 2018-08-13 at 5 48 23 pm

With text filter:

screen shot 2018-08-13 at 5 48 42 pm

Copy link
Member

@tiffon tiffon left a 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';
Copy link
Member

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';

Copy link
Contributor Author

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">
Copy link
Member

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 = {
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

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;

Copy link
Contributor Author

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.

Copy link
Member

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?

https://codesandbox.io/s/lp1r4yqz8q

};
}

updateTextFilter = (textFilter: string) => {
Copy link
Member

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('')} />
Copy link
Member

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';
Copy link
Member

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}
Copy link
Member

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}

Copy link
Contributor Author

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());
Copy link
Member

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() ...

@davit-y davit-y changed the title Span Search - Add result count, navigation and clear buttons [WIP] Span Search - Add result count, navigation and clear buttons Aug 14, 2018
@davit-y
Copy link
Contributor Author

davit-y commented Aug 14, 2018

Old disabled state:
screen shot 2018-08-13 at 5 48 23 pm

Lighter disabled state:
screen shot 2018-08-14 at 12 52 11 pm

nextResult: () => {},
resultCount: 0,
};
wrapper = shallow(<TracePageSearchBar {...searchBarProps} />);
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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?

https://codesandbox.io/s/lp1r4yqz8q

Copy link
Member

@tiffon tiffon left a 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 {
Copy link
Member

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 });
Copy link
Member

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>,
Copy link
Member

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);
    }

Copy link
Contributor Author

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}
Copy link
Member

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;

Davit Yeghshatyan added 9 commits August 16, 2018 19:30
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]>
@davit-y davit-y changed the title [WIP] Span Search - Add result count, navigation and clear buttons Span Search - Add result count, navigation and clear buttons Aug 16, 2018
Signed-off-by: Davit Yeghshatyan <[email protected]>
Copy link
Member

@tiffon tiffon left a 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) {
Copy link
Member

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>
Copy link
Member

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();
Copy link
Member

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>,
Copy link
Member

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;
Copy link
Member

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',
Copy link
Member

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 ?

Copy link
Contributor Author

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.

@codecov
Copy link

codecov bot commented Aug 24, 2018

Codecov Report

Merging #234 into master will decrease coverage by 1%.
The diff coverage is 48%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...components/TracePage/TracePageSearchBar.markers.js 100% <ø> (ø)
.../components/TracePage/TraceTimelineViewer/index.js 100% <ø> (ø) ⬆️
...c/components/TracePage/TraceTimelineViewer/duck.js 100% <ø> (ø) ⬆️
...-ui/src/components/TracePage/keyboard-shortcuts.js 81.81% <ø> (ø) ⬆️
.../src/components/TracePage/KeyboardShortcutsHelp.js 20% <ø> (-13.34%) ⬇️
...ger-ui/src/components/TracePage/TracePageHeader.js 70% <0%> (-10%) ⬇️
...cePage/TraceTimelineViewer/VirtualizedTraceView.js 93.51% <100%> (-0.35%) ⬇️
...ckages/jaeger-ui/src/components/TracePage/index.js 76.1% <28.57%> (-18.95%) ⬇️
...-ui/src/components/TracePage/TracePageSearchBar.js 75% <75%> (ø)
...ges/jaeger-ui/src/components/common/LabeledList.js 20% <0%> (-80%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d148dc5...e23f6a1. Read the comment docs.

@tiffon
Copy link
Member

tiffon commented Aug 24, 2018

Looks great. Thanks for the hard work!

@tiffon
Copy link
Member

tiffon commented Sep 25, 2018

@yurishkuro, can you merge this PR? I'll take care of the test coverage when I address test coverage in trace comparison.

@yurishkuro yurishkuro merged commit 3c6b248 into jaegertracing:master Sep 26, 2018
vvvprabhakar pushed a commit to vvvprabhakar/jaeger-ui that referenced this pull request Jul 5, 2021
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants