🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Add dashboard embed disable functionality and related UI updates
Bill Yang819d972fad2a
diff --git a/client/messages/en.json b/client/messages/en.jsonindex eba33b675..70558d0be 100644--- a/client/messages/en.json+++ b/client/messages/en.json@@ -93,6 +93,7 @@"1SjAqf": "Leading","1ZgrhW": "Role","1bNJRY": "User Traits",+ "1bgBOg": "Yes, disable embed","1bqKv/": "User ID:","1fe3VI": "API keys are available on Standard and Pro plans.","1gYD1y": "Session Info",@@ -441,8 +442,10 @@"ExtTiK": "Add Path","F/6VqP": "Server","F1HScC": "Filter by URL parameter",+ "F3R2oM": "This revokes the private link for this site. Any embedded dashboards and shared dashboard links using it will stop working immediately. You can generate a new private link later, but it will have a different URL.","F3XA9+": "Delete Goal","F4tWun": "Create a new flag",+ "F6Fr+e": "Dashboard embed disabled","F9J0jM": "Failed to clone funnel: {message}","F9OK6H": "Member removed successfully","FAGQUA": "Enabling error tracking will increase your event usage.",@@ -713,6 +716,7 @@"Oh4usQ": "Select metric","Oj6AtK": "OS Version","OlRI+i": "Organization API Keys",+ "Omj2fC": "Disabling...","OtO9EF": "Add tags to organize and filter your sites.","OtSSs+": "{count} sites","Otefae": "Dimension",@@ -794,6 +798,7 @@"Rqzsq/": "Add Filter","RsY5rI": "Converted Sessions","RumeRz": "Regions",+ "Rw7iI7": "Disable","RwzAp9": "Event Types","RzSw2z": "Button Text (optional)","S1utKH": "Lon",@@ -986,6 +991,7 @@"ZbWc+A": "IP address","ZcBC7s": "Manage your subscription and billing.","Zh+5A6": "On",+ "Zqi/ST": "Disable dashboard embed?","ZrO1i3": "Moving...","ZvKSfJ": "Events","ZwGYjD": "Greater than",@@ -1174,6 +1180,7 @@"h6rdDs": "Cumulative Layout Shift","hJL4XZ": "Less than","hL1XMn": "Only enable this if you will actually use it.",+ "hLeBOD": "Failed to disable dashboard embed","hO42EP": "Daily Events","hPFnGJ": "Failed to update embed setting","hPQ9ZV": "not equals",diff --git a/client/src/api/admin/hooks/usePrivateLink.ts b/client/src/api/admin/hooks/usePrivateLink.tsindex 4218fd83d..aeefe2372 100644--- a/client/src/api/admin/hooks/usePrivateLink.ts+++ b/client/src/api/admin/hooks/usePrivateLink.ts@@ -41,7 +41,10 @@ export const useRevokePrivateLinkKey = () => {const response = await revokePrivateLinkKey(siteId);return response.data;},- onSuccess: (_, siteId) => {+ onSuccess: (data, siteId) => {+ // Write through so the UI flips to "disabled" immediately instead of+ // rendering the stale key until the refetch lands.+ queryClient.setQueryData(["privateLinkConfig", siteId], data);queryClient.invalidateQueries({ queryKey: ["privateLinkConfig", siteId] });},});diff --git a/client/src/components/SiteSettings/DashboardEmbedTab.tsx b/client/src/components/SiteSettings/DashboardEmbedTab.tsxindex c75985d6b..f852fd002 100644--- a/client/src/components/SiteSettings/DashboardEmbedTab.tsx+++ b/client/src/components/SiteSettings/DashboardEmbedTab.tsx@@ -5,8 +5,23 @@ import { useExtracted } from "next-intl";import { useState } from "react";import { SiteResponse } from "@/api/admin/endpoints";-import { useGeneratePrivateLinkKey, useGetPrivateLinkConfig } from "@/api/admin/hooks/usePrivateLink";+import {+ useGeneratePrivateLinkKey,+ useGetPrivateLinkConfig,+ useRevokePrivateLinkKey,+} from "@/api/admin/hooks/usePrivateLink";import { CodeSnippet } from "@/components/CodeSnippet";+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger,+} from "@/components/ui/alert-dialog";import { Button } from "@/components/ui/button";import { toast } from "@/components/ui/sonner";import { Switch } from "@/components/ui/switch";@@ -47,7 +62,9 @@ export function DashboardEmbedTab({ siteMetadata, disabled = false }: DashboardEdata: generatedPrivateLink,mutate: generatePrivateLinkKey,isPending: isGeneratingPrivateLink,+ reset: resetGeneratedPrivateLink,} = useGeneratePrivateLinkKey();+ const { mutate: revokePrivateLinkKey, isPending: isRevokingPrivateLink } = useRevokePrivateLinkKey();const privateLinkKey = privateLink?.privateLinkKey ?? generatedPrivateLink?.privateLinkKey ?? null;const hasPrivateLink = !!privateLinkKey;const dashboardEmbedAvailable = hasPrivateLink;@@ -88,6 +105,18 @@ export function DashboardEmbedTab({ siteMetadata, disabled = false }: DashboardE});};+ const handleRevokePrivateLink = () => {+ revokePrivateLinkKey(siteId, {+ onSuccess: () => {+ resetGeneratedPrivateLink();+ toast.success(t("Dashboard embed disabled"));+ },+ onError: error => {+ toast.error(error instanceof Error ? error.message : t("Failed to disable dashboard embed"));+ },+ });+ };+return (<SettingsSections className="min-w-0 overflow-x-hidden"><SettingsSection description={t("Embed the main analytics dashboard on another site using a private link.")}>@@ -103,10 +132,35 @@ export function DashboardEmbedTab({ siteMetadata, disabled = false }: DashboardE)}>{hasPrivateLink ? (- <span className="inline-flex items-center gap-1.5 rounded-md border border-neutral-150 bg-neutral-50 px-2 py-1 text-xs text-muted-foreground dark:border-neutral-800 dark:bg-neutral-900">- <span className="h-1.5 w-1.5 rounded-full bg-emerald-500" aria-hidden />- {t("Private link enabled")}- </span>+ <>+ <span className="inline-flex items-center gap-1.5 rounded-md border border-neutral-150 bg-neutral-50 px-2 py-1 text-xs text-muted-foreground dark:border-neutral-800 dark:bg-neutral-900">+ <span className="h-1.5 w-1.5 rounded-full bg-emerald-500" aria-hidden />+ {t("Private link enabled")}+ </span>+ <AlertDialog>+ <AlertDialogTrigger asChild>+ <Button type="button" size="sm" variant="outline" disabled={isRevokingPrivateLink}>+ {isRevokingPrivateLink ? t("Disabling...") : t("Disable")}+ </Button>+ </AlertDialogTrigger>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>{t("Disable dashboard embed?")}</AlertDialogTitle>+ <AlertDialogDescription>+ {t(+ "This revokes the private link for this site. Any embedded dashboards and shared dashboard links using it will stop working immediately. You can generate a new private link later, but it will have a different URL."+ )}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>{t("Cancel")}</AlertDialogCancel>+ <AlertDialogAction onClick={handleRevokePrivateLink} disabled={isRevokingPrivateLink}>+ {isRevokingPrivateLink ? t("Disabling...") : t("Yes, disable embed")}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ </>) : !isLoadingPrivateLink ? (<Buttontype="button"