import { usePrevious } from '@uidotdev/usehooks' import { noop } from 'lodash' import { HelpCircle } from 'lucide-react' import { useEffect } from 'react' import { Tooltip, TooltipContent, TooltipTrigger } from 'ui' import SqlEditor from '@/components/ui/SqlEditor' interface PolicyDefinitionProps { operation: string definition: string check: string onUpdatePolicyUsing: (using: string | undefined) => void onUpdatePolicyCheck: (check: string | undefined) => void } const PolicyDefinition = ({ operation = '', definition = '', check = '', onUpdatePolicyUsing = noop, onUpdatePolicyCheck = noop, }: PolicyDefinitionProps) => { const showUsing = (operation: string) => ['SELECT', 'UPDATE', 'DELETE', 'ALL'].includes(operation) || !operation const showCheck = (operation: string) => ['INSERT', 'UPDATE', 'ALL'].includes(operation) const previousOperation = usePrevious(operation) || '' useEffect(() => { if (showUsing(previousOperation) && !showUsing(operation)) onUpdatePolicyUsing(undefined) if (showCheck(previousOperation) && !showCheck(operation)) onUpdatePolicyCheck(undefined) }, [operation]) return (
This expression will be added to queries that refer to the table if row-level security is enabled.
Rows for which the expression returns true will be visible. Any rows for which the expression returns false or null will not be visible to the user (in a SELECT), and will not be available for modification (in an UPDATE or DELETE).
Such rows are silently suppressed - no error is reported.
Provide a SQL conditional expression that returns a boolean.
This expression will be used in INSERT and UPDATE queries against the table if row-level security is enabled.
Only rows for which the expression evaluates to true will be allowed. An error will be thrown if the expression evaluates to false or null for any of the records inserted or any of the records that result from the update.
Note that this expression is evaluated against the proposed new contents of the row, not the original contents.
Provide a SQL conditional expression that returns a boolean.