Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(docs): add Copy as Markdown and Ask AI to troubleshooting pages (#51501)

Alexis Aguilarbb1a2ab70d0a
diff --git a/apps/docs/components/AiTools.tsx b/apps/docs/components/AiTools.tsx
new file mode 100644
index 00000000000..a69ea0a355f
--- /dev/null
+++ b/apps/docs/components/AiTools.tsx
@@ -0,0 +1,115 @@
+'use client'
+
+import { useSendTelemetryEvent } from '~/lib/telemetry'
+import { askAiUrls, useCopyMarkdownFromUrl } from 'common'
+import { type MarkdownAffordancePageType } from 'common/telemetry-constants'
+import { Chatgpt, Claude } from 'icons'
+import { Check, Copy, Sparkles } from 'lucide-react'
+import Link from 'next/link'
+import { usePathname } from 'next/navigation'
+import { cn } from 'ui'
+
+function AiTools({
+ pageType,
+ articleId,
+ showAgentSetup = false,
+ className,
+}: {
+ pageType: MarkdownAffordancePageType
+ articleId: string
+ showAgentSetup?: boolean
+ className?: string
+}) {
+ const path = usePathname()
+ const sendTelemetryEvent = useSendTelemetryEvent()
+ const { copied, copyMarkdown } = useCopyMarkdownFromUrl()
+ const urls = askAiUrls(`https://supabase.com/docs${path}`)
+
+ function handleAgentSetupClick() {
+ sendTelemetryEvent({ action: 'agent_setup_clicked' })
+ }
+
+ async function handleCopy() {
+ const ok = await copyMarkdown(`/docs${path}.md`, {
+ fallback: () => document.getElementById(articleId)?.innerHTML ?? '',
+ })
+ if (ok) {
+ sendTelemetryEvent({ action: 'copy_as_markdown_clicked', properties: { pageType } })
+ }
+ }
+
+ return (
+ <section className={className} aria-labelledby="ai-tools-title">
+ <h2
+ id="ai-tools-title"
+ className={cn(
+ 'mb-3',
+ pageType === 'troubleshooting'
+ ? 'text-sm text-foreground-lighter'
+ : 'block font-mono uppercase text-xs text-foreground-light'
+ )}
+ >
+ AI tools
+ </h2>
+ <div className="flex flex-col gap-2">
+ {showAgentSetup && (
+ <Link
+ href="/guides/ai-tools"
+ onClick={handleAgentSetupClick}
+ className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
+ >
+ <Sparkles size={14} strokeWidth={1.5} />
+ Connect your AI agent
+ </Link>
+ )}
+ <button
+ tabIndex={0}
+ onClick={handleCopy}
+ className="flex cursor-pointer items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground text-left transition-colors"
+ >
+ {copied ? (
+ <Check size={14} strokeWidth={1.5} className="text-primary" aria-hidden />
+ ) : (
+ <Copy size={14} strokeWidth={1.5} aria-hidden />
+ )}
+ {copied ? 'Copied!' : 'Copy as Markdown'}
+ </button>
+ <span className="sr-only" role="status">
+ {copied ? 'Copied to clipboard' : ''}
+ </span>
+ <a
+ href={urls.chatgpt}
+ target="_blank"
+ onClick={() =>
+ sendTelemetryEvent({
+ action: 'ask_ai_clicked',
+ properties: { agent: 'chatgpt', pageType },
+ })
+ }
+ rel="noreferrer noopener"
+ className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
+ >
+ <Chatgpt size={14} aria-hidden />
+ Ask ChatGPT
+ </a>
+ <a
+ href={urls.claude}
+ target="_blank"
+ onClick={() =>
+ sendTelemetryEvent({
+ action: 'ask_ai_clicked',
+ properties: { agent: 'claude', pageType },
+ })
+ }
+ rel="noreferrer noopener"
+ className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
+ >
+ <Claude size={14} aria-hidden />
+ Ask Claude
+ </a>
+ </div>
+ </section>
+ )
+}
+
+export { AiTools }
diff --git a/apps/docs/components/GuidesSidebar.tsx b/apps/docs/components/GuidesSidebar.tsx
index 8de66f5a342..e65845d0b67 100644
--- a/apps/docs/components/GuidesSidebar.tsx
+++ b/apps/docs/components/GuidesSidebar.tsx
@@ -1,11 +1,8 @@
'use client'
+import { AiTools } from '~/components/AiTools'
import { Feedback } from '~/components/Feedback'
-import { useSendTelemetryEvent } from '~/lib/telemetry'
-import { askAiUrls, isFeatureEnabled, useCopyMarkdownFromUrl } from 'common'
-import { Chatgpt, Claude } from 'icons'
-import { Check, Copy, Sparkles } from 'lucide-react'
-import Link from 'next/link'
+import { isFeatureEnabled } from 'common'
import { usePathname } from 'next/navigation'
import { cn } from 'ui'
import { ExpandableVideo } from 'ui-patterns/ExpandableVideo'
@@ -20,92 +17,6 @@ interface TOCHeader {
level: number
}
-function AiTools({ className }: { className?: string }) {
- const path = usePathname()
- const sendTelemetryEvent = useSendTelemetryEvent()
- const { copied, copyMarkdown } = useCopyMarkdownFromUrl()
- const urls = askAiUrls(`https://supabase.com/docs${path}`)
-
- function handleAgentSetupClick() {
- sendTelemetryEvent({ action: 'agent_setup_clicked' })
- }
-
- async function handleCopy() {
- const ok = await copyMarkdown(`/docs${path}.md`, {
- fallback: () => document.getElementById('sb-docs-guide-main-article')?.innerHTML ?? '',
- })
- if (ok) {
- sendTelemetryEvent({ action: 'copy_as_markdown_clicked', properties: { pageType: 'guide' } })
- }
- }
-
- return (
- <section className={cn(className)} aria-labelledby="ai-tools-title">
- <h3
- id="ai-tools-title"
- className="block font-mono uppercase text-xs text-foreground-light mb-3"
- >
- AI Tools
- </h3>
- <div className="flex flex-col gap-2">
- <Link
- href="/guides/ai-tools"
- onClick={handleAgentSetupClick}
- className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
- >
- <Sparkles size={14} strokeWidth={1.5} />
- Connect your AI agent
- </Link>
- <button
- tabIndex={0}
- onClick={handleCopy}
- className="flex cursor-pointer items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground text-left transition-colors"
- >
- {copied ? (
- <Check size={14} strokeWidth={1.5} className="text-primary" aria-hidden />
- ) : (
- <Copy size={14} strokeWidth={1.5} aria-hidden />
- )}
- {copied ? 'Copied!' : 'Copy as Markdown'}
- </button>
- <span className="sr-only" role="status">
- {copied ? 'Copied to clipboard' : ''}
- </span>
- <a
- href={urls.chatgpt}
- target="_blank"
- onClick={() =>
- sendTelemetryEvent({
- action: 'ask_ai_clicked',
- properties: { agent: 'chatgpt', pageType: 'guide' },
- })
- }
- rel="noreferrer noopener"
- className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
- >
- <Chatgpt size={14} aria-hidden />
- Ask ChatGPT
- </a>
- <a
- href={urls.claude}
- target="_blank"
- onClick={() =>
- sendTelemetryEvent({
- action: 'ask_ai_clicked',
- properties: { agent: 'claude', pageType: 'guide' },
- })
- }
- rel="noreferrer noopener"
- className="flex items-center gap-1.5 text-xs text-foreground-lighter hover:text-foreground transition-colors"
- >
- <Claude size={14} aria-hidden />
- Ask Claude
- </a>
- </div>
- </section>
- )
-}
-
const GuidesSidebar = ({
className,
video,
@@ -136,7 +47,12 @@ const GuidesSidebar = ({
</div>
)}
<div className="pl-5">
- <AiTools key={pathname} />
+ <AiTools
+ key={pathname}
+ pageType="guide"
+ articleId="sb-docs-guide-main-article"
+ showAgentSetup
+ />
</div>
{!hideToc && toc.length !== 0 && (
<Toc className="-ml-[calc(0.25rem+6px)]">
diff --git a/apps/docs/features/docs/Troubleshooting.page.tsx b/apps/docs/features/docs/Troubleshooting.page.tsx
index 438df7f4cd7..5ee029c2bb7 100644
--- a/apps/docs/features/docs/Troubleshooting.page.tsx
+++ b/apps/docs/features/docs/Troubleshooting.page.tsx
@@ -1,6 +1,7 @@
import { Github } from 'lucide-react'
import Link from 'next/link'
import { cn } from 'ui'
+import { AiTools } from '~/components/AiTools'
import Breadcrumbs from '~/components/Breadcrumbs'
import { Feedback } from '~/components/Feedback'
import { SidebarSkeleton } from '~/layouts/MainSkeleton'
@@ -34,7 +35,7 @@ export default async function TroubleshootingPage({ entry }: { entry: ITroublesh
)}
<hr className="my-7" aria-hidden />
<div className="grid gap-10 @3xl/troubleshooting-entry-layout:grid-cols-[1fr_250px]">
- <div className="min-w-0">
+ <div id="sb-docs-troubleshooting-article-body" className="min-w-0">
<MDXRemoteBase source={entry.content} />
</div>
<aside aria-labelledby="heading--metadata" className="not-prose mt-5">
@@ -99,6 +100,11 @@ export default async function TroubleshootingPage({ entry }: { entry: ITroublesh
<hr className="my-6" aria-hidden />
</>
)}
+ <AiTools
+ pageType="troubleshooting"
+ articleId="sb-docs-troubleshooting-article-body"
+ />
+ <hr className="my-6" aria-hidden />
<Feedback className="px-0 mb-6 lg:mb-8" />
{entry.data.github_url && (
<>
diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts
index 0983ac0b168..f563ac23ad9 100644
--- a/packages/common/telemetry-constants.ts
+++ b/packages/common/telemetry-constants.ts
@@ -1018,6 +1018,7 @@ export type MarkdownAffordancePageType =
| 'pricing'
| 'changelog'
| 'guide'
+ | 'troubleshooting'
/**
* User clicked 'Copy as Markdown' on a page and the markdown was copied successfully.