mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 18:59:10 +08:00
feat: add drag support to alert history horizontal graph (#5928)
* feat: add drag support to alert history horizontal graph * chore: use startTimestamp and endTimestamp * fix: fix the issue of alert history breaking on navigating back from selected time range
This commit is contained in:
parent
5ba9c9d48c
commit
a98c8db949
@ -1,10 +1,15 @@
|
|||||||
import { Color } from '@signozhq/design-tokens';
|
import { Color } from '@signozhq/design-tokens';
|
||||||
import Uplot from 'components/Uplot';
|
import Uplot from 'components/Uplot';
|
||||||
|
import { QueryParams } from 'constants/query';
|
||||||
import { useIsDarkMode } from 'hooks/useDarkMode';
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
||||||
import { useResizeObserver } from 'hooks/useDimensions';
|
import { useResizeObserver } from 'hooks/useDimensions';
|
||||||
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
|
import history from 'lib/history';
|
||||||
import heatmapPlugin from 'lib/uPlotLib/plugins/heatmapPlugin';
|
import heatmapPlugin from 'lib/uPlotLib/plugins/heatmapPlugin';
|
||||||
import timelinePlugin from 'lib/uPlotLib/plugins/timelinePlugin';
|
import timelinePlugin from 'lib/uPlotLib/plugins/timelinePlugin';
|
||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { UpdateTimeInterval } from 'store/actions';
|
||||||
import { AlertRuleTimelineGraphResponse } from 'types/api/alerts/def';
|
import { AlertRuleTimelineGraphResponse } from 'types/api/alerts/def';
|
||||||
import uPlot, { AlignedData } from 'uplot';
|
import uPlot, { AlignedData } from 'uplot';
|
||||||
|
|
||||||
@ -41,11 +46,13 @@ function HorizontalTimelineGraph({
|
|||||||
return [timestamps, states];
|
return [timestamps, states];
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
|
const urlQuery = useUrlQuery();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const options: uPlot.Options = useMemo(
|
const options: uPlot.Options = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
width,
|
width,
|
||||||
height: 85,
|
height: 85,
|
||||||
cursor: { show: false },
|
|
||||||
|
|
||||||
axes: [
|
axes: [
|
||||||
{
|
{
|
||||||
@ -66,6 +73,40 @@ function HorizontalTimelineGraph({
|
|||||||
label: 'States',
|
label: 'States',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
hooks: {
|
||||||
|
setSelect: [
|
||||||
|
(self): void => {
|
||||||
|
const selection = self.select;
|
||||||
|
if (selection) {
|
||||||
|
const startTime = self.posToVal(selection.left, 'x');
|
||||||
|
const endTime = self.posToVal(selection.left + selection.width, 'x');
|
||||||
|
|
||||||
|
const diff = endTime - startTime;
|
||||||
|
|
||||||
|
if (diff > 0) {
|
||||||
|
if (urlQuery.has(QueryParams.relativeTime)) {
|
||||||
|
urlQuery.delete(QueryParams.relativeTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
const startTimestamp = Math.floor(startTime * 1000);
|
||||||
|
const endTimestamp = Math.floor(endTime * 1000);
|
||||||
|
|
||||||
|
if (startTimestamp !== endTimestamp) {
|
||||||
|
dispatch(UpdateTimeInterval('custom', [startTimestamp, endTimestamp]));
|
||||||
|
}
|
||||||
|
|
||||||
|
urlQuery.set(QueryParams.startTime, startTimestamp.toString());
|
||||||
|
urlQuery.set(QueryParams.endTime, endTimestamp.toString());
|
||||||
|
|
||||||
|
history.push({
|
||||||
|
search: urlQuery.toString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
transformedData?.length > 1
|
transformedData?.length > 1
|
||||||
? [
|
? [
|
||||||
@ -76,7 +117,7 @@ function HorizontalTimelineGraph({
|
|||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
}),
|
}),
|
||||||
[width, isDarkMode, transformedData],
|
[width, isDarkMode, transformedData.length, urlQuery, dispatch],
|
||||||
);
|
);
|
||||||
return <Uplot data={transformedData} options={options} />;
|
return <Uplot data={transformedData} options={options} />;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import AlertHistory from 'container/AlertHistory';
|
|||||||
import { TIMELINE_TABLE_PAGE_SIZE } from 'container/AlertHistory/constants';
|
import { TIMELINE_TABLE_PAGE_SIZE } from 'container/AlertHistory/constants';
|
||||||
import { AlertDetailsTab, TimelineFilter } from 'container/AlertHistory/types';
|
import { AlertDetailsTab, TimelineFilter } from 'container/AlertHistory/types';
|
||||||
import { urlKey } from 'container/AllError/utils';
|
import { urlKey } from 'container/AllError/utils';
|
||||||
|
import { RelativeTimeMap } from 'container/TopNav/DateTimeSelection/config';
|
||||||
import useAxiosError from 'hooks/useAxiosError';
|
import useAxiosError from 'hooks/useAxiosError';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
import useUrlQuery from 'hooks/useUrlQuery';
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
@ -31,9 +32,7 @@ import PaginationInfoText from 'periscope/components/PaginationInfoText/Paginati
|
|||||||
import { useAlertRule } from 'providers/Alert';
|
import { useAlertRule } from 'providers/Alert';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useMutation, useQuery, useQueryClient } from 'react-query';
|
import { useMutation, useQuery, useQueryClient } from 'react-query';
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import { generatePath, useLocation } from 'react-router-dom';
|
import { generatePath, useLocation } from 'react-router-dom';
|
||||||
import { AppState } from 'store/reducers';
|
|
||||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
import {
|
import {
|
||||||
AlertDef,
|
AlertDef,
|
||||||
@ -44,7 +43,6 @@ import {
|
|||||||
AlertRuleTopContributorsPayload,
|
AlertRuleTopContributorsPayload,
|
||||||
} from 'types/api/alerts/def';
|
} from 'types/api/alerts/def';
|
||||||
import { PayloadProps } from 'types/api/alerts/get';
|
import { PayloadProps } from 'types/api/alerts/get';
|
||||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
||||||
import { nanoToMilli } from 'utils/timeUtils';
|
import { nanoToMilli } from 'utils/timeUtils';
|
||||||
|
|
||||||
export const useAlertHistoryQueryParams = (): {
|
export const useAlertHistoryQueryParams = (): {
|
||||||
@ -56,11 +54,10 @@ export const useAlertHistoryQueryParams = (): {
|
|||||||
} => {
|
} => {
|
||||||
const params = useUrlQuery();
|
const params = useUrlQuery();
|
||||||
|
|
||||||
const globalTime = useSelector<AppState, GlobalReducer>(
|
|
||||||
(state) => state.globalTime,
|
|
||||||
);
|
|
||||||
const startTime = params.get(QueryParams.startTime);
|
const startTime = params.get(QueryParams.startTime);
|
||||||
const endTime = params.get(QueryParams.endTime);
|
const endTime = params.get(QueryParams.endTime);
|
||||||
|
const relativeTime =
|
||||||
|
params.get(QueryParams.relativeTime) ?? RelativeTimeMap['6hr'];
|
||||||
|
|
||||||
const intStartTime = parseInt(startTime || '0', 10);
|
const intStartTime = parseInt(startTime || '0', 10);
|
||||||
const intEndTime = parseInt(endTime || '0', 10);
|
const intEndTime = parseInt(endTime || '0', 10);
|
||||||
@ -69,8 +66,8 @@ export const useAlertHistoryQueryParams = (): {
|
|||||||
const { maxTime, minTime } = useMemo(() => {
|
const { maxTime, minTime } = useMemo(() => {
|
||||||
if (hasStartAndEndParams)
|
if (hasStartAndEndParams)
|
||||||
return GetMinMax('custom', [intStartTime, intEndTime]);
|
return GetMinMax('custom', [intStartTime, intEndTime]);
|
||||||
return GetMinMax(globalTime.selectedTime);
|
return GetMinMax(relativeTime);
|
||||||
}, [hasStartAndEndParams, intStartTime, intEndTime, globalTime.selectedTime]);
|
}, [hasStartAndEndParams, intStartTime, intEndTime, relativeTime]);
|
||||||
|
|
||||||
const ruleId = params.get(QueryParams.ruleId);
|
const ruleId = params.get(QueryParams.ruleId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user