1+ import { PostgresTrigger } from '@supabase/postgres-meta'
12import { PermissionAction } from '@supabase/shared-types/out/constants'
23import { includes , sortBy } from 'lodash'
34import { Check , Copy , Edit , Edit2 , MoreVertical , Trash , X } from 'lucide-react'
45
5- import { ButtonTooltip } from 'components/ui/ButtonTooltip '
6+ import { useParams } from 'common '
67import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
8+ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
9+ import { InlineLink } from 'components/ui/InlineLink'
710import { useDatabaseTriggersQuery } from 'data/database-triggers/database-triggers-query'
811import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
912import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
@@ -24,7 +27,6 @@ import {
2427 TooltipTrigger ,
2528} from 'ui'
2629import { generateTriggerCreateSQL } from './TriggerList.utils'
27- import { PostgresTrigger } from '@supabase/postgres-meta'
2830
2931interface TriggerListProps {
3032 schema : string
@@ -35,18 +37,24 @@ interface TriggerListProps {
3537 deleteTrigger : ( trigger : PostgresTrigger ) => void
3638}
3739
38- const TriggerList = ( {
40+ export const TriggerList = ( {
3941 schema,
4042 filterString,
4143 isLocked,
4244 editTrigger,
4345 duplicateTrigger,
4446 deleteTrigger,
4547} : TriggerListProps ) => {
48+ const { ref : projectRef } = useParams ( )
4649 const { data : project } = useSelectedProjectQuery ( )
4750 const aiSnap = useAiAssistantStateSnapshot ( )
4851 const { openSidebar } = useSidebarManagerSnapshot ( )
4952
53+ const { can : canUpdateTriggers } = useAsyncCheckPermissions (
54+ PermissionAction . TENANT_SQL_ADMIN_WRITE ,
55+ 'triggers'
56+ )
57+
5058 const { data : triggers } = useDatabaseTriggersQuery ( {
5159 projectRef : project ?. ref ,
5260 connectionString : project ?. connectionString ,
@@ -56,15 +64,10 @@ const TriggerList = ({
5664 includes ( x . name . toLowerCase ( ) , filterString . toLowerCase ( ) ) ||
5765 ( x . function_name && includes ( x . function_name . toLowerCase ( ) , filterString . toLowerCase ( ) ) )
5866 )
59-
6067 const _triggers = sortBy (
6168 filteredTriggers . filter ( ( x ) => x . schema == schema ) ,
6269 ( trigger ) => trigger . name . toLocaleLowerCase ( )
6370 )
64- const { can : canUpdateTriggers } = useAsyncCheckPermissions (
65- PermissionAction . TENANT_SQL_ADMIN_WRITE ,
66- 'triggers'
67- )
6871
6972 if ( _triggers . length === 0 && filterString . length === 0 ) {
7073 return (
@@ -94,7 +97,7 @@ const TriggerList = ({
9497
9598 return (
9699 < >
97- { _triggers . map ( ( x : any ) => (
100+ { _triggers . map ( ( x ) => (
98101 < TableRow key = { x . id } >
99102 < TableCell className = "space-x-2" >
100103 < Tooltip >
@@ -111,15 +114,33 @@ const TriggerList = ({
111114 </ TableCell >
112115
113116 < TableCell className = "break-all" >
114- < p title = { x . table } className = "truncate" >
115- { x . table }
116- </ p >
117+ { x . table_id ? (
118+ < InlineLink
119+ title = { x . table }
120+ href = { `/project/${ projectRef } /editor/${ x . table_id } ` }
121+ className = "truncate block max-w-40"
122+ >
123+ { x . table }
124+ </ InlineLink >
125+ ) : (
126+ < p title = { x . table } className = "truncate" >
127+ { x . table }
128+ </ p >
129+ ) }
117130 </ TableCell >
118131
119132 < TableCell className = "space-x-2" >
120- < p title = { x . function_name } className = "truncate" >
121- { x . function_name }
122- </ p >
133+ { x . function_name ? (
134+ < InlineLink
135+ title = { x . function_name }
136+ href = { `/project/${ projectRef } /database/functions?search=${ x . function_name } &schema=${ x . function_schema } ` }
137+ className = "truncate block max-w-40"
138+ >
139+ { x . function_name }
140+ </ InlineLink >
141+ ) : (
142+ < p className = "truncate text-foreground-light" > -</ p >
143+ ) }
123144 </ TableCell >
124145
125146 < TableCell >
@@ -176,7 +197,7 @@ const TriggerList = ({
176197 const sql = generateTriggerCreateSQL ( x )
177198 openSidebar ( SIDEBAR_KEYS . AI_ASSISTANT )
178199 aiSnap . newChat ( {
179- name : `Update trigger ${ X . name } ` ,
200+ name : `Update trigger ${ x . name } ` ,
180201 initialInput : `Update this trigger which exists on the ${ x . schema } .${ x . table } table to...` ,
181202 suggestions : {
182203 title :
@@ -237,5 +258,3 @@ const TriggerList = ({
237258 </ >
238259 )
239260}
240-
241- export default TriggerList
0 commit comments