diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index 413487c7b..6a6833422 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -13,6 +13,7 @@ import Dashboard from 'src/dashboards/components/Dashboard' import TemplateVariableManager from 'src/dashboards/components/TemplateVariableManager' import {errorThrown as errorThrownAction} from 'shared/actions/errors' +import {quoteIfTimestamp} from 'src/utils/influxql' import * as dashboardActionCreators from 'src/dashboards/actions' @@ -246,7 +247,6 @@ class DashboardPage extends Component { render() { const { source, - timeRange: {lower, upper}, timeRange, showTemplateControlBar, dashboards, @@ -259,13 +259,15 @@ class DashboardPage extends Component { params: {sourceID}, } = this.props + const {lower, upper} = quoteIfTimestamp(timeRange) + const dashboardTime = { id: 'dashtime', tempVar: ':dashboardTime:', type: 'constant', values: [ { - value: `'${lower}'`, + value: lower, type: 'constant', selected: true, }, @@ -278,7 +280,7 @@ class DashboardPage extends Component { type: 'constant', values: [ { - value: `'${upper}'`, + value: upper, type: 'constant', selected: true, }, @@ -296,9 +298,26 @@ class DashboardPage extends Component { } const dashboard = this.getActiveDashboard() - const templatesIncludingDashTime = dashboard - ? [...dashboard.templates, dashboardTime, upperDashboardTime, interval] - : [] + + let templatesIncludingDashTime + if (dashboard) { + if (upper) { + templatesIncludingDashTime = [ + ...dashboard.templates, + dashboardTime, + upperDashboardTime, + interval, + ] + } else { + templatesIncludingDashTime = [ + ...dashboard.templates, + dashboardTime, + interval, + ] + } + } else { + templatesIncludingDashTime = [] + } const {selectedCell, isEditMode, isTemplating} = this.state diff --git a/ui/src/utils/influxql.js b/ui/src/utils/influxql.js index 49a65aaac..59b7d1540 100644 --- a/ui/src/utils/influxql.js +++ b/ui/src/utils/influxql.js @@ -5,6 +5,18 @@ import { DEFAULT_DASHBOARD_GROUP_BY_INTERVAL, } from 'shared/constants' +export const quoteIfTimestamp = ({lower, upper}) => { + if (lower && lower.includes('Z') && !lower.includes('\'')) { + lower = `'${lower}'` + } + + if (upper && upper.includes('Z') && !upper.includes('\'')) { + upper = `'${upper}'` + } + + return {lower, upper} +} + export default function buildInfluxQLQuery(timeBounds, config) { const {groupBy, tags, areTagsAccepted} = config const {upper, lower} = timeBounds @@ -58,19 +70,13 @@ function _buildFields(fieldFuncs) { function _buildWhereClause({lower, upper, tags, areTagsAccepted}) { const timeClauses = [] - if (lower && lower.includes('Z') && !lower.includes('\'')) { - lower = `'${lower}'` - } + const timeClause = quoteIfTimestamp({lower, upper}) - if (upper && upper.includes('Z') && !upper.includes('\'')) { - upper = `'${upper}'` - } - - if (lower) { + if (timeClause.lower) { timeClauses.push(`time > ${lower}`) } - if (upper) { + if (timeClause.upper) { timeClauses.push(`time < ${upper}`) }