Postgres/MySQL/MSSQL: Adds support for region annotations (#20752)

Adds support for region annotations in Postgres, MySQL and 
MSSQL data sources by adding a column named timeend to 
annotation query.

Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Closes #20918
Ref #10589
This commit is contained in:
Jerry Ylilammi
2019-12-13 18:25:36 +02:00
committed by Marcus Efraimsson
parent f65da93d72
commit e27ab89aed
13 changed files with 249 additions and 28 deletions

View File

@ -107,6 +107,7 @@ export default class ResponseParser {
const table = data.data.results[options.annotation.name].tables[0];
let timeColumnIndex = -1;
let timeEndColumnIndex = -1;
const titleColumnIndex = -1;
let textColumnIndex = -1;
let tagsColumnIndex = -1;
@ -114,6 +115,8 @@ export default class ResponseParser {
for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time') {
timeColumnIndex = i;
} else if (table.columns[i].text === 'timeend') {
timeEndColumnIndex = i;
} else if (table.columns[i].text === 'text') {
textColumnIndex = i;
} else if (table.columns[i].text === 'tags') {
@ -130,9 +133,12 @@ export default class ResponseParser {
const list = [];
for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i];
const timeEnd =
timeEndColumnIndex !== -1 && row[timeEndColumnIndex] ? Math.floor(row[timeEndColumnIndex]) : undefined;
list.push({
annotation: options.annotation,
time: Math.floor(row[timeColumnIndex]),
timeEnd,
title: row[titleColumnIndex],
text: row[textColumnIndex],
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],