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.

4.6 KB
Raw Blame
import { Button } from '@signozhq/ui/button';
import { DialogWrapper } from '@signozhq/ui/dialog';
import { Typography } from '@signozhq/ui/typography';
import { ArrowUpRight, Copy, RotateCw } from '@signozhq/icons';
import { useCopyToClipboard } from 'react-use';
import { toast } from '@signozhq/ui/sonner';
import logEvent from 'api/common/logEvent';
import { handleContactSupport } from 'container/Integrations/utils';
import { useDashboardPermissions } from 'hooks/dashboards/useDashboardPermissions';
import { useGetTenantLicense } from 'hooks/useGetTenantLicense';
import AuthZButton from 'lib/authz/components/AuthZButton/AuthZButton';
import { DashboardListEvents } from 'pages/DashboardsListPage/constants/events';

import { useRetryMigration } from '../../hooks/useRetryMigration';

import styles from './LegacyDashboardDialog.module.scss';

interface LegacyDashboardDialogProps {
	open: boolean;
	dashboardId: string;
	dashboardName: string;
	onClose: () => void;
}

/**
 * Explains why a legacy (pre-v2) dashboard can't be opened in the new experience
 * and offers to re-run the migration. Legacy rows are surfaced by the list API
 * with `legacy: true` but have no v2 spec to render. Retrying runs a migrate
 * call, which the backend gates on dashboard:update.
 */
function LegacyDashboardDialog({
	open,
	dashboardId,
	dashboardName,
	onClose,
}: LegacyDashboardDialogProps): JSX.Element {
	const [, copyToClipboard] = useCopyToClipboard();
	const { isCloudUser } = useGetTenantLicense();
	const { retryMigration, isMigrating } = useRetryMigration(onClose);
	const { canEdit, editChecks } = useDashboardPermissions(dashboardId);

	const onCopyId = (): void => {
		copyToClipboard(dashboardId);
		toast.success('Dashboard ID copied');
		void logEvent(DashboardListEvents.LegacyDialogAction, {
			action: 'copyId',
			dashboardId,
		});
	};

	const onContactSupport = (): void => {
		handleContactSupport(!!isCloudUser);
		void logEvent(DashboardListEvents.LegacyDialogAction, {
			action: 'contactSupport',
			dashboardId,
		});
	};

	const onRetryMigration = (): void => {
		retryMigration(dashboardId);
		void logEvent(DashboardListEvents.LegacyDialogAction, {
			action: 'retryMigration',
			dashboardId,
		});
	};

	return (
		<DialogWrapper
			title="This dashboard isn't available in the new experience"
			open={open}
			width="narrow"
			onOpenChange={(next): void => {
				if (!next) {
					onClose();
				}
			}}
			footer={
				<div className={styles.footer}>
					<Button
						variant="ghost"
						color="secondary"
						size="md"
						loading={isMigrating}
						onClick={onClose}
						testId="legacy-dashboard-close"
					>
						Close
					</Button>
					{canEdit ? (
						<Button
							variant="outlined"
							color="secondary"
							size="md"
							suffix={<ArrowUpRight size={14} />}
							onClick={onContactSupport}
							testId="legacy-dashboard-contact-support"
						>
							Contact Support
						</Button>
					) : (
						<Button
							variant="solid"
							color="primary"
							size="md"
							suffix={<ArrowUpRight size={14} />}
							onClick={onContactSupport}
							testId="legacy-dashboard-contact-support"
						>
							Contact Support
						</Button>
					)}
					<AuthZButton
						checks={editChecks}
						variant="solid"
						color="primary"
						size="md"
						prefix={<RotateCw size={14} />}
						disabled={isMigrating}
						loading={isMigrating}
						onClick={onRetryMigration}
						testId="legacy-dashboard-retry-migration"
					>
						Retry migration
					</AuthZButton>
				</div>
			}
		>
			<div className={styles.body}>
				<Typography.Text className={styles.description}>
					<strong>{dashboardName || 'This dashboard'}</strong> hasn&apos;t been
					migrated to the new dashboard experience yet, so it can&apos;t be opened
					here.{' '}
					{canEdit
						? "Retrying the migration often works once we've handled the case that blocked it. If it still fails, share the dashboard ID below with support."
						: "Share the dashboard ID below with support and we'll help you move it over."}
				</Typography.Text>

				<div className={styles.idField}>
					<Typography.Text className={styles.idLabel}>Dashboard ID</Typography.Text>
					<div className={styles.idRow}>
						<Typography.Text
							className={styles.idValue}
							data-testid="legacy-dashboard-id"
						>
							{dashboardId}
						</Typography.Text>
						<Button
							variant="ghost"
							color="secondary"
							size="sm"
							icon
							aria-label="Copy dashboard ID"
							onClick={onCopyId}
							testId="legacy-dashboard-copy-id"
						>
							<Copy size={14} />
						</Button>
					</div>
				</div>
			</div>
		</DialogWrapper>
	);
}

export default LegacyDashboardDialog;