mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-13 12:51:30 +08:00

* fix: add converting to ms for the durationNano attrbute * fix: add ms title to the graph --------- Co-authored-by: Vishal Sharma <makeavish786@gmail.com>
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
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 { useMemo } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { AppState } from 'store/reducers';
|
|
import { DataSource } from 'types/common/queryBuilder';
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
|
|
import TimeSeriesView from './TimeSeriesView';
|
|
import { convertDataValueToMs } from './utils';
|
|
|
|
function TimeSeriesViewContainer({
|
|
dataSource = DataSource.TRACES,
|
|
}: TimeSeriesViewProps): JSX.Element {
|
|
const { stagedQuery, currentQuery, panelType } = useQueryBuilder();
|
|
|
|
const { selectedTime: globalSelectedTime, maxTime, minTime } = useSelector<
|
|
AppState,
|
|
GlobalReducer
|
|
>((state) => state.globalTime);
|
|
|
|
const isValidToConvertToMs = useMemo(() => {
|
|
const isValid: boolean[] = [];
|
|
|
|
currentQuery.builder.queryData.forEach(
|
|
({ aggregateAttribute, aggregateOperator }) => {
|
|
const isExistDurationNanoAttribute =
|
|
aggregateAttribute.key === 'durationNano';
|
|
|
|
const isCountOperator =
|
|
aggregateOperator === 'count' || aggregateOperator === 'count_distinct';
|
|
|
|
isValid.push(!isCountOperator && isExistDurationNanoAttribute);
|
|
},
|
|
);
|
|
|
|
return isValid.every(Boolean);
|
|
}, [currentQuery]);
|
|
|
|
const { data, isLoading, isError } = useGetQueryRange(
|
|
{
|
|
query: stagedQuery || initialQueriesMap[dataSource],
|
|
graphType: panelType || PANEL_TYPES.TIME_SERIES,
|
|
selectedTime: 'GLOBAL_TIME',
|
|
globalSelectedInterval: globalSelectedTime,
|
|
params: {
|
|
dataSource,
|
|
},
|
|
},
|
|
{
|
|
queryKey: [
|
|
REACT_QUERY_KEY.GET_QUERY_RANGE,
|
|
globalSelectedTime,
|
|
maxTime,
|
|
minTime,
|
|
stagedQuery,
|
|
],
|
|
enabled: !!stagedQuery && panelType === PANEL_TYPES.TIME_SERIES,
|
|
},
|
|
);
|
|
|
|
const responseData = useMemo(
|
|
() => (isValidToConvertToMs ? convertDataValueToMs(data) : data),
|
|
[data, isValidToConvertToMs],
|
|
);
|
|
|
|
return (
|
|
<TimeSeriesView
|
|
isError={isError}
|
|
isLoading={isLoading}
|
|
data={responseData}
|
|
yAxisUnit={isValidToConvertToMs ? 'ms' : 'short'}
|
|
/>
|
|
);
|
|
}
|
|
|
|
interface TimeSeriesViewProps {
|
|
dataSource?: DataSource;
|
|
}
|
|
|
|
TimeSeriesViewContainer.defaultProps = {
|
|
dataSource: DataSource.TRACES,
|
|
};
|
|
|
|
export default TimeSeriesViewContainer;
|