forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update QueryBarInput to accept index pattern strings (elastic#36916)
For many use cases a consumer of the QueryBarInput (or QueryBar) might only have an index pattern string in hand. Instead of forcing every consumer to reimplement the fetching logic to get a full pattern object, this PR updates the QueryBarInput to do the fetching itself if the indexPatterns array prop contains any strings. If a string does not exactly match the title of any of the saved objects then we return the default index pattern instead.
- Loading branch information
Showing
8 changed files
with
142 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ | |
*/ | ||
|
||
export { QueryBar } from './query_bar'; | ||
export { QueryBarInput } from './query_bar_input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/legacy/core_plugins/data/public/query/query_bar/lib/fetch_index_patterns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import chrome from 'ui/chrome'; | ||
import { getFromSavedObject } from 'ui/index_patterns/static_utils'; | ||
|
||
const config = chrome.getUiSettingsClient(); | ||
|
||
export async function fetchIndexPatterns(indexPatternStrings: string[]) { | ||
const quotedIndexPatternStrings = indexPatternStrings.map( | ||
indexPatternString => `"${indexPatternString}"` | ||
); | ||
const searchString = quotedIndexPatternStrings.join(' | '); | ||
const indexPatternsFromSavedObjects = await chrome.getSavedObjectsClient().find({ | ||
type: 'index-pattern', | ||
fields: ['title', 'fields'], | ||
search: `"${searchString}"`, | ||
searchFields: ['title'], | ||
}); | ||
|
||
const exactMatches = indexPatternsFromSavedObjects.savedObjects.filter(savedObject => { | ||
return indexPatternStrings.includes(savedObject.attributes.title as string); | ||
}); | ||
|
||
const allMatches = | ||
exactMatches.length === indexPatternStrings.length | ||
? exactMatches | ||
: [...exactMatches, await fetchDefaultIndexPattern()]; | ||
|
||
return allMatches.map(getFromSavedObject); | ||
} | ||
|
||
const fetchDefaultIndexPattern = async () => { | ||
const savedObjectsClient = chrome.getSavedObjectsClient(); | ||
const indexPattern = await savedObjectsClient.get('index-pattern', config.get('defaultIndex')); | ||
|
||
return getFromSavedObject(indexPattern); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters