From 7fe10e2eef3abff8946ba4de2ce39c150b7ddd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 10 Dec 2018 13:23:38 +0100 Subject: [PATCH] fix search tag issues, fixes #14391 (cherry picked from commit e05f6c539785bc9fd3a5227640acff5e9ba723d3) --- public/app/core/angular_wrappers.ts | 2 +- .../core/components/TagFilter/TagFilter.tsx | 21 +++++++++---------- public/app/core/components/search/search.html | 2 +- public/app/core/components/search/search.ts | 14 ++++++------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/public/app/core/angular_wrappers.ts b/public/app/core/angular_wrappers.ts index 7be28272f11..5609c058a27 100644 --- a/public/app/core/angular_wrappers.ts +++ b/public/app/core/angular_wrappers.ts @@ -16,7 +16,7 @@ export function registerAngularDirectives() { react2AngularDirective('searchResult', SearchResult, []); react2AngularDirective('tagFilter', TagFilter, [ 'tags', - ['onSelect', { watchDepth: 'reference' }], + ['onChange', { watchDepth: 'reference' }], ['tagOptions', { watchDepth: 'reference' }], ]); } diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index 14b6ef4932b..6a4203f8739 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -10,7 +10,7 @@ import ResetStyles from 'app/core/components/Picker/ResetStyles'; export interface Props { tags: string[]; tagOptions: () => any; - onSelect: (tag: string) => void; + onChange: (tags: string[]) => void; } export class TagFilter extends React.Component { @@ -18,12 +18,9 @@ export class TagFilter extends React.Component { constructor(props) { super(props); - - this.searchTags = this.searchTags.bind(this); - this.onChange = this.onChange.bind(this); } - searchTags(query) { + onLoadOptions = query => { return this.props.tagOptions().then(options => { return options.map(option => ({ value: option.term, @@ -31,18 +28,20 @@ export class TagFilter extends React.Component { count: option.count, })); }); - } + }; - onChange(newTags) { - this.props.onSelect(newTags); - } + onChange = (newTags: any[]) => { + this.props.onChange(newTags.map(tag => tag.value)); + }; render() { + const tags = this.props.tags.map(tag => ({ value: tag, label: tag, count: 0 })); + const selectOptions = { classNamePrefix: 'gf-form-select-box', isMulti: true, defaultOptions: true, - loadOptions: this.searchTags, + loadOptions: this.onLoadOptions, onChange: this.onChange, className: 'gf-form-input gf-form-input--form-dropdown', placeholder: 'Tags', @@ -50,7 +49,7 @@ export class TagFilter extends React.Component { noOptionsMessage: () => 'No tags found', getOptionValue: i => i.value, getOptionLabel: i => i.label, - value: this.props.tags, + value: tags, styles: ResetStyles, components: { Option: TagOption, diff --git a/public/app/core/components/search/search.html b/public/app/core/components/search/search.html index 8723d5d0584..8a83ecbc205 100644 --- a/public/app/core/components/search/search.html +++ b/public/app/core/components/search/search.html @@ -41,7 +41,7 @@ - + diff --git a/public/app/core/components/search/search.ts b/public/app/core/components/search/search.ts index 322dd2bdf10..ff63ca5a8fe 100644 --- a/public/app/core/components/search/search.ts +++ b/public/app/core/components/search/search.ts @@ -25,8 +25,6 @@ export class SearchCtrl { appEvents.on('hide-dash-search', this.closeSearch.bind(this), $scope); this.initialFolderFilterTitle = 'All'; - this.getTags = this.getTags.bind(this); - this.onTagSelect = this.onTagSelect.bind(this); this.isEditor = contextSrv.isEditor; this.hasEditPermissionInFolders = contextSrv.hasEditPermissionInFolders; } @@ -162,7 +160,7 @@ export class SearchCtrl { const localSearchId = this.currentSearchId; const query = { ...this.query, - tag: this.query.tag.map(i => i.value), + tag: this.query.tag, }; return this.searchSrv.search(query).then(results => { @@ -195,14 +193,14 @@ export class SearchCtrl { evt.preventDefault(); } - getTags() { + getTags = () => { return this.searchSrv.getDashboardTags(); - } + }; - onTagSelect(newTags) { - this.query.tag = newTags; + onTagFiltersChanged = (tags: string[]) => { + this.query.tag = tags; this.search(); - } + }; clearSearchFilter() { this.query.tag = [];