grafana/public/app/features/scenes/components/SceneTimePicker.tsx
Torkel Ödegaard 8c585a4ebf
Scene: Variables interpolation formats and multi value handling (#58591)
* Component that can cache and extract variable dependencies

* Component that can cache and extract variable dependencies

* Updates

* Refactoring

* Lots of refactoring and iterations of supporting both re-rendering and query re-execution

* Updated SceneCanvasText

* Updated name of file

* Updated

* Refactoring a bit

* Added back getName

* Added comment

* minor fix

* Minor fix

* Merge fixes

* Scene variable interpolation progress

* Merge fixes

* Added all format registeries

* Progress on multi value support

* Progress on multi value support

* Updates

* Progress on scoped vars

* Fixed circular dependency

* Updates

* Some review fixes

* Updated comment

* Added forceRender function

* Add back fail on console log

* Update public/app/features/scenes/variables/interpolation/sceneInterpolator.test.ts

* Moving functions from SceneObjectBase

* fixing tests

* Fixed e2e

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2022-11-16 11:36:30 +01:00

45 lines
1.4 KiB
TypeScript

import React from 'react';
import { RefreshPicker, ToolbarButtonRow } from '@grafana/ui';
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
import { SceneObjectBase } from '../core/SceneObjectBase';
import { sceneGraph } from '../core/sceneGraph';
import { SceneComponentProps, SceneObjectStatePlain } from '../core/types';
export interface SceneTimePickerState extends SceneObjectStatePlain {
hidePicker?: boolean;
}
export class SceneTimePicker extends SceneObjectBase<SceneTimePickerState> {
public static Component = SceneTimePickerRenderer;
}
function SceneTimePickerRenderer({ model }: SceneComponentProps<SceneTimePicker>) {
const { hidePicker } = model.useState();
const timeRange = sceneGraph.getTimeRange(model);
const timeRangeState = timeRange.useState();
if (hidePicker) {
return null;
}
return (
<ToolbarButtonRow alignment="right">
<TimePickerWithHistory
value={timeRangeState}
onChange={timeRange.onTimeRangeChange}
timeZone={'browser'}
fiscalYearStartMonth={0}
onMoveBackward={() => {}}
onMoveForward={() => {}}
onZoom={() => {}}
onChangeTimeZone={() => {}}
onChangeFiscalYearStartMonth={() => {}}
/>
<RefreshPicker onRefresh={timeRange.onRefresh} onIntervalChanged={timeRange.onIntervalChanged} />
</ToolbarButtonRow>
);
}