Vishal Sharma 02ef1744b4
feat: add autocomplete to groupBy filters (#2156)
* feat: add autocomplete to groupBy filters

* chore: handle none groupby in frontend

---------

Co-authored-by: Palash Gupta <palashgdev@gmail.com>
2023-02-07 11:41:09 +05:30

62 lines
1.4 KiB
TypeScript

import { Typography } from 'antd';
import Graph from 'components/Graph';
import Spinner from 'components/Spinner';
import React, { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useMeasure } from 'react-use';
import { AppState } from 'store/reducers';
import { TraceReducer } from 'types/reducer/trace';
import { getChartData, getChartDataforGroupBy } from './config';
import { Container } from './styles';
function TraceGraph(): JSX.Element {
const [ref, { width }] = useMeasure();
const { spansGraph, selectedGroupBy, yAxisUnit } = useSelector<
AppState,
TraceReducer
>((state) => state.traces);
const { loading, error, errorMessage, payload } = spansGraph;
const ChartData = useMemo(
() =>
selectedGroupBy.length === 0 || selectedGroupBy === 'none'
? getChartData(payload)
: getChartDataforGroupBy(payload),
[payload, selectedGroupBy],
);
if (error) {
return (
<Container center>
<Typography>{errorMessage || 'Something went wrong'}</Typography>
</Container>
);
}
if (loading) {
return (
<Container>
<Spinner height="20vh" size="small" tip="Loading..." />
</Container>
);
}
return (
<Container ref={ref as never}>
<Graph
animate={false}
data={ChartData}
name="traceGraph"
type="line"
yAxisUnit={yAxisUnit}
forceReRender={width}
/>
</Container>
);
}
export default TraceGraph;