Skip to content

Commit

Permalink
SelectPopover improvements (Graylog2#4697)
Browse files Browse the repository at this point in the history
* Add disabled prop to SelectPopover

* Fix condition to update state when prop changes
  • Loading branch information
edmundoa authored and Marius Sturm committed Apr 3, 2018
1 parent 921d04d commit 5d7e0eb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions graylog2-web-interface/src/components/common/SelectPopover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const SelectPopover = createReactClass({
filterPlaceholder: PropTypes.string,
/** Text to display in the entry to clear the current selection. */
clearSelectionText: PropTypes.string,
/** Indicates whether items will be clickable or not. */
disabled: PropTypes.bool,
},

getDefaultProps() {
Expand All @@ -64,6 +66,7 @@ const SelectPopover = createReactClass({
displayDataFilter: true,
filterPlaceholder: 'Type to filter',
clearSelectionText: 'Clear selection',
disabled: false,
};
},

Expand All @@ -76,7 +79,7 @@ const SelectPopover = createReactClass({
},

componentWillReceiveProps(nextProps) {
if (lodash.isEqual(this.props.selectedItems, nextProps.selectedItems)) {
if (!lodash.isEqual(this.props.selectedItems, nextProps.selectedItems)) {
this.setState({ selectedItems: nextProps.selectedItems });
}
if (this.props.items !== nextProps.items) {
Expand Down Expand Up @@ -140,7 +143,7 @@ const SelectPopover = createReactClass({
},

render() {
const { displayDataFilter, itemFormatter, items, placement, triggerAction, triggerNode, ...otherProps } = this.props;
const { displayDataFilter, itemFormatter, items, placement, triggerAction, triggerNode, disabled, ...otherProps } = this.props;
const popoverProps = this.pickPopoverProps(otherProps);
const { filteredItems, selectedItems } = this.state;

Expand All @@ -153,8 +156,9 @@ const SelectPopover = createReactClass({
{filteredItems.map((item) => {
return (
<ListGroupItem key={item}
onClick={this.handleItemSelection(item)}
active={this.state.selectedItems.includes(item)}>
onClick={disabled ? () => {} : this.handleItemSelection(item)}
active={this.state.selectedItems.includes(item)}
disabled={disabled}>
{itemFormatter(item)}
</ListGroupItem>
);
Expand Down

0 comments on commit 5d7e0eb

Please sign in to comment.