Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add error handling for permissions + small style fix on triggers UI

Joshen Lim03193945994e
diff --git a/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx b/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx
index 8c67c3367d9..ab10ddb09ce 100644
--- a/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx
+++ b/studio/components/interfaces/Database/Triggers/ChooseFunctionForm.tsx
@@ -1,4 +1,4 @@
-import { FC, createContext, useContext, useState } from 'react'
+import { createContext, useContext, useState } from 'react'
import { useRouter } from 'next/router'
import { observer, useLocalObservable } from 'mobx-react-lite'
import { uniqBy, map as lodashMap } from 'lodash'
@@ -24,19 +24,19 @@ class ChooseFunctionFormStore implements IChooseFunctionFormStore {
const ChooseFunctionFormContext = createContext<IChooseFunctionFormStore | null>(null)
-type ChooseFunctionFormProps = {
+export interface ChooseFunctionFormProps {
triggerFunctions: Dictionary<any>[]
visible: boolean
onChange: (id: number) => void
setVisible: (value: boolean) => void
}
-const ChooseFunctionForm: FC<ChooseFunctionFormProps> = ({
+const ChooseFunctionForm = ({
triggerFunctions,
visible,
onChange,
setVisible,
-}) => {
+}: ChooseFunctionFormProps) => {
const _localState = useLocalObservable(() => new ChooseFunctionFormStore())
_localState.triggerFunctions = triggerFunctions as any
@@ -55,25 +55,27 @@ const ChooseFunctionForm: FC<ChooseFunctionFormProps> = ({
onCancel={() => setVisible(!visible)}
className="hooks-sidepanel"
>
- {hasPublicSchemaFunctions ? (
- <ChooseFunctionFormContext.Provider value={_localState}>
- <div className="space-y-6">
- <NoticeBox />
- {_localState.functionSchemas.map((schema: string) => (
- <SchemaFunctionGroup key={schema} schema={schema} selectFunction={selectFunction} />
- ))}
- </div>
- </ChooseFunctionFormContext.Provider>
- ) : (
- <NoFunctionsState />
- )}
+ <div className="py-6">
+ {hasPublicSchemaFunctions ? (
+ <ChooseFunctionFormContext.Provider value={_localState}>
+ <div className="space-y-6">
+ <NoticeBox />
+ {_localState.functionSchemas.map((schema: string) => (
+ <SchemaFunctionGroup key={schema} schema={schema} selectFunction={selectFunction} />
+ ))}
+ </div>
+ </ChooseFunctionFormContext.Provider>
+ ) : (
+ <NoFunctionsState />
+ )}
+ </div>
</SidePanel>
)
}
export default observer(ChooseFunctionForm)
-const NoticeBox: FC = ({}) => {
+const NoticeBox = ({}) => {
const router = useRouter()
const { ref } = router.query
return (
@@ -84,7 +86,7 @@ const NoticeBox: FC = ({}) => {
description={`You can make functions by using the Database Functions`}
button={
<Button
- type="secondary"
+ type="default"
onClick={() => {
router.push(`/project/${ref}/database/functions`)
}}
@@ -97,7 +99,7 @@ const NoticeBox: FC = ({}) => {
)
}
-const NoFunctionsState: FC = ({}) => {
+const NoFunctionsState = ({}) => {
// for the empty 'no tables' state link
const router = useRouter()
const { ref } = router.query
@@ -117,12 +119,12 @@ const NoFunctionsState: FC = ({}) => {
)
}
-type SchemaFunctionGroupProps = {
+export interface SchemaFunctionGroupProps {
schema: string
selectFunction: (id: number) => void
}
-const SchemaFunctionGroup: FC<SchemaFunctionGroupProps> = observer(({ schema, selectFunction }) => {
+const SchemaFunctionGroup = observer(({ schema, selectFunction }: SchemaFunctionGroupProps) => {
const _pageState = useContext(ChooseFunctionFormContext)
const _functions = _pageState!.triggerFunctions.filter((x) => x.schema == schema)
return (
@@ -146,14 +148,14 @@ const SchemaFunctionGroup: FC<SchemaFunctionGroupProps> = observer(({ schema, se
)
})
-type FunctionProps = {
+export interface FunctionProps {
id: number
completeStatement: string
name: string
onClick: (id: number) => void
}
-const Function: FC<FunctionProps> = ({ id, completeStatement, name, onClick }) => {
+const Function = ({ id, completeStatement, name, onClick }: FunctionProps) => {
const [visible, setVisible] = useState(false)
return (
<div
@@ -165,7 +167,7 @@ const Function: FC<FunctionProps> = ({ id, completeStatement, name, onClick }) =
<div className="flex items-center justify-center rounded bg-scale-1200 p-1 text-scale-100 ">
<IconTerminal strokeWidth={2} size={14} />
</div>
- <h5 className="mb-0">{name}</h5>
+ <p className="mb-0 text-sm">{name}</p>
</div>
<Button
type="text"
@@ -174,7 +176,7 @@ const Function: FC<FunctionProps> = ({ id, completeStatement, name, onClick }) =
setVisible(!visible)
}}
icon={
- <IconChevronDown className={visible ? 'rotate-0 transform' : 'rotate-180 transform'} />
+ <IconChevronDown className={visible ? 'rotate-180 transform' : 'rotate-0 transform'} />
}
>
{visible ? 'Hide definition' : 'View definition'}
diff --git a/studio/components/interfaces/Database/Triggers/TriggersList/SchemaTable.tsx b/studio/components/interfaces/Database/Triggers/TriggersList/SchemaTable.tsx
index 52672ba6421..b84e7897c68 100644
--- a/studio/components/interfaces/Database/Triggers/TriggersList/SchemaTable.tsx
+++ b/studio/components/interfaces/Database/Triggers/TriggersList/SchemaTable.tsx
@@ -24,10 +24,10 @@ const SchemaTable: FC<Props> = ({ filterString, schema, editTrigger, deleteTrigg
className="table-fixed px-6"
head={
<>
- <Table.th key="name" className="space-x-4">
+ <Table.th key="name" className="w-[25%] space-x-4">
Name
</Table.th>
- <Table.th key="table" className="hidden lg:table-cell">
+ <Table.th key="table" className="hidden w-[13%] lg:table-cell">
Table
</Table.th>
<Table.th key="function" className="hidden xl:table-cell">
diff --git a/studio/components/interfaces/Database/Triggers/TriggersList/TriggerList.tsx b/studio/components/interfaces/Database/Triggers/TriggersList/TriggerList.tsx
index f459c145aa0..bf876832723 100644
--- a/studio/components/interfaces/Database/Triggers/TriggersList/TriggerList.tsx
+++ b/studio/components/interfaces/Database/Triggers/TriggersList/TriggerList.tsx
@@ -37,16 +37,16 @@ const TriggerList: FC<Props> = ({ filterString, schema, editTrigger, deleteTrigg
<>
{_triggers.map((x: any) => (
<Table.tr key={x.id}>
- <Table.td className="space-x-2 break-all">
- <p>{x.name}</p>
+ <Table.td className="space-x-2">
+ <p title={x.name} className="truncate">
+ {x.name}
+ </p>
</Table.td>
<Table.td className="hidden lg:table-cell break-all">
- <p>{x.table}</p>
+ <p title={x.table}>{x.table}</p>
</Table.td>
<Table.td className="hidden space-x-2 xl:table-cell">
- <div className="flex flex-col">
- <p>{x.function_name}</p>
- </div>
+ <p title={x.function_name}>{x.function_name}</p>
</Table.td>
<Table.td className="hidden xl:table-cell">
<div className="flex space-x-2">
diff --git a/studio/hooks/misc/withAuth.tsx b/studio/hooks/misc/withAuth.tsx
index 35c36197825..be44628398e 100644
--- a/studio/hooks/misc/withAuth.tsx
+++ b/studio/hooks/misc/withAuth.tsx
@@ -50,6 +50,13 @@ export function withAuth<T>(
onSuccess(permissions) {
ui.setPermissions(permissions)
},
+ onError(error: any) {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Failed to fetch permissions: ${error.message}. Try refreshing your browser, or reach out to us via a support ticket if the issue persists`,
+ })
+ },
})
const isLoggedIn = Boolean(session)