Skip to content

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

feat: sticky warning when viewing old client lib version

Greg Richardson7bb8cfd998e9
diff --git a/apps/docs/components/reference/OldVersionAlert.tsx b/apps/docs/components/reference/OldVersionAlert.tsx
new file mode 100644
index 00000000000..8bcb7013170
--- /dev/null
+++ b/apps/docs/components/reference/OldVersionAlert.tsx
@@ -0,0 +1,28 @@
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { useMenuActiveRefId } from '~/hooks/useMenuState'
+import Admonition from '../Admonition'
+
+const OldVersionAlert = () => {
+ const router = useRouter()
+ const activeRefId = useMenuActiveRefId()
+
+ // Remove the version number from URL to get the latest
+ const latestVersionUrl = router.asPath.split('/').slice(0, -2).concat([activeRefId]).join('/')
+
+ return (
+ <div className="sticky top-10 z-10 lg:top-14 lg:w-1/2">
+ <Admonition type="caution">
+ You&apos;re viewing an older version of this library.&nbsp;
+ <Link href={latestVersionUrl}>
+ <a className="underline decoration-brand-700 underline-offset-4 decoration-1">
+ Switch to the latest
+ </a>
+ </Link>
+ .
+ </Admonition>
+ </div>
+ )
+}
+
+export default OldVersionAlert
diff --git a/apps/docs/components/reference/RefSectionHandler.tsx b/apps/docs/components/reference/RefSectionHandler.tsx
index b1b5bebf134..3e2c443035c 100644
--- a/apps/docs/components/reference/RefSectionHandler.tsx
+++ b/apps/docs/components/reference/RefSectionHandler.tsx
@@ -8,6 +8,7 @@ import RefFunctionSection from '~/components/reference/RefFunctionSection'
import RefSubLayout from '~/layouts/ref/RefSubLayout'
import ApiOperationSection from './ApiOperationSection'
import CliCommandSection from './CLICommandSection'
+import OldVersionAlert from './OldVersionAlert'
import { IAPISpec, ICommonFunc, IRefStaticDoc, ISpec, TypeSpec } from './Reference.types'
interface RefSectionHandlerProps {
@@ -16,6 +17,7 @@ interface RefSectionHandlerProps {
typeSpec?: TypeSpec
pageProps: { docs: IRefStaticDoc[] }
type: 'client-lib' | 'cli' | 'api'
+ isOldVersion?: boolean
}
const RefSectionHandler = (props: RefSectionHandlerProps) => {
@@ -58,6 +60,7 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => {
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</Head>
+ {props.isOldVersion && <OldVersionAlert />}
<RefSubLayout>
{props.sections.map((x, i) => {
switch (x.type) {
diff --git a/apps/docs/pages/reference/dart/v0/[...slug].tsx b/apps/docs/pages/reference/dart/v0/[...slug].tsx
index 4b6a485d9c6..f3895268e5c 100644
--- a/apps/docs/pages/reference/dart/v0/[...slug].tsx
+++ b/apps/docs/pages/reference/dart/v0/[...slug].tsx
@@ -9,7 +9,15 @@ import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps'
const sections = flattenSections(clientLibsCommonSections)
export default function JSReference(props) {
- return <RefSectionHandler sections={sections} spec={spec} pageProps={props} type="client-lib" />
+ return (
+ <RefSectionHandler
+ sections={sections}
+ spec={spec}
+ pageProps={props}
+ type="client-lib"
+ isOldVersion
+ />
+ )
}
export async function getStaticProps() {
diff --git a/apps/docs/pages/reference/javascript/v1/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/[...slug].tsx
index 4dd32c156ca..bee10557063 100644
--- a/apps/docs/pages/reference/javascript/v1/[...slug].tsx
+++ b/apps/docs/pages/reference/javascript/v1/[...slug].tsx
@@ -17,6 +17,7 @@ export default function JSReference(props) {
typeSpec={typeSpec}
pageProps={props}
type="client-lib"
+ isOldVersion
/>
)
}