The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: Expandable code editor in the Create Function panel (#22000)
Ivan Vasilov221ee13f799c
diff --git a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyHeader.tsx b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyHeader.tsxindex ced99acc728..e3c23df101e 100644--- a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyHeader.tsx+++ b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/AIPolicyHeader.tsx@@ -1,6 +1,6 @@import type { PostgresPolicy } from '@supabase/postgres-meta'-import clsx from 'clsx'import { PanelLeftClose, PanelRightClose, X } from 'lucide-react'+import {SheetClose,SheetHeader,@@ -29,7 +29,7 @@ export const AIPolicyHeader = ({><div className="flex flex-row gap-3 items-center max-w-[75%]"><SheetClose- className={clsx(+ className={cn('text-muted hover:text ring-offset-background transition-opacity hover:opacity-100','focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2','disabled:pointer-events-none data-[state=open]:bg-secondary',diff --git a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/index.tsx b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/index.tsxindex c37158fdd30..6e5791fd6c0 100644--- a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/index.tsx+++ b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/index.tsx@@ -14,9 +14,9 @@ import {IconGrid,Modal,ScrollArea,+ Sheet,SheetContent,SheetFooter,- Sheet,TabsContent_Shadcn_,TabsList_Shadcn_,TabsTrigger_Shadcn_,@@ -301,6 +301,7 @@ export const AIPolicyEditorPanel = memo(function ({'p-0 flex flex-row gap-0',assistantVisible ? '!min-w-[1200px]' : '!min-w-[600px]')}+ showClose={false}><div className={cn('flex flex-col grow w-full', assistantVisible && 'w-[60%]')}><AIPolicyHeaderdiff --git a/apps/studio/components/interfaces/Database/Functions/CreateFunction.tsx b/apps/studio/components/interfaces/Database/Functions/CreateFunction.tsxdeleted file mode 100644index a031f03a86d..00000000000--- a/apps/studio/components/interfaces/Database/Functions/CreateFunction.tsx+++ /dev/null@@ -1,605 +0,0 @@-import { zodResolver } from '@hookform/resolvers/zod'-import { PostgresFunction } from '@supabase/postgres-meta'-import { isEmpty, isNull, keyBy, mapValues, partition } from 'lodash'-import { useEffect, useState } from 'react'-import { SubmitHandler, useFieldArray, useForm } from 'react-hook-form'-import toast from 'react-hot-toast'-import z from 'zod'-import { Plus, Trash } from 'lucide-react'--import { POSTGRES_DATA_TYPES } from 'components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants'-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'-import SchemaSelector from 'components/ui/SchemaSelector'-import SqlEditor from 'components/ui/SqlEditor'-import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'-import { useDatabaseFunctionCreateMutation } from 'data/database-functions/database-functions-create-mutation'-import { useDatabaseFunctionUpdateMutation } from 'data/database-functions/database-functions-update-mutation'-import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'-import { FormSchema } from 'types'-import {- Button,- FormControl_Shadcn_,- FormDescription_Shadcn_,- FormField_Shadcn_,- FormItem_Shadcn_,- FormLabel_Shadcn_,- FormMessage_Shadcn_,- Form_Shadcn_,- Input_Shadcn_,- Modal,- Radio,- ScrollArea,- SelectContent_Shadcn_,- SelectItem_Shadcn_,- SelectTrigger_Shadcn_,- SelectValue_Shadcn_,- Select_Shadcn_,- SidePanel,- Toggle,-} from 'ui'-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'-import { convertArgumentTypes, convertConfigParams } from './Functions.utils'--const FORM_ID = 'create-function-sidepanel'--interface CreateFunctionProps {- func?: PostgresFunction- visible: boolean- setVisible: (value: boolean) => void-}--const FormSchema = z.object({- name: z.string().trim().min(1),- schema: z.string().trim().min(1),- args: z.array(z.object({ name: z.string().trim().min(1), type: z.string().trim() })),- behavior: z.enum(['IMMUTABLE', 'STABLE', 'VOLATILE']),- definition: z.string().trim(),- language: z.string().trim(),- return_type: z.string().trim(),- security_definer: z.boolean(),- config_params: z- .array(z.object({ name: z.string().trim().min(1), value: z.string().trim().min(1) }))- .optional(),-})--const CreateFunction = ({ func, visible, setVisible }: CreateFunctionProps) => {- const { project } = useProjectContext()- const [isClosingPanel, setIsClosingPanel] = useState(false)- const [advancedSettingsShown, setAdvancedSettingsShown] = useState(false)-- const isEditing = !!func?.id-- const form = useForm<z.infer<typeof FormSchema>>({- resolver: zodResolver(FormSchema),- })-- const { mutate: createDatabaseFunction, isLoading: isCreating } =- useDatabaseFunctionCreateMutation()- const { mutate: updateDatabaseFunction, isLoading: isUpdating } =- useDatabaseFunctionUpdateMutation()-- function isClosingSidePanel() {- form.formState.isDirty ? setIsClosingPanel(true) : setVisible(!visible)- }-- const onSubmit: SubmitHandler<z.infer<typeof FormSchema>> = async (data) => {- if (!project) return console.error('Project is required')- const payload = {- ...data,- args: data.args.map((x) => `${x.name} ${x.type}`),- config_params: mapValues(keyBy(data.config_params, 'name'), 'value') as Record<string, never>,- }-- if (isEditing) {- updateDatabaseFunction(- {- id: func.id,- projectRef: project.ref,- connectionString: project.connectionString,- payload,- },- {- onSuccess: () => {- toast.success(`Successfully updated function ${data.name}`)- setVisible(!visible)- },- }- )- } else {- createDatabaseFunction(- {- projectRef: project.ref,- connectionString: project.connectionString,- payload,- },- {- onSuccess: () => {- toast.success(`Successfully created function ${data.name}`)- setVisible(!visible)- },- }- )- }- }-- useEffect(() => {- if (visible) {- form.reset({- name: func?.name ?? '',- schema: func?.schema ?? 'public',- args: convertArgumentTypes(func?.argument_types || '').value,- behavior: func?.behavior ?? 'VOLATILE',- definition: func?.definition ?? '',- language: func?.language ?? 'plpgsql',- return_type: func?.return_type ?? 'void',- security_definer: func?.security_definer ?? false,- config_params: convertConfigParams(func?.config_params).value,- })- }- }, [visible, func])-- return (- <SidePanel- size="large"- visible={visible}- header={isEditing ? `Edit '${func.name}' function` : 'Add a new function'}- className="mr-0 transform transition-all duration-300 ease-in-out"- onCancel={() => isClosingSidePanel()}- customFooter={- <div className="flex justify-end gap-2 p-4 bg-overlay border-t border-overlay">- <Button disabled={isCreating || isUpdating} type="default" onClick={isClosingSidePanel}>- Cancel- </Button>-- <Button- form={FORM_ID}- htmlType="submit"- disabled={isCreating || isUpdating}- loading={isCreating || isUpdating}- >- Confirm- </Button>- </div>- }- >- <Form_Shadcn_ {...form}>- <form id={FORM_ID} className="space-y-6 mt-4" onSubmit={form.handleSubmit(onSubmit)}>- <SidePanel.Content>- <FormField_Shadcn_- control={form.control}- name="name"- render={({ field }) => (- <FormItemLayout- label="Name of function"- description="Name will also be used for the function name in postgres"- layout="horizontal"- >- <FormControl_Shadcn_>- <Input_Shadcn_ {...field} />- </FormControl_Shadcn_>- </FormItemLayout>- )}- />- </SidePanel.Content>- <SidePanel.Separator />- <SidePanel.Content className="space-y-4">- <FormField_Shadcn_- control={form.control}- name="schema"- render={({ field }) => (- <FormItemLayout- label="Schema"- description="Tables made in the table editor will be in 'public'"- layout="horizontal"- >- <FormControl_Shadcn_>- <SchemaSelector- selectedSchemaName={field.value}- excludedSchemas={EXCLUDED_SCHEMAS}- size="small"- onSelectSchema={(name) => field.onChange(name)}- />- </FormControl_Shadcn_>- </FormItemLayout>- )}- />- {!isEditing && (- <FormField_Shadcn_- control={form.control}- name="return_type"- render={({ field }) => (- <FormItemLayout label="Return type" layout="horizontal">- {/* Form selects don't need form controls, otherwise the CSS gets weird */}- <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>- <SelectTrigger_Shadcn_ className="col-span-8">- <SelectValue_Shadcn_ />- </SelectTrigger_Shadcn_>- <SelectContent_Shadcn_>- {['void', 'record', 'trigger', 'integer', ...POSTGRES_DATA_TYPES].map(- (option) => (- <SelectItem_Shadcn_ value={option} key={option}>- {option}- </SelectItem_Shadcn_>- )- )}- </SelectContent_Shadcn_>- </Select_Shadcn_>- </FormItemLayout>- )}- />- )}- </SidePanel.Content>- <SidePanel.Separator />- <SidePanel.Content>- <FormFieldArgs readonly={isEditing} />- </SidePanel.Content>- <SidePanel.Separator />- <SidePanel.Content>- <FormField_Shadcn_- control={form.control}- name="definition"- render={({ field }) => (- <FormItem_Shadcn_ className="space-y-4">- <div>- <FormLabel_Shadcn_ className="text-base text-foreground">- Definition- </FormLabel_Shadcn_>- <FormDescription_Shadcn_ className="text-sm text-foreground-light">- <p>The language below should be written in `plpgsql`.</p>- {!isEditing && <p>Change the language in the advanced settings below.</p>}- </FormDescription_Shadcn_>- </div>-- <div className="h-60 resize-y border border-default">- <FormControl_Shadcn_>- <SqlEditor- defaultValue={field.value}- onInputChange={(value: string | undefined) => {- field.onChange(value)- }}- contextmenu={false}- />- </FormControl_Shadcn_>- </div>-- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />- </SidePanel.Content>- <SidePanel.Separator />- {isEditing ? null : (- <>- <SidePanel.Content className="!m-0 py-6">- <div className="space-y-8 rounded bg-studio py-4 px-6 border border-overlay">- <Toggle- onChange={() => setAdvancedSettingsShown(!advancedSettingsShown)}- label="Show advanced settings"- checked={advancedSettingsShown}- labelOptional="These are settings that might be familiar for Postgres developers"- />- </div>- </SidePanel.Content>- {advancedSettingsShown && (- <>- <SidePanel.Content className="!m-0">- <div className="space-y-2">- <FormFieldLanguage />- <FormField_Shadcn_- control={form.control}- name="behavior"- render={({ field }) => (- <FormItemLayout label="Behavior" layout="horizontal">- <Select_Shadcn_- defaultValue={field.value}- onValueChange={field.onChange}- >- <SelectTrigger_Shadcn_ className="col-span-8">- <SelectValue_Shadcn_ />- </SelectTrigger_Shadcn_>- <SelectContent_Shadcn_>- <SelectItem_Shadcn_ value="IMMUTABLE" key="IMMUTABLE">- immutable- </SelectItem_Shadcn_>- <SelectItem_Shadcn_ value="STABLE" key="STABLE">- stable- </SelectItem_Shadcn_>- <SelectItem_Shadcn_ value="VOLATILE" key="VOLATILE">- volatile- </SelectItem_Shadcn_>- </SelectContent_Shadcn_>- </Select_Shadcn_>- </FormItemLayout>- )}- />- </div>- </SidePanel.Content>- <SidePanel.Separator />- <SidePanel.Content>- <FormFieldConfigParams readonly={isEditing} />- </SidePanel.Content>- <SidePanel.Separator />- <SidePanel.Content className="!m-0 py-6">- <div className="space-y-4">- <h5 className="text-base text-foreground">Type of security</h5>- <FormField_Shadcn_- control={form.control}- name="security_definer"- render={({ field }) => (- <FormItem_Shadcn_>- <FormControl_Shadcn_ className="col-span-8">- {/* TODO: This RadioGroup imports Formik state, replace it with a clean component */}- <Radio.Group- type="cards"- layout="vertical"- onChange={(event) =>- field.onChange(event.target.value == 'SECURITY_DEFINER')- }- value={field.value ? 'SECURITY_DEFINER' : 'SECURITY_INVOKER'}- >- <Radio- id="SECURITY_INVOKER"- label="SECURITY INVOKER"- value="SECURITY_INVOKER"- checked={!field.value}- description={- <>- Function is to be executed with the privileges of the user- that <span className="text-foreground">calls it</span>.- </>- }- />- <Radio- id="SECURITY_DEFINER"- label="SECURITY DEFINER"- value="SECURITY_DEFINER"- checked={field.value}- description={- <>- Function is to be executed with the privileges of the user- that <span className="text-foreground">created it</span>.- </>- }- />- </Radio.Group>- </FormControl_Shadcn_>- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />- </div>- </SidePanel.Content>- </>- )}- </>- )}- </form>- </Form_Shadcn_>-- <ConfirmationModal- visible={isClosingPanel}- header="Discard changes"- buttonLabel="Discard"- onSelectCancel={() => setIsClosingPanel(false)}- onSelectConfirm={() => {- setIsClosingPanel(false)- setVisible(!visible)- }}- >- <Modal.Content>- <p className="py-4 text-sm text-foreground-light">- There are unsaved changes. Are you sure you want to close the panel? Your changes will- be lost.- </p>- </Modal.Content>- </ConfirmationModal>- </SidePanel>- )-}--export default CreateFunction--interface FormFieldConfigParamsProps {- readonly?: boolean-}--const FormFieldArgs = ({ readonly }: FormFieldConfigParamsProps) => {- const { fields, append, remove } = useFieldArray<z.infer<typeof FormSchema>>({- name: 'args',- })-- return (- <>- <div className="flex flex-col">- <h5 className="text-base text-foreground">Arguments</h5>- <p className="text-sm text-foreground-light">- Arguments can be referenced in the function body using either names or numbers.- </p>- </div>- <div className="space-y-2 pt-4">- {readonly && isEmpty(fields) && (- <span className="text-foreground-lighter">No argument for this function</span>- )}- {fields.map((field, index) => {- return (- <div className="flex flex-row space-x-1" key={field.id}>- <FormField_Shadcn_- name={`args.${index}.name`}- render={({ field }) => (- <FormItem_Shadcn_ className="flex-1">- <FormControl_Shadcn_>- <Input_Shadcn_ {...field} disabled={readonly} placeholder="argument_name" />- </FormControl_Shadcn_>- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />- <FormField_Shadcn_- name={`args.${index}.type`}- render={({ field }) => (- <FormItem_Shadcn_ className="flex-1">- <FormControl_Shadcn_>- {readonly ? (- <Input_Shadcn_ value={field.value} disabled readOnly className="h-auto" />- ) : (- <Select_Shadcn_- disabled={readonly}- onValueChange={field.onChange}- defaultValue={field.value}- >- <SelectTrigger_Shadcn_ className="h-[38px]">- <SelectValue_Shadcn_ />- </SelectTrigger_Shadcn_>- <SelectContent_Shadcn_>- <ScrollArea className="h-52">- {['integer', ...POSTGRES_DATA_TYPES].map((option) => (- <SelectItem_Shadcn_ value={option} key={option}>- {option}- </SelectItem_Shadcn_>- ))}- </ScrollArea>- </SelectContent_Shadcn_>- </Select_Shadcn_>- )}- </FormControl_Shadcn_>- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />-- {!readonly && (- <Button- type="danger"- icon={<Trash size={12} />}- onClick={() => remove(index)}- size="small"- className="h-[38px]"- />- )}- </div>- )- })}-- {!readonly && (- <Button- type="default"- icon={<Plus size={12} />}- onClick={() => append({ name: '', type: 'integer' })}- disabled={readonly}- >- Add a new argument- </Button>- )}- </div>- </>- )-}--interface FormFieldConfigParamsProps {- readonly?: boolean-}--const FormFieldConfigParams = ({ readonly }: FormFieldConfigParamsProps) => {- const { fields, append, remove } = useFieldArray<z.infer<typeof FormSchema>>({- name: 'config_params',- })-- return (- <>- <h5 className="text-base text-foreground">Configuration parameters</h5>- <div className="space-y-2 pt-4">- {readonly && isEmpty(fields) && (- <span className="text-foreground-lighter">No argument for this function</span>- )}- {fields.map((field, index) => {- return (- <div className="flex flex-row space-x-1" key={field.id}>- <FormField_Shadcn_- name={`config_params.${index}.name`}- render={({ field }) => (- <FormItem_Shadcn_ className="flex-1">- <FormControl_Shadcn_>- <Input_Shadcn_ {...field} placeholder="parameter_name" />- </FormControl_Shadcn_>- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />- <FormField_Shadcn_- name={`config_params.${index}.value`}- render={({ field }) => (- <FormItem_Shadcn_ className="flex-1">- <FormControl_Shadcn_>- <Input_Shadcn_ {...field} placeholder="parameter_value" />- </FormControl_Shadcn_>- <FormMessage_Shadcn_ />- </FormItem_Shadcn_>- )}- />-- {!readonly && (- <Button- type="danger"- icon={<Trash size={12} />}- onClick={() => remove(index)}- size="small"- className="h-[38px]"- />- )}- </div>- )- })}-- {!readonly && (- <Button- type="default"- icon={<Plus size={12} />}- onClick={() => append({ name: '', type: '' })}- disabled={readonly}- >- Add a new config- </Button>- )}- </div>- </>- )-}--const FormFieldLanguage = () => {- const { project } = useProjectContext()-- const { data } = useDatabaseExtensionsQuery({- projectRef: project?.ref,- connectionString: project?.connectionString,- })-- const [enabledExtensions] = partition(data ?? [], (ext) => !isNull(ext.installed_version))-- return (- <FormField_Shadcn_- name="language"- render={({ field }) => (- <FormItemLayout label="Language" layout="horizontal">- {/* Form selects don't need form controls, otherwise the CSS gets weird */}- <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>- <SelectTrigger_Shadcn_ className="col-span-8">- <SelectValue_Shadcn_ />- </SelectTrigger_Shadcn_>- <SelectContent_Shadcn_>- {enabledExtensions- .filter((ex) => {- return ex.name.startsWith('pl')- })- .map((option) => (- <SelectItem_Shadcn_ value={option.name} key={option.name}>- {option.name}- </SelectItem_Shadcn_>- ))}- </SelectContent_Shadcn_>- </Select_Shadcn_>- </FormItemLayout>- )}- />- )-}diff --git a/apps/studio/components/interfaces/Database/Functions/CreateFunction/CreateFunctionHeader.tsx b/apps/studio/components/interfaces/Database/Functions/CreateFunction/CreateFunctionHeader.tsxnew file mode 100644index 00000000000..bf8eb775cfc--- /dev/null+++ b/apps/studio/components/interfaces/Database/Functions/CreateFunction/CreateFunctionHeader.tsx@@ -0,0 +1,64 @@+import { X } from 'lucide-react'++import { SheetClose, SheetHeader, SheetTitle, cn } from 'ui'++export const CreateFunctionHeader = ({+ selectedFunction,+ assistantVisible,+ setAssistantVisible,+}: {+ selectedFunction?: string+ assistantVisible: boolean+ setAssistantVisible: (v: boolean) => void+}) => {+ return (+ <SheetHeader+ className={cn(+ selectedFunction !== undefined ? 'pt-3 pb-0' : 'py-3',+ 'flex flex-row justify-between items-center border-b-0'+ )}+ >+ <div className="flex flex-row gap-3 items-center max-w-[75%]">+ <SheetClose+ className={cn(+ 'text-muted hover:text ring-offset-background transition-opacity hover:opacity-100',+ 'focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',+ 'disabled:pointer-events-none data-[state=open]:bg-secondary',+ 'transition'+ )}+ >+ <X className="h-3 w-3" />+ <span className="sr-only">Close</span>+ </SheetClose>+ <SheetTitle className="truncate">+ {selectedFunction !== undefined+ ? `Edit '${selectedFunction}' function`+ : 'Add a new function'}+ </SheetTitle>+ </div>+ {/* <Tooltip_Shadcn_>+ <TooltipTrigger_Shadcn_ asChild>+ <button+ aria-expanded={assistantVisible}+ aria-controls="ai-chat-assistant"+ className={cn(+ !assistantVisible ? 'text-foreground-lighter' : 'text-light',+ 'hover:text-foreground',+ 'transition'+ )}+ onClick={() => setAssistantVisible(!assistantVisible)}+ >+ {!assistantVisible ? (+ <PanelLeftClose size={19} strokeWidth={1} />+ ) : (+ <PanelRightClose size={19} strokeWidth={1} />+ )}+ </button>+ </TooltipTrigger_Shadcn_>+ <TooltipContent_Shadcn_ side="left">+ {assistantVisible ? 'Hide' : 'Show'} tools+ </TooltipContent_Shadcn_>+ </Tooltip_Shadcn_> */}+ </SheetHeader>+ )+}diff --git a/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.tsx b/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.tsxnew file mode 100644index 00000000000..8742807280e--- /dev/null+++ b/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.tsx@@ -0,0 +1,59 @@+import { Maximize2, Minimize2 } from 'lucide-react'++import SqlEditor from 'components/ui/SqlEditor'+import {+ Button,+ FormControl_Shadcn_,+ TooltipContent_Shadcn_,+ TooltipTrigger_Shadcn_,+ Tooltip_Shadcn_,+ cn,+} from 'ui'++export const FunctionEditor = ({+ field,+ focused,+ setFocused,+}: {+ field: any+ focused: boolean+ setFocused: (b: boolean) => void+}) => {+ return (+ <div className={cn('rounded-md relative group flex-grow')}>+ <FormControl_Shadcn_>+ <SqlEditor+ defaultValue={field.value}+ onInputChange={(value: string | undefined) => {+ field.onChange(value)+ }}+ contextmenu={false}+ />+ </FormControl_Shadcn_>+ <div+ className={cn(+ 'absolute top-0 right-2 bg-surface-300 border border-strong rounded h-[28px]',+ 'opacity-0 group-hover:opacity-100 group-hover:top-2 transition-all'+ )}+ >+ <Tooltip_Shadcn_>+ <TooltipTrigger_Shadcn_ asChild>+ <Button+ type="text"+ size="tiny"+ className={cn(+ 'px-2 text-foreground-lighter hover:text-foreground',+ 'transition z-50'+ )}+ onClick={() => setFocused(!focused)}+ icon={focused ? <Minimize2 /> : <Maximize2 />}+ ></Button>+ </TooltipTrigger_Shadcn_>+ <TooltipContent_Shadcn_ side="bottom">+ {focused ? 'Minimize editor' : 'Maximize editor'}+ </TooltipContent_Shadcn_>+ </Tooltip_Shadcn_>+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Database/Functions/CreateFunction/index.tsx b/apps/studio/components/interfaces/Database/Functions/CreateFunction/index.tsxnew file mode 100644index 00000000000..02e0b08dbb2--- /dev/null+++ b/apps/studio/components/interfaces/Database/Functions/CreateFunction/index.tsx@@ -0,0 +1,632 @@+import { zodResolver } from '@hookform/resolvers/zod'+import { PostgresFunction } from '@supabase/postgres-meta'+import { isEmpty, isNull, keyBy, mapValues, partition } from 'lodash'+import { useEffect, useState } from 'react'+import { SubmitHandler, useFieldArray, useForm } from 'react-hook-form'+import toast from 'react-hot-toast'+import z from 'zod'+import { Plus, Trash } from 'lucide-react'++import { POSTGRES_DATA_TYPES } from 'components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.constants'+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'+import SchemaSelector from 'components/ui/SchemaSelector'+import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'+import { useDatabaseFunctionCreateMutation } from 'data/database-functions/database-functions-create-mutation'+import { useDatabaseFunctionUpdateMutation } from 'data/database-functions/database-functions-update-mutation'+import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'+import { FormSchema } from 'types'+import {+ Button,+ FormControl_Shadcn_,+ FormDescription_Shadcn_,+ FormField_Shadcn_,+ FormItem_Shadcn_,+ FormLabel_Shadcn_,+ FormMessage_Shadcn_,+ Form_Shadcn_,+ Input_Shadcn_,+ Modal,+ Radio,+ SelectContent_Shadcn_,+ SelectItem_Shadcn_,+ SelectTrigger_Shadcn_,+ SelectValue_Shadcn_,+ Select_Shadcn_,+ Separator,+ Sheet,+ ScrollArea,+ SheetContent,+ SheetFooter,+ SheetSection,+ Toggle,+ cn,+} from 'ui'+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'+import { convertArgumentTypes, convertConfigParams } from '../Functions.utils'+import { CreateFunctionHeader } from './CreateFunctionHeader'+import { FunctionEditor } from './FunctionEditor'++const FORM_ID = 'create-function-sidepanel'++interface CreateFunctionProps {+ func?: PostgresFunction+ visible: boolean+ setVisible: (value: boolean) => void+}++const FormSchema = z.object({+ name: z.string().trim().min(1),+ schema: z.string().trim().min(1),+ args: z.array(z.object({ name: z.string().trim().min(1), type: z.string().trim() })),+ behavior: z.enum(['IMMUTABLE', 'STABLE', 'VOLATILE']),+ definition: z.string().trim(),+ language: z.string().trim(),+ return_type: z.string().trim(),+ security_definer: z.boolean(),+ config_params: z+ .array(z.object({ name: z.string().trim().min(1), value: z.string().trim().min(1) }))+ .optional(),+})++const CreateFunction = ({ func, visible, setVisible }: CreateFunctionProps) => {+ const { project } = useProjectContext()+ const [isClosingPanel, setIsClosingPanel] = useState(false)+ const [advancedSettingsShown, setAdvancedSettingsShown] = useState(false)+ // For now, there's no AI assistant for functions+ const [assistantVisible, setAssistantVisible] = useState(false)+ const [focusedEditor, setFocusedEditor] = useState(false)++ const isEditing = !!func?.id++ const form = useForm<z.infer<typeof FormSchema>>({+ resolver: zodResolver(FormSchema),+ })++ const { mutate: createDatabaseFunction, isLoading: isCreating } =+ useDatabaseFunctionCreateMutation()+ const { mutate: updateDatabaseFunction, isLoading: isUpdating } =+ useDatabaseFunctionUpdateMutation()++ function isClosingSidePanel() {+ form.formState.isDirty ? setIsClosingPanel(true) : setVisible(!visible)+ }++ const onSubmit: SubmitHandler<z.infer<typeof FormSchema>> = async (data) => {+ if (!project) return console.error('Project is required')+ const payload = {+ ...data,+ args: data.args.map((x) => `${x.name} ${x.type}`),+ config_params: mapValues(keyBy(data.config_params, 'name'), 'value') as Record<string, never>,+ }++ if (isEditing) {+ updateDatabaseFunction(+ {+ id: func.id,+ projectRef: project.ref,+ connectionString: project.connectionString,+ payload,+ },+ {+ onSuccess: () => {+ toast.success(`Successfully updated function ${data.name}`)+ setVisible(!visible)+ },+ }+ )+ } else {+ createDatabaseFunction(+ {+ projectRef: project.ref,+ connectionString: project.connectionString,+ payload,+ },+ {+ onSuccess: () => {+ toast.success(`Successfully created function ${data.name}`)+ setVisible(!visible)+ },+ }+ )+ }+ }++ useEffect(() => {+ if (visible) {+ form.reset({+ name: func?.name ?? '',+ schema: func?.schema ?? 'public',+ args: convertArgumentTypes(func?.argument_types || '').value,+ behavior: func?.behavior ?? 'VOLATILE',+ definition: func?.definition ?? '',+ language: func?.language ?? 'plpgsql',+ return_type: func?.return_type ?? 'void',+ security_definer: func?.security_definer ?? false,+ config_params: convertConfigParams(func?.config_params).value,+ })+ }+ }, [visible, func])++ return (+ <Sheet open={visible} onOpenChange={() => isClosingSidePanel()}>+ <SheetContent+ showClose={false}+ size={assistantVisible ? 'lg' : 'default'}+ className={cn(+ // 'bg-surface-200',+ 'p-0 flex flex-row gap-0',+ assistantVisible ? '!min-w-[1200px]' : '!min-w-[600px]'+ )}+ >+ <div className={cn('flex flex-col grow w-full', assistantVisible && 'w-[60%]')}>+ <CreateFunctionHeader+ selectedFunction={func?.name}+ assistantVisible={assistantVisible}+ setAssistantVisible={setAssistantVisible}+ />+ <Separator />+ <Form_Shadcn_ {...form}>+ <form+ id={FORM_ID}+ className="flex-grow overflow-auto"+ onSubmit={form.handleSubmit(onSubmit)}+ >+ <SheetSection className={focusedEditor ? 'hidden' : ''}>+ <FormField_Shadcn_+ control={form.control}+ name="name"+ render={({ field }) => (+ <FormItemLayout+ label="Name of function"+ description="Name will also be used for the function name in postgres"+ layout="horizontal"+ >+ <FormControl_Shadcn_>+ <Input_Shadcn_ {...field} />+ </FormControl_Shadcn_>+ </FormItemLayout>+ )}+ />+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ <SheetSection className={focusedEditor ? 'hidden' : 'space-y-4'}>+ <FormField_Shadcn_+ control={form.control}+ name="schema"+ render={({ field }) => (+ <FormItemLayout+ label="Schema"+ description="Tables made in the table editor will be in 'public'"+ layout="horizontal"+ >+ <FormControl_Shadcn_>+ <SchemaSelector+ selectedSchemaName={field.value}+ excludedSchemas={EXCLUDED_SCHEMAS}+ size="small"+ onSelectSchema={(name) => field.onChange(name)}+ />+ </FormControl_Shadcn_>+ </FormItemLayout>+ )}+ />+ {!isEditing && (+ <FormField_Shadcn_+ control={form.control}+ name="return_type"+ render={({ field }) => (+ <FormItemLayout label="Return type" layout="horizontal">+ {/* Form selects don't need form controls, otherwise the CSS gets weird */}+ <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>+ <SelectTrigger_Shadcn_ className="col-span-8">+ <SelectValue_Shadcn_ />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ <ScrollArea className="h-52">+ {['void', 'record', 'trigger', 'integer', ...POSTGRES_DATA_TYPES].map(+ (option) => (+ <SelectItem_Shadcn_ value={option} key={option}>+ {option}+ </SelectItem_Shadcn_>+ )+ )}+ </ScrollArea>+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </FormItemLayout>+ )}+ />+ )}+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ <SheetSection className={focusedEditor ? 'hidden' : ''}>+ <FormFieldArgs readonly={isEditing} />+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ <SheetSection className={`${focusedEditor ? 'h-full' : ''} !px-0`}>+ <FormField_Shadcn_+ control={form.control}+ name="definition"+ render={({ field }) => (+ <FormItem_Shadcn_ className="space-y-4 flex flex-col h-full">+ <div className="px-content">+ <FormLabel_Shadcn_ className="text-base text-foreground">+ Definition+ </FormLabel_Shadcn_>+ <FormDescription_Shadcn_ className="text-sm text-foreground-light">+ <p>The language below should be written in `plpgsql`.</p>+ {!isEditing && <p>Change the language in the Advanced Settings below.</p>}+ </FormDescription_Shadcn_>+ </div>+ <div+ className={cn(+ 'border border-default flex',+ focusedEditor ? 'flex-grow ' : 'h-72'+ )}+ >+ <FunctionEditor+ field={field}+ focused={focusedEditor}+ setFocused={setFocusedEditor}+ />+ </div>++ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ {isEditing ? (+ <></>+ ) : (+ <>+ <SheetSection className={focusedEditor ? 'hidden' : ''}>+ <div className="space-y-8 rounded bg-studio py-4 px-6 border border-overlay">+ <Toggle+ onChange={() => setAdvancedSettingsShown(!advancedSettingsShown)}+ label="Show advanced settings"+ checked={advancedSettingsShown}+ labelOptional="These are settings that might be familiar for Postgres developers"+ />+ </div>+ </SheetSection>+ {advancedSettingsShown && (+ <>+ <SheetSection className={focusedEditor ? 'hidden' : 'space-y-2 pt-0'}>+ <FormFieldLanguage />+ <FormField_Shadcn_+ control={form.control}+ name="behavior"+ render={({ field }) => (+ <FormItemLayout label="Behavior" layout="horizontal">+ {/* Form selects don't need form controls, otherwise the CSS gets weird */}+ <Select_Shadcn_+ defaultValue={field.value}+ onValueChange={field.onChange}+ >+ <SelectTrigger_Shadcn_ className="col-span-8">+ <SelectValue_Shadcn_ />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ <SelectItem_Shadcn_ value="IMMUTABLE" key="IMMUTABLE">+ immutable+ </SelectItem_Shadcn_>+ <SelectItem_Shadcn_ value="STABLE" key="STABLE">+ stable+ </SelectItem_Shadcn_>+ <SelectItem_Shadcn_ value="VOLATILE" key="VOLATILE">+ volatile+ </SelectItem_Shadcn_>+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </FormItemLayout>+ )}+ />+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ <SheetSection className={focusedEditor ? 'hidden' : ''}>+ <FormFieldConfigParams readonly={isEditing} />+ </SheetSection>+ <Separator className={focusedEditor ? 'hidden' : ''} />+ <SheetSection className={focusedEditor ? 'hidden' : ''}>+ <h5 className="text-base text-foreground mb-4">Type of Security</h5>+ <FormField_Shadcn_+ control={form.control}+ name="security_definer"+ render={({ field }) => (+ <FormItem_Shadcn_>+ <FormControl_Shadcn_ className="col-span-8">+ {/* TODO: This RadioGroup imports Formik state, replace it with a clean component */}+ <Radio.Group+ type="cards"+ layout="vertical"+ onChange={(event) =>+ field.onChange(event.target.value == 'SECURITY_DEFINER')+ }+ value={field.value ? 'SECURITY_DEFINER' : 'SECURITY_INVOKER'}+ >+ <Radio+ id="SECURITY_INVOKER"+ label="SECURITY INVOKER"+ value="SECURITY_INVOKER"+ checked={!field.value}+ description={+ <>+ Function is to be executed with the privileges of the user+ that <span className="text-foreground">calls it</span>.+ </>+ }+ />+ <Radio+ id="SECURITY_DEFINER"+ label="SECURITY DEFINER"+ value="SECURITY_DEFINER"+ checked={field.value}+ description={+ <>+ Function is to be executed with the privileges of the user+ that <span className="text-foreground">created it</span>.+ </>+ }+ />+ </Radio.Group>+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />+ </SheetSection>+ </>+ )}+ </>+ )}+ </form>+ </Form_Shadcn_>+ <SheetFooter>+ <Button disabled={isCreating || isUpdating} type="default" onClick={isClosingSidePanel}>+ Cancel+ </Button>+ <Button+ form={FORM_ID}+ htmlType="submit"+ disabled={isCreating || isUpdating}+ loading={isCreating || isUpdating}+ >+ Confirm+ </Button>+ </SheetFooter>+ </div>+ {assistantVisible ? (+ <div className="border-l shadow-[rgba(0,0,0,0.13)_-4px_0px_6px_0px] z-10 w-[50%] bg-studio">+ {/* This is where the AI assistant would be added */}+ </div>+ ) : null}+ <ConfirmationModal+ visible={isClosingPanel}+ header="Discard changes"+ buttonLabel="Discard"+ onSelectCancel={() => setIsClosingPanel(false)}+ onSelectConfirm={() => {+ setIsClosingPanel(false)+ setVisible(!visible)+ }}+ >+ <Modal.Content>+ <p className="py-4 text-sm text-foreground-light">+ There are unsaved changes. Are you sure you want to close the panel? Your changes will+ be lost.+ </p>+ </Modal.Content>+ </ConfirmationModal>+ </SheetContent>+ </Sheet>+ )+}++export default CreateFunction++interface FormFieldConfigParamsProps {+ readonly?: boolean+}++const FormFieldArgs = ({ readonly }: FormFieldConfigParamsProps) => {+ const { fields, append, remove } = useFieldArray<z.infer<typeof FormSchema>>({+ name: 'args',+ })++ return (+ <>+ <div className="flex flex-col">+ <h5 className="text-base text-foreground">Arguments</h5>+ <p className="text-sm text-foreground-light">+ Arguments can be referenced in the function body using either names or numbers.+ </p>+ </div>+ <div className="space-y-2 pt-4">+ {readonly && isEmpty(fields) && (+ <span className="text-foreground-lighter">No argument for this function</span>+ )}+ {fields.map((field, index) => {+ return (+ <div className="flex flex-row space-x-1" key={field.id}>+ <FormField_Shadcn_+ name={`args.${index}.name`}+ render={({ field }) => (+ <FormItem_Shadcn_ className="flex-1">+ <FormControl_Shadcn_>+ <Input_Shadcn_ {...field} disabled={readonly} placeholder="argument_name" />+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />+ <FormField_Shadcn_+ name={`args.${index}.type`}+ render={({ field }) => (+ <FormItem_Shadcn_ className="flex-1">+ <FormControl_Shadcn_>+ {readonly ? (+ <Input_Shadcn_ value={field.value} disabled readOnly className="h-auto" />+ ) : (+ <>+ <Select_Shadcn_+ disabled={readonly}+ onValueChange={field.onChange}+ defaultValue={field.value}+ >+ <SelectTrigger_Shadcn_ className="h-[38px]">+ <SelectValue_Shadcn_ />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ <ScrollArea className="h-52">+ {['integer', ...POSTGRES_DATA_TYPES].map((option) => (+ <SelectItem_Shadcn_ value={option} key={option}>+ {option}+ </SelectItem_Shadcn_>+ ))}+ </ScrollArea>+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </>+ )}+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />++ {!readonly && (+ <Button+ type="danger"+ icon={<Trash size={12} />}+ onClick={() => remove(index)}+ className="h-[38px] w-[38px]"+ />+ )}+ </div>+ )+ })}++ {!readonly && (+ <Button+ type="default"+ icon={<Plus size={12} />}+ onClick={() => append({ name: '', type: 'integer' })}+ disabled={readonly}+ >+ Add a new argument+ </Button>+ )}+ </div>+ </>+ )+}++interface FormFieldConfigParamsProps {+ readonly?: boolean+}++const FormFieldConfigParams = ({ readonly }: FormFieldConfigParamsProps) => {+ const { fields, append, remove } = useFieldArray<z.infer<typeof FormSchema>>({+ name: 'config_params',+ })++ return (+ <>+ <h5 className="text-base text-foreground">Configuration Parameters</h5>+ <div className="space-y-2 pt-4">+ {readonly && isEmpty(fields) && (+ <span className="text-foreground-lighter">No argument for this function</span>+ )}+ {fields.map((field, index) => {+ return (+ <div className="flex flex-row space-x-1" key={field.id}>+ <FormField_Shadcn_+ name={`config_params.${index}.name`}+ render={({ field }) => (+ <FormItem_Shadcn_ className="flex-1">+ <FormControl_Shadcn_>+ <Input_Shadcn_ {...field} placeholder="parameter_name" />+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />+ <FormField_Shadcn_+ name={`config_params.${index}.value`}+ render={({ field }) => (+ <FormItem_Shadcn_ className="flex-1">+ <FormControl_Shadcn_>+ <Input_Shadcn_ {...field} placeholder="parameter_value" />+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ </FormItem_Shadcn_>+ )}+ />++ {!readonly && (+ <Button+ type="danger"+ icon={<Trash size={12} />}+ onClick={() => remove(index)}+ className="h-[38px] w-[38px]"+ />+ )}+ </div>+ )+ })}++ {!readonly && (+ <Button+ type="default"+ icon={<Plus size={12} />}+ onClick={() => append({ name: '', type: '' })}+ disabled={readonly}+ >+ Add a new config+ </Button>+ )}+ </div>+ </>+ )+}++const FormFieldLanguage = () => {+ const { project } = useProjectContext()++ const { data } = useDatabaseExtensionsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })++ const [enabledExtensions] = partition(data ?? [], (ext) => !isNull(ext.installed_version))++ return (+ <FormField_Shadcn_+ name="language"+ render={({ field }) => (+ <FormItemLayout label="Language" layout="horizontal">+ {/* Form selects don't need form controls, otherwise the CSS gets weird */}+ <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>+ <SelectTrigger_Shadcn_ className="col-span-8">+ <SelectValue_Shadcn_ />+ </SelectTrigger_Shadcn_>+ <SelectContent_Shadcn_>+ {enabledExtensions+ .filter((ex) => {+ return ex.name.startsWith('pl')+ })+ .map((option) => (+ <SelectItem_Shadcn_ value={option.name} key={option.name}>+ {option.name}+ </SelectItem_Shadcn_>+ ))}+ </SelectContent_Shadcn_>+ </Select_Shadcn_>+ </FormItemLayout>+ )}+ />+ )+}diff --git a/apps/studio/components/ui/SchemaSelector.tsx b/apps/studio/components/ui/SchemaSelector.tsxindex 49ae9392028..4c03ee83959 100644--- a/apps/studio/components/ui/SchemaSelector.tsx+++ b/apps/studio/components/ui/SchemaSelector.tsx@@ -106,7 +106,7 @@ const SchemaSelector = ({</div></Button></PopoverTrigger_Shadcn_>- <PopoverContent_Shadcn_ className="p-0 popover-trigger-width" side="bottom" align="start">+ <PopoverContent_Shadcn_ className="p-0" side="bottom" align="start"><Command_Shadcn_><CommandInput_Shadcn_ placeholder="Find schema..." /><CommandList_Shadcn_>diff --git a/apps/studio/styles/ui.scss b/apps/studio/styles/ui.scssindex cc1890276ca..b2e37296cc0 100644--- a/apps/studio/styles/ui.scss+++ b/apps/studio/styles/ui.scss@@ -442,7 +442,3 @@}}-// Used on radix popover contents so that the width matches the trigger-.popover-trigger-width {- width: var(--radix-popover-trigger-width);-}diff --git a/packages/ui/src/components/shadcn/ui/popover.module.css b/packages/ui/src/components/shadcn/ui/popover.module.cssnew file mode 100644index 00000000000..aca2f5f45c4--- /dev/null+++ b/packages/ui/src/components/shadcn/ui/popover.module.css@@ -0,0 +1,3 @@+.popover-trigger-width {+ width: var(--radix-popover-trigger-width);+}diff --git a/packages/ui/src/components/shadcn/ui/popover.tsx b/packages/ui/src/components/shadcn/ui/popover.tsxindex 2208cb77505..e4b5e9a589e 100644--- a/packages/ui/src/components/shadcn/ui/popover.tsx+++ b/packages/ui/src/components/shadcn/ui/popover.tsx@@ -2,6 +2,7 @@ import * as PopoverPrimitive from '@radix-ui/react-popover'import * as React from 'react'import { cn } from '../../../lib/utils/cn'+import styles from './popover.module.css'const Popover = PopoverPrimitive.Root@@ -11,28 +12,42 @@ type PopoverContentProps = {portal?: booleanalign?: 'center' | 'start' | 'end'sideOffset?: number+ sameWidthAsTrigger?: boolean} & React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>const PopoverContent = React.forwardRef<React.ElementRef<typeof PopoverPrimitive.Content>,PopoverContentProps->(({ className, align = 'center', sideOffset = 4, portal = false, ...props }, ref) => {- const Portal = portal ? PopoverPrimitive.Portal : React.Fragment- return (- <Portal>- <PopoverPrimitive.Content- ref={ref}- align={align}- sideOffset={sideOffset}- className={cn(- 'z-50 w-72 rounded-md border border-overlay bg-overlay p-4 text-popover-foreground shadow-md outline-none animate-in data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',- className- )}- {...props}- />- </Portal>- )-})+>(+ (+ {+ className,+ align = 'center',+ sideOffset = 4,+ portal = false,+ sameWidthAsTrigger = true,+ ...props+ },+ ref+ ) => {+ const Portal = portal ? PopoverPrimitive.Portal : React.Fragment+ return (+ <Portal>+ <PopoverPrimitive.Content+ ref={ref}+ align={align}+ sideOffset={sideOffset}+ className={cn(+ sameWidthAsTrigger ? styles['popover-trigger-width'] : '',+ 'z-50 w-72 rounded-md border border-overlay bg-overlay p-4 text-popover-foreground shadow-md outline-none animate-in data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',+ className+ )}+ {...props}+ />+ </Portal>+ )+ }+)PopoverContent.displayName = 'PopoverContent'export { Popover, PopoverContent, PopoverTrigger }diff --git a/packages/ui/src/components/shadcn/ui/sheet.tsx b/packages/ui/src/components/shadcn/ui/sheet.tsxindex 3600c2f60a9..87a84256f4c 100644--- a/packages/ui/src/components/shadcn/ui/sheet.tsx+++ b/packages/ui/src/components/shadcn/ui/sheet.tsx@@ -4,8 +4,8 @@ import * as SheetPrimitive from '@radix-ui/react-dialog'import { cva, type VariantProps } from 'class-variance-authority'import * as React from 'react'-import { cn } from '../../../lib/utils/cn'import { X } from 'lucide-react'+import { cn } from '../../../lib/utils/cn'const Sheet = SheetPrimitive.Root@@ -144,12 +144,14 @@ const sheetVariants = cva('fixed z-40 scale-100 gap-4 bg-studio opacity-100 shadexport interface DialogContentPropsextends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,- VariantProps<typeof sheetVariants> {}+ VariantProps<typeof sheetVariants> {+ showClose?: boolean+}const SheetContent = React.forwardRef<React.ElementRef<typeof SheetPrimitive.Content>,DialogContentProps->(({ side, size, className, children, ...props }, ref) => (+>(({ side, size, className, children, showClose = true, ...props }, ref) => (<SheetPortal side={side}><SheetOverlay /><SheetPrimitive.Content@@ -158,10 +160,12 @@ const SheetContent = React.forwardRef<{...props}>{children}- <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">- <X className="h-4 w-4" />- <span className="sr-only">Close</span>- </SheetPrimitive.Close>+ {showClose ? (+ <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">+ <X className="h-4 w-4" />+ <span className="sr-only">Close</span>+ </SheetPrimitive.Close>+ ) : null}</SheetPrimitive.Content></SheetPortal>))@@ -218,9 +222,9 @@ export {SheetClose,SheetContent,SheetDescription,+ SheetFooter,SheetHeader,SheetSection,- SheetFooter,SheetTitle,SheetTrigger,}