Skip to content

Commit

Permalink
feat: added changes for empty layout
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarRajput-7 committed Feb 10, 2025
1 parent 80042e0 commit 7835de3
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions frontend/src/hooks/dashboard/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PANEL_TYPES } from 'constants/queryBuilder';
import { convertKeysToColumnFields } from 'container/LogsExplorerList/utils';
import { placeWidgetAtBottom } from 'container/NewWidget/utils';
import { Dashboard } from 'types/api/dashboard/getAll';
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
Expand All @@ -22,27 +23,16 @@ export const addEmptyWidgetInDashboardJSONWithQuery = (
...convertKeysToColumnFields(selectedColumns || []),
];

const { maxY } = dashboard?.data?.layout?.reduce(
(acc, curr) => ({
maxY: Math.max(acc.maxY, curr.y + curr.h),
}),
{ maxY: 0 },
) ?? { maxY: 0 };
const newLayoutItem = placeWidgetAtBottom(
widgetId,
dashboard?.data?.layout || [],
);

return {
...dashboard,
data: {
...dashboard.data,
layout: [
...(dashboard?.data?.layout || []),
{
i: widgetId,
w: 6,
x: 0,
h: 6,
y: maxY,
},
],
layout: [...(dashboard?.data?.layout || []), newLayoutItem],
widgets: [
...(dashboard?.data?.widgets || []),
{
Expand Down

0 comments on commit 7835de3

Please sign in to comment.