grafana/public/app/features/explore/TraceView/useViewRange.ts
Andre Pereira afd39c18ba
Explore: Refactor trace view and move to core (#61938)
* Move TraceView to core grafana

* Remove unused code

* yarn install

* Remove jaeger-ui-components from CODEOWNERS and other tools

* Type fixes

* yarn install

* Remove mock that we no longer need

* Fix merge conflicts

* Re-add Apache license for trace view components

* Use an exclamation-circle instead of triangle to denote errors

* Remove eslint disables and update betterer results instead
2023-01-27 14:13:17 +00:00

33 lines
1.1 KiB
TypeScript

import { useCallback, useState } from 'react';
import { ViewRangeTimeUpdate, ViewRange } from './components';
/**
* Controls state of the zoom function that can be used through minimap in header or on the timeline. ViewRange contains
* state not only for current range that is showing but range that is currently being selected by the user.
*/
export function useViewRange() {
const [viewRange, setViewRange] = useState<ViewRange>({
time: {
current: [0, 1],
},
});
const updateNextViewRangeTime = useCallback(function updateNextViewRangeTime(update: ViewRangeTimeUpdate) {
setViewRange((prevRange): ViewRange => {
const time = { ...prevRange.time, ...update };
return { ...prevRange, time };
});
}, []);
const updateViewRangeTime = useCallback(function updateViewRangeTime(start: number, end: number) {
const current: [number, number] = [start, end];
const time = { current };
setViewRange((prevRange): ViewRange => {
return { ...prevRange, time };
});
}, []);
return { viewRange, updateViewRangeTime, updateNextViewRangeTime };
}