From e20fa1ba70f15e0310f13b249aa5fa05fede58bb Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Wed, 10 Oct 2018 11:32:44 +0200 Subject: [PATCH] Fixes for the tag filtering in the search #13425 --- .../core/components/TagFilter/TagFilter.tsx | 54 ++++--------------- .../core/components/TagFilter/TagOption.tsx | 2 +- public/app/core/components/search/search.ts | 8 ++- public/sass/components/_form_select_box.scss | 15 +++--- 4 files changed, 25 insertions(+), 54 deletions(-) diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index e86a703af6c..967e0312704 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -1,7 +1,5 @@ -import _ from 'lodash'; import React from 'react'; 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'; @@ -23,7 +21,6 @@ export class TagFilter extends React.Component { this.searchTags = this.searchTags.bind(this); this.onChange = this.onChange.bind(this); - this.onTagRemove = this.onTagRemove.bind(this); } searchTags(query) { @@ -40,14 +37,6 @@ export class TagFilter extends React.Component { this.props.onSelect(newTags); } - onTagRemove(tag) { - let newTags = _.without(this.props.tags, tag.label); - newTags = _.map(newTags, tag => { - return { value: tag }; - }); - this.props.onSelect(newTags); - } - render() { const selectOptions = { classNamePrefix: 'gf-form-select2', @@ -61,50 +50,27 @@ export class TagFilter extends React.Component { noOptionsMessage: () => 'No tags found', getOptionValue: i => i.value, getOptionLabel: i => i.label, + value: this.props.tags, styles: ResetStyles, components: { Option: TagOption, IndicatorsContainer, NoOptionsMessage, - MultiValueContainer: props => { - const { data } = props; - return ( - - - - ); + MultiValueLabel: () => { + return null; // We want the whole tag to be clickable so we use MultiValueRemove instead }, MultiValueRemove: props => { - return X; + const { data } = props; + + return ( + + + + ); }, }, }; - // { - // 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 72d83453637..a50fa24d177 100644 --- a/public/app/core/components/TagFilter/TagOption.tsx +++ b/public/app/core/components/TagFilter/TagOption.tsx @@ -13,7 +13,7 @@ export const TagOption = (props: ExtendedOptionProps) => { return (
- +
); diff --git a/public/app/core/components/search/search.ts b/public/app/core/components/search/search.ts index e347fcd829a..322dd2bdf10 100644 --- a/public/app/core/components/search/search.ts +++ b/public/app/core/components/search/search.ts @@ -160,8 +160,12 @@ export class SearchCtrl { searchDashboards() { this.currentSearchId = this.currentSearchId + 1; const localSearchId = this.currentSearchId; + const query = { + ...this.query, + tag: this.query.tag.map(i => i.value), + }; - return this.searchSrv.search(this.query).then(results => { + return this.searchSrv.search(query).then(results => { if (localSearchId < this.currentSearchId) { return; } @@ -196,7 +200,7 @@ export class SearchCtrl { } onTagSelect(newTags) { - this.query.tag = _.map(newTags, tag => tag.value); + this.query.tag = newTags; this.search(); } diff --git a/public/sass/components/_form_select_box.scss b/public/sass/components/_form_select_box.scss index 2ec848c757f..97d0155430f 100644 --- a/public/sass/components/_form_select_box.scss +++ b/public/sass/components/_form_select_box.scss @@ -46,19 +46,13 @@ $select-input-bg-disabled: $input-bg-disabled; } .gf-form-select2__input { - position: absolute; - z-index: 1; - top: 0; - left: 0; - right: 0; - padding: 8px 10px; + padding-left: 5px; } .gf-form-select2__menu { background: $select-input-bg-disabled; position: absolute; z-index: 2; - width: 100%; } .tag-filter .gf-form-select2__menu { @@ -83,9 +77,16 @@ $select-input-bg-disabled: $input-bg-disabled; } } +.gf-form-select2__control--is-focused .gf-form-select2__placeholder { + display: none; +} + .gf-form-select2__value-container { display: table-cell; padding: 8px 10px; + > div { + display: inline-block; + } } .gf-form-select2__indicators {