Skip to content

Commit 32c78ff

Browse files
authored
Merge pull request #1514 from supabase/master
[pull] master from supabase:master
2 parents 8b2a849 + 36d3847 commit 32c78ff

File tree

38 files changed

+934
-1077
lines changed

38 files changed

+934
-1077
lines changed

apps/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ import { Button, SidePanel } from 'ui'
99
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
1010
import InformationBox from 'components/ui/InformationBox'
1111
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'
1418

1519
export interface ChooseFunctionFormProps {
16-
triggerFunctions: DatabaseFunction[]
1720
visible: boolean
18-
onChange: (id: number) => void
1921
setVisible: (value: boolean) => void
22+
onChange: (fn: DatabaseFunction) => void
2023
}
2124

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')
2833
const hasPublicSchemaFunctions = triggerFunctions.length >= 1
2934
const functionSchemas = lodashMap(uniqBy(triggerFunctions, 'schema'), 'schema')
3035

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)
3339
setVisible(!visible)
3440
}
3541

0 commit comments

Comments
 (0)