[ML] Fix for Explorer time range when selected jobs have no data (#31093) (#31163)

This commit is contained in:
Pete Harverson 2019-02-15 09:29:59 +00:00 committed by GitHub
parent 1226e0784a
commit 3d26a69c00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,18 +21,21 @@ import { mlJobService } from 'plugins/ml/services/job_service';
import { injectI18n } from '@kbn/i18n/react';
function getLink(location, jobs) {
let from = 0;
let to = 0;
let from = undefined;
let to = undefined;
if (jobs.length === 1) {
from = jobs[0].earliestTimestampMs;
to = jobs[0].latestTimestampMs;
} else {
from = Math.min(...jobs.map(j => j.earliestTimestampMs));
to = Math.max(...jobs.map(j => j.latestTimestampMs));
const jobsWithData = jobs.filter(j => (j.earliestTimestampMs !== undefined));
if (jobsWithData.length > 0) {
from = Math.min(...jobsWithData.map(j => j.earliestTimestampMs));
to = Math.max(...jobsWithData.map(j => j.latestTimestampMs));
}
}
const fromString = moment(from).format(TIME_FORMAT);
const toString = moment(to).format(TIME_FORMAT);
const fromString = moment(from).format(TIME_FORMAT); // Defaults to 'now' if 'from' is undefined
const toString = moment(to).format(TIME_FORMAT); // Defaults to 'now' if 'to' is undefined
const jobIds = jobs.map(j => j.id);
const url = mlJobService.createResultsUrl(jobIds, fromString, toString, location);