fix(ui): prefer zoomed time range in flux dashboard cell
parent
b0458a3a95
commit
349f3c6018
|
@ -1,6 +1,10 @@
|
|||
import {Template, TimeRange} from 'src/types'
|
||||
import {Template, TemplateValueType, TimeRange} from 'src/types'
|
||||
import {computeInterval} from 'src/tempVars/utils/replace'
|
||||
import {DEFAULT_DURATION_MS} from 'src/shared/constants'
|
||||
import {
|
||||
DEFAULT_DURATION_MS,
|
||||
TEMP_VAR_DASHBOARD_TIME,
|
||||
TEMP_VAR_UPPER_DASHBOARD_TIME,
|
||||
} from 'src/shared/constants'
|
||||
import {extractImports} from 'src/shared/parsing/flux/extractImports'
|
||||
import {getMinDuration} from 'src/shared/parsing/flux/durations'
|
||||
import fluxString from './fluxString'
|
||||
|
@ -61,6 +65,30 @@ function fluxVariables(
|
|||
return `dashboardTime = ${lower}\nupperDashboardTime = ${upper}\nv = {${extraVars} timeRangeStart: dashboardTime , timeRangeStop: upperDashboardTime }`
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts exact time range from `dashboardTime` and `upperDashboardTime` variables or returns undefined.
|
||||
*/
|
||||
export function extractExactTimeRange(
|
||||
templates: Template[]
|
||||
): TimeRange | undefined {
|
||||
const lower = templates.find(x => x.tempVar === TEMP_VAR_DASHBOARD_TIME)
|
||||
const upper = templates.find(x => x.tempVar === TEMP_VAR_UPPER_DASHBOARD_TIME)
|
||||
if (!lower || !upper) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (
|
||||
lower.values?.[0]?.type === TemplateValueType.TimeStamp &&
|
||||
upper.values?.[0]?.type === TemplateValueType.TimeStamp
|
||||
) {
|
||||
return {
|
||||
lower: lower.values?.[0]?.value,
|
||||
upper: upper.values?.[0]?.value,
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export const renderTemplatesInScript = async (
|
||||
script: string,
|
||||
timeRange: TimeRange,
|
||||
|
|
|
@ -16,7 +16,10 @@ import {notify} from 'src/shared/actions/notifications'
|
|||
import {fluxResponseTruncatedError} from 'src/shared/copy/notifications'
|
||||
import {getDeep} from 'src/utils/wrappers'
|
||||
import {restartable} from 'src/shared/utils/restartable'
|
||||
import {renderTemplatesInScript} from 'src/flux/helpers/templates'
|
||||
import {
|
||||
extractExactTimeRange,
|
||||
renderTemplatesInScript,
|
||||
} from 'src/flux/helpers/templates'
|
||||
import {parseResponse} from 'src/shared/parsing/flux/response'
|
||||
import DefaultDebouncer, {Debouncer} from 'src/shared/utils/debouncer'
|
||||
import {DEFAULT_X_PIXELS} from 'src/shared/constants'
|
||||
|
@ -281,7 +284,7 @@ class TimeSeries extends PureComponent<Props, State> {
|
|||
|
||||
const renderedScript = await renderTemplatesInScript(
|
||||
script,
|
||||
timeRange,
|
||||
extractExactTimeRange(templates) || timeRange, // zoom functionality updates templates, prefer zoomed time range in flux
|
||||
templates,
|
||||
fluxASTLink
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue