-
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
Changes from 10 commits
755b1d4
df6f51b
407f1f7
af12460
5168c6e
c46d954
02dc925
fe9df64
cc48630
7bdc815
98ca290
e23f6a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright (c) 2018 Uber Technologies, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.TracePageSearchBar { | ||
max-width: 20rem; | ||
} | ||
|
||
.TracePageSearchBar--bar { | ||
display: flex; | ||
max-width: 20rem; | ||
} | ||
|
||
.TracePageSearchBar--count { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm |
||
opacity: 0.6; | ||
} | ||
|
||
.TracePageSearchBar--btn { | ||
transition: 0.2s; | ||
} | ||
|
||
.TracePageSearchBar--btn.is-disabled { | ||
opacity: 0.5; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// @flow | ||
|
||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as React from 'react'; | ||
import { Button, Input } from 'antd'; | ||
|
||
import * as markers from './TracePageSearchBar.markers'; | ||
|
||
import './TracePageSearchBar.css'; | ||
|
||
type TracePageSearchBarProps = { | ||
updateTextFilter: string => void, | ||
textFilter: string, | ||
prevResult: () => void, | ||
nextResult: () => void, | ||
clearSearch: () => void, | ||
resultCount: number, | ||
}; | ||
|
||
function TracePageSearchBar(props: TracePageSearchBarProps, ref: any) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Did you get a chance to try this without the |
||
) : null; | ||
|
||
const updateFilter = event => updateTextFilter(event.target.value); | ||
const onKeyDown = e => { | ||
if (e.keyCode === 27) clearSearch(); | ||
}; | ||
|
||
const btnClass = `TracePageSearchBar--btn${textFilter ? '' : ' is-disabled'}`; | ||
|
||
return ( | ||
<div className="ub-flex-auto ub-mr2 TracePageSearchBar"> | ||
{/* style inline because compact overwrites the display */} | ||
<Input.Group compact style={{ display: 'flex' }}> | ||
<Input | ||
name="search" | ||
className="TracePageSearchBar--bar ub-flex-auto" | ||
placeholder="Search..." | ||
onChange={updateFilter} | ||
value={textFilter} | ||
data-test={markers.IN_TRACE_SEARCH} | ||
suffix={count} | ||
ref={ref} | ||
onKeyDown={onKeyDown} | ||
onPressEnter={nextResult} | ||
/> | ||
<Button className={btnClass} disabled={!textFilter} icon="up" onClick={prevResult} /> | ||
<Button className={btnClass} disabled={!textFilter} icon="down" onClick={nextResult} /> | ||
<Button className={btnClass} disabled={!textFilter} icon="close" onClick={clearSearch} /> | ||
</Input.Group> | ||
</div> | ||
); | ||
} | ||
|
||
// ghetto fabulous cast because the 16.3 API is not in flow yet | ||
// https://github.com/facebook/flow/issues/6103 | ||
export default (React: any).forwardRef(TracePageSearchBar); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import * as markers from './TracePageSearchBar.markers'; | ||
import TracePageSearchBar from './TracePageSearchBar'; | ||
|
||
describe('<TracePageSearchBar>', () => { | ||
const defaultProps = { | ||
updateTextFilter: () => {}, | ||
textFilter: 'something', | ||
prevResult: () => {}, | ||
nextResult: () => {}, | ||
resultCount: 0, | ||
}; | ||
|
||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<TracePageSearchBar {...defaultProps} />); | ||
}); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
const props = { ...defaultProps, updateTextFilter }; | ||
wrapper = shallow(<TracePageSearchBar {...props} />); | ||
const event = { target: { value: 'my new value' } }; | ||
wrapper | ||
.find(`[data-test="${markers.IN_TRACE_SEARCH}"]`) | ||
.first() | ||
.simulate('change', event); | ||
expect(updateTextFilter.calledWith('my new value')).toBeTruthy(); | ||
}); | ||
|
||
it('renders the search bar', () => { | ||
expect(wrapper.find('Input').length).toBe(1); | ||
}); | ||
|
||
it('renders the buttons', () => { | ||
expect(wrapper.find('Button').length).toBe(3); | ||
}); | ||
}); |
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
: