mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-22 09:56:57 +00:00
* feat: custom hook to prevent redundant navigation and handle default params with URL comparison * feat: implement useSafeNavigation to QB, to ensure that the back navigation works properly * fix: handle syncing the relativeTime param with the time picker selected relative time * feat: add support for absolute and relative time sync with time picker component * refactor: integrate safeNavigate in LogsExplorerChart and deprecate the existing back navigation * feat: update pagination query params on pressing next/prev page * fix: fix the issue of NOOP getting converted to Count on coming back from alert creation page * refactor: replace history navigation with safeNavigate in DateTimeSelectionV2 component it also fixes the issue of relativeTime not being added to the url on mounting * feat: integrate useSafeNavigate across service details tabs * fix: fix duplicate redirections by converting the timestamp to milliseconds * fix: replace history navigation with useSafeNavigate in LogsExplorerViews and useUrlQueryData * fix: replace history navigation with useSafeNavigate across dashboard components * fix: use safeNavigate in alert components * fix: fix the issue of back navigation in alert table and sync the pagination with url param * fix: handle back navigation for resource filter and sync the state with url query * fix: fix the issue of double redirection from top operations to traces * fix: replace history.push with safeNavigate in TracesExplorer's updateDashboard * fix: prevent unnecessary query re-runs by checking stagedQuery before redirecting in NewWidget * chore: cleanup * fix: fix the failing tests * fix: fix the documentation redirection failing tests * test: mock useSafeNavigate hook in WidgetGraphComponent test * test: mock useSafeNavigate hook in ExplorerCard test
103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import Graph from 'components/Graph';
|
|
import Spinner from 'components/Spinner';
|
|
import { QueryParams } from 'constants/query';
|
|
import { themeColors } from 'constants/theme';
|
|
import { useSafeNavigate } from 'hooks/useSafeNavigate';
|
|
import useUrlQuery from 'hooks/useUrlQuery';
|
|
import getChartData, { GetChartDataProps } from 'lib/getChartData';
|
|
import GetMinMax from 'lib/getMinMax';
|
|
import { colors } from 'lib/getRandomColor';
|
|
import { memo, useCallback, useMemo } from 'react';
|
|
import { useDispatch } from 'react-redux';
|
|
import { useLocation } from 'react-router-dom';
|
|
import { UpdateTimeInterval } from 'store/actions';
|
|
|
|
import { LogsExplorerChartProps } from './LogsExplorerChart.interfaces';
|
|
import { CardStyled } from './LogsExplorerChart.styled';
|
|
import { getColorsForSeverityLabels } from './utils';
|
|
|
|
function LogsExplorerChart({
|
|
data,
|
|
isLoading,
|
|
isLabelEnabled = true,
|
|
className,
|
|
isLogsExplorerViews = false,
|
|
}: LogsExplorerChartProps): JSX.Element {
|
|
const dispatch = useDispatch();
|
|
const urlQuery = useUrlQuery();
|
|
const location = useLocation();
|
|
const { safeNavigate } = useSafeNavigate();
|
|
const handleCreateDatasets: Required<GetChartDataProps>['createDataset'] = useCallback(
|
|
(element, index, allLabels) => ({
|
|
data: element,
|
|
backgroundColor: isLogsExplorerViews
|
|
? getColorsForSeverityLabels(allLabels[index], index)
|
|
: colors[index % colors.length] || themeColors.red,
|
|
borderColor: isLogsExplorerViews
|
|
? getColorsForSeverityLabels(allLabels[index], index)
|
|
: colors[index % colors.length] || themeColors.red,
|
|
...(isLabelEnabled
|
|
? {
|
|
label: allLabels[index],
|
|
}
|
|
: {}),
|
|
}),
|
|
[isLabelEnabled, isLogsExplorerViews],
|
|
);
|
|
|
|
const onDragSelect = useCallback(
|
|
(start: number, end: number): void => {
|
|
const startTimestamp = Math.trunc(start);
|
|
const endTimestamp = Math.trunc(end);
|
|
|
|
if (startTimestamp !== endTimestamp) {
|
|
dispatch(UpdateTimeInterval('custom', [startTimestamp, endTimestamp]));
|
|
}
|
|
|
|
const { maxTime, minTime } = GetMinMax('custom', [
|
|
startTimestamp,
|
|
endTimestamp,
|
|
]);
|
|
|
|
urlQuery.set(QueryParams.startTime, minTime.toString());
|
|
urlQuery.set(QueryParams.endTime, maxTime.toString());
|
|
urlQuery.delete(QueryParams.relativeTime);
|
|
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
|
|
safeNavigate(generatedUrl);
|
|
},
|
|
[dispatch, location.pathname, safeNavigate, urlQuery],
|
|
);
|
|
|
|
const graphData = useMemo(
|
|
() =>
|
|
getChartData({
|
|
queryData: [
|
|
{
|
|
queryData: data,
|
|
},
|
|
],
|
|
createDataset: handleCreateDatasets,
|
|
}),
|
|
[data, handleCreateDatasets],
|
|
);
|
|
|
|
return (
|
|
<CardStyled className={className}>
|
|
{isLoading ? (
|
|
<Spinner size="default" height="100%" />
|
|
) : (
|
|
<Graph
|
|
name="logsExplorerChart"
|
|
data={graphData.data}
|
|
isStacked={isLogsExplorerViews}
|
|
type="bar"
|
|
animate
|
|
onDragSelect={onDragSelect}
|
|
/>
|
|
)}
|
|
</CardStyled>
|
|
);
|
|
}
|
|
|
|
export default memo(LogsExplorerChart);
|