DashboardScenes: Fix issue where relative time does not pass properly (#99282) (#99798)

fix issue where relative time does not pass properly

(cherry picked from commit bf1a0837af)

Co-authored-by: Victor Marin <36818606+mdvictor@users.noreply.github.com>
This commit is contained in:
Sergej-Vlasov
2025-01-30 10:48:25 +00:00
committed by GitHub
co-authored by Victor Marin
parent c7917bf9c8
commit d41e17725c
2 changed files with 22 additions and 0 deletions
@@ -47,6 +47,19 @@ describe('PanelTimeRange', () => {
expect(panelTime.state.value.from.toISOString()).toBe('2019-02-11T15:00:00.000Z');
expect(panelTime.state.timeInfo).toBe('Last 2 hours timeshift -2h');
});
it('should update panelTimeRange from/to based on scene timeRange on activate', () => {
const panelTime = new PanelTimeRange({});
const panel = new SceneCanvasText({ text: 'Hello', $timeRange: panelTime });
const scene = new SceneFlexLayout({
$timeRange: new SceneTimeRange({ from: 'now-12h', to: 'now-2h' }),
children: [new SceneFlexItem({ body: panel })],
});
activateFullSceneTree(scene);
expect(panelTime.state.from).toBe('now-12h');
expect(panelTime.state.to).toBe('now-2h');
});
});
function buildAndActivateSceneFor(panelTime: PanelTimeRange) {
@@ -43,6 +43,15 @@ export class PanelTimeRange extends SceneTimeRangeTransformerBase<PanelTimeRange
}
})
);
const { timeRange } = this.getTimeOverride(this.getAncestorTimeRange().state.value);
// set initial values on activate
this.setState({
value: timeRange,
from: timeRange.raw.from.toString(),
to: timeRange.raw.to.toString(),
});
}
protected ancestorTimeRangeChanged(timeRange: SceneTimeRangeState): void {
const overrideResult = this.getTimeOverride(timeRange.value);