Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: Chart loaders on reload and change of time interval at dashboard (#2068)

Chintan Sudani213838a021ef
diff --git a/frontend/.husky/commit-msg b/frontend/.husky/commit-msg
index 818ef8b9b5..be422b654c 100755
--- a/frontend/.husky/commit-msg
+++ b/frontend/.husky/commit-msg
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
-cd frontend && npm run commitlint
+cd frontend && yarn run commitlint --edit $1
diff --git a/frontend/src/components/Spinner/index.tsx b/frontend/src/components/Spinner/index.tsx
index 160bfb75f5..819e552442 100644
--- a/frontend/src/components/Spinner/index.tsx
+++ b/frontend/src/components/Spinner/index.tsx
@@ -4,9 +4,9 @@ import React from 'react';
import { SpinerStyle } from './styles';
-function Spinner({ size, tip, height }: SpinnerProps): JSX.Element {
+function Spinner({ size, tip, height, style }: SpinnerProps): JSX.Element {
return (
- <SpinerStyle height={height}>
+ <SpinerStyle height={height} style={style}>
<Spin spinning size={size} tip={tip} indicator={<LoadingOutlined spin />} />
</SpinerStyle>
);
@@ -16,11 +16,13 @@ interface SpinnerProps {
size?: SpinProps['size'];
tip?: SpinProps['tip'];
height?: React.CSSProperties['height'];
+ style?: React.CSSProperties;
}
Spinner.defaultProps = {
size: undefined,
tip: undefined,
height: undefined,
+ style: {},
};
export default Spinner;
diff --git a/frontend/src/container/GridGraphLayout/Graph/FullView/index.metricsBuilder.tsx b/frontend/src/container/GridGraphLayout/Graph/FullView/index.metricsBuilder.tsx
index 4c1912f471..e2ffff224e 100644
--- a/frontend/src/container/GridGraphLayout/Graph/FullView/index.metricsBuilder.tsx
+++ b/frontend/src/container/GridGraphLayout/Graph/FullView/index.metricsBuilder.tsx
@@ -9,7 +9,7 @@ import {
} from 'container/NewWidget/RightContainer/timeItems';
import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables';
import getChartData from 'lib/getChartData';
-import React, { useCallback, useState } from 'react';
+import React, { useCallback, useMemo, useState } from 'react';
import { useQuery } from 'react-query';
import { useSelector } from 'react-redux';
import { GetMetricQueryRange } from 'store/actions/dashboard/getQueryResults';
@@ -58,6 +58,18 @@ function FullView({
}),
);
+ const chartDataSet = useMemo(
+ () =>
+ getChartData({
+ queryData: [
+ {
+ queryData: response?.data?.payload?.data?.result || [],
+ },
+ ],
+ }),
+ [response],
+ );
+
const isLoading = response.isLoading === true;
if (isLoading) {
@@ -86,25 +98,15 @@ function FullView({
)}
<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,
- }}
+ GRAPH_TYPES={widget.panelTypes}
+ data={chartDataSet}
+ isStacked={widget.isStacked}
+ opacity={widget.opacity}
+ title={widget.title}
+ onClickHandler={onClickHandler}
+ name={name}
+ yAxisUnit={yAxisUnit}
+ onDragSelect={onDragSelect}
/>
</>
);
diff --git a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx
index b9c8ba7f38..ff3545bf92 100644
--- a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx
+++ b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx
@@ -15,7 +15,7 @@ import GetMaxMinTime from 'lib/getMaxMinTime';
import GetMinMax from 'lib/getMinMax';
import getStartAndEndTime from 'lib/getStartAndEndTime';
import getStep from 'lib/getStep';
-import React, { useCallback, useState } from 'react';
+import React, { useCallback, useMemo, useState } from 'react';
import { useQueries } from 'react-query';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
@@ -115,6 +115,18 @@ function FullView({
})),
);
+ const chartDataSet = useMemo(
+ () =>
+ getChartData({
+ queryData: data.map((e) => ({
+ query: e?.map((e) => e.query).join(' ') || '',
+ queryData: e?.map((e) => e.queryData) || [],
+ legend: e?.map((e) => e.legend).join('') || '',
+ })),
+ }),
+ [data],
+ );
+
if (isLoading) {
return <Spinner height="100%" size="large" tip="Loading..." />;
}
@@ -149,23 +161,15 @@ function FullView({
)}
<GridGraphComponent
- {...{
- GRAPH_TYPES: widget.panelTypes,
- data: getChartData({
- queryData: data.map((e) => ({
- query: e?.map((e) => e.query).join(' ') || '',
- queryData: e?.map((e) => e.queryData) || [],
- legend: e?.map((e) => e.legend).join('') || '',
- })),
- }),
- isStacked: widget.isStacked,
- opacity: widget.opacity,
- title: widget.title,
- onClickHandler,
- name,
- yAxisUnit,
- onDragSelect,
- }}
+ GRAPH_TYPES={widget.panelTypes}
+ data={chartDataSet}
+ isStacked={widget.isStacked}
+ opacity={widget.opacity}
+ title={widget.title}
+ onClickHandler={onClickHandler}
+ name={name}
+ yAxisUnit={yAxisUnit}
+ onDragSelect={onDragSelect}
/>
</>
);
diff --git a/frontend/src/container/GridGraphLayout/Graph/index.tsx b/frontend/src/container/GridGraphLayout/Graph/index.tsx
index d88bfdc1ad..a47fc6b53d 100644
--- a/frontend/src/container/GridGraphLayout/Graph/index.tsx
+++ b/frontend/src/container/GridGraphLayout/Graph/index.tsx
@@ -1,6 +1,8 @@
import { Typography } from 'antd';
+import { ChartData } from 'chart.js';
import Spinner from 'components/Spinner';
import GridGraphComponent from 'container/GridGraphComponent';
+import usePreviousValue from 'hooks/usePreviousValue';
import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables';
import getChartData from 'lib/getChartData';
import isEmpty from 'lodash-es/isEmpty';
@@ -18,9 +20,7 @@ import { GetMetricQueryRange } from 'store/actions/dashboard/getQueryResults';
import { AppState } from 'store/reducers';
import AppActions from 'types/actions';
import { GlobalTime } from 'types/actions/globalTime';
-import { ErrorResponse, SuccessResponse } from 'types/api';
import { Widgets } from 'types/api/dashboard/getAll';
-import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
import DashboardReducer from 'types/reducer/dashboards';
import { GlobalReducer } from 'types/reducer/globalTime';
@@ -28,7 +28,7 @@ import { LayoutProps } from '..';
import EmptyWidget from '../EmptyWidget';
import WidgetHeader from '../WidgetHeader';
import FullView from './FullView/index.metricsBuilder';
-import { ErrorContainer, FullViewContainer, Modal } from './styles';
+import { FullViewContainer, Modal } from './styles';
function GridCardGraph({
widget,
@@ -39,6 +39,7 @@ function GridCardGraph({
setLayout,
onDragSelect,
}: GridCardGraphProps): JSX.Element {
+ const [errorMessage, setErrorMessage] = useState<string | undefined>('');
const [hovered, setHovered] = useState(false);
const [modal, setModal] = useState(false);
const [deleteModal, setDeleteModal] = useState(false);
@@ -57,9 +58,7 @@ function GridCardGraph({
const selectedData = selectedDashboard?.data;
const { variables } = selectedData;
- const response = useQuery<
- SuccessResponse<MetricRangePayloadProps> | ErrorResponse
- >(
+ const queryResponse = useQuery(
[
`GetMetricsQueryRange-${widget.timePreferance}-${globalSelectedInterval}-${widget.id}`,
{
@@ -81,6 +80,11 @@ function GridCardGraph({
{
keepPreviousData: true,
refetchOnMount: false,
+ onError: (error) => {
+ if (error instanceof Error) {
+ setErrorMessage(error.message);
+ }
+ },
},
);
@@ -89,15 +93,15 @@ function GridCardGraph({
getChartData({
queryData: [
{
- queryData: response?.data?.payload?.data?.result
- ? response?.data?.payload?.data?.result
- : [],
+ queryData: queryResponse?.data?.payload?.data?.result || [],
},
],
}),
- [response?.data?.payload],
+ [queryResponse],
);
+ const prevChartDataSetRef = usePreviousValue<ChartData>(chartData);
+
const onToggleModal = useCallback(
(func: React.Dispatch<React.SetStateAction<boolean>>) => {
func((value) => !value);
@@ -154,39 +158,68 @@ function GridCardGraph({
const isEmptyLayout = widget?.id === 'empty' || isEmpty(widget);
- if (response.isError && !isEmptyLayout) {
+ if (queryResponse.isError && !isEmptyLayout) {
return (
- <>
+ <span>
{getModals()}
- <div className="drag-handle">
- <WidgetHeader
- parentHover={hovered}
- title={widget?.title}
- widget={widget}
- onView={handleOnView}
- onDelete={handleOnDelete}
- />
- </div>
-
- <ErrorContainer>
- {response.isError && 'Something went wrong'}
- </ErrorContainer>
- </>
+ {!isEmpty(widget) && prevChartDataSetRef && (
+ <>
+ <div className="drag-handle">
+ <WidgetHeader
+ parentHover={hovered}
+ title={widget?.title}
+ widget={widget}
+ onView={handleOnView}
+ onDelete={handleOnDelete}
+ queryResponse={queryResponse}
+ errorMessage={errorMessage}
+ />
+ </div>
+ <GridGraphComponent
+ GRAPH_TYPES={widget.panelTypes}
+ data={prevChartDataSetRef}
+ isStacked={widget.isStacked}
+ opacity={widget.opacity}
+ title={' '}
+ name={name}
+ yAxisUnit={yAxisUnit}
+ />
+ </>
+ )}
+ </span>
);
}
- if (response.isFetching) {
+ if (prevChartDataSetRef?.labels === undefined && queryResponse.isLoading) {
return (
- <>
- <WidgetHeader
- parentHover={hovered}
- title={widget?.title}
- widget={widget}
- onView={handleOnView}
- onDelete={handleOnDelete}
- />
- <Spinner height="20vh" tip="Loading..." />
- </>
+ <span>
+ {!isEmpty(widget) && prevChartDataSetRef?.labels ? (
+ <>
+ <div className="drag-handle">
+ <WidgetHeader
+ parentHover={hovered}
+ title={widget?.title}
+ widget={widget}
+ onView={handleOnView}
+ onDelete={handleOnDelete}
+ queryResponse={queryResponse}
+ errorMessage={errorMessage}
+ />
+ </div>
+ <GridGraphComponent
+ GRAPH_TYPES={widget.panelTypes}
+ data={prevChartDataSetRef}
+ isStacked={widget.isStacked}
+ opacity={widget.opacity}
+ title={' '}
+ name={name}
+ yAxisUnit={yAxisUnit}
+ />
+ </>
+ ) : (
+ <Spinner height="20vh" tip="Loading..." />
+ )}
+ </span>
);
}
@@ -213,13 +246,15 @@ function GridCardGraph({
widget={widget}
onView={handleOnView}
onDelete={handleOnDelete}
+ queryResponse={queryResponse}
+ errorMessage={errorMessage}
/>
</div>
)}
{!isEmptyLayout && getModals()}
- {!isEmpty(widget) && !!response.data?.payload?.data?.result && (
+ {!isEmpty(widget) && !!queryResponse.data?.payload && (
<GridGraphComponent
GRAPH_TYPES={widget.panelTypes}
data={chartData}
diff --git a/frontend/src/container/GridGraphLayout/WidgetHeader/config.ts b/frontend/src/container/GridGraphLayout/WidgetHeader/config.ts
new file mode 100644
index 0000000000..55f00c9a86
--- /dev/null
+++ b/frontend/src/container/GridGraphLayout/WidgetHeader/config.ts
@@ -0,0 +1,13 @@
+import { themeColors } from 'constants/theme';
+
+const positionCss: React.CSSProperties['position'] = 'fixed';
+
+export const spinnerStyles = { position: positionCss, right: '0.5rem' };
+export const tooltipStyles = {
+ fontSize: '1rem',
+ top: '0.313rem',
+ position: positionCss,
+ right: '0.313rem',
+ color: themeColors.errorColor,
+};
+export const errorTooltipPosition = 'top';
diff --git a/frontend/src/container/GridGraphLayout/WidgetHeader/index.tsx b/frontend/src/container/GridGraphLayout/WidgetHeader/index.tsx
index d560aaab82..0626f4b3e8 100644
--- a/frontend/src/container/GridGraphLayout/WidgetHeader/index.tsx
+++ b/frontend/src/container/GridGraphLayout/WidgetHeader/index.tsx
@@ -2,17 +2,23 @@ import {
DeleteOutlined,
DownOutlined,
EditFilled,
+ ExclamationCircleOutlined,
FullscreenOutlined,
} from '@ant-design/icons';
-import { Dropdown, Menu, Typography } from 'antd';
+import { Dropdown, Menu, Tooltip, Typography } from 'antd';
+import Spinner from 'components/Spinner';
import useComponentPermission from 'hooks/useComponentPermission';
import history from 'lib/history';
import React, { useState } from 'react';
+import { UseQueryResult } from 'react-query';
import { useSelector } from 'react-redux';
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 AppReducer from 'types/reducer/app';
+import { errorTooltipPosition, spinnerStyles, tooltipStyles } from './config';
import {
ArrowContainer,
HeaderContainer,
@@ -27,6 +33,10 @@ interface IWidgetHeaderProps {
onView: VoidFunction;
onDelete: VoidFunction;
parentHover: boolean;
+ queryResponse: UseQueryResult<
+ SuccessResponse<MetricRangePayloadProps> | ErrorResponse
+ >;
+ errorMessage: string | undefined;
}
function WidgetHeader({
title,
@@ -34,6 +44,8 @@ function WidgetHeader({
onView,
onDelete,
parentHover,
+ queryResponse,
+ errorMessage,
}: IWidgetHeaderProps): JSX.Element {
const [localHover, setLocalHover] = useState(false);
@@ -106,20 +118,30 @@ function WidgetHeader({
overlayStyle={{ minWidth: 100 }}
placement="bottom"
>
- <HeaderContainer
- onMouseOver={(): void => setLocalHover(true)}
- onMouseOut={(): void => setLocalHover(false)}
- hover={localHover}
- >
- <HeaderContentContainer onClick={(e): void => e.preventDefault()}>
- <Typography.Text style={{ maxWidth: '80%' }} ellipsis>
- {title}
- </Typography.Text>
- <ArrowContainer hover={parentHover}>
- <DownOutlined />
- </ArrowContainer>
- </HeaderContentContainer>
- </HeaderContainer>
+ <>
+ <HeaderContainer
+ onMouseOver={(): void => setLocalHover(true)}
+ onMouseOut={(): void => setLocalHover(false)}
+ hover={localHover}
+ >
+ <HeaderContentContainer onClick={(e): void => e.preventDefault()}>
+ <Typography.Text style={{ maxWidth: '80%' }} ellipsis>
+ {title}
+ </Typography.Text>
+ <ArrowContainer hover={parentHover}>
+ <DownOutlined />
+ </ArrowContainer>
+ </HeaderContentContainer>
+ </HeaderContainer>
+ {queryResponse.isFetching && !queryResponse.isError && (
+ <Spinner height="5vh" style={spinnerStyles} />
+ )}
+ {queryResponse.isError && (
+ <Tooltip title={errorMessage} placement={errorTooltipPosition}>
+ <ExclamationCircleOutlined style={tooltipStyles} />
+ </Tooltip>
+ )}
+ </>
</Dropdown>
);
}
diff --git a/frontend/src/container/MetricsApplication/index.tsx b/frontend/src/container/MetricsApplication/index.tsx
index 1465103dc0..af76ca95ae 100644
--- a/frontend/src/container/MetricsApplication/index.tsx
+++ b/frontend/src/container/MetricsApplication/index.tsx
@@ -1,6 +1,6 @@
import RouteTab from 'components/RouteTab';
import ROUTES from 'constants/routes';
-import React from 'react';
+import React, { memo } from 'react';
import { generatePath, useParams } from 'react-router-dom';
import { useLocation } from 'react-use';
@@ -85,4 +85,4 @@ function ServiceMetrics(): JSX.Element {
);
}
-export default React.memo(ServiceMetrics);
+export default memo(ServiceMetrics);
diff --git a/frontend/src/hooks/usePreviousValue.ts b/frontend/src/hooks/usePreviousValue.ts
new file mode 100644
index 0000000000..dcda2f013c
--- /dev/null
+++ b/frontend/src/hooks/usePreviousValue.ts
@@ -0,0 +1,13 @@
+import { useEffect, useRef } from 'react';
+
+function usePreviousValue<T>(value: T): T {
+ const ref = useRef<T>();
+
+ useEffect(() => {
+ ref.current = value;
+ }, [value]);
+
+ return ref.current as T;
+}
+
+export default usePreviousValue;