-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Trigger accounts/contracts search on search input change #2838
Changes from all commits
e522ac2
f44f0a3
5ae25d5
78f234f
957b834
4ae357d
cbd8df8
bc3319e
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 |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React, { Component, PropTypes } from 'react'; | ||
import { Chip } from 'material-ui'; | ||
import { blue300 } from 'material-ui/styles/colors'; | ||
// import ChipInput from 'material-ui-chip-input'; | ||
import ChipInput from 'material-ui-chip-input/src/ChipInput'; | ||
import ActionSearch from 'material-ui/svg-icons/action/search'; | ||
|
@@ -43,6 +45,10 @@ export default class ActionbarSearch extends Component { | |
if (tokens.length > 0 && this.props.tokens.length === 0) { | ||
this.handleOpenSearch(true, true); | ||
} | ||
|
||
if (tokens.length !== this.props.tokens.length) { | ||
this.handleSearchChange(tokens); | ||
} | ||
} | ||
|
||
componentWillUnmount () { | ||
|
@@ -71,16 +77,26 @@ export default class ActionbarSearch extends Component { | |
<ChipInput | ||
clearOnBlur={ false } | ||
className={ styles.input } | ||
chipRenderer={ this.chipRenderer } | ||
hintText='Enter search input...' | ||
hintStyle={ { | ||
transition: 'none' | ||
} } | ||
ref='searchInput' | ||
value={ tokens } | ||
onBlur={ this.handleSearchBlur } | ||
onRequestAdd={ this.handleTokenAdd } | ||
onRequestDelete={ this.handleTokenDelete } | ||
onUpdateInput={ this.handleInputChange } /> | ||
onUpdateInput={ this.handleInputChange } | ||
hintStyle={ { | ||
bottom: 16, | ||
left: 2, | ||
transition: 'none' | ||
} } | ||
inputStyle={ { | ||
marginBottom: 18 | ||
} } | ||
textFieldStyle={ { | ||
height: 42 | ||
} } | ||
/> | ||
</div> | ||
|
||
<Button | ||
|
@@ -92,42 +108,83 @@ export default class ActionbarSearch extends Component { | |
); | ||
} | ||
|
||
chipRenderer = (state, key) => { | ||
const { value, isFocused, isDisabled, handleClick, handleRequestDelete } = state; | ||
|
||
return ( | ||
<Chip | ||
key={ key } | ||
className={ styles.chip } | ||
style={ { | ||
margin: '8px 8px 0 0', | ||
float: 'left', | ||
pointerEvents: isDisabled ? 'none' : undefined, | ||
alignItems: 'center' | ||
} } | ||
labelStyle={ { | ||
paddingRight: 6, | ||
fontSize: '0.9rem', | ||
lineHeight: 'initial' | ||
} } | ||
backgroundColor={ isFocused ? blue300 : 'rgba(0, 0, 0, 0.73)' } | ||
onTouchTap={ handleClick } | ||
onRequestDelete={ handleRequestDelete } | ||
> | ||
{ value } | ||
</Chip> | ||
); | ||
} | ||
|
||
handleTokenAdd = (value) => { | ||
const { tokens } = this.props; | ||
|
||
const newSearchValues = uniq([].concat(tokens, value)); | ||
|
||
this.setState({ | ||
inputValue: '' | ||
}); | ||
const newSearchTokens = uniq([].concat(tokens, value)); | ||
|
||
this.handleSearchChange(newSearchValues); | ||
this.handleSearchChange(newSearchTokens); | ||
} | ||
|
||
handleTokenDelete = (value) => { | ||
const { tokens } = this.props; | ||
|
||
const newSearchValues = [] | ||
const newSearchTokens = [] | ||
.concat(tokens) | ||
.filter(v => v !== value); | ||
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.
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. Same as above |
||
|
||
this.setState({ | ||
inputValue: '' | ||
}); | ||
|
||
this.handleSearchChange(newSearchValues); | ||
this.handleSearchChange(newSearchTokens); | ||
this.refs.searchInput.focus(); | ||
} | ||
|
||
handleInputChange = (value) => { | ||
this.setState({ inputValue: value }); | ||
const splitTokens = value.split(/[\s,;]/); | ||
|
||
const inputValue = (splitTokens.length <= 1) | ||
? value | ||
: splitTokens.slice(-1)[0].trim(); | ||
|
||
this.refs.searchInput.setState({ inputValue }); | ||
this.setState({ inputValue }, () => { | ||
if (splitTokens.length > 1) { | ||
const tokensToAdd = splitTokens.slice(0, -1); | ||
tokensToAdd.forEach(token => this.handleTokenAdd(token)); | ||
} else { | ||
this.handleSearchChange(); | ||
} | ||
}); | ||
} | ||
|
||
handleSearchChange = (searchValues) => { | ||
const { onChange } = this.props; | ||
const newSearchValues = searchValues.filter(v => v.length > 0); | ||
handleSearchChange = (searchTokens) => { | ||
const { onChange, tokens } = this.props; | ||
const { inputValue } = this.state; | ||
|
||
const newSearchTokens = [] | ||
.concat(searchTokens || tokens) | ||
.filter(v => v.length > 0); | ||
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.
|
||
|
||
const newSearchValues = [] | ||
.concat(searchTokens || tokens, inputValue) | ||
.filter(v => v.length > 0); | ||
|
||
onChange(newSearchValues); | ||
onChange(newSearchTokens, newSearchValues); | ||
} | ||
|
||
handleSearchClick = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ class Accounts extends Component { | |
addressBook: false, | ||
newDialog: false, | ||
sortOrder: '', | ||
searchValues: [] | ||
searchValues: [], | ||
searchTokens: [] | ||
} | ||
|
||
render () { | ||
|
@@ -69,14 +70,14 @@ class Accounts extends Component { | |
} | ||
|
||
renderSearchButton () { | ||
const onChange = (searchValues) => { | ||
this.setState({ searchValues }); | ||
const onChange = (searchTokens, searchValues) => { | ||
this.setState({ searchTokens, searchValues }); | ||
}; | ||
|
||
return ( | ||
<ActionbarSearch | ||
key='searchAccount' | ||
tokens={ this.state.searchValues } | ||
tokens={ this.state.searchTokens } | ||
onChange={ onChange } /> | ||
); | ||
} | ||
|
@@ -136,9 +137,9 @@ class Accounts extends Component { | |
} | ||
|
||
onAddSearchToken = (token) => { | ||
const { searchValues } = this.state; | ||
const newSearchValues = uniq([].concat(searchValues, token)); | ||
this.setState({ searchValues: newSearchValues }); | ||
const { searchTokens } = this.state; | ||
const newSearchTokens = uniq([].concat(searchTokens, token)); | ||
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.
|
||
this.setState({ searchTokens: newSearchTokens }); | ||
} | ||
|
||
onNewAccountClick = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,8 @@ class Addresses extends Component { | |
state = { | ||
showAdd: false, | ||
sortOrder: '', | ||
searchValues: [] | ||
searchValues: [], | ||
searchTokens: [] | ||
} | ||
|
||
render () { | ||
|
@@ -79,14 +80,14 @@ class Addresses extends Component { | |
} | ||
|
||
renderSearchButton () { | ||
const onChange = (searchValues) => { | ||
this.setState({ searchValues }); | ||
const onChange = (searchTokens, searchValues) => { | ||
this.setState({ searchTokens, searchValues }); | ||
}; | ||
|
||
return ( | ||
<ActionbarSearch | ||
key='searchAddress' | ||
tokens={ this.state.searchValues } | ||
tokens={ this.state.searchTokens } | ||
onChange={ onChange } /> | ||
); | ||
} | ||
|
@@ -127,9 +128,9 @@ class Addresses extends Component { | |
} | ||
|
||
onAddSearchToken = (token) => { | ||
const { searchValues } = this.state; | ||
const newSearchValues = uniq([].concat(searchValues, token)); | ||
this.setState({ searchValues: newSearchValues }); | ||
const { searchTokens } = this.state; | ||
const newSearchTokens = uniq([].concat(searchTokens, token)); | ||
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.
|
||
this.setState({ searchTokens: newSearchTokens }); | ||
} | ||
|
||
onOpenAdd = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,8 @@ class Contracts extends Component { | |
addContract: false, | ||
deployContract: false, | ||
sortOrder: '', | ||
searchValues: [] | ||
searchValues: [], | ||
searchTokens: [] | ||
} | ||
|
||
render () { | ||
|
@@ -84,14 +85,14 @@ class Contracts extends Component { | |
} | ||
|
||
renderSearchButton () { | ||
const onChange = (searchValues) => { | ||
this.setState({ searchValues }); | ||
const onChange = (searchTokens, searchValues) => { | ||
this.setState({ searchTokens, searchValues }); | ||
}; | ||
|
||
return ( | ||
<ActionbarSearch | ||
key='searchContract' | ||
tokens={ this.state.searchValues } | ||
tokens={ this.state.searchTokens } | ||
onChange={ onChange } /> | ||
); | ||
} | ||
|
@@ -152,9 +153,9 @@ class Contracts extends Component { | |
} | ||
|
||
onAddSearchToken = (token) => { | ||
const { searchValues } = this.state; | ||
const newSearchValues = uniq([].concat(searchValues, token)); | ||
this.setState({ searchValues: newSearchValues }); | ||
const { searchTokens } = this.state; | ||
const newSearchTokens = uniq([].concat(searchTokens, token)); | ||
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.
|
||
this.setState({ searchTokens: newSearchTokens }); | ||
} | ||
|
||
onDeployContractClose = () => { | ||
|
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.
tokens.concat(value)
?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.
That's just in case tokens isn't really an
Array
, but I guess that's taken care of by thePropTypes
Object