2023-06-16 13:38:39 +03:00
|
|
|
import Graph from 'components/Graph';
|
|
|
|
|
import Spinner from 'components/Spinner';
|
|
|
|
|
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
|
|
|
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
|
|
|
|
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
|
|
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
|
|
|
|
import { getExplorerChartData } from 'lib/explorer/getExplorerChartData';
|
2023-06-23 11:19:53 +03:00
|
|
|
import { memo, useMemo } from 'react';
|
2023-06-16 13:38:39 +03:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
import { AppState } from 'store/reducers';
|
|
|
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
|
|
|
|
|
|
|
|
import { CardStyled } from './LogsExplorerChart.styled';
|
|
|
|
|
|
2023-06-23 11:19:53 +03:00
|
|
|
function LogsExplorerChart(): JSX.Element {
|
|
|
|
|
const { stagedQuery, panelType, isEnabledQuery } = useQueryBuilder();
|
2023-06-16 13:38:39 +03:00
|
|
|
|
|
|
|
|
const { selectedTime } = useSelector<AppState, GlobalReducer>(
|
|
|
|
|
(state) => state.globalTime,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { data, isFetching } = useGetQueryRange(
|
|
|
|
|
{
|
|
|
|
|
query: stagedQuery || initialQueriesMap.metrics,
|
2023-06-23 11:19:53 +03:00
|
|
|
graphType: panelType || PANEL_TYPES.LIST,
|
2023-06-16 13:38:39 +03:00
|
|
|
globalSelectedInterval: selectedTime,
|
|
|
|
|
selectedTime: 'GLOBAL_TIME',
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-06-23 11:19:53 +03:00
|
|
|
queryKey: [REACT_QUERY_KEY.GET_QUERY_RANGE, selectedTime, stagedQuery],
|
|
|
|
|
enabled: isEnabledQuery,
|
2023-06-16 13:38:39 +03:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const graphData = useMemo(() => {
|
|
|
|
|
if (data?.payload.data && data.payload.data.result.length > 0) {
|
|
|
|
|
return getExplorerChartData([data.payload.data.result[0]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getExplorerChartData([]);
|
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CardStyled>
|
|
|
|
|
{isFetching ? (
|
|
|
|
|
<Spinner size="default" height="100%" />
|
|
|
|
|
) : (
|
|
|
|
|
<Graph
|
|
|
|
|
name="logsExplorerChart"
|
|
|
|
|
data={graphData}
|
|
|
|
|
type="bar"
|
|
|
|
|
containerHeight="100%"
|
|
|
|
|
animate
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</CardStyled>
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-06-23 11:19:53 +03:00
|
|
|
|
|
|
|
|
export default memo(LogsExplorerChart);
|