[ML] Add support to Data Visualizer for index patterns without a time field (#28511) (#28695)

* Prevent docCount fetch and remove sidebar if no timeField set.

* Don't show metrics section if no metrics cards

* Add parens to conditional statement as per styleguide

* Don't create docCount card if not timeseries based
This commit is contained in:
Melissa Alvarez 2019-01-14 14:21:15 -05:00 committed by GitHub
parent 6e4ae71663
commit 3062069d52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -7,7 +7,7 @@
<h1>{{indexPattern.title}}</h1>
</div>
<div class="euiFlexItem euiFlexItem--flexGrowZero">
<ml-full-time-range-selector index-pattern='indexPattern' query='searchQuery' />
<ml-full-time-range-selector ng-if="showSidebar" index-pattern='indexPattern' query='searchQuery' />
</div>
</div>
@ -86,7 +86,7 @@
</div>
<div class="kuiPanel kuiVerticalRhythm datavisualizer-panel card-panel">
<div ng-if="metricCards.length > 0" class="kuiPanel kuiVerticalRhythm datavisualizer-panel card-panel">
<div class="euiText">
<h2
class="kuiSubTitle kuiVerticalRhythm"

View file

@ -302,12 +302,18 @@ module
const metricCards = [];
// Add a config for 'document count', identified by no field name.
metricCards.push({
type: ML_JOB_FIELD_TYPES.NUMBER,
existsInDocs: true,
loading: true
});
// Add a config for 'document count', identified by no field name if index is timeseries based
if (indexPattern.timeFieldName !== undefined) {
metricCards.push({
type: ML_JOB_FIELD_TYPES.NUMBER,
existsInDocs: true,
loading: true
});
} else {
// disable timeRangeSelector and remove sidebar if index not timeseries based
timefilter.disableTimeRangeSelector();
$scope.showSidebar = false;
}
// Add on 1 for the document count card.
// TODO - remove the '+1' if document count goes in its own section.
@ -477,7 +483,7 @@ module
fields: numberFields
})
.then((resp) => {
// Add the metric stats to the existing stats in the corresponding card.
// Add the metric stats to the existing stats in the corresponding card. [ {documentCounts:...}, {fieldName: ..} ]
_.each($scope.metricCards, (card) => {
if (card.fieldName !== undefined) {
card.stats = { ...card.stats, ...(_.find(resp, { fieldName: card.fieldName })) };

View file

@ -122,7 +122,10 @@ export class DataVisualizer {
_.each(fields, (field) => {
if (field.fieldName === undefined) {
// undefined fieldName is used for a document count request.
batches.push([field]);
// getDocumentCountStats requires timeField - don't add to batched requests if not defined
if (timeFieldName !== undefined) {
batches.push([field]);
}
} else {
const fieldType = field.type;
if (batchedFields[fieldType] === undefined) {