( projectId, chartId, noSource = false, skipParsing = false, getCache, filters )
| 233 | } |
| 234 | |
| 235 | export function runQuery( |
| 236 | projectId, chartId, noSource = false, skipParsing = false, getCache, filters |
| 237 | ) { |
| 238 | return (dispatch) => { |
| 239 | const token = cookie.load("brewToken"); |
| 240 | let url = `${API_HOST}/project/${projectId}/chart/${chartId}/query?no_source=${noSource}&skip_parsing=${skipParsing}`; |
| 241 | const method = "POST"; |
| 242 | const headers = new Headers({ |
| 243 | "Accept": "application/json", |
| 244 | "authorization": `Bearer ${token}`, |
| 245 | "Content-Type": "application/json", |
| 246 | }); |
| 247 | const body = JSON.stringify({ filters: filters && !filters.length ? [filters] : filters }); |
| 248 | |
| 249 | if (getCache) { |
| 250 | url += "&getCache=true"; |
| 251 | } |
| 252 | |
| 253 | dispatch({ type: FETCH_CHART, chartId }); |
| 254 | return fetch(url, { method, body, headers }) |
| 255 | .then((response) => { |
| 256 | if (!response.ok) { |
| 257 | dispatch(addError(response.status)); |
| 258 | return new Promise((resolve, reject) => reject(response.status)); |
| 259 | } |
| 260 | |
| 261 | return response.json(); |
| 262 | }) |
| 263 | .then((chart) => { |
| 264 | dispatch({ type: FETCH_CHART_SUCCESS, chart }); |
| 265 | return chart; |
| 266 | }) |
| 267 | .catch((error) => { |
| 268 | dispatch({ type: FETCH_CHART_FAIL, chartId }); |
| 269 | return new Promise((resolve, reject) => reject(error)); |
| 270 | }); |
| 271 | }; |
| 272 | } |
| 273 | |
| 274 | export function runQueryWithFilters(projectId, chartId, filters) { |
| 275 | return (dispatch) => { |
no test coverage detected