Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Trigger accounts/contracts search on search input change #2838

Merged
merged 8 commits into from
Oct 24, 2016
49 changes: 26 additions & 23 deletions js/src/ui/Actionbar/Search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,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 () {
Expand Down Expand Up @@ -127,10 +131,6 @@ export default class ActionbarSearch extends Component {

const newSearchTokens = uniq([].concat(tokens, value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens.concat(value)?

Copy link
Contributor Author

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 the PropTypes Object


this.setState({
inputValue: ''
});

this.handleSearchChange(newSearchTokens);
}

Expand All @@ -141,10 +141,6 @@ export default class ActionbarSearch extends Component {
.concat(tokens)
.filter(v => v !== value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newSearchTokens = tokens.filter((v) => v !== value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


this.setState({
inputValue: ''
});

this.handleSearchChange(newSearchTokens);
this.refs.searchInput.focus();
}
Expand All @@ -154,27 +150,34 @@ export default class ActionbarSearch extends Component {

const inputValue = (splitTokens.length <= 1)
? value
: splitTokens.slice(-1)[0];

if (splitTokens.length > 1) {
const tokensToAdd = splitTokens.slice(0, -1);
tokensToAdd.forEach(token => this.handleTokenAdd(token));
}
: splitTokens.slice(-1)[0].trim();

this.refs.searchInput.setState({ inputValue });
this.setState({ inputValue });

if (inputValue && inputValue.length > 0) {
const { tokens, onChange } = this.props;
onChange(tokens, [].concat(tokens, inputValue));
}
this.setState({ inputValue }, () => {
if (splitTokens.length > 1) {
const tokensToAdd = splitTokens.slice(0, -1);
tokensToAdd.forEach(token => this.handleTokenAdd(token));
} else {
this.handleSearchChange();
}
});
}

handleSearchChange = (searchTokens) => {
const { onChange } = this.props;
const newSearchTokens = searchTokens.filter(v => v.length > 0);
const { onChange, tokens } = this.props;
const { inputValue } = this.state;

const newSearchTokens = []
.concat(searchTokens || tokens)
.filter(v => v.length > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newSearchTokens = (searchTokens || tokens).filter(v => v.length > 0)?


const newSearchValues = []
.concat(searchTokens || tokens, inputValue)
.filter(v => v.length > 0);

console.log('handleSearchChange', newSearchTokens, newSearchValues);

onChange(newSearchTokens, newSearchTokens);
onChange(newSearchTokens, newSearchValues);
}

handleSearchClick = () => {
Expand Down
2 changes: 1 addition & 1 deletion js/src/views/Accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Accounts extends Component {
onAddSearchToken = (token) => {
const { searchTokens } = this.state;
const newSearchTokens = uniq([].concat(searchTokens, token));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searchValues.concat(token)?

this.setState({ searchTokens: newSearchTokens });
this.setState({ searchTokens: newSearchTokens, searchValues: newSearchTokens });
}

onNewAccountClick = () => {
Expand Down