Add handler for fetching query status

pull/10616/head
Delmer Reed 2018-07-11 17:14:26 -04:00
parent a94a00cd7f
commit 1f2f4f9e48
1 changed files with 29 additions and 17 deletions

View File

@ -31,27 +31,11 @@ export const fetchTimeSeries = async (
editQueryStatus: () => any = noop
) => {
const timeSeriesPromises = queries.map(async query => {
const {database, rp} = query
const db = _.get(query, 'db', database)
try {
const text = await replace(query.text, source, templates, resolution)
handleLoading({...query, text}, editQueryStatus)
const payload = {
source: source.links.proxy,
db,
rp,
query: text,
}
const {data} = await proxy(payload)
return handleSuccess(data, query, editQueryStatus)
return handleQueryFetchStatus({...query, text}, source, editQueryStatus)
} catch (error) {
console.error(error)
handleError(error, query, editQueryStatus)
throw error
}
})
@ -59,6 +43,34 @@ export const fetchTimeSeries = async (
return Promise.all(timeSeriesPromises)
}
const handleQueryFetchStatus = async (
query: Query,
source: Source,
editQueryStatus: () => any
) => {
const {database, rp} = query
const db = _.get(query, 'db', database)
try {
handleLoading(query, editQueryStatus)
const payload = {
source: source.links.proxy,
db,
rp,
query: query.text,
}
const {data} = await proxy(payload)
return handleSuccess(data, query, editQueryStatus)
} catch (error) {
console.error(error)
handleError(error, query, editQueryStatus)
throw error
}
}
const replace = async (
query: string,
source: Source,