Files
supabase/apps/studio/components/interfaces/QueryPerformance/IndexAdvisorDisabledState.tsx
T
df52ea7ee0 feat: Replace all toasts with sonner (#28250)
* Update the design of the sonner toasts. Add the close button by default.

* Migrate studio and www apps to use the SonnerToaster.

* Migrate all toasts from studio.

* Migrate all leftover toasts in studio.

* Add a new toast component with progress. Use it in studio.

* Migrate the design-system app.

* Refactor the consent toast to use sonner.

* Switch docs to use the new sonner toasts.

* Remove toast examples from the design-system app.

* Remove all toast-related components and old code.

* Fix the progress bar in the toast progress component. Also make the bottom components vertically centered.

* Fix the width of the toast progress.

* Use text-foreground-lighter instead of muted for ToastProgress text

* Rename ToastProgress to SonnerProgress.

* Shorten the text in sonner progress.

* Use the correct classes for the close button. Add a const var for the default toast duration. Remove the custom width class from sonner.

* Set the position for all progress toasts to bottom right. Set the duration for all toasts to the default (when reusing a toast id from loading/progress toast, the duration is set to infinity).

* Fix the playwright tests.

* Refactor imports to use ui instead of @ui.

* Change all imports of react-hot-toast with sonner. These components were merged since the last commit to this branch.

* Remove react-hot-toast lib.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
2024-08-31 07:50:51 +08:00

105 lines
3.8 KiB
TypeScript

import { ExternalLink } from 'lucide-react'
import Link from 'next/link'
import { toast } from 'sonner'
import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useDatabaseExtensionEnableMutation } from 'data/database-extensions/database-extension-enable-mutation'
import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
import { Markdown } from '../Markdown'
export const IndexAdvisorDisabledState = () => {
const { ref } = useParams()
const { project } = useProjectContext()
const { data: extensions } = useDatabaseExtensionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const hypopgExtension = (extensions ?? []).find((ext) => ext.name === 'hypopg')
const indexAdvisorExtension = (extensions ?? []).find((ext) => ext.name === 'index_advisor')
const { mutateAsync: enableExtension, isLoading: isEnablingExtension } =
useDatabaseExtensionEnableMutation()
const onEnableIndexAdvisor = async () => {
if (project === undefined) return console.error('Project is required')
try {
if (hypopgExtension?.installed_version === null) {
await enableExtension({
projectRef: project?.ref,
connectionString: project?.connectionString,
name: hypopgExtension.name,
schema: hypopgExtension?.schema ?? 'extensions',
version: hypopgExtension.default_version,
})
}
if (indexAdvisorExtension?.installed_version === null) {
await enableExtension({
projectRef: project?.ref,
connectionString: project?.connectionString,
name: indexAdvisorExtension.name,
schema: indexAdvisorExtension?.schema ?? 'extensions',
version: indexAdvisorExtension.default_version,
})
}
toast.success('Successfully enabled index advisor!')
} catch (error: any) {
toast.error(`Failed to enable index advisor: ${error.message}`)
}
}
return (
<Alert_Shadcn_ className="mb-6">
<AlertTitle_Shadcn_>
<Markdown
className="text-foreground"
content={
indexAdvisorExtension === undefined
? 'Newer version of Postgres required'
: 'Postgres extensions `index_advisor` and `hypopg` required'
}
/>
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
<Markdown
content={
indexAdvisorExtension === undefined
? 'Upgrade to the latest version of Postgres to get recommendations on indexes for your queries'
: 'These extensions can help in recommending database indexes to reduce the costs of your query.'
}
/>
</AlertDescription_Shadcn_>
<AlertDescription_Shadcn_ className="mt-3">
<div className="flex items-center gap-x-2">
{indexAdvisorExtension === undefined ? (
<Button asChild type="default">
<Link href={`/project/${ref}/settings/infrastructure`}>Upgrade Postgres version</Link>
</Button>
) : (
<Button
type="default"
disabled={isEnablingExtension}
loading={isEnablingExtension}
onClick={() => onEnableIndexAdvisor()}
>
Enable extensions
</Button>
)}
<Button asChild type="outline" icon={<ExternalLink />}>
<a
target="_blank"
rel="noreferrer"
href="https://supabase.com/docs/guides/database/extensions/index_advisor"
>
Documentation
</a>
</Button>
</div>
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
)
}