mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
## Screenshots ### Table editor: foreign record selector Before: <img width="802" height="213" alt="image" src="https://github.com/user-attachments/assets/82ee3ce6-ac72-4b49-b1b0-2e635688cbb1" /> After: <img width="609" height="194" alt="image" src="https://github.com/user-attachments/assets/e9cc09c1-1c6b-4099-8cae-abe08f50fda9" /> ### Account - Add TOTP Before: <img width="527" height="679" alt="image" src="https://github.com/user-attachments/assets/b9f4a626-e24b-46e3-8385-700ef181308b" /> After: <img width="531" height="684" alt="image" src="https://github.com/user-attachments/assets/549745a7-9655-4a7d-9e0e-51f75b6a1c61" /> ### Organisation Audit Logs Details Before: <img width="673" height="1321" alt="image" src="https://github.com/user-attachments/assets/0bb360cf-6f27-4574-b9af-485a3836b17b" /> After: <img width="669" height="1273" alt="image" src="https://github.com/user-attachments/assets/0382c662-e270-41fd-a8ee-08528dedfce3" /> ### Data API Integration Docs Before: <img width="1115" height="891" alt="image" src="https://github.com/user-attachments/assets/db0c7698-53b7-4422-aac3-5e674b0bf151" /> After: <img width="1193" height="1272" alt="image" src="https://github.com/user-attachments/assets/927e5c43-413b-49c1-9b71-8ab628179c70" /> ### Edge Function Edit Secret Before: <img width="599" height="255" alt="image" src="https://github.com/user-attachments/assets/d6aa2f87-e247-4724-9e43-02b71933241c" /> After: <img width="596" height="261" alt="image" src="https://github.com/user-attachments/assets/d94acb41-07e1-497f-9697-830390526f4a" /> ### JWT Key Details Before: <img width="536" height="549" alt="image" src="https://github.com/user-attachments/assets/43672adc-dc0e-4e65-b7d4-b4537d22f6ea" /> After: <img width="523" height="517" alt="image" src="https://github.com/user-attachments/assets/e501e8a8-7f41-46a0-bb69-d240cea594f0" /> ### Realtime Filter Popover Before: <img width="403" height="576" alt="image" src="https://github.com/user-attachments/assets/73842450-ba87-456b-98fc-625b99149449" /> After: <img width="387" height="564" alt="image" src="https://github.com/user-attachments/assets/f2b35035-947c-4342-84dd-3548f9bd5e9f" /> ### Realtime broadcast message dialog Before: <img width="520" height="393" alt="image" src="https://github.com/user-attachments/assets/4f4a1a93-e0cf-4268-ae4e-baf8b8a62e74" /> After: <img width="525" height="392" alt="image" src="https://github.com/user-attachments/assets/e1c1934a-1812-4013-8606-9b846dc2498d" /> ### Impersonation Popover Before: <img width="604" height="501" alt="image" src="https://github.com/user-attachments/assets/9abdc604-94f8-4ed4-9a95-4688e6504e76" /> <img width="587" height="599" alt="image" src="https://github.com/user-attachments/assets/5293c80c-9abd-43eb-899f-da759c83b598" /> After: <img width="594" height="585" alt="image" src="https://github.com/user-attachments/assets/5eaf2162-2d7f-444c-9052-c9afb00080f6" /> <img width="590" height="597" alt="image" src="https://github.com/user-attachments/assets/149dc7c1-689c-4e0f-a884-c6f5b0228ebc" /> ### Storage move item Before: <img width="521" height="285" alt="image" src="https://github.com/user-attachments/assets/7d0f945f-add5-412b-813a-9325b260ab28" /> After: <img width="529" height="274" alt="image" src="https://github.com/user-attachments/assets/ab0891a1-b31b-40b6-be53-92afc95095ea" /> ### Table Editor - Spreadsheet import Before: <img width="673" height="506" alt="image" src="https://github.com/user-attachments/assets/7a722908-10c2-4c04-95fb-b12d3c23557c" /> After: <img width="671" height="638" alt="image" src="https://github.com/user-attachments/assets/689b1fb6-031c-4a02-9e7f-739356c1453d" /> ### Org Billing downgrade survey Before: <img width="788" height="655" alt="image" src="https://github.com/user-attachments/assets/c7a0d4c6-e9b9-4c6c-9cf1-e7d05016233f" /> After: <img width="1630" height="1354" alt="image" src="https://github.com/user-attachments/assets/e3f5473b-db9a-42b1-9242-40480c25fc02" /> ### Project API Docs Before: <img width="1030" height="396" alt="image" src="https://github.com/user-attachments/assets/95643b21-811a-4ba7-918a-5e655c262ac1" /> After: <img width="1012" height="457" alt="image" src="https://github.com/user-attachments/assets/d5559646-bb89-43b6-ad62-c5684b54b3fb" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Standardized form field layouts across panels, dialogs, and modals for a more consistent editing and reading experience. * Replaced several Input-based textareas with dedicated TextArea/ExpandingTextArea controls and aligned labels with wrapper layouts for clearer accessibility. * Introduced grouped/composable input controls, added additional read-only detail fields and labeled value/copy blocks, and tightened header/layout spacing and control alignment. * Swapped notice styles for improved warning/admonition presentation. * **Chores** * Removed a deprecated AutoTextArea component. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
248 lines
8.6 KiB
TypeScript
248 lines
8.6 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Select_Shadcn_,
|
|
SelectContent_Shadcn_,
|
|
SelectItem_Shadcn_,
|
|
SelectTrigger_Shadcn_,
|
|
SelectValue_Shadcn_,
|
|
Separator,
|
|
Sheet,
|
|
SheetContent,
|
|
SheetFooter,
|
|
SheetHeader,
|
|
SheetSection,
|
|
SheetTitle,
|
|
Switch,
|
|
TextArea_Shadcn_ as TextArea,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
import { LintInfo } from '../Linter/Linter.constants'
|
|
import { lintInfoMap } from '../Linter/Linter.utils'
|
|
import { generateRuleDescription } from './AdvisorRules.utils'
|
|
import { useLintRuleCreateMutation } from '@/data/lint/create-lint-rule-mutation'
|
|
import { useOrganizationMembersQuery } from '@/data/organizations/organization-members-query'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
|
|
interface CreateRuleSheetProps {
|
|
lint?: LintInfo
|
|
open: boolean
|
|
onOpenChange: (value: boolean) => void
|
|
}
|
|
|
|
const FormSchema = z.object({
|
|
lint_name: z.string().optional(),
|
|
note: z.string().optional(),
|
|
assigned_to: z.string().optional(),
|
|
is_disabled: z.boolean(),
|
|
})
|
|
|
|
const defaultValues = {
|
|
lint_name: undefined,
|
|
note: undefined,
|
|
assigned_to: 'all',
|
|
is_disabled: true,
|
|
}
|
|
|
|
/**
|
|
* [Joshen] JFYI while the API supports adding rules on a category, I'm intentionally leaving that functionality out for now
|
|
* as the only use case for that would be to ignore _all_ lints in that category (which I'm not sure if that's what we want to advise users doing atm)
|
|
*
|
|
* (Spoken with Hieu) We'll eventually support granularity of Entity/Items as well, just not atm
|
|
*/
|
|
export const CreateRuleSheet = ({ lint, open, onOpenChange }: CreateRuleSheetProps) => {
|
|
const router = useRouter()
|
|
const { ref: projectRef } = useParams()
|
|
|
|
const routeCategory = router.pathname.split('/').pop()
|
|
const { data: organization } = useSelectedOrganizationQuery()
|
|
const { data: members = [] } = useOrganizationMembersQuery({ slug: organization?.slug })
|
|
|
|
const { mutate: createRule, isPending: isCreating } = useLintRuleCreateMutation({
|
|
onSuccess: (_, vars) => {
|
|
const ruleLint = vars.exception.lint_name
|
|
const ruleLintMeta = lintInfoMap.find((x) => x.name === ruleLint)
|
|
toast.success(`Successfully created new rule for ${ruleLintMeta?.title}`)
|
|
|
|
if (ruleLintMeta) {
|
|
if (!!routeCategory && routeCategory !== ruleLintMeta.category) {
|
|
router.push(
|
|
`/project/${projectRef}/advisors/rules/${ruleLintMeta.category}?lint=${ruleLintMeta.name}`
|
|
)
|
|
} else {
|
|
// setExpandedLint(ruleLintMeta?.name)
|
|
}
|
|
}
|
|
onOpenChange(false)
|
|
},
|
|
})
|
|
|
|
const formId = 'create-lint-rule-form'
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
mode: 'onBlur',
|
|
reValidateMode: 'onChange',
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues,
|
|
})
|
|
|
|
const { lint_name, assigned_to, is_disabled } = form.watch()
|
|
|
|
const onSubmit: SubmitHandler<z.infer<typeof FormSchema>> = async (values) => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
|
|
createRule({
|
|
projectRef,
|
|
exception: {
|
|
...values,
|
|
lint_category: undefined,
|
|
lint_name: values.lint_name,
|
|
assigned_to: values.assigned_to === 'all' ? undefined : values.assigned_to,
|
|
},
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (open) form.reset({ ...defaultValues, lint_name: lint?.name })
|
|
}, [open])
|
|
|
|
return (
|
|
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
<SheetContent className="flex flex-col gap-0">
|
|
<SheetHeader className="shrink-0 flex items-center gap-4">
|
|
<SheetTitle>Create a rule for "{lint?.title}"</SheetTitle>
|
|
</SheetHeader>
|
|
<SheetSection className="overflow-auto grow px-0">
|
|
<Form {...form}>
|
|
<form
|
|
id={formId}
|
|
className="flex flex-col gap-y-4"
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
>
|
|
<FormField
|
|
name="is_disabled"
|
|
control={form.control}
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
className="px-5"
|
|
label={`Disable this lint for ${assigned_to === 'all' ? 'project' : 'the assigned member'}`}
|
|
description="Toggles the visiblity of this lint in the Advisor reports"
|
|
>
|
|
<Tooltip>
|
|
<TooltipTrigger type="button">
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={field.disabled || assigned_to === 'all'}
|
|
/>
|
|
</FormControl>
|
|
</TooltipTrigger>
|
|
{assigned_to === 'all' && (
|
|
<TooltipContent side="bottom" className="w-72">
|
|
Assign this rule to a specific project member before toggling this option
|
|
off. This will then configure the rule to{' '}
|
|
<span className="text-brand">only be visible</span> to that member in the
|
|
advisor reports.
|
|
</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
<Separator />
|
|
|
|
<FormField
|
|
name="assigned_to"
|
|
control={form.control}
|
|
render={({ field }) => (
|
|
<FormItemLayout label="Assign rule to" layout="vertical" className="px-5">
|
|
<Select_Shadcn_
|
|
onValueChange={(val) => {
|
|
field.onChange(val)
|
|
if (val === 'all') form.setValue('is_disabled', true)
|
|
}}
|
|
defaultValue={field.value}
|
|
>
|
|
<SelectTrigger_Shadcn_ className="col-span-8">
|
|
<SelectValue_Shadcn_ />
|
|
</SelectTrigger_Shadcn_>
|
|
<SelectContent_Shadcn_>
|
|
<SelectItem_Shadcn_ value="all">All project members</SelectItem_Shadcn_>
|
|
{members.map((m) => (
|
|
<SelectItem_Shadcn_ key={m.gotrue_id} value={m.gotrue_id}>
|
|
{m.username || m.primary_email}
|
|
</SelectItem_Shadcn_>
|
|
))}
|
|
</SelectContent_Shadcn_>
|
|
</Select_Shadcn_>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
{!!lint_name && (
|
|
<div className="px-5">
|
|
<Admonition showIcon={false} type="default">
|
|
{generateRuleDescription({
|
|
name: lint_name,
|
|
disabled: is_disabled,
|
|
member: members.find((x) => x.gotrue_id === assigned_to),
|
|
})}
|
|
</Admonition>
|
|
</div>
|
|
)}
|
|
|
|
<Separator />
|
|
|
|
<FormField
|
|
name="note"
|
|
control={form.control}
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="vertical"
|
|
className="px-5"
|
|
label="Description"
|
|
labelOptional="Optional"
|
|
>
|
|
<FormControl>
|
|
<TextArea
|
|
{...field}
|
|
rows={4}
|
|
className="text-sm"
|
|
placeholder="e.g Describe why this rule is being set"
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</form>
|
|
</Form>
|
|
</SheetSection>
|
|
<SheetFooter>
|
|
<Button disabled={isCreating} type="default" onClick={() => onOpenChange(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button form={formId} htmlType="submit" loading={isCreating}>
|
|
Create rule
|
|
</Button>
|
|
</SheetFooter>
|
|
</SheetContent>
|
|
</Sheet>
|
|
)
|
|
}
|