import * as Tooltip from '@radix-ui/react-tooltip' import { PostgresFunction } from '@supabase/postgres-meta' import { PermissionAction } from '@supabase/shared-types/out/constants' import { noop, partition } from 'lodash' import { observer } from 'mobx-react-lite' import { useState } from 'react' import { Button, IconLock, IconSearch, Input, Listbox } from 'ui' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState' import Table from 'components/to-be-cleaned/Table' import AlertError from 'components/ui/AlertError' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import { useSchemasQuery } from 'data/database/schemas-query' import { useCheckPermissions, useStore } from 'hooks' import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas' import FunctionList from './FunctionList' import SchemaSelector from 'components/ui/SchemaSelector' import ProtectedSchemaWarning from '../../ProtectedSchemaWarning' interface FunctionsListProps { createFunction: () => void editFunction: (fn: PostgresFunction) => void deleteFunction: (fn: PostgresFunction) => void } const FunctionsList = ({ createFunction = noop, editFunction = noop, deleteFunction = noop, }: FunctionsListProps) => { const { project } = useProjectContext() const { meta } = useStore() const [selectedSchema, setSelectedSchema] = useState('public') const [filterString, setFilterString] = useState('') const canCreateFunctions = useCheckPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, 'functions' ) const { data: schemas } = useSchemasQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const [protectedSchemas] = partition(schemas ?? [], (schema) => EXCLUDED_SCHEMAS.includes(schema?.name ?? '') ) const schema = schemas?.find((schema) => schema.name === selectedSchema) const isLocked = protectedSchemas.some((s) => s.id === schema?.id) const functions = meta.functions.list() if (meta.functions.isLoading) { return } if (meta.functions.hasError) { return ( ) } return ( <> {functions.length == 0 ? (
createFunction()} disabled={!canCreateFunctions} disabledMessage="You need additional permissions to create functions" >

PostgreSQL functions, also known as stored procedures, is a set of SQL and procedural commands such as declarations, assignments, loops, flow-of-control, etc.

It's stored on the database server and can be invoked using the SQL interface.

) : (
} value={filterString} className="w-64" onChange={(e) => setFilterString(e.target.value)} />
{!canCreateFunctions && (
You need additional permissions to create functions
)}
{isLocked && } Name Arguments Return type Security } body={ } /> )} ) } export default observer(FunctionsList)