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(dashboards): restore all series when the isolated legend row is clicked (#12864)

Abhi kumar861e5f75cf1c
diff --git a/frontend/src/lib/uPlotV2/components/Legend/LegendRow.tsx b/frontend/src/lib/uPlotV2/components/Legend/LegendRow.tsx
index fd8eec2596..5400ea51ae 100644
--- a/frontend/src/lib/uPlotV2/components/Legend/LegendRow.tsx
+++ b/frontend/src/lib/uPlotV2/components/Legend/LegendRow.tsx
@@ -45,15 +45,17 @@ function LegendRow({
// a usable CSS colour for the marker.
const seriesColor = typeof item.color === 'string' ? item.color : undefined;
- /** Everything showing -> isolate, since there is nothing to exclude yet. */
- const handleRowClick = useCallback(
- (): void =>
- onAction({
- type: isAllShown ? LegendAction.SHOW_ONLY : LegendAction.TOGGLE,
- seriesIndex,
- }),
- [isAllShown, onAction, seriesIndex],
- );
+ /** Everything showing -> isolate; showing alone -> restore all. */
+ const handleRowClick = useCallback((): void => {
+ if (isSoleShown) {
+ onAction({ type: LegendAction.SHOW_ALL });
+ return;
+ }
+ onAction({
+ type: isAllShown ? LegendAction.SHOW_ONLY : LegendAction.TOGGLE,
+ seriesIndex,
+ });
+ }, [isSoleShown, isAllShown, onAction, seriesIndex]);
const handleMarkerClick = useCallback(
(event: MouseEvent<HTMLButtonElement>): void => {
diff --git a/frontend/src/lib/uPlotV2/components/__tests__/UPlotLegend.test.tsx b/frontend/src/lib/uPlotV2/components/Legend/__tests__/UPlotLegend.test.tsx
similarity index 95%
rename from frontend/src/lib/uPlotV2/components/__tests__/UPlotLegend.test.tsx
rename to frontend/src/lib/uPlotV2/components/Legend/__tests__/UPlotLegend.test.tsx
index 061173d07b..97b559d790 100644
--- a/frontend/src/lib/uPlotV2/components/__tests__/UPlotLegend.test.tsx
+++ b/frontend/src/lib/uPlotV2/components/Legend/__tests__/UPlotLegend.test.tsx
@@ -5,9 +5,9 @@ import { TooltipProvider } from '@signozhq/ui/tooltip';
import { LegendItem } from 'lib/uPlotV2/config/types';
import useLegendsSync from 'lib/uPlotV2/hooks/useLegendsSync';
-import { useLegendActions } from '../../hooks/useLegendActions';
-import UPlotLegend from '../Legend/UPlotLegend';
-import { LegendAction, LegendActionPayload, LegendPosition } from '../types';
+import { useLegendActions } from '../../../hooks/useLegendActions';
+import UPlotLegend from '../UPlotLegend';
+import { LegendAction, LegendActionPayload, LegendPosition } from '../../types';
jest.mock('react-virtuoso', () => ({
VirtuosoGrid: ({
@@ -404,5 +404,16 @@ describe('UPlotLegend', () => {
expect(dispatched(onAction, LegendAction.SHOW_ALL)).toHaveLength(1);
});
+
+ it('restores everything when the row showing alone is clicked again', async () => {
+ const user = userEvent.setup();
+ renderLegend(LegendPosition.RIGHT);
+
+ await user.click(screen.getByText('A'));
+
+ expect(dispatched(onAction, LegendAction.SHOW_ALL)).toHaveLength(1);
+ expect(dispatched(onAction, LegendAction.TOGGLE)).toHaveLength(0);
+ expect(dispatched(onAction, LegendAction.SHOW_ONLY)).toHaveLength(0);
+ });
});
});