Skip to content

Commit

Permalink
Add validate function
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jun 17, 2020
1 parent 7e32841 commit 36add48
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,10 @@ function discoverController(
if (!init.complete) return;
$scope.fetchCounter++;
$scope.fetchError = undefined;
if (!validateTimeRange()) {
$scope.resultState = 'none';
return;
}

// Abort any in-progress requests before fetching again
if (abortController) abortController.abort();
Expand Down Expand Up @@ -913,15 +917,39 @@ function discoverController(
});
}

function validateTimeRange() {
const { from, to } = timefilter.getTime();
if (!from || !to || !dateMath.parse(from) || !dateMath.parse(to)) {
toastNotifications.addDanger({
title: i18n.translate('discover.notifications.invalidTimeRangeTitle', {
defaultMessage: `Invalid time range`,
}),
text: i18n.translate('discover.notifications.invalidTimeRangeText', {
defaultMessage: `The provided time range is invalid. (from: '{from}', to: '{to}')`,
values: {
from,
to,
},
}),
});
return false;
}
return true;
}

$scope.updateTime = function () {
//this is the timerange for the histogram, should be refactored
const { from, to } = timefilter.getTime();
// this is the timerange for the histogram, should be refactored
$scope.timeRange = {
from: dateMath.parse(timefilter.getTime().from),
to: dateMath.parse(timefilter.getTime().to, { roundUp: true }),
from: dateMath.parse(from),
to: dateMath.parse(to, { roundUp: true }),
};
};

$scope.toMoment = function (datetime) {
if (!datetime) {
return;
}
return moment(datetime).format(config.get('dateFormat'));
};

Expand Down

0 comments on commit 36add48

Please sign in to comment.