The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/explore/TraceView/useHoverIndentGuide.ts

30 lines
1.2 KiB

import { useCallback, useState } from 'react';
/**
* This is used internally to handle hover state of indent guide. As indent guides are separate
* components per each row/span and you need to highlight all in multiple rows to make the effect of single line
* they need this kind of common imperative state changes.
*
* Ideally would be changed to trace view internal state.
*/
export function useHoverIndentGuide() {
const [hoverIndentGuideIds, setHoverIndentGuideIds] = useState(new Set<string>());
const addHoverIndentGuideId = useCallback(function addHoverIndentGuideId(spanID: string) {
setHoverIndentGuideIds((prevState) => {
const newHoverIndentGuideIds = new Set(prevState);
newHoverIndentGuideIds.add(spanID);
return newHoverIndentGuideIds;
});
}, []);
const removeHoverIndentGuideId = useCallback(function removeHoverIndentGuideId(spanID: string) {
setHoverIndentGuideIds((prevState) => {
const newHoverIndentGuideIds = new Set(prevState);
newHoverIndentGuideIds.delete(spanID);
return newHoverIndentGuideIds;
});
}, []);
return { hoverIndentGuideIds, addHoverIndentGuideId, removeHoverIndentGuideId };
}