Skip to content

Instantly share code, notes, and snippets.

@gpbaculio
Last active January 23, 2018 16:33
Show Gist options
  • Save gpbaculio/433f194f0985295de0b5e4f518424b0e to your computer and use it in GitHub Desktop.
Save gpbaculio/433f194f0985295de0b5e4f518424b0e to your computer and use it in GitHub Desktop.
onExchangeClick(operand) {
this.setState((state) => {
const exchangeColumn = state.filters.find(filter => filter.column === 'exchange');
if (exchangeColumn.operand.indexOf(operand) === -1) {
return ({
filters: [
...state.filters.filter(f => f.column !== 'exchange'), // this will return other elements of filters array that has no column = exchange
{ ...exchangeColumn, operand: [...exchangeColumn.operand, operand] },
],
});
}
return ({
filters: [
...state.filters.filter(f => f.column !== 'exchange'),
{ ...exchangeColumn, operand: [...exchangeColumn.operand].filter(o => o !== operand) },
],
});
}, () => {
const { filters } = this.state;
this.executeSignalsQuery(filters);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment