Update addTimeBoundsToRawText to use regex in its string matching checks instead of strings

pull/10616/head
Iris Scholten 2018-05-29 13:55:16 -07:00
parent ba871fe07e
commit 822618fab3
1 changed files with 13 additions and 3 deletions

View File

@ -57,15 +57,25 @@ const addTimeBoundsToRawText = (rawText: string): string => {
return
}
const dashboardTimeRegex = new RegExp(
`time( )?>( )?${TEMP_VAR_DASHBOARD_TIME}`,
'g'
)
const dashboardTimeText: string = `time > ${TEMP_VAR_DASHBOARD_TIME}`
if (rawText.indexOf(dashboardTimeText) !== -1) {
const isUsingTimeSelectorBounds: boolean = !_.isEmpty(
rawText.match(dashboardTimeRegex)
)
if (isUsingTimeSelectorBounds) {
const upperTimeBoundRegex = new RegExp('time( )?<', 'g')
const hasUpperTimeBound = !_.isEmpty(rawText.match(upperTimeBoundRegex))
if (
rawText.indexOf(TEMP_VAR_UPPER_DASHBOARD_TIME) === -1 &&
rawText.indexOf('time <') === -1
!hasUpperTimeBound
) {
const upperDashboardTimeText = `time < ${TEMP_VAR_UPPER_DASHBOARD_TIME}`
const fullTimeText = `${dashboardTimeText} AND ${upperDashboardTimeText}`
const boundedQueryText = rawText.replace(dashboardTimeText, fullTimeText)
const boundedQueryText = rawText.replace(dashboardTimeRegex, fullTimeText)
return boundedQueryText
}
}