mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | **4** | **#54307 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.) | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
290 lines
11 KiB
TypeScript
290 lines
11 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { SupportCategories } from '@supabase/shared-types/out/constants'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { ExternalLinkIcon, InfoIcon } from 'lucide-react'
|
|
import { SetStateAction, useEffect, useMemo } from 'react'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Alert,
|
|
AlertDescription,
|
|
AlertTitle,
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormInputGroupInput,
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupText,
|
|
InfoIcon as StatusInfoIcon,
|
|
WarningIcon,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
import * as z from 'zod'
|
|
|
|
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
|
|
import { COOLDOWN_DURATION } from '@/data/config/disk-attributes-update-mutation'
|
|
import { useProjectDiskResizeMutation } from '@/data/config/project-disk-resize-mutation'
|
|
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
|
|
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
export interface DiskSizeConfigurationProps {
|
|
visible: boolean
|
|
hideModal: (value: SetStateAction<boolean>) => void
|
|
loading: boolean
|
|
}
|
|
|
|
const formId = 'disk-size-form'
|
|
const maxDiskSize = 200
|
|
|
|
const DiskSizeConfigurationModal = ({
|
|
visible,
|
|
loading,
|
|
hideModal,
|
|
}: DiskSizeConfigurationProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: organization } = useSelectedOrganizationQuery()
|
|
const { data: project, isPending: isLoadingProject } = useSelectedProjectQuery()
|
|
const { lastDatabaseResizeAt } = project ?? {}
|
|
|
|
const { data: projectSubscriptionData, isPending: isLoadingSubscription } =
|
|
useOrgSubscriptionQuery({ orgSlug: organization?.slug }, { enabled: visible })
|
|
|
|
const { hasAccess: hasAccessToDiskModifications, isLoading: isLoadingDiskEntitlement } =
|
|
useCheckEntitlements('instances.disk_modifications')
|
|
|
|
const isLoading = isLoadingProject || isLoadingSubscription || isLoadingDiskEntitlement
|
|
|
|
// COOLDOWN_DURATION is in seconds; convert to minutes to match the diff unit below.
|
|
const cooldownMinutes = COOLDOWN_DURATION / 60
|
|
const timeTillNextAvailableDatabaseResize =
|
|
lastDatabaseResizeAt == null
|
|
? 0
|
|
: Math.max(0, cooldownMinutes - dayjs().diff(lastDatabaseResizeAt, 'minutes'))
|
|
const isAbleToResizeDatabase = timeTillNextAvailableDatabaseResize <= 0
|
|
const formattedTimeTillNextAvailableResize =
|
|
timeTillNextAvailableDatabaseResize < 60
|
|
? `${timeTillNextAvailableDatabaseResize} minute(s)`
|
|
: `${Math.floor(timeTillNextAvailableDatabaseResize / 60)} hours and ${
|
|
timeTillNextAvailableDatabaseResize % 60
|
|
} minute(s)`
|
|
|
|
const { mutate: updateProjectUsage, isPending: isUpdatingDiskSize } =
|
|
useProjectDiskResizeMutation({
|
|
onSuccess: (_res, variables) => {
|
|
toast.success(`Successfully updated disk size to ${variables.volumeSize} GB`)
|
|
hideModal(false)
|
|
},
|
|
})
|
|
|
|
const currentDiskSize = project?.volumeSizeGb ?? 0
|
|
|
|
const INITIAL_VALUES = useMemo(
|
|
() => ({
|
|
'new-disk-size': currentDiskSize,
|
|
}),
|
|
[currentDiskSize]
|
|
)
|
|
|
|
const diskSizeValidationSchema = useMemo(
|
|
() =>
|
|
z.object({
|
|
'new-disk-size': z
|
|
.union([
|
|
z.literal(''),
|
|
z.coerce
|
|
.number()
|
|
.min(Number(currentDiskSize ?? 0), `Must be at least ${currentDiskSize} GB`)
|
|
// to do, update with max_disk_volume_size_gb
|
|
.max(Number(maxDiskSize), `Must not be more than ${maxDiskSize} GB`),
|
|
])
|
|
.refine(
|
|
(value) => value !== '',
|
|
'Please enter a GB amount you want to resize the disk up to'
|
|
),
|
|
}),
|
|
[currentDiskSize]
|
|
)
|
|
|
|
const handleSubmit: SubmitHandler<z.infer<typeof diskSizeValidationSchema>> = async (values) => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
const volumeSize = values['new-disk-size']
|
|
updateProjectUsage({ projectRef, volumeSize })
|
|
}
|
|
|
|
const form = useForm<z.infer<typeof diskSizeValidationSchema>>({
|
|
resolver: zodResolver(diskSizeValidationSchema),
|
|
defaultValues: INITIAL_VALUES,
|
|
})
|
|
const { reset, formState } = form
|
|
const { isDirty } = formState
|
|
|
|
useEffect(() => {
|
|
if (isDirty) return
|
|
reset(INITIAL_VALUES)
|
|
}, [INITIAL_VALUES, isDirty, reset])
|
|
|
|
return (
|
|
<Dialog open={visible} onOpenChange={(open) => hideModal(open)}>
|
|
<DialogContent size="medium">
|
|
<DialogHeader>
|
|
<DialogTitle>Increase Disk Storage Size</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
{isLoading ? (
|
|
<div className="flex flex-col gap-4 p-4">
|
|
<ShimmeringLoader />
|
|
<ShimmeringLoader />
|
|
</div>
|
|
) : projectSubscriptionData?.usage_billing_enabled === true &&
|
|
hasAccessToDiskModifications ? (
|
|
<>
|
|
{currentDiskSize >= maxDiskSize ? (
|
|
<Alert variant="warning" className="rounded-t-none border-0">
|
|
<WarningIcon />
|
|
<AlertTitle>Maximum manual disk size increase reached</AlertTitle>
|
|
<AlertDescription>
|
|
<p>
|
|
You cannot manually expand the disk size any more than {maxDiskSize}GB. If you
|
|
need more than this, contact us via support for help.
|
|
</p>
|
|
<Button asChild className="mt-3">
|
|
<SupportLink
|
|
queryParams={{
|
|
projectRef,
|
|
category: SupportCategories.PERFORMANCE_ISSUES,
|
|
subject: 'Increase disk size beyond 200GB',
|
|
}}
|
|
>
|
|
Contact support
|
|
</SupportLink>
|
|
</Button>
|
|
</AlertDescription>
|
|
</Alert>
|
|
) : (
|
|
<>
|
|
<DialogSection className="w-full space-y-4">
|
|
<Alert variant={isAbleToResizeDatabase ? 'default' : 'warning'}>
|
|
<InfoIcon size={16} />
|
|
<AlertTitle>This operation is only possible every 4 hours</AlertTitle>
|
|
<AlertDescription>
|
|
<div className="mb-4">
|
|
{isAbleToResizeDatabase
|
|
? `Upon updating your disk size, the next disk size update will only be available from ${dayjs().format(
|
|
'DD MMM YYYY, HH:mm (ZZ)'
|
|
)}`
|
|
: `Your database was last resized at ${dayjs(lastDatabaseResizeAt).format(
|
|
'DD MMM YYYY, HH:mm (ZZ)'
|
|
)}. You can resize your database again in approximately ${formattedTimeTillNextAvailableResize}`}
|
|
</div>
|
|
<Button asChild iconRight={<ExternalLinkIcon size={14} />}>
|
|
<a
|
|
href={`${DOCS_URL}/guides/platform/database-size#disk-management`}
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
>
|
|
Read more about disk management
|
|
</a>
|
|
</Button>
|
|
</AlertDescription>
|
|
</Alert>
|
|
<Form {...form}>
|
|
<form id={formId} onSubmit={form.handleSubmit(handleSubmit)} noValidate>
|
|
<FormField
|
|
control={form.control}
|
|
name="new-disk-size"
|
|
disabled={!isAbleToResizeDatabase}
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
name="new-disk-size"
|
|
layout="vertical"
|
|
label="New disk size"
|
|
>
|
|
<FormControl>
|
|
<InputGroup>
|
|
<FormInputGroupInput {...field} id="new-disk-size" type="number" />
|
|
<InputGroupAddon align="inline-end">
|
|
<InputGroupText>GB</InputGroupText>
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</form>
|
|
</Form>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button onClick={() => hideModal(false)}>Cancel</Button>
|
|
<Button
|
|
form={formId}
|
|
type="submit"
|
|
variant="primary"
|
|
disabled={!isAbleToResizeDatabase || isUpdatingDiskSize || !isDirty || loading}
|
|
loading={isUpdatingDiskSize || loading}
|
|
>
|
|
Update disk size
|
|
</Button>
|
|
</DialogFooter>
|
|
</>
|
|
)}
|
|
</>
|
|
) : (
|
|
<Alert className="border-none">
|
|
<StatusInfoIcon />
|
|
<AlertTitle>
|
|
{hasAccessToDiskModifications === false
|
|
? 'Disk size configuration is not available for projects on the Free Plan'
|
|
: 'Disk size configuration is only available when the spend cap has been disabled'}
|
|
</AlertTitle>
|
|
<AlertDescription>
|
|
{hasAccessToDiskModifications === false ? (
|
|
<p>
|
|
If you are intending to use more than 500MB of disk space, then you will need to
|
|
upgrade to at least the Pro Plan.
|
|
</p>
|
|
) : (
|
|
<p>
|
|
If you are intending to use more than 8GB of disk space, then you will need to
|
|
disable your spend cap.
|
|
</p>
|
|
)}
|
|
<Button asChild className="mt-3">
|
|
<Link
|
|
to="/org/$slug/billing"
|
|
params={{ slug: organization?.slug ?? '_' }}
|
|
search={{
|
|
panel:
|
|
hasAccessToDiskModifications === false ? 'subscriptionPlan' : 'costControl',
|
|
}}
|
|
target="_blank"
|
|
>
|
|
{hasAccessToDiskModifications === false
|
|
? 'Upgrade subscription'
|
|
: 'Disable spend cap'}
|
|
</Link>
|
|
</Button>
|
|
</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|
|
|
|
export default DiskSizeConfigurationModal
|