[v11.3.x] DashboardScenes: Fix issue where relative time does not pass properly (#99299)
DashboardScenes: Fix issue where relative time does not pass properly (#99282)
fix issue where relative time does not pass properly
(cherry picked from commit bf1a0837af)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user