Commit c91e5a2d by ryan

cleaner version

parent 80d64752
...@@ -49,49 +49,28 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> { ...@@ -49,49 +49,28 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
.then(res => { .then(res => {
const data: TestData[] = []; const data: TestData[] = [];
// The results are not in the order we asked for them // Returns data in the order it was asked for.
if (res.data.results) { // if the response has data with different refId, it is ignored
const byRefID: TestDataRegistry = {}; for (let i = 0; i < queries.length; i++) {
const query = queries[i];
_.forEach(res.data.results, queryRes => { const results = res.data.results[query.refId];
const refId = queryRes.refId || 'Result' + data.length + 1; if (results) {
const qdata: TestData[] = []; if (results.tables) {
byRefID[refId] = qdata; for (const table of results.tables) {
data.push(table as TableData);
if (queryRes.tables) {
for (const table of queryRes.tables) {
qdata.push(table as TableData);
} }
} }
if (queryRes.series) { if (results.series) {
for (const series of queryRes.series) { for (const series of results.series) {
qdata.push({ data.push({
target: series.name, target: series.name,
datapoints: series.points, datapoints: series.points,
}); });
} }
} }
}); } else {
console.warn('No Results for:', query);
// Return them in the order they were asked for }
queries.forEach(q => {
const found = byRefID[q.refId];
if (found) {
for (const d of found) {
data.push(d);
byRefID[q.refId] = null;
}
}
});
// In case there are items left over
_.forEach(byRefID, v => {
if (v) {
for (const d of v) {
data.push(d);
}
}
});
} }
return { data: data }; return { data: data };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment