import type { IServiceReport } from '@openpanel/db'; import { useMemo } from 'react'; import { Responsive, WidthProvider } from 'react-grid-layout'; const ResponsiveGridLayout = WidthProvider(Responsive); export type Layout = ReactGridLayout.Layout; export const useReportLayouts = ( reports: NonNullable[], ): ReactGridLayout.Layouts => { return useMemo(() => { const baseLayout = reports.map((report, index) => ({ i: report.id, x: report.layout?.x ?? (index % 2) * 6, y: report.layout?.y ?? Math.floor(index / 2) * 4, w: report.layout?.w ?? 6, h: report.layout?.h ?? 4, minW: 3, minH: 3, })); return { lg: baseLayout, md: baseLayout, sm: baseLayout.map((item) => ({ ...item, w: Math.min(item.w, 6) })), xs: baseLayout.map((item) => ({ ...item, w: 4, x: 0 })), xxs: baseLayout.map((item) => ({ ...item, w: 2, x: 0 })), }; }, [reports]); }; export function GrafanaGrid({ layouts, children, transitions, onLayoutChange, onDragStop, onResizeStop, isDraggable, isResizable, }: { children: React.ReactNode; transitions?: boolean; } & Pick< ReactGridLayout.ResponsiveProps, | 'layouts' | 'onLayoutChange' | 'onDragStop' | 'onResizeStop' | 'isDraggable' | 'isResizable' >) { return ( <>
{children}
); }