DashboardScene: Support panel relative time overrides and timeshift (#62844)

* Things are working

* update

* Added unit tests

* More tests

* minor fix

* Update

* Support hideTimeOverride
This commit is contained in:
Torkel Ödegaard
2023-09-01 10:21:41 +02:00
committed by GitHub
parent 8113707dc8
commit f4c127a1d8
17 changed files with 386 additions and 265 deletions
@@ -86,7 +86,7 @@ const hiddenRangeOptions: TimeOption[] = [
{ from: 'now', to: 'now+5y', display: 'Next 5 years' },
];
const rangeIndex: Record<string, any> = {};
const rangeIndex: Record<string, TimeOption> = {};
each(rangeOptions, (frame) => {
rangeIndex[frame.from + ' to ' + frame.to] = frame;
});
@@ -100,7 +100,7 @@ each(hiddenRangeOptions, (frame) => {
// now/d to now
// now/d
// if no to <expr> then to now is assumed
export function describeTextRange(expr: string) {
export function describeTextRange(expr: string): TimeOption {
const isLast = expr.indexOf('+') !== 0;
if (expr.indexOf('now') === -1) {
expr = (isLast ? 'now-' : 'now') + expr;
@@ -112,9 +112,9 @@ export function describeTextRange(expr: string) {
}
if (isLast) {
opt = { from: expr, to: 'now' };
opt = { from: expr, to: 'now', display: '' };
} else {
opt = { from: 'now', to: expr };
opt = { from: 'now', to: expr, display: '' };
}
const parts = /^now([-+])(\d+)(\w)/.exec(expr);