diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/EdgeFunctionSection.tsx b/apps/studio/components/interfaces/Integrations/CronJobs/EdgeFunctionSection.tsx index bea8fed5bdc..39439769882 100644 --- a/apps/studio/components/interfaces/Integrations/CronJobs/EdgeFunctionSection.tsx +++ b/apps/studio/components/interfaces/Integrations/CronJobs/EdgeFunctionSection.tsx @@ -1,18 +1,29 @@ -import Link from 'next/link' -import { UseFormReturn } from 'react-hook-form' - import { useParams } from 'common/hooks' import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' -import { useEffect, useMemo } from 'react' +import { Check, ChevronsUpDown } from 'lucide-react' +import Link from 'next/link' +import { useEffect, useId, useMemo, useState } from 'react' +import { UseFormReturn } from 'react-hook-form' import { Button, + cn, + Command_Shadcn_, + CommandEmpty_Shadcn_, + CommandGroup_Shadcn_, + CommandInput_Shadcn_, + CommandItem_Shadcn_, + CommandList_Shadcn_, FormControl_Shadcn_, FormField_Shadcn_, FormItem_Shadcn_, FormLabel_Shadcn_, FormMessage_Shadcn_, Input, + Popover_Shadcn_, + PopoverContent_Shadcn_, + PopoverTrigger_Shadcn_, + ScrollArea, Select_Shadcn_, SelectContent_Shadcn_, SelectItem_Shadcn_, @@ -21,6 +32,7 @@ import { SheetSection, } from 'ui' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' + import { CreateCronJobForm } from './CreateCronJobSheet/CreateCronJobSheet.constants' interface HTTPRequestFieldsProps { @@ -41,19 +53,22 @@ export const EdgeFunctionSection = ({ form }: HTTPRequestFieldsProps) => { isSuccess, isPending: isLoading, } = useEdgeFunctionsQuery({ projectRef: ref }) - - const edgeFunctions = useMemo(() => functions ?? [], [functions]) + const [open, setOpen] = useState(false) + const listboxId = useId() + const edgeFunctions = useMemo( + () => + functions?.map((fn) => ({ + ...fn, + url: buildFunctionUrl(fn.slug, selectedProject?.ref || '', selectedProject?.restUrl), + })) ?? [], + [functions, selectedProject] + ) // Only set a default value if the field is empty useEffect(() => { if (isSuccess && edgeFunctions.length > 0 && !form.getValues('values.edgeFunctionName')) { const fn = edgeFunctions[0] - const functionUrl = buildFunctionUrl( - fn.slug, - selectedProject?.ref || '', - selectedProject?.restUrl - ) - form.setValue('values.edgeFunctionName', functionUrl) + form.setValue('values.edgeFunctionName', fn.url) } }, [edgeFunctions, form, isSuccess, selectedProject?.ref, selectedProject?.restUrl]) @@ -84,47 +99,88 @@ export const EdgeFunctionSection = ({ form }: HTTPRequestFieldsProps) => { {edgeFunctions.length === 0 ? (

Select which edge function to trigger

-
-

No edge functions created yet

- -
+ ) : ( +
+

No edge functions created yet

+ +
+ )}
) : edgeFunctions.length > 0 ? ( { + const selectedFunction = edgeFunctions.find((fn) => fn.url === field.value) + return ( Edge Function - - - - - - - - {edgeFunctions.map((fn) => { - const functionUrl = buildFunctionUrl( - fn.slug, - selectedProject?.ref || '', - selectedProject?.restUrl - ) - - return ( - - {fn.name} - - ) - })} - - + + + + + + + + + + + No edge function found. + + 7 ? 'h-[210px]' : ''}> + {edgeFunctions.map((fn) => { + return ( + { + field.onChange(fn.url === field.value ? '' : fn.url) + setOpen(false) + }} + > + + {fn.name} + + ) + })} + + + + + + )