mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 02:45:07 +03:00
Follow up of #49637. Usages that impacted tests were fixed in the previous PR. This PR fixes the other usages so that label are correctly linked to their inputs. No visual changes ## How to test 1. Design system: [Form examples](https://design-system-git-fix-form-item-layout-usages-supabase.vercel.app/design-system/docs/ui-patterns/forms): moved `FormControl` around the `SelectTrigger` so that the label is linked to the button (It's actually done like this in the [Select Form example](https://design-system-git-fix-form-item-layout-usages-supabase.vercel.app/design-system/docs/components/select#form) and Radix recommend targeting the button too in their [documentation](https://www.radix-ui.com/primitives/docs/components/select#labelling)) 2. [Access tokens](https://studio-staging-463111oii-supabase.vercel.app/dashboard/account/tokens): updated usage to fallback on generated ids and fixed the select just like _1_ 3. [New TOTP factor](https://studio-staging-463111oii-supabase.vercel.app/dashboard/account/security): updated usage to fallback on generated ids 4. _Studio/Database/Extensions_ (`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/database/extensions`): updated the extension enabling modal to fallback on generated ids 5. _Studio/Integrations/Vault (`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/integrations/vault/secrets`): updated the secret edition modal to fallback on generated ids 6. _Studio/Observability(`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/observability`): updated the report creation and edition modals to fallback on generated ids 7. _Studio/SQL Editor(`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/sql/new`): updated the query renaming modal to fallback on generated ids 8. _Studio/Storage/Analytics(`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/storage/analytics`): updated the table creation sheet to fallback on generated ids (you must have a bucket first) 9. _Studio/Workers(`https://studio-staging-463111oii-supabase.vercel.app/dashboard/project/[PROJECT]/workers`): updated the worker creation modal to fallback on generated ids (you must have a bucket first) 10. Updated [Signup](https://studio-staging-463111oii-supabase.vercel.app/dashboard/sign-up?returnTo=%2Fnew), [Signin](https://studio-staging-463111oii-supabase.vercel.app/dashboard/sign-in) and [SSO Signin](https://studio-staging-463111oii-supabase.vercel.app/dashboard/sign-in-sso) forms to fallback on generated ids <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Improvements** - Standardized form field presentation across access tokens, authentication, reports, integrations, database extensions, SQL editor, storage, and worker deployment workflows. - Updated password fields and visibility toggles for more consistent input behavior. - Refined token expiration selection, verification code entry, and dropdown layouts. - Preserved existing labels, validation, options, and form functionality while simplifying the interface structure. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
169 lines
5.1 KiB
TypeScript
169 lines
5.1 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useRouter } from 'next/router'
|
|
import { useMemo } from 'react'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Input,
|
|
Textarea,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
import { useContentUpsertMutation } from '@/data/content/content-upsert-mutation'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { uuidv4 } from '@/lib/helpers'
|
|
import { useProfile } from '@/lib/profile'
|
|
|
|
export interface CreateReportModal {
|
|
visible: boolean
|
|
onCancel: () => void
|
|
afterSubmit: () => void
|
|
}
|
|
|
|
const formSchema = z.object({
|
|
name: z.string().min(1, 'Required'),
|
|
description: z.string().optional(),
|
|
})
|
|
|
|
type CustomReport = z.infer<typeof formSchema>
|
|
|
|
export const CreateReportModal = ({ visible, onCancel, afterSubmit }: CreateReportModal) => {
|
|
const router = useRouter()
|
|
const { profile } = useProfile()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const ref = project?.ref ?? 'default'
|
|
|
|
// Preserve date range query parameters when navigating to new report
|
|
const preservedQueryParams = useMemo(() => {
|
|
const { its, ite, isHelper, helperText } = router.query
|
|
const params = new URLSearchParams()
|
|
|
|
if (its && typeof its === 'string') params.set('its', its)
|
|
if (ite && typeof ite === 'string') params.set('ite', ite)
|
|
if (isHelper && typeof isHelper === 'string') params.set('isHelper', isHelper)
|
|
if (helperText && typeof helperText === 'string') params.set('helperText', helperText)
|
|
|
|
const queryString = params.toString()
|
|
return queryString ? `?${queryString}` : ''
|
|
}, [router.query])
|
|
|
|
const { mutate: upsertContent, isPending: isCreating } = useContentUpsertMutation({
|
|
onSuccess: (_, vars) => {
|
|
toast.success('Successfully created new report')
|
|
const newReportId = vars.payload.id
|
|
router.push(`/project/${ref}/observability/${newReportId}${preservedQueryParams}`)
|
|
afterSubmit()
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to create report: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const createCustomReport: SubmitHandler<CustomReport> = async ({ name, description }) => {
|
|
if (!ref) return console.error('Project ref is required')
|
|
if (!profile) return console.error('Profile is required')
|
|
|
|
upsertContent({
|
|
projectRef: ref,
|
|
payload: {
|
|
id: uuidv4(),
|
|
type: 'report',
|
|
name,
|
|
description: description || '',
|
|
visibility: 'project',
|
|
owner_id: profile?.id,
|
|
content: {
|
|
schema_version: 1,
|
|
period_start: {
|
|
time_period: '7d',
|
|
date: '',
|
|
},
|
|
period_end: {
|
|
time_period: 'today',
|
|
date: '',
|
|
},
|
|
interval: '1d',
|
|
layout: [],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
const handleCancel = () => {
|
|
onCancel()
|
|
form.reset()
|
|
}
|
|
|
|
const form = useForm<CustomReport>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: { name: '', description: '' },
|
|
})
|
|
const { isDirty } = form.formState
|
|
|
|
return (
|
|
<Dialog open={visible} onOpenChange={handleCancel}>
|
|
<DialogContent size="small">
|
|
<DialogHeader>
|
|
<DialogTitle>Create a custom report</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(createCustomReport)} noValidate>
|
|
<DialogSection>
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItemLayout layout="vertical" label="Name">
|
|
<FormControl>
|
|
<Input {...field} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</DialogSection>
|
|
<DialogSection>
|
|
<FormField
|
|
control={form.control}
|
|
name="description"
|
|
render={({ field }) => (
|
|
<FormItemLayout layout="vertical" label="Description">
|
|
<FormControl>
|
|
<Textarea
|
|
{...field}
|
|
rows={4}
|
|
placeholder="Describe your custom report"
|
|
className="resize-none"
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button type="reset" variant="default" onClick={handleCancel} disabled={isCreating}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" loading={isCreating} disabled={isCreating || !isDirty}>
|
|
Create report
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|