mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem We decided to keep the search_v2 experiment. ## Solution Delete all files related to the variant experimentation, old components and ingest flow. <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. Open the docs preview 2. Search V2 should be the default search ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
103 lines
3.0 KiB
TypeScript
103 lines
3.0 KiB
TypeScript
'use client'
|
|
|
|
import ButtonCard from '~/components/ButtonCard'
|
|
import { useSendTelemetryEvent } from '~/lib/telemetry'
|
|
import { useDocsSearchV2, type DocsSearchV2Result } from 'common'
|
|
import { usePathname } from 'next/navigation'
|
|
import { useEffect } from 'react'
|
|
import { Button, cn } from 'ui'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { SearchV2Dialog, useSearchV2Dialog } from '@/features/SearchV2'
|
|
import { SEARCH_V2_ENDPOINT } from '@/features/SearchV2/constants'
|
|
|
|
function SearchButton() {
|
|
const { open, openDialog, handleOpenChange } = useSearchV2Dialog()
|
|
|
|
return (
|
|
<>
|
|
<Button variant="primary" size="small" onClick={() => openDialog('not_found_button')}>
|
|
Search for page
|
|
</Button>
|
|
<SearchV2Dialog open={open} onOpenChange={handleOpenChange} />
|
|
</>
|
|
)
|
|
}
|
|
|
|
function Recommendations() {
|
|
const pathname = usePathname()
|
|
|
|
const { searchState: state, handleDocsSearch: handleSearch } = useDocsSearchV2({
|
|
endpoint: SEARCH_V2_ENDPOINT,
|
|
})
|
|
|
|
const loading = state.status === 'initial' || state.status === 'loading'
|
|
const recommendations = state.status === 'results' ? uniqueByPath(state.results) : []
|
|
|
|
useEffect(() => {
|
|
if (!pathname) return
|
|
|
|
const query = decodeURIComponent(pathname.replace(/^\/(?:guides|reference)\//, '')).replace(
|
|
/[_\/-]/g,
|
|
' '
|
|
)
|
|
|
|
handleSearch(query)
|
|
}, [handleSearch, pathname])
|
|
|
|
return (
|
|
<section aria-labelledby="empty-page-recommendations" className="min-h-96 mt-20">
|
|
<h2 id="empty-page-recommendations">Are you looking for...?</h2>
|
|
{loading && <LoadingState />}
|
|
{!loading && recommendations.length === 0 && <NoResults />}
|
|
{!loading && recommendations.length > 0 && (
|
|
<RecommendationsList recommendations={recommendations} />
|
|
)}
|
|
</section>
|
|
)
|
|
}
|
|
|
|
// results are per heading, so a page can match more than once
|
|
function uniqueByPath(results: DocsSearchV2Result[]) {
|
|
return results.filter(
|
|
(result, index) => results.findIndex(({ path }) => path === result.path) === index
|
|
)
|
|
}
|
|
|
|
function LoadingState() {
|
|
return <GenericSkeletonLoader />
|
|
}
|
|
|
|
function NoResults() {
|
|
return <span>No recommendations found.</span>
|
|
}
|
|
|
|
function RecommendationsList({ recommendations }: { recommendations: DocsSearchV2Result[] }) {
|
|
const pathname = usePathname()
|
|
const sendTelemetryEvent = useSendTelemetryEvent()
|
|
|
|
return (
|
|
<ul className={cn('not-prose', 'grid grid-cols-[repeat(auto-fit,minmax(300px,1fr))] gap-4')}>
|
|
{recommendations
|
|
.filter(({ title }) => !!title)
|
|
.slice(0, 6)
|
|
.map(({ path, title, excerpt }) => (
|
|
<ButtonCard
|
|
key={path}
|
|
to={path}
|
|
title={title}
|
|
description={excerpt || undefined}
|
|
onClick={() =>
|
|
sendTelemetryEvent({
|
|
action: 'docs_404_recommendation_clicked',
|
|
properties: { destinationPath: path, sourcePath: pathname ?? '' },
|
|
})
|
|
}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|
|
|
|
export { Recommendations, SearchButton }
|