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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: collapsed panels not expanding (#10716)
Ashwin Bhatkal31b61a89fd4f
diff --git a/frontend/src/container/GridCardLayout/GridCardLayout.tsx b/frontend/src/container/GridCardLayout/GridCardLayout.tsxindex 9cc55db4f7..b9a1ba55c3 100644--- a/frontend/src/container/GridCardLayout/GridCardLayout.tsx+++ b/frontend/src/container/GridCardLayout/GridCardLayout.tsx@@ -48,6 +48,7 @@ import DashboardEmptyState from './DashboardEmptyState/DashboardEmptyState';import GridCard from './GridCard';import { Card, CardContainer, ReactGridLayout } from './styles';import {+ applyRowCollapse,hasColumnWidthsChanged,removeUndefinedValuesFromLayout,} from './utils';@@ -268,13 +269,10 @@ function GraphLayout(props: GraphLayoutProps): JSX.Element {return;}- currentWidget.title = newTitle;- const updatedWidgets = selectedDashboard?.data?.widgets?.filter(- (e) => e.id !== currentSelectRowId,+ const updatedWidgets = selectedDashboard?.data?.widgets?.map((e) =>+ e.id === currentSelectRowId ? { ...e, title: newTitle } : e,);- updatedWidgets?.push(currentWidget);-const updatedSelectedDashboard: Props = {id: selectedDashboard.id,data: {@@ -316,88 +314,13 @@ function GraphLayout(props: GraphLayoutProps): JSX.Element {if (!selectedDashboard) {return;}- const rowProperties = { ...currentPanelMap[id] };- const updatedPanelMap = { ...currentPanelMap };-- let updatedDashboardLayout = [...dashboardLayout];- if (rowProperties.collapsed === true) {- rowProperties.collapsed = false;- const widgetsInsideTheRow = rowProperties.widgets;- let maxY = 0;- widgetsInsideTheRow.forEach((w) => {- maxY = Math.max(maxY, w.y + w.h);- });- const currentRowWidget = dashboardLayout.find((w) => w.i === id);- if (currentRowWidget && widgetsInsideTheRow.length) {- maxY -= currentRowWidget.h + currentRowWidget.y;- }-- const idxCurrentRow = dashboardLayout.findIndex((w) => w.i === id);-- for (let j = idxCurrentRow + 1; j < dashboardLayout.length; j++) {- updatedDashboardLayout[j].y += maxY;- if (updatedPanelMap[updatedDashboardLayout[j].i]) {- updatedPanelMap[updatedDashboardLayout[j].i].widgets = updatedPanelMap[- updatedDashboardLayout[j].i- ].widgets.map((w) => ({- ...w,- y: w.y + maxY,- }));- }- }- updatedDashboardLayout = [...updatedDashboardLayout, ...widgetsInsideTheRow];- } else {- rowProperties.collapsed = true;- const currentIdx = dashboardLayout.findIndex((w) => w.i === id);-- let widgetsInsideTheRow: Layout[] = [];- let isPanelMapUpdated = false;- for (let j = currentIdx + 1; j < dashboardLayout.length; j++) {- if (currentPanelMap[dashboardLayout[j].i]) {- rowProperties.widgets = widgetsInsideTheRow;- widgetsInsideTheRow = [];- isPanelMapUpdated = true;- break;- } else {- widgetsInsideTheRow.push(dashboardLayout[j]);- }- }- if (!isPanelMapUpdated) {- rowProperties.widgets = widgetsInsideTheRow;- }- let maxY = 0;- widgetsInsideTheRow.forEach((w) => {- maxY = Math.max(maxY, w.y + w.h);- });- const currentRowWidget = dashboardLayout[currentIdx];- if (currentRowWidget && widgetsInsideTheRow.length) {- maxY -= currentRowWidget.h + currentRowWidget.y;- }- for (let j = currentIdx + 1; j < updatedDashboardLayout.length; j++) {- updatedDashboardLayout[j].y += maxY;- if (updatedPanelMap[updatedDashboardLayout[j].i]) {- updatedPanelMap[updatedDashboardLayout[j].i].widgets = updatedPanelMap[- updatedDashboardLayout[j].i- ].widgets.map((w) => ({- ...w,- y: w.y + maxY,- }));- }- }-- updatedDashboardLayout = updatedDashboardLayout.filter(- (widget) => !rowProperties.widgets.some((w: Layout) => w.i === widget.i),- );- }- setCurrentPanelMap((prev) => ({- ...prev,- ...updatedPanelMap,- [id]: {- ...rowProperties,- },- }));-- setDashboardLayout(sortLayout(updatedDashboardLayout));+ const { updatedLayout, updatedPanelMap } = applyRowCollapse(+ id,+ dashboardLayout,+ currentPanelMap,+ );+ setCurrentPanelMap((prev) => ({ ...prev, ...updatedPanelMap }));+ setDashboardLayout(sortLayout(updatedLayout));};const handleDragStop: ItemCallback = (_, oldItem, newItem): void => {diff --git a/frontend/src/container/GridCardLayout/__tests__/rowCollapse.test.ts b/frontend/src/container/GridCardLayout/__tests__/rowCollapse.test.tsnew file mode 100644index 0000000000..e98594d7ca--- /dev/null+++ b/frontend/src/container/GridCardLayout/__tests__/rowCollapse.test.ts@@ -0,0 +1,181 @@+import { Layout } from 'react-grid-layout';++import { applyRowCollapse, PanelMap } from '../utils';++// Helper to produce deeply-frozen objects that mimic what zustand/immer returns.+function freeze<T>(obj: T): T {+ return JSON.parse(JSON.stringify(obj), (_, v) =>+ typeof v === 'object' && v !== null ? Object.freeze(v) : v,+ ) as T;+}++// ─── fixtures ────────────────────────────────────────────────────────────────++const ROW_ID = 'row1';++/** A layout with one row followed by two widgets. */+function makeLayout(): Layout[] {+ return [+ { i: ROW_ID, x: 0, y: 0, w: 12, h: 1 },+ { i: 'w1', x: 0, y: 1, w: 6, h: 4 },+ { i: 'w2', x: 6, y: 1, w: 6, h: 4 },+ ];+}++/** panelMap where the row is expanded (collapsed = false, widgets = []). */+function makeExpandedPanelMap(): PanelMap {+ return {+ [ROW_ID]: { collapsed: false, widgets: [] },+ };+}++/** panelMap where the row is collapsed (widgets stored inside). */+function makeCollapsedPanelMap(): PanelMap {+ return {+ [ROW_ID]: {+ collapsed: true,+ widgets: [+ { i: 'w1', x: 0, y: 1, w: 6, h: 4 },+ { i: 'w2', x: 6, y: 1, w: 6, h: 4 },+ ],+ },+ };+}++// ─── frozen-input guard (regression for zustand/immer read-only bug) ──────────++describe('applyRowCollapse – does not mutate frozen inputs', () => {+ it('does not throw when collapsing a row with frozen layout + panelMap', () => {+ expect(() =>+ applyRowCollapse(+ ROW_ID,+ freeze(makeLayout()),+ freeze(makeExpandedPanelMap()),+ ),+ ).not.toThrow();+ });++ it('does not throw when expanding a row with frozen layout + panelMap', () => {+ // Collapsed layout only has the row item; widgets live in panelMap.+ const collapsedLayout = freeze([{ i: ROW_ID, x: 0, y: 0, w: 12, h: 1 }]);+ expect(() =>+ applyRowCollapse(ROW_ID, collapsedLayout, freeze(makeCollapsedPanelMap())),+ ).not.toThrow();+ });++ it('leaves the original layout array untouched after collapse', () => {+ const layout = makeLayout();+ const originalY = layout[1].y; // w1.y before collapse+ applyRowCollapse(ROW_ID, layout, makeExpandedPanelMap());+ expect(layout[1].y).toBe(originalY);+ });++ it('leaves the original panelMap untouched after collapse', () => {+ const panelMap = makeExpandedPanelMap();+ applyRowCollapse(ROW_ID, makeLayout(), panelMap);+ expect(panelMap[ROW_ID].collapsed).toBe(false);+ });+});++// ─── collapse behaviour ───────────────────────────────────────────────────────++describe('applyRowCollapse – collapsing a row', () => {+ it('sets collapsed = true on the row entry', () => {+ const { updatedPanelMap } = applyRowCollapse(+ ROW_ID,+ makeLayout(),+ makeExpandedPanelMap(),+ );+ expect(updatedPanelMap[ROW_ID].collapsed).toBe(true);+ });++ it('stores the child widgets inside the panelMap entry', () => {+ const { updatedPanelMap } = applyRowCollapse(+ ROW_ID,+ makeLayout(),+ makeExpandedPanelMap(),+ );+ const ids = updatedPanelMap[ROW_ID].widgets.map((w) => w.i);+ expect(ids).toContain('w1');+ expect(ids).toContain('w2');+ });++ it('removes child widgets from the returned layout', () => {+ const { updatedLayout } = applyRowCollapse(+ ROW_ID,+ makeLayout(),+ makeExpandedPanelMap(),+ );+ const ids = updatedLayout.map((l) => l.i);+ expect(ids).not.toContain('w1');+ expect(ids).not.toContain('w2');+ expect(ids).toContain(ROW_ID);+ });+});++// ─── expand behaviour ─────────────────────────────────────────────────────────++describe('applyRowCollapse – expanding a row', () => {+ it('sets collapsed = false on the row entry', () => {+ const collapsedLayout: Layout[] = [{ i: ROW_ID, x: 0, y: 0, w: 12, h: 1 }];+ const { updatedPanelMap } = applyRowCollapse(+ ROW_ID,+ collapsedLayout,+ makeCollapsedPanelMap(),+ );+ expect(updatedPanelMap[ROW_ID].collapsed).toBe(false);+ });++ it('restores child widgets to the returned layout', () => {+ const collapsedLayout: Layout[] = [{ i: ROW_ID, x: 0, y: 0, w: 12, h: 1 }];+ const { updatedLayout } = applyRowCollapse(+ ROW_ID,+ collapsedLayout,+ makeCollapsedPanelMap(),+ );+ const ids = updatedLayout.map((l) => l.i);+ expect(ids).toContain('w1');+ expect(ids).toContain('w2');+ });++ it('restored child widgets appear in both the layout and the panelMap entry', () => {+ const collapsedLayout: Layout[] = [{ i: ROW_ID, x: 0, y: 0, w: 12, h: 1 }];+ const { updatedLayout, updatedPanelMap } = applyRowCollapse(+ ROW_ID,+ collapsedLayout,+ makeCollapsedPanelMap(),+ );+ // The previously-stored widgets should now be back in the live layout.+ expect(updatedLayout.map((l) => l.i)).toContain('w1');+ // The panelMap entry still holds a reference to them (stale until next collapse).+ expect(updatedPanelMap[ROW_ID].widgets.map((w) => w.i)).toContain('w1');+ });+});++// ─── y-offset adjustment ──────────────────────────────────────────────────────++describe('applyRowCollapse – y-offset adjustments for rows below', () => {+ it('shifts items below a second row down when the first row expands', () => {+ const ROW2 = 'row2';+ // Layout: row1 (y=0,h=1) | w1 (y=1,h=4) | row2 (y=5,h=1) | w3 (y=6,h=2)+ const layout: Layout[] = [+ { i: ROW_ID, x: 0, y: 0, w: 12, h: 1 },+ { i: 'w1', x: 0, y: 1, w: 12, h: 4 },+ { i: ROW2, x: 0, y: 5, w: 12, h: 1 },+ { i: 'w3', x: 0, y: 6, w: 12, h: 2 },+ ];+ const panelMap: PanelMap = {+ [ROW_ID]: {+ collapsed: true,+ widgets: [{ i: 'w1', x: 0, y: 1, w: 12, h: 4 }],+ },+ [ROW2]: { collapsed: false, widgets: [] },+ };+ // Expanding row1 should push row2 and w3 down by the height of w1 (4).+ const collapsedLayout = layout.filter((l) => l.i !== 'w1');+ const { updatedLayout } = applyRowCollapse(ROW_ID, collapsedLayout, panelMap);++ const row2Item = updatedLayout.find((l) => l.i === ROW2);+ expect(row2Item?.y).toBe(5 + 4); // shifted by maxY = 4+ });+});diff --git a/frontend/src/container/GridCardLayout/utils.ts b/frontend/src/container/GridCardLayout/utils.tsindex 62b949b3d0..710b308815 100644--- a/frontend/src/container/GridCardLayout/utils.ts+++ b/frontend/src/container/GridCardLayout/utils.ts@@ -4,6 +4,122 @@ import { isEmpty, isEqual } from 'lodash-es';import { Dashboard, Widgets } from 'types/api/dashboard/getAll';import { IBuilderQuery, Query } from 'types/api/queryBuilder/queryBuilderData';+export type PanelMap = Record<+ string,+ { widgets: Layout[]; collapsed: boolean }+>;++export interface RowCollapseResult {+ updatedLayout: Layout[];+ updatedPanelMap: PanelMap;+}++/**+ * Pure function that computes the new layout and panelMap after toggling a+ * row's collapsed state. All inputs are treated as immutable — no input object+ * is mutated, so it is safe to pass frozen objects from the zustand store.+ */+// eslint-disable-next-line sonarjs/cognitive-complexity+export function applyRowCollapse(+ id: string,+ dashboardLayout: Layout[],+ currentPanelMap: PanelMap,+): RowCollapseResult {+ // Deep-copy the row's own properties so we can mutate our local copy.+ const rowProperties = {+ ...currentPanelMap[id],+ widgets: [...(currentPanelMap[id]?.widgets ?? [])],+ };++ // Shallow-copy each entry's widgets array so inner .map() calls are safe.+ const updatedPanelMap: PanelMap = Object.fromEntries(+ Object.entries(currentPanelMap).map(([k, v]) => [+ k,+ { ...v, widgets: [...v.widgets] },+ ]),+ );++ let updatedDashboardLayout = [...dashboardLayout];++ if (rowProperties.collapsed === true) {+ // ── EXPAND ──────────────────────────────────────────────────────────────+ rowProperties.collapsed = false;+ const widgetsInsideTheRow = rowProperties.widgets;++ let maxY = 0;+ widgetsInsideTheRow.forEach((w) => {+ maxY = Math.max(maxY, w.y + w.h);+ });+ const currentRowWidget = dashboardLayout.find((w) => w.i === id);+ if (currentRowWidget && widgetsInsideTheRow.length) {+ maxY -= currentRowWidget.h + currentRowWidget.y;+ }++ const idxCurrentRow = dashboardLayout.findIndex((w) => w.i === id);+ for (let j = idxCurrentRow + 1; j < dashboardLayout.length; j++) {+ updatedDashboardLayout[j] = {+ ...updatedDashboardLayout[j],+ y: updatedDashboardLayout[j].y + maxY,+ };+ if (updatedPanelMap[updatedDashboardLayout[j].i]) {+ updatedPanelMap[updatedDashboardLayout[j].i].widgets = updatedPanelMap[+ updatedDashboardLayout[j].i+ ].widgets.map((w) => ({ ...w, y: w.y + maxY }));+ }+ }+ updatedDashboardLayout = [...updatedDashboardLayout, ...widgetsInsideTheRow];+ } else {+ // ── COLLAPSE ─────────────────────────────────────────────────────────────+ rowProperties.collapsed = true;+ const currentIdx = dashboardLayout.findIndex((w) => w.i === id);++ let widgetsInsideTheRow: Layout[] = [];+ let isPanelMapUpdated = false;+ for (let j = currentIdx + 1; j < dashboardLayout.length; j++) {+ if (currentPanelMap[dashboardLayout[j].i]) {+ rowProperties.widgets = widgetsInsideTheRow;+ widgetsInsideTheRow = [];+ isPanelMapUpdated = true;+ break;+ } else {+ widgetsInsideTheRow.push(dashboardLayout[j]);+ }+ }+ if (!isPanelMapUpdated) {+ rowProperties.widgets = widgetsInsideTheRow;+ }++ let maxY = 0;+ widgetsInsideTheRow.forEach((w) => {+ maxY = Math.max(maxY, w.y + w.h);+ });+ const currentRowWidget = dashboardLayout[currentIdx];+ if (currentRowWidget && widgetsInsideTheRow.length) {+ maxY -= currentRowWidget.h + currentRowWidget.y;+ }++ for (let j = currentIdx + 1; j < updatedDashboardLayout.length; j++) {+ updatedDashboardLayout[j] = {+ ...updatedDashboardLayout[j],+ y: updatedDashboardLayout[j].y + maxY,+ };+ if (updatedPanelMap[updatedDashboardLayout[j].i]) {+ updatedPanelMap[updatedDashboardLayout[j].i].widgets = updatedPanelMap[+ updatedDashboardLayout[j].i+ ].widgets.map((w) => ({ ...w, y: w.y + maxY }));+ }+ }++ updatedDashboardLayout = updatedDashboardLayout.filter(+ (widget) => !rowProperties.widgets.some((w: Layout) => w.i === widget.i),+ );+ }++ updatedPanelMap[id] = { ...rowProperties };++ return { updatedLayout: updatedDashboardLayout, updatedPanelMap };+}+export const removeUndefinedValuesFromLayout = (layout: Layout[]): Layout[] =>layout.map((obj) =>Object.fromEntries(diff --git a/frontend/src/container/LogsPanelTable/LogsPanelComponent.tsx b/frontend/src/container/LogsPanelTable/LogsPanelComponent.tsxindex a3ef74481e..10ec768d14 100644--- a/frontend/src/container/LogsPanelTable/LogsPanelComponent.tsx+++ b/frontend/src/container/LogsPanelTable/LogsPanelComponent.tsx@@ -42,8 +42,15 @@ function LogsPanelComponent({setPageSize(value);setOffset(0);setRequestData((prev) => {- const newQueryData = { ...prev.query };- newQueryData.builder.queryData[0].pageSize = value;+ const newQueryData = {+ ...prev.query,+ builder: {+ ...prev.query.builder,+ queryData: prev.query.builder.queryData.map((qd, i) =>+ i === 0 ? { ...qd, pageSize: value } : qd,+ ),+ },+ };return {...prev,query: newQueryData,diff --git a/frontend/src/container/PublicDashboardContainer/Panel.tsx b/frontend/src/container/PublicDashboardContainer/Panel.tsxindex be561d1d71..456b1850be 100644--- a/frontend/src/container/PublicDashboardContainer/Panel.tsx+++ b/frontend/src/container/PublicDashboardContainer/Panel.tsx@@ -42,11 +42,19 @@ function Panel({};}- updatedQuery.builder.queryData[0].pageSize = 10;const initialDataSource = updatedQuery.builder.queryData[0].dataSource;+ const updatedQueryForList = {+ ...updatedQuery,+ builder: {+ ...updatedQuery.builder,+ queryData: updatedQuery.builder.queryData.map((qd, i) =>+ i === 0 ? { ...qd, pageSize: 10 } : qd,+ ),+ },+ };return {- query: updatedQuery,+ query: updatedQueryForList,graphType: PANEL_TYPES.LIST,selectedTime: widget.timePreferance || 'GLOBAL_TIME',tableParams: {diff --git a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts b/frontend/src/hooks/queryBuilder/useGetQueryRange.tsindex c7711fa70d..4b7b9a3f05 100644--- a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts+++ b/frontend/src/hooks/queryBuilder/useGetQueryRange.ts@@ -52,37 +52,44 @@ export const useGetQueryRange: UseGetQueryRange = (!firstQueryData?.filters?.items.some((filter) => filter.key?.key === 'id') &&firstQueryData?.orderBy[0].columnName === 'timestamp';- const modifiedRequestData = {- ...requestData,- graphType:- requestData.graphType === PANEL_TYPES.BAR- ? PANEL_TYPES.TIME_SERIES- : requestData.graphType,- };-- // If the query is a list with a single timestamp order, we need to add the id column to the order by clauseif (isListWithSingleTimestampOrder &&firstQueryData?.dataSource === DataSource.LOGS) {- modifiedRequestData.query.builder = {- ...requestData.query.builder,- queryData: [- {- ...firstQueryData,- orderBy: [- ...(firstQueryData?.orderBy || []),+ return {+ ...requestData,+ graphType:+ requestData.graphType === PANEL_TYPES.BAR+ ? PANEL_TYPES.TIME_SERIES+ : requestData.graphType,+ query: {+ ...requestData.query,+ builder: {+ ...requestData.query.builder,+ queryData: [{- columnName: 'id',- order: firstQueryData?.orderBy[0]?.order,+ ...firstQueryData,+ orderBy: [+ ...(firstQueryData?.orderBy || []),+ {+ columnName: 'id',+ order: firstQueryData?.orderBy[0]?.order,+ },+ ],},],},- ],+ },};}- return modifiedRequestData;+ return {+ ...requestData,+ graphType:+ requestData.graphType === PANEL_TYPES.BAR+ ? PANEL_TYPES.TIME_SERIES+ : requestData.graphType,+ };}, [requestData]);const queryKey = useMemo(() => {