mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-24 03:14:26 +08:00
fix: empty widget is handled (#3830)
* fix: empty widget is updated * chore: widget is updated * fix: handling is updated
This commit is contained in:
parent
7603e0ebe0
commit
2d60805b28
@ -125,7 +125,7 @@ function GraphLayout({
|
|||||||
<CardContainer isDarkMode={isDarkMode} key={id} data-grid={layout}>
|
<CardContainer isDarkMode={isDarkMode} key={id} data-grid={layout}>
|
||||||
<Card $panelType={currentWidget?.panelTypes || PANEL_TYPES.TIME_SERIES}>
|
<Card $panelType={currentWidget?.panelTypes || PANEL_TYPES.TIME_SERIES}>
|
||||||
<GridCard
|
<GridCard
|
||||||
widget={currentWidget || ({ id } as Widgets)}
|
widget={currentWidget || ({ id, query: {} } as Widgets)}
|
||||||
name={currentWidget?.id || ''}
|
name={currentWidget?.id || ''}
|
||||||
headerMenuList={headerMenuList}
|
headerMenuList={headerMenuList}
|
||||||
/>
|
/>
|
||||||
|
@ -6,6 +6,7 @@ import Editor from 'components/Editor';
|
|||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import { MESSAGE } from 'hooks/useFeatureFlag';
|
import { MESSAGE } from 'hooks/useFeatureFlag';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
|
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -65,6 +66,12 @@ function ImportJSON({
|
|||||||
setDashboardCreating(true);
|
setDashboardCreating(true);
|
||||||
const dashboardData = JSON.parse(editorValue) as DashboardData;
|
const dashboardData = JSON.parse(editorValue) as DashboardData;
|
||||||
|
|
||||||
|
if (dashboardData?.layout) {
|
||||||
|
dashboardData.layout = getUpdatedLayout(dashboardData.layout);
|
||||||
|
} else {
|
||||||
|
dashboardData.layout = [];
|
||||||
|
}
|
||||||
|
|
||||||
const response = await createDashboard({
|
const response = await createDashboard({
|
||||||
...dashboardData,
|
...dashboardData,
|
||||||
uploadedGrafana,
|
uploadedGrafana,
|
||||||
|
23
frontend/src/lib/dashboard/getUpdatedLayout.ts
Normal file
23
frontend/src/lib/dashboard/getUpdatedLayout.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||||
|
import { Layout } from 'react-grid-layout';
|
||||||
|
|
||||||
|
export const getUpdatedLayout = (layout?: Layout[]): Layout[] => {
|
||||||
|
let widgetLayout = layout;
|
||||||
|
|
||||||
|
// filter empty from i from i due to previous version of signoz
|
||||||
|
widgetLayout = layout?.filter((i) => i.i !== 'empty');
|
||||||
|
|
||||||
|
const seen = new Set();
|
||||||
|
|
||||||
|
// filter duplicate i values
|
||||||
|
widgetLayout = widgetLayout?.filter((i) => {
|
||||||
|
const duplicate = seen.has(i.i);
|
||||||
|
seen.add(i.i);
|
||||||
|
return !duplicate;
|
||||||
|
});
|
||||||
|
|
||||||
|
// filter EMPTY_WIDGET from i due to previous version of signoz
|
||||||
|
widgetLayout = widgetLayout?.filter((i) => i.i !== PANEL_TYPES.EMPTY_WIDGET);
|
||||||
|
|
||||||
|
return widgetLayout || [];
|
||||||
|
};
|
@ -1,11 +1,11 @@
|
|||||||
import { Modal } from 'antd';
|
import { Modal } from 'antd';
|
||||||
import get from 'api/dashboard/get';
|
import get from 'api/dashboard/get';
|
||||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
|
||||||
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import { getMinMax } from 'container/TopNav/AutoRefresh/config';
|
import { getMinMax } from 'container/TopNav/AutoRefresh/config';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import useTabVisibility from 'hooks/useTabFocus';
|
import useTabVisibility from 'hooks/useTabFocus';
|
||||||
|
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
PropsWithChildren,
|
PropsWithChildren,
|
||||||
@ -107,11 +107,7 @@ export function DashboardProvider({
|
|||||||
|
|
||||||
dashboardRef.current = data;
|
dashboardRef.current = data;
|
||||||
|
|
||||||
setLayouts(
|
setLayouts(getUpdatedLayout(data.data.layout));
|
||||||
data.data.layout?.filter(
|
|
||||||
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
|
|
||||||
) || [],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -147,11 +143,7 @@ export function DashboardProvider({
|
|||||||
|
|
||||||
updatedTimeRef.current = dayjs(data.updated_at);
|
updatedTimeRef.current = dayjs(data.updated_at);
|
||||||
|
|
||||||
setLayouts(
|
setLayouts(getUpdatedLayout(data.data.layout));
|
||||||
data.data.layout?.filter(
|
|
||||||
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
|
|
||||||
) || [],
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -164,11 +156,7 @@ export function DashboardProvider({
|
|||||||
|
|
||||||
setSelectedDashboard(data);
|
setSelectedDashboard(data);
|
||||||
|
|
||||||
setLayouts(
|
setLayouts(getUpdatedLayout(data.data.layout));
|
||||||
data.data.layout?.filter(
|
|
||||||
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
|
|
||||||
) || [],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user