Skip to content

Commit

Permalink
TSVB flashes a chart upon clicking create (elastic#30946)
Browse files Browse the repository at this point in the history
* TSVB flashes a chart upon clicking create
  • Loading branch information
alexwizp committed Feb 20, 2019
1 parent 55ac88e commit d8fb056
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export default async (req, panel, esQueryConfig) => {
};

async function getAnnotationBody(req, panel, annotation, esQueryConfig) {
const indexPatternString = annotation.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const indexPattern = annotation.index_pattern;
const { indexPatternObject, indexPatternString } = await getIndexPatternObject(req, indexPattern);
const request = buildAnnotationRequest(req, panel, annotation, esQueryConfig, indexPatternObject);
const esShardTimeout = getEsShardTimeout(req);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import { getEsQueryConfig } from './helpers/get_es_query_uisettings';
export async function getTableData(req, panel) {
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data');
const includeFrozen = await req.getUiSettingsService().get('search:includeFrozen');
const indexPatternString = panel.index_pattern;

const esQueryConfig = await getEsQueryConfig(req);
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const indexPattern = panel.index_pattern;
const { indexPatternObject, indexPatternString } = await getIndexPatternObject(req, indexPattern);

const params = {
index: indexPatternString,
ignore_throttled: !includeFrozen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,36 @@
*/

export async function getIndexPatternObject(req, indexPatternString) {
let defaultIndex;

if (!indexPatternString) {
defaultIndex = await req.getUiSettingsService().get('defaultIndex');
}

// getting the matching index pattern
const savedObjectClient = req.getSavedObjectsClient();
const indexPatternObjects = await savedObjectClient.find({
type: 'index-pattern',
fields: ['title', 'fields'],
search: `"${indexPatternString}"`,
search: indexPatternString ? `"${indexPatternString}"` : null,
search_fields: ['title'],
});

// getting the index pattern fields
const indexPatterns = indexPatternObjects.saved_objects
.filter(obj => obj.attributes.title === indexPatternString)
.filter(obj => obj.attributes.title === indexPatternString || (defaultIndex && obj.id === defaultIndex))
.map(indexPattern => {
const { title, fields } = indexPattern.attributes;
return {
title,
fields: JSON.parse(fields),
};
});
return indexPatterns.length === 1 ? indexPatterns[0] : null;

const indexPatternObject = indexPatterns.length === 1 ? indexPatterns[0] : null;

return {
indexPatternObject,
indexPatternString: indexPatternString || indexPatternObject.title
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { getIndexPatternObject } from '../helpers/get_index_pattern';
import getEsShardTimeout from '../helpers/get_es_shard_timeout';

export default async (req, panel, series, esQueryConfig) => {
const indexPatternString = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const indexPattern = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const { indexPatternObject, indexPatternString } = await getIndexPatternObject(req, indexPattern);
const request = buildRequestBody(req, panel, series, esQueryConfig, indexPatternObject);
const esShardTimeout = getEsShardTimeout(req);

Expand Down

0 comments on commit d8fb056

Please sign in to comment.