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
import { useCallback, useState } from 'react';
import { newPanelSearch, NEW_PANEL_ID } from '../PanelEditor/newPanelRoute';
import type { NewPanelTarget } from '../patchOps';
import type { PanelKind } from '../Panels/types/panelKind';
import { clearColumnWidths } from '../Panels/utils/columnWidthStorage';
import { useOpenPanelEditor } from './useOpenPanelEditor';
interface UseCreatePanelResult {
isPickerOpen: boolean;
/** Pass the target section's layout index; omit → last/new section. */
openPicker: (layoutIndex?: number) => void;
closePicker: () => void;
/** The section the picker was opened against — seeds its section dropdown. */
targetLayoutIndex: number | undefined;
/** `target` overrides the opened-against section (the picker's choice). */
createPanel: (panelKind: PanelKind, target?: NewPanelTarget) => void;
}
/**
* Drives new-panel creation from any "Add panel" trigger: owns the panel-type
* picker state and navigates to the editor on a draft panel. Nothing is persisted
* until save.
*/
export function useCreatePanel(): UseCreatePanelResult {
const openPanelEditor = useOpenPanelEditor();
const [isPickerOpen, setIsPickerOpen] = useState(false);
// Captured on open, consumed on select.
const [layoutIndex, setLayoutIndex] = useState<number | undefined>(undefined);
const openPicker = useCallback((index?: number): void => {
setLayoutIndex(index);
setIsPickerOpen(true);
}, []);
const closePicker = useCallback((): void => {
setIsPickerOpen(false);
}, []);
const createPanel = useCallback(
(panelKind: PanelKind, pickedTarget?: NewPanelTarget): void => {
setIsPickerOpen(false);
const target =
pickedTarget ??
(layoutIndex === undefined
? undefined
: { type: 'section' as const, layoutIndex });
// Every draft shares the sentinel id, so an abandoned draft's column widths
// would otherwise seed this one.
clearColumnWidths(NEW_PANEL_ID);
openPanelEditor(NEW_PANEL_ID, {
search: newPanelSearch(panelKind, target),
});
},
[openPanelEditor, layoutIndex],
);
return {
isPickerOpen,
openPicker,
closePicker,
targetLayoutIndex: layoutIndex,
createPanel,
};
}