@@ -9,27 +9,33 @@ import { Button, SidePanel } from 'ui'
9
9
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
10
10
import InformationBox from 'components/ui/InformationBox'
11
11
import SqlEditor from 'components/ui/SqlEditor'
12
- import type { DatabaseFunction } from 'data/database-functions/database-functions-query'
13
- import { HelpCircle , Terminal , ChevronDown } from 'lucide-react'
12
+ import {
13
+ useDatabaseFunctionsQuery ,
14
+ type DatabaseFunction ,
15
+ } from 'data/database-functions/database-functions-query'
16
+ import { useSelectedProject } from 'hooks/misc/useSelectedProject'
17
+ import { ChevronDown , HelpCircle , Terminal } from 'lucide-react'
14
18
15
19
export interface ChooseFunctionFormProps {
16
- triggerFunctions : DatabaseFunction [ ]
17
20
visible : boolean
18
- onChange : ( id : number ) => void
19
21
setVisible : ( value : boolean ) => void
22
+ onChange : ( fn : DatabaseFunction ) => void
20
23
}
21
24
22
- const ChooseFunctionForm = ( {
23
- triggerFunctions,
24
- visible,
25
- onChange,
26
- setVisible,
27
- } : ChooseFunctionFormProps ) => {
25
+ const ChooseFunctionForm = ( { visible, onChange, setVisible } : ChooseFunctionFormProps ) => {
26
+ const project = useSelectedProject ( )
27
+
28
+ const { data = [ ] } = useDatabaseFunctionsQuery ( {
29
+ projectRef : project ?. ref ,
30
+ connectionString : project ?. connectionString ,
31
+ } )
32
+ const triggerFunctions = data . filter ( ( fn ) => fn . return_type === 'trigger' )
28
33
const hasPublicSchemaFunctions = triggerFunctions . length >= 1
29
34
const functionSchemas = lodashMap ( uniqBy ( triggerFunctions , 'schema' ) , 'schema' )
30
35
31
- function selectFunction ( id : number ) {
32
- onChange ( id )
36
+ const selectFunction = ( id : number ) => {
37
+ const fn = triggerFunctions . find ( ( x ) => x . id === id )
38
+ if ( ! ! fn ) onChange ( fn )
33
39
setVisible ( ! visible )
34
40
}
35
41
0 commit comments