diff --git a/public/app/core/components/TagFilter/TagBadge.tsx b/public/app/core/components/TagFilter/TagBadge.tsx index d93b5fd1e74..b00b95b70cb 100644 --- a/public/app/core/components/TagFilter/TagBadge.tsx +++ b/public/app/core/components/TagFilter/TagBadge.tsx @@ -5,17 +5,12 @@ export interface Props { label: string; removeIcon: boolean; count: number; - onClick: any; + onClick?: any; } export class TagBadge extends React.Component { constructor(props) { super(props); - this.onClick = this.onClick.bind(this); - } - - onClick(event) { - this.props.onClick(event); } render() { @@ -28,7 +23,7 @@ export class TagBadge extends React.Component { const countLabel = count !== 0 && {`(${count})`}; return ( - + {removeIcon && } {label} {countLabel} diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index a879f544da0..e86a703af6c 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -1,8 +1,13 @@ import _ from 'lodash'; import React from 'react'; -import { Async } from 'react-select'; +import AsyncSelect from 'react-select/lib/Async'; import { TagValue } from './TagValue'; import { TagOption } from './TagOption'; +import { TagBadge } from './TagBadge'; +import IndicatorsContainer from 'app/core/components/Picker/IndicatorsContainer'; +import NoOptionsMessage from 'app/core/components/Picker/NoOptionsMessage'; +import { components } from 'react-select'; +import ResetStyles from 'app/core/components/Picker/ResetStyles'; export interface Props { tags: string[]; @@ -23,10 +28,11 @@ export class TagFilter extends React.Component { searchTags(query) { return this.props.tagOptions().then(options => { - const tags = _.map(options, tagOption => { - return { value: tagOption.term, label: tagOption.term, count: tagOption.count }; - }); - return { options: tags }; + return options.map(option => ({ + value: option.term, + label: option.term, + count: option.count, + })); }); } @@ -44,23 +50,65 @@ export class TagFilter extends React.Component { render() { const selectOptions = { + classNamePrefix: 'gf-form-select2', + isMulti: true, + defaultOptions: true, loadOptions: this.searchTags, onChange: this.onChange, - value: this.props.tags, - multi: true, className: 'gf-form-input gf-form-input--form-dropdown', placeholder: 'Tags', - loadingPlaceholder: 'Loading...', - noResultsText: 'No tags found', - optionComponent: TagOption, + loadingMessage: () => 'Loading...', + noOptionsMessage: () => 'No tags found', + getOptionValue: i => i.value, + getOptionLabel: i => i.label, + styles: ResetStyles, + components: { + Option: TagOption, + IndicatorsContainer, + NoOptionsMessage, + MultiValueContainer: props => { + const { data } = props; + return ( + + + + ); + }, + MultiValueRemove: props => { + return X; + }, + }, }; + // { + // return option.label.includes(searchText); + // }} + // loadingMessage={() => 'Loading...'} + // noOptionsMessage={() => 'No users found'} + // getOptionValue={i => i.id} + // getOptionLabel={i => i.label} + selectOptions['valueComponent'] = TagValue; return (
- +
diff --git a/public/app/core/components/TagFilter/TagOption.tsx b/public/app/core/components/TagFilter/TagOption.tsx index 5938c98f870..72d83453637 100644 --- a/public/app/core/components/TagFilter/TagOption.tsx +++ b/public/app/core/components/TagFilter/TagOption.tsx @@ -1,52 +1,75 @@ import React from 'react'; +import { components } from 'react-select'; +import { OptionProps } from 'react-select/lib/components/Option'; import { TagBadge } from './TagBadge'; -export interface Props { - onSelect: any; - onFocus: any; - option: any; - isFocused: any; - className: any; +// https://github.com/JedWatson/react-select/issues/3038 +interface ExtendedOptionProps extends OptionProps { + data: any; } -export class TagOption extends React.Component { - constructor(props) { - super(props); - this.handleMouseDown = this.handleMouseDown.bind(this); - this.handleMouseEnter = this.handleMouseEnter.bind(this); - this.handleMouseMove = this.handleMouseMove.bind(this); - } +export const TagOption = (props: ExtendedOptionProps) => { + const { data, className, label } = props; + return ( + +
+ +
+
+ ); +}; - handleMouseDown(event) { - event.preventDefault(); - event.stopPropagation(); - this.props.onSelect(this.props.option, event); - } +export default TagOption; - handleMouseEnter(event) { - this.props.onFocus(this.props.option, event); - } +// import React from 'react'; +// import { TagBadge } from './TagBadge'; - handleMouseMove(event) { - if (this.props.isFocused) { - return; - } - this.props.onFocus(this.props.option, event); - } +// export interface Props { +// onSelect: any; +// onFocus: any; +// option: any; +// isFocused: any; +// className: any; +// } - render() { - const { option, className } = this.props; +// export class TagOption extends React.Component { +// constructor(props) { +// super(props); +// this.handleMouseDown = this.handleMouseDown.bind(this); +// this.handleMouseEnter = this.handleMouseEnter.bind(this); +// this.handleMouseMove = this.handleMouseMove.bind(this); +// } - return ( - - ); - } -} +// handleMouseDown(event) { +// event.preventDefault(); +// event.stopPropagation(); +// this.props.onSelect(this.props.option, event); +// } + +// handleMouseEnter(event) { +// this.props.onFocus(this.props.option, event); +// } + +// handleMouseMove(event) { +// if (this.props.isFocused) { +// return; +// } +// this.props.onFocus(this.props.option, event); +// } + +// render() { +// const { option, className } = this.props; + +// return ( +// +// ); +// } +// } diff --git a/public/app/core/components/TagFilter/TagValue.tsx b/public/app/core/components/TagFilter/TagValue.tsx index ca8ca9e4fba..43e41c7fdc2 100644 --- a/public/app/core/components/TagFilter/TagValue.tsx +++ b/public/app/core/components/TagFilter/TagValue.tsx @@ -21,6 +21,6 @@ export class TagValue extends React.Component { render() { const { value } = this.props; - return ; + return ; } } diff --git a/public/sass/components/_form_select_box.scss b/public/sass/components/_form_select_box.scss index 844879caf3b..2ec848c757f 100644 --- a/public/sass/components/_form_select_box.scss +++ b/public/sass/components/_form_select_box.scss @@ -58,6 +58,15 @@ $select-input-bg-disabled: $input-bg-disabled; background: $select-input-bg-disabled; position: absolute; z-index: 2; + width: 100%; +} + +.tag-filter .gf-form-select2__menu { + width: 100%; +} + +.gf-form-select2__multi-value { + display: inline; } .gf-form-select2__option { @@ -106,3 +115,9 @@ $select-input-bg-disabled: $input-bg-disabled; border: 0; overflow: visible; } + +.gf-form--has-input-icon { + .gf-form-select2__value-container { + padding-left: 30px; + } +}