import { FC } from 'react' import { uniqBy, map as lodashMap, includes } from 'lodash' import { Button, IconSearch, IconLoader, Input } from 'ui' import { observer } from 'mobx-react-lite' import * as Tooltip from '@radix-ui/react-tooltip' import { PermissionAction } from '@supabase/shared-types/out/constants' import { checkPermissions, useStore } from 'hooks' import AlphaPreview from 'components/to-be-cleaned/AlphaPreview' import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState' import SchemaTable from './SchemaTable' const FunctionsList: FC = ({ filterString, setFilterString = () => {}, createFunction = () => {}, editFunction = () => {}, deleteFunction = () => {}, }) => { const { meta } = useStore() const functions = meta.functions.list((fn: any) => !meta.excludedSchemas.includes(fn.schema)) const filteredFunctions = functions.filter((x: any) => includes(x.name.toLowerCase(), filterString.toLowerCase()) ) const filteredFunctionSchemas = lodashMap(uniqBy(filteredFunctions, 'schema'), 'schema') const canCreateFunctions = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'functions') if (meta.functions.isLoading) { return (

Loading functions...

) } if (meta.functions.hasError) { return (

Error connecting to API

{`${meta.functions.error?.message ?? 'Unknown error'}`}

) } return ( <> {functions.length == 0 ? (
createFunction()} >

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} onChange={(e) => setFilterString(e.target.value)} /> {!canCreateFunctions && (
You need additional permissions to create functions
)}
{filteredFunctions.length <= 0 && (

No results match your filter query

)} {filteredFunctionSchemas.map((schema: any) => ( ))}
)} ) } export default observer(FunctionsList)