Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty widget is handled #3830

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/container/GridCardLayout/GridCardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function GraphLayout({
<CardContainer isDarkMode={isDarkMode} key={id} data-grid={layout}>
<Card $panelType={currentWidget?.panelTypes || PANEL_TYPES.TIME_SERIES}>
<GridCard
widget={currentWidget || ({ id } as Widgets)}
widget={currentWidget || ({ id, query: {} } as Widgets)}
name={currentWidget?.id || ''}
headerMenuList={headerMenuList}
/>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/container/ListOfDashboard/ImportJSON/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Editor from 'components/Editor';
import ROUTES from 'constants/routes';
import { MESSAGE } from 'hooks/useFeatureFlag';
import { useNotifications } from 'hooks/useNotifications';
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
import history from 'lib/history';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -65,6 +66,12 @@ function ImportJSON({
setDashboardCreating(true);
const dashboardData = JSON.parse(editorValue) as DashboardData;

if (dashboardData?.layout) {
dashboardData.layout = getUpdatedLayout(dashboardData.layout);
} else {
dashboardData.layout = [];
}

const response = await createDashboard({
...dashboardData,
uploadedGrafana,
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/lib/dashboard/getUpdatedLayout.ts
Original file line number Diff line number Diff line change
@@ -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 || [];
palashgdev marked this conversation as resolved.
Show resolved Hide resolved
};
20 changes: 4 additions & 16 deletions frontend/src/providers/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Modal } from 'antd';
import get from 'api/dashboard/get';
import { PANEL_TYPES } from 'constants/queryBuilder';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import ROUTES from 'constants/routes';
import { getMinMax } from 'container/TopNav/AutoRefresh/config';
import dayjs, { Dayjs } from 'dayjs';
import useTabVisibility from 'hooks/useTabFocus';
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
import {
createContext,
PropsWithChildren,
Expand Down Expand Up @@ -107,11 +107,7 @@ export function DashboardProvider({

dashboardRef.current = data;

setLayouts(
data.data.layout?.filter(
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
) || [],
);
setLayouts(getUpdatedLayout(data.data.layout));
}

if (
Expand Down Expand Up @@ -147,11 +143,7 @@ export function DashboardProvider({

updatedTimeRef.current = dayjs(data.updated_at);

setLayouts(
data.data.layout?.filter(
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
) || [],
);
setLayouts(getUpdatedLayout(data.data.layout));
},
});

Expand All @@ -164,11 +156,7 @@ export function DashboardProvider({

setSelectedDashboard(data);

setLayouts(
data.data.layout?.filter(
(layout) => layout.i !== PANEL_TYPES.EMPTY_WIDGET,
) || [],
);
setLayouts(getUpdatedLayout(data.data.layout));
}
},
},
Expand Down
Loading