mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-23 18:36:16 +00:00
* feat: created a component for apdex * refactor: added get and set apDexSetting API support * refactor: done with ApDexSetting * feat: done with the traces graph for ApDex * refactor: separated traces using feature flag * refactor: restucture the component level * feat: done with metrics ApDex application * refactor: removed unwanted logs * fix: some css part * refactor: handle error state * refactor: made use of constants and handleGraphClick for apDex * refactor: shifted type to type.ts * chore: css fixes * refactor: handle error and loading state * refactor: one on one mapping * refactor: according to review comments * refactor: removed unwanted color from local theme colors * refactor: one on one mapping for queryKey * refactor: updated css for view traces button issue * chore: commented out the ExcludeStatusCode feature * refactor: updated some css part of ApDexSetting popover * test: added test case for ApDexApplication and ApDexSettings * refactor: test cases * refactor: review comments * refactor: remove the checked for threshold size upto 1 * refactor: changed some text part of ApDex * refactor: only ApDexMetrics inuse * refactor: changes due to merge conflicts * fix: build pipeline * chore: change the type of the threshold * feat: widget header as ReactNode * chore: error for the title is updated * refactor: widget header as Reactnode * refactor: show tooltip when hover over the question icon * refactor: review changes * refactor: convert threadhold to ReactNode * refactor: updated test cases * refactor: move allow threshold a level up * fix: build pipeline * fix: input number issue for value 0 --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
188 lines
4.8 KiB
TypeScript
188 lines
4.8 KiB
TypeScript
import { ChartData } from 'chart.js';
|
|
import Spinner from 'components/Spinner';
|
|
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
|
|
import { useStepInterval } from 'hooks/queryBuilder/useStepInterval';
|
|
import usePreviousValue from 'hooks/usePreviousValue';
|
|
import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables';
|
|
import getChartData from 'lib/getChartData';
|
|
import isEmpty from 'lodash-es/isEmpty';
|
|
import { memo, useMemo, useState } from 'react';
|
|
import { useInView } from 'react-intersection-observer';
|
|
import { useSelector } from 'react-redux';
|
|
import { AppState } from 'store/reducers';
|
|
import DashboardReducer from 'types/reducer/dashboards';
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
import { getSelectedDashboardVariable } from 'utils/dashboard/selectedDashboard';
|
|
|
|
import EmptyWidget from '../EmptyWidget';
|
|
import { MenuItemKeys } from '../WidgetHeader/contants';
|
|
import { GridCardGraphProps } from './types';
|
|
import WidgetGraphComponent from './WidgetGraphComponent';
|
|
|
|
function GridCardGraph({
|
|
widget,
|
|
name,
|
|
yAxisUnit,
|
|
layout = [],
|
|
setLayout,
|
|
onDragSelect,
|
|
onClickHandler,
|
|
headerMenuList = [MenuItemKeys.View],
|
|
isQueryEnabled,
|
|
threshold,
|
|
}: GridCardGraphProps): JSX.Element {
|
|
const { isAddWidget } = useSelector<AppState, DashboardReducer>(
|
|
(state) => state.dashboards,
|
|
);
|
|
|
|
const { ref: graphRef, inView: isGraphVisible } = useInView({
|
|
threshold: 0,
|
|
triggerOnce: true,
|
|
initialInView: false,
|
|
});
|
|
|
|
const [errorMessage, setErrorMessage] = useState<string | undefined>('');
|
|
|
|
const { minTime, maxTime, selectedTime: globalSelectedInterval } = useSelector<
|
|
AppState,
|
|
GlobalReducer
|
|
>((state) => state.globalTime);
|
|
const { dashboards } = useSelector<AppState, DashboardReducer>(
|
|
(state) => state.dashboards,
|
|
);
|
|
|
|
const variables = getSelectedDashboardVariable(dashboards);
|
|
|
|
const updatedQuery = useStepInterval(widget?.query);
|
|
|
|
const isEmptyWidget = useMemo(
|
|
() => widget?.id === 'empty' || isEmpty(widget),
|
|
[widget],
|
|
);
|
|
|
|
const queryResponse = useGetQueryRange(
|
|
{
|
|
selectedTime: widget?.timePreferance,
|
|
graphType: widget?.panelTypes,
|
|
query: updatedQuery,
|
|
globalSelectedInterval,
|
|
variables: getDashboardVariables(),
|
|
},
|
|
{
|
|
queryKey: [
|
|
`GetMetricsQueryRange-${widget?.timePreferance}-${globalSelectedInterval}-${widget?.id}`,
|
|
maxTime,
|
|
minTime,
|
|
globalSelectedInterval,
|
|
variables,
|
|
widget?.query,
|
|
widget?.panelTypes,
|
|
],
|
|
keepPreviousData: true,
|
|
enabled: isGraphVisible && !isEmptyWidget && isQueryEnabled && !isAddWidget,
|
|
refetchOnMount: false,
|
|
onError: (error) => {
|
|
setErrorMessage(error.message);
|
|
},
|
|
},
|
|
);
|
|
|
|
const chartData = useMemo(
|
|
() =>
|
|
getChartData({
|
|
queryData: [
|
|
{
|
|
queryData: queryResponse?.data?.payload?.data?.result || [],
|
|
},
|
|
],
|
|
}),
|
|
[queryResponse],
|
|
);
|
|
|
|
const prevChartDataSetRef = usePreviousValue<ChartData>(chartData);
|
|
|
|
const isEmptyLayout = widget?.id === 'empty' || isEmpty(widget);
|
|
|
|
if (queryResponse.isRefetching || queryResponse.isLoading) {
|
|
return <Spinner height="20vh" tip="Loading..." />;
|
|
}
|
|
|
|
if ((queryResponse.isError && !isEmptyLayout) || !isQueryEnabled) {
|
|
return (
|
|
<span ref={graphRef}>
|
|
{!isEmpty(widget) && prevChartDataSetRef && (
|
|
<WidgetGraphComponent
|
|
enableModel
|
|
enableWidgetHeader
|
|
widget={widget}
|
|
queryResponse={queryResponse}
|
|
errorMessage={errorMessage}
|
|
data={prevChartDataSetRef}
|
|
name={name}
|
|
yAxisUnit={yAxisUnit}
|
|
layout={layout}
|
|
setLayout={setLayout}
|
|
threshold={threshold}
|
|
headerMenuList={headerMenuList}
|
|
/>
|
|
)}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
if (!isEmpty(widget) && prevChartDataSetRef?.labels) {
|
|
return (
|
|
<span ref={graphRef}>
|
|
<WidgetGraphComponent
|
|
enableModel={false}
|
|
enableWidgetHeader
|
|
widget={widget}
|
|
queryResponse={queryResponse}
|
|
errorMessage={errorMessage}
|
|
data={prevChartDataSetRef}
|
|
name={name}
|
|
yAxisUnit={yAxisUnit}
|
|
layout={layout}
|
|
setLayout={setLayout}
|
|
threshold={threshold}
|
|
headerMenuList={headerMenuList}
|
|
onClickHandler={onClickHandler}
|
|
/>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<span ref={graphRef}>
|
|
{!isEmpty(widget) && !!queryResponse.data?.payload && (
|
|
<WidgetGraphComponent
|
|
enableModel={!isEmptyLayout}
|
|
enableWidgetHeader={!isEmptyLayout}
|
|
widget={widget}
|
|
queryResponse={queryResponse}
|
|
errorMessage={errorMessage}
|
|
data={chartData}
|
|
name={name}
|
|
yAxisUnit={yAxisUnit}
|
|
onDragSelect={onDragSelect}
|
|
threshold={threshold}
|
|
headerMenuList={headerMenuList}
|
|
onClickHandler={onClickHandler}
|
|
/>
|
|
)}
|
|
|
|
{isEmptyLayout && <EmptyWidget />}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
GridCardGraph.defaultProps = {
|
|
onDragSelect: undefined,
|
|
onClickHandler: undefined,
|
|
isQueryEnabled: true,
|
|
threshold: undefined,
|
|
headerMenuList: [MenuItemKeys.View],
|
|
};
|
|
|
|
export default memo(GridCardGraph);
|