mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-12 15:31:32 +08:00

* feat: add drag select functionality to chart * fix: use redux stored values for time frame selection * fix: ignore clicks on chart without dragging * feat: add intersection cursor to chart * refactor: update drag-select chart plugin * fix: respond to drag-select mouseup outside of chart * fix: remove unnecessary chart update * feat: add drag-select to dashboard charts * refactor: add util functions to create custom plugin options * fix: enable custom chart plugins Co-authored-by: Palash Gupta <palashgdev@gmail.com> Co-authored-by: Ankit Nayan <ankit@signoz.io>
130 lines
3.2 KiB
TypeScript
130 lines
3.2 KiB
TypeScript
import { Button } from 'antd';
|
|
import { GraphOnClickHandler } from 'components/Graph';
|
|
import Spinner from 'components/Spinner';
|
|
import TimePreference from 'components/TimePreferenceDropDown';
|
|
import GridGraphComponent from 'container/GridGraphComponent';
|
|
import {
|
|
timeItems,
|
|
timePreferance,
|
|
} from 'container/NewWidget/RightContainer/timeItems';
|
|
import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables';
|
|
import getChartData from 'lib/getChartData';
|
|
import React, { useCallback, useState } from 'react';
|
|
import { useQuery } from 'react-query';
|
|
import { useSelector } from 'react-redux';
|
|
import { GetMetricQueryRange } from 'store/actions/dashboard/getQueryResults';
|
|
import { AppState } from 'store/reducers';
|
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
|
import { Widgets } from 'types/api/dashboard/getAll';
|
|
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
|
|
import { TimeContainer } from './styles';
|
|
|
|
function FullView({
|
|
widget,
|
|
fullViewOptions = true,
|
|
onClickHandler,
|
|
name,
|
|
yAxisUnit,
|
|
onDragSelect,
|
|
}: FullViewProps): JSX.Element {
|
|
const { selectedTime: globalSelectedTime } = useSelector<
|
|
AppState,
|
|
GlobalReducer
|
|
>((state) => state.globalTime);
|
|
|
|
const getSelectedTime = useCallback(
|
|
() =>
|
|
timeItems.find((e) => e.enum === (widget?.timePreferance || 'GLOBAL_TIME')),
|
|
[widget],
|
|
);
|
|
|
|
const [selectedTime, setSelectedTime] = useState<timePreferance>({
|
|
name: getSelectedTime()?.name || '',
|
|
enum: widget?.timePreferance || 'GLOBAL_TIME',
|
|
});
|
|
const response = useQuery<
|
|
SuccessResponse<MetricRangePayloadProps> | ErrorResponse
|
|
>(
|
|
`FullViewGetMetricsQueryRange-${selectedTime.enum}-${globalSelectedTime}-${widget.id}`,
|
|
() =>
|
|
GetMetricQueryRange({
|
|
selectedTime: selectedTime.enum,
|
|
graphType: widget.panelTypes,
|
|
query: widget.query,
|
|
globalSelectedInterval: globalSelectedTime,
|
|
variables: getDashboardVariables(),
|
|
}),
|
|
);
|
|
|
|
const isLoading = response.isLoading === true;
|
|
|
|
if (isLoading) {
|
|
return <Spinner height="100%" size="large" tip="Loading..." />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{fullViewOptions && (
|
|
<TimeContainer>
|
|
<TimePreference
|
|
{...{
|
|
selectedTime,
|
|
setSelectedTime,
|
|
}}
|
|
/>
|
|
<Button
|
|
onClick={(): void => {
|
|
response.refetch();
|
|
}}
|
|
type="primary"
|
|
>
|
|
Refresh
|
|
</Button>
|
|
</TimeContainer>
|
|
)}
|
|
|
|
<GridGraphComponent
|
|
{...{
|
|
GRAPH_TYPES: widget.panelTypes,
|
|
data: getChartData({
|
|
queryData: [
|
|
{
|
|
queryData: response.data?.payload?.data?.result
|
|
? response.data?.payload?.data?.result
|
|
: [],
|
|
},
|
|
],
|
|
}),
|
|
isStacked: widget.isStacked,
|
|
opacity: widget.opacity,
|
|
title: widget.title,
|
|
onClickHandler,
|
|
name,
|
|
yAxisUnit,
|
|
onDragSelect,
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
interface FullViewProps {
|
|
widget: Widgets;
|
|
fullViewOptions?: boolean;
|
|
onClickHandler?: GraphOnClickHandler;
|
|
name: string;
|
|
yAxisUnit?: string;
|
|
onDragSelect?: (start: number, end: number) => void;
|
|
}
|
|
|
|
FullView.defaultProps = {
|
|
fullViewOptions: undefined,
|
|
onClickHandler: undefined,
|
|
yAxisUnit: undefined,
|
|
onDragSelect: undefined,
|
|
};
|
|
|
|
export default FullView;
|