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: autosave layout to layout change (#4385)
Yunus M4a1c48b72b4e
diff --git a/frontend/src/container/GridCardLayout/GridCardLayout.tsx b/frontend/src/container/GridCardLayout/GridCardLayout.tsxindex 3ee11b4008..ed93df3a07 100644--- a/frontend/src/container/GridCardLayout/GridCardLayout.tsx+++ b/frontend/src/container/GridCardLayout/GridCardLayout.tsx@@ -1,6 +1,6 @@import './GridCardLayout.styles.scss';-import { PlusOutlined, SaveFilled } from '@ant-design/icons';+import { PlusOutlined } from '@ant-design/icons';import { SOMETHING_WENT_WRONG } from 'constants/api';import { PANEL_TYPES } from 'constants/queryBuilder';import { themeColors } from 'constants/theme';@@ -8,9 +8,12 @@ import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';import useComponentPermission from 'hooks/useComponentPermission';import { useIsDarkMode } from 'hooks/useDarkMode';import { useNotifications } from 'hooks/useNotifications';+import isEqual from 'lodash-es/isEqual';import { FullscreenIcon } from 'lucide-react';import { useDashboard } from 'providers/Dashboard/Dashboard';+import { useEffect, useState } from 'react';import { FullScreen, useFullScreenHandle } from 'react-full-screen';+import { Layout } from 'react-grid-layout';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';import { AppState } from 'store/reducers';@@ -29,6 +32,7 @@ import {ReactGridLayout,} from './styles';import { GraphLayoutProps } from './types';+import { removeUndefinedValuesFromLayout } from './utils';function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {const {@@ -51,6 +55,8 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {const isDarkMode = useIsDarkMode();+ const [dashboardLayout, setDashboardLayout] = useState(layouts);+const updateDashboardMutation = useUpdateDashboard();const { notifications } = useNotifications();@@ -78,7 +84,7 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {...selectedDashboard,data: {...selectedDashboard.data,- layout: layouts.filter((e) => e.i !== PANEL_TYPES.EMPTY_WIDGET),+ layout: dashboardLayout.filter((e) => e.i !== PANEL_TYPES.EMPTY_WIDGET),},uuid: selectedDashboard.uuid,};@@ -90,9 +96,6 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {setLayouts(updatedDashboard.payload.data.layout);setSelectedDashboard(updatedDashboard.payload);}- notifications.success({- message: t('dashboard:layout_saved_successfully'),- });featureResponse.refetch();},@@ -108,6 +111,32 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {? [...ViewMenuAction, ...EditMenuAction]: [...ViewMenuAction];+ const handleLayoutChange = (layout: Layout[]): void => {+ const filterLayout = removeUndefinedValuesFromLayout(layout);+ const filterDashboardLayout = removeUndefinedValuesFromLayout(+ dashboardLayout,+ );+ if (!isEqual(filterLayout, filterDashboardLayout)) {+ setDashboardLayout(layout);+ }+ };++ useEffect(() => {+ if (+ dashboardLayout &&+ Array.isArray(dashboardLayout) &&+ dashboardLayout.length > 0 &&+ !isEqual(layouts, dashboardLayout) &&+ !isDashboardLocked &&+ saveLayoutPermission &&+ !updateDashboardMutation.isLoading+ ) {+ onSaveHandler();+ }++ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [dashboardLayout]);+return (<><ButtonContainer>@@ -120,17 +149,6 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {{t('dashboard:full_view')}</Button>- {!isDashboardLocked && saveLayoutPermission && (- <Button- loading={updateDashboardMutation.isLoading}- onClick={onSaveHandler}- icon={<SaveFilled />}- disabled={updateDashboardMutation.isLoading}- >- {t('dashboard:save_layout')}- </Button>- )}-{!isDashboardLocked && addPanelPermission && (<ButtononClick={onAddPanelHandler}@@ -153,12 +171,12 @@ function GraphLayout({ onAddPanelHandler }: GraphLayoutProps): JSX.Element {isDroppable={!isDashboardLocked && addPanelPermission}isResizable={!isDashboardLocked && addPanelPermission}allowOverlap={false}- onLayoutChange={setLayouts}+ onLayoutChange={handleLayoutChange}draggableHandle=".drag-handle"- layout={layouts}+ layout={dashboardLayout}style={{ backgroundColor: isDarkMode ? '' : themeColors.snowWhite }}>- {layouts.map((layout) => {+ {dashboardLayout.map((layout) => {const { i: id } = layout;const currentWidget = (widgets || [])?.find((e) => e.id === id);diff --git a/frontend/src/container/GridCardLayout/WidgetHeader/WidgetHeader.styles.scss b/frontend/src/container/GridCardLayout/WidgetHeader/WidgetHeader.styles.scssindex 40d138e7df..799f0ed2f2 100644--- a/frontend/src/container/GridCardLayout/WidgetHeader/WidgetHeader.styles.scss+++ b/frontend/src/container/GridCardLayout/WidgetHeader/WidgetHeader.styles.scss@@ -8,6 +8,8 @@box-sizing: border-box;font-size: 14px;font-weight: 600;++ cursor: move;}.widget-header-title {diff --git a/frontend/src/container/GridCardLayout/utils.ts b/frontend/src/container/GridCardLayout/utils.tsnew file mode 100644index 0000000000..2623e5b623--- /dev/null+++ b/frontend/src/container/GridCardLayout/utils.ts@@ -0,0 +1,8 @@+import { Layout } from 'react-grid-layout';++export const removeUndefinedValuesFromLayout = (layout: Layout[]): Layout[] =>+ layout.map((obj) =>+ Object.fromEntries(+ Object.entries(obj).filter(([, value]) => value !== undefined),+ ),+ ) as Layout[];