Validate URL query for zoomed time range input & notify if invalid
Co-authored-by: Jared Scheib <jared.scheib@gmail.com> Co-authored-by: Deniz Kusefoglu <denizk@gmail.com>pull/10616/head
parent
af5fca84ff
commit
48e46c0f31
|
@ -50,9 +50,11 @@ import {
|
||||||
TEMP_VAR_UPPER_DASHBOARD_TIME,
|
TEMP_VAR_UPPER_DASHBOARD_TIME,
|
||||||
} from 'shared/constants'
|
} from 'shared/constants'
|
||||||
import {FORMAT_INFLUXQL, defaultTimeRange} from 'src/shared/data/timeRanges'
|
import {FORMAT_INFLUXQL, defaultTimeRange} from 'src/shared/data/timeRanges'
|
||||||
|
import {validAbsoluteTimeRange} from 'src/dashboards/utils/time'
|
||||||
import {
|
import {
|
||||||
notifyDashboardNotFound,
|
notifyDashboardNotFound,
|
||||||
notifyInvalidTempVarValueInURLQuery,
|
notifyInvalidTempVarValueInURLQuery,
|
||||||
|
notifyInvalidZoomedTimeRangeValueInURLQuery,
|
||||||
} from 'shared/copy/notifications'
|
} from 'shared/copy/notifications'
|
||||||
import {colorsStringSchema, colorsNumberSchema} from 'shared/schemas'
|
import {colorsStringSchema, colorsNumberSchema} from 'shared/schemas'
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
@ -64,12 +66,21 @@ class DashboardPage extends Component {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
const urlQueries = queryString.parse(window.location.search)
|
const urlQueries = queryString.parse(window.location.search)
|
||||||
const {zoomedLower = null, zoomedUpper = null} = urlQueries
|
let {zoomedLower, zoomedUpper} = urlQueries
|
||||||
|
|
||||||
|
if (!validAbsoluteTimeRange({lower: zoomedLower, upper: zoomedUpper})) {
|
||||||
|
if (zoomedLower || zoomedUpper) {
|
||||||
|
props.notify(notifyInvalidZoomedTimeRangeValueInURLQuery())
|
||||||
|
}
|
||||||
|
zoomedLower = null
|
||||||
|
zoomedUpper = null
|
||||||
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isEditMode: false,
|
isEditMode: false,
|
||||||
selectedCell: null,
|
selectedCell: null,
|
||||||
zoomedTimeRange: {zoomedLower, zoomedUpper},
|
zoomedLower,
|
||||||
|
zoomedUpper,
|
||||||
scrollTop: 0,
|
scrollTop: 0,
|
||||||
windowHeight: window.innerHeight,
|
windowHeight: window.innerHeight,
|
||||||
}
|
}
|
||||||
|
@ -91,9 +102,11 @@ class DashboardPage extends Component {
|
||||||
notify,
|
notify,
|
||||||
getAnnotationsAsync,
|
getAnnotationsAsync,
|
||||||
timeRange,
|
timeRange,
|
||||||
|
timeRange: {upper, lower},
|
||||||
autoRefresh,
|
autoRefresh,
|
||||||
location,
|
location,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
const {zoomedUpper, zoomedLower} = this.state
|
||||||
|
|
||||||
const annotationRange = millisecondTimeRange(timeRange)
|
const annotationRange = millisecondTimeRange(timeRange)
|
||||||
getAnnotationsAsync(source.links.annotations, annotationRange)
|
getAnnotationsAsync(source.links.annotations, annotationRange)
|
||||||
|
@ -122,8 +135,12 @@ class DashboardPage extends Component {
|
||||||
notify(notifyInvalidTempVarValueInURLQuery(invalidURLQuery))
|
notify(notifyInvalidTempVarValueInURLQuery(invalidURLQuery))
|
||||||
})
|
})
|
||||||
|
|
||||||
const {upper, lower} = timeRange
|
syncURLQueryFromTempVars(location, dashboard.templates, [], {
|
||||||
syncURLQueryFromTempVars(location, dashboard.templates, [], {upper, lower})
|
upper,
|
||||||
|
lower,
|
||||||
|
zoomedUpper,
|
||||||
|
zoomedLower,
|
||||||
|
})
|
||||||
|
|
||||||
// Refresh and persists influxql generated template variable values.
|
// Refresh and persists influxql generated template variable values.
|
||||||
// If using auth and role is Viewer, temp vars will be stale until dashboard
|
// If using auth and role is Viewer, temp vars will be stale until dashboard
|
||||||
|
@ -343,7 +360,7 @@ class DashboardPage extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleZoomedTimeRange = (zoomedLower, zoomedUpper) => {
|
handleZoomedTimeRange = (zoomedLower, zoomedUpper) => {
|
||||||
this.setState({zoomedTimeRange: {zoomedLower, zoomedUpper}})
|
this.setState({zoomedLower, zoomedUpper})
|
||||||
const {dashboardActions, location} = this.props
|
const {dashboardActions, location} = this.props
|
||||||
dashboardActions.syncURLQueryFromQueriesObject(location, {
|
dashboardActions.syncURLQueryFromQueriesObject(location, {
|
||||||
zoomedLower,
|
zoomedLower,
|
||||||
|
@ -356,10 +373,6 @@ class DashboardPage extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
|
||||||
zoomedTimeRange,
|
|
||||||
zoomedTimeRange: {zoomedLower, zoomedUpper},
|
|
||||||
} = this.state
|
|
||||||
const {
|
const {
|
||||||
isUsingAuth,
|
isUsingAuth,
|
||||||
meRole,
|
meRole,
|
||||||
|
@ -387,6 +400,7 @@ class DashboardPage extends Component {
|
||||||
handleClickPresentationButton,
|
handleClickPresentationButton,
|
||||||
params: {sourceID, dashboardID},
|
params: {sourceID, dashboardID},
|
||||||
} = this.props
|
} = this.props
|
||||||
|
const {zoomedLower, zoomedUpper} = this.state
|
||||||
|
|
||||||
const low = zoomedLower || lower
|
const low = zoomedLower || lower
|
||||||
const up = zoomedUpper || upper
|
const up = zoomedUpper || upper
|
||||||
|
@ -469,7 +483,7 @@ class DashboardPage extends Component {
|
||||||
isHidden={inPresentationMode}
|
isHidden={inPresentationMode}
|
||||||
onAddCell={this.handleAddCell}
|
onAddCell={this.handleAddCell}
|
||||||
onManualRefresh={onManualRefresh}
|
onManualRefresh={onManualRefresh}
|
||||||
zoomedTimeRange={zoomedTimeRange}
|
zoomedTimeRange={{zoomedUpper, zoomedLower}}
|
||||||
onSave={this.handleRenameDashboard}
|
onSave={this.handleRenameDashboard}
|
||||||
onCancel={this.handleCancelEditDashboard}
|
onCancel={this.handleCancelEditDashboard}
|
||||||
onEditDashboard={this.handleEditDashboard}
|
onEditDashboard={this.handleEditDashboard}
|
||||||
|
|
|
@ -34,9 +34,7 @@ export const millisecondTimeRange = ({
|
||||||
return {since, until}
|
return {since, until}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validRelativeTimeRange = (
|
const validRelativeTimeRange = (timeRange: TimeRange): TimeRange | null => {
|
||||||
timeRange: TimeRange
|
|
||||||
): TimeRange | null => {
|
|
||||||
const matchedRange = timeRanges.find(t => t.lower === timeRange.lower)
|
const matchedRange = timeRanges.find(t => t.lower === timeRange.lower)
|
||||||
|
|
||||||
if (matchedRange) {
|
if (matchedRange) {
|
||||||
|
|
|
@ -452,6 +452,12 @@ export const notifyInvalidTimeRangeValueInURLQuery = () => ({
|
||||||
message: `Invalid URL query value supplied for lower or upper time range.`,
|
message: `Invalid URL query value supplied for lower or upper time range.`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const notifyInvalidZoomedTimeRangeValueInURLQuery = () => ({
|
||||||
|
...defaultErrorNotification,
|
||||||
|
icon: 'cube',
|
||||||
|
message: `Invalid URL query value supplied for zoomed lower or zoomed upper time range.`,
|
||||||
|
})
|
||||||
|
|
||||||
// Rule Builder Notifications
|
// Rule Builder Notifications
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
export const notifyAlertRuleCreated = () => ({
|
export const notifyAlertRuleCreated = () => ({
|
||||||
|
|
Loading…
Reference in New Issue