Skip to content

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.

1.1 KB
Raw Blame
import { useQueryClient } from 'react-query';
import logEvent from 'api/common/logEvent';
import { invalidateListDashboardsForUserV2 } from 'api/generated/services/dashboard';
import {
	type ToggleDashboardLock,
	useToggleDashboardLock,
} from 'hooks/dashboards/useToggleDashboardLock';
import { DashboardListEvents } from 'pages/DashboardsListPage/constants/events';
import { useErrorModal } from 'providers/ErrorModalProvider';

/**
 * The row menu's lock toggle. The call, toast and cache patch are shared with the
 * toolbar; the list adds refreshing the rows and logging a row action.
 */
export function useLockToggleAction({
	dashboardId,
	isLocked,
}: {
	dashboardId: string;
	isLocked: boolean;
}): ToggleDashboardLock {
	const queryClient = useQueryClient();
	const { showErrorModal } = useErrorModal();

	return useToggleDashboardLock({
		dashboardId,
		isLocked,
		onSuccess: (locked) => {
			void logEvent(DashboardListEvents.RowAction, {
				action: locked ? 'lock' : 'unlock',
				dashboardId,
			});
			void invalidateListDashboardsForUserV2(queryClient);
		},
		onError: showErrorModal,
	});
}