-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0d502ae
commit df40112
Showing
4 changed files
with
80 additions
and
31 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
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
47 changes: 47 additions & 0 deletions
47
src/core_plugins/metrics/public/lib/__tests__/extract_index_pattern.js
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,47 @@ | ||
import { extractIndexPatterns } from '../extract_index_patterns'; | ||
import { expect } from 'chai'; | ||
describe('extractIndexPatterns(vis)', () => { | ||
let vis; | ||
beforeEach(() => { | ||
vis = { | ||
fields: { | ||
'*': [] | ||
}, | ||
params: { | ||
index_pattern: '*', | ||
series: [ | ||
{ | ||
override_index_pattern: 1, | ||
series_index_pattern: 'example-1-*' | ||
}, | ||
{ | ||
override_index_pattern: 1, | ||
series_index_pattern: 'example-2-*' | ||
} | ||
], | ||
annotations: [ | ||
{ index_pattern: 'notes-*' }, | ||
{ index_pattern: 'example-1-*' } | ||
] | ||
} | ||
}; | ||
}); | ||
|
||
it('should return index patterns', () => { | ||
vis.fields = {}; | ||
expect(extractIndexPatterns(vis)).to.eql([ | ||
'*', | ||
'example-1-*', | ||
'example-2-*', | ||
'notes-*' | ||
]); | ||
}); | ||
|
||
it('should return index patterns that do not exist in vis.fields', () => { | ||
expect(extractIndexPatterns(vis)).to.eql([ | ||
'example-1-*', | ||
'example-2-*', | ||
'notes-*' | ||
]); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/core_plugins/metrics/public/lib/extract_index_patterns.js
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,27 @@ | ||
import { uniq } from 'lodash'; | ||
export function extractIndexPatterns(vis) { | ||
const patternsToFetch = []; | ||
|
||
if (!vis.fields[vis.params.index_pattern]) { | ||
patternsToFetch.push(vis.params.index_pattern); | ||
} | ||
|
||
vis.params.series.forEach(series => { | ||
const indexPattern = series.series_index_pattern; | ||
if (series.override_index_pattern && !vis.fields[indexPattern]) { | ||
patternsToFetch.push(indexPattern); | ||
} | ||
}); | ||
|
||
if (vis.params.annotations) { | ||
vis.params.annotations.forEach(item => { | ||
const indexPattern = item.index_pattern; | ||
if (indexPattern && !vis.fields[indexPattern]) { | ||
patternsToFetch.push(indexPattern); | ||
} | ||
}); | ||
} | ||
|
||
return uniq(patternsToFetch); | ||
|
||
} |