mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
* start * added panels * remove stuff * fixes and refinements * clean up * remove old assistant panel * resizable assistant kinda * use icon * Add missing package * remove canvas * add suggestions * updated empty state if no tables exist * fix table condition * Implement diffing if using assistant in sql editor * Reinstate old assistant in SQL editor if feature preview is off * pane size adjustment * assistant button corners * Add SQL snippet content to assistant if opening assistant in sql editor * Add the necessary checks for opt in and hipaa * revert adding snippet to assistant when opening assistant in sql editor * Add cmd i shortcut * Add admonitions for when disablePrompt is toggled on, and if no api key is set. Add footer note RE rate limitation * Bump ai package in packages * some fixes for backwards compability depending on feature preview toggled * Rename feature preview property for new assistant * Smol fix * Prevent SQL snippet from running until message is finished * only loading last message * fix z-index * save chat state to global state * add debug to failed ai queries * Add basic contextual invalidation * Add explain code action to SQL editor * Add link to abort ongoing queries from SqlSnippet * Update feature preview content * Fix * Fix * Fix * Te4st * Fix tests * ONly show ai button within a project * Fix PH tracking * Beef up a bit more event tracking * Rough fix to padding when assistant is open * A bit more telemetry stuff * Update prompts * fix rls editing via assistant * Update generate-v3.ts prompt to get auth schema too * Add policy satement to assistant when editing * Address all comments * fixc * Fix SqlSnippet not taking full width on larger viewports * Adjust max width --------- Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
150 lines
5.1 KiB
TypeScript
150 lines
5.1 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { noop } from 'lodash'
|
|
import { Lock, Unlock } from 'lucide-react'
|
|
import { useQueryState } from 'nuqs'
|
|
|
|
import { useParams } from 'common'
|
|
import { useIsAssistantV2Enabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import { EditorTablePageLink } from 'data/prefetchers/project.$ref.editor.$id'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useAppStateSnapshot } from 'state/app-state'
|
|
import { AiIconAnimation, Badge } from 'ui'
|
|
|
|
interface PolicyTableRowHeaderProps {
|
|
table: {
|
|
id: number
|
|
schema: string
|
|
name: string
|
|
rls_enabled: boolean
|
|
}
|
|
isLocked: boolean
|
|
onSelectToggleRLS: (table: {
|
|
id: number
|
|
schema: string
|
|
name: string
|
|
rls_enabled: boolean
|
|
}) => void
|
|
onSelectCreatePolicy: () => void
|
|
}
|
|
|
|
const PolicyTableRowHeader = ({
|
|
table,
|
|
isLocked,
|
|
onSelectToggleRLS = noop,
|
|
onSelectCreatePolicy,
|
|
}: PolicyTableRowHeaderProps) => {
|
|
const { ref } = useParams()
|
|
const { setAiAssistantPanel } = useAppStateSnapshot()
|
|
|
|
const enableAssistantV2 = useIsAssistantV2Enabled()
|
|
const canCreatePolicies = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'policies')
|
|
const canToggleRLS = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')
|
|
|
|
const isRealtimeSchema = table.schema === 'realtime'
|
|
const isRealtimeMessagesTable = isRealtimeSchema && table.name === 'messages'
|
|
const isTableLocked = isRealtimeSchema ? !isRealtimeMessagesTable : isLocked
|
|
const [_, setEditView] = useQueryState('view', { defaultValue: '' })
|
|
|
|
return (
|
|
<div id={table.id.toString()} className="flex w-full items-center justify-between">
|
|
<div className="flex gap-x-4 text-left">
|
|
<EditorTablePageLink
|
|
projectRef={ref}
|
|
id={String(table.id)}
|
|
className="flex items-center gap-x-2"
|
|
>
|
|
{table.rls_enabled ? (
|
|
<div className="flex items-center gap-x-1 text-xs">
|
|
<Lock size={14} strokeWidth={2} className="text-brand" />
|
|
</div>
|
|
) : (
|
|
<div className="flex items-center gap-x-1 text-xs">
|
|
<Unlock size={14} strokeWidth={2} className="text-warning-600" />
|
|
</div>
|
|
)}
|
|
<h4 className="m-0">{table.name}</h4>
|
|
</EditorTablePageLink>
|
|
<div className="flex items-center gap-x-2">
|
|
{isTableLocked && (
|
|
<Badge>
|
|
<span className="flex gap-2 items-center text-xs uppercase text-foreground-lighter">
|
|
<Lock size={12} /> Locked
|
|
</span>
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
</div>
|
|
{!isTableLocked && (
|
|
<div className="flex-1">
|
|
<div className="flex flex-row justify-end gap-x-2">
|
|
{!isRealtimeMessagesTable && (
|
|
<ButtonTooltip
|
|
type="default"
|
|
disabled={!canToggleRLS}
|
|
onClick={() => onSelectToggleRLS(table)}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canToggleRLS
|
|
? 'You need additional permissions to toggle RLS'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
{table.rls_enabled ? 'Disable RLS' : 'Enable RLS'}
|
|
</ButtonTooltip>
|
|
)}
|
|
<ButtonTooltip
|
|
type="default"
|
|
disabled={!canToggleRLS || !canCreatePolicies}
|
|
onClick={() => onSelectCreatePolicy()}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canToggleRLS
|
|
? !canToggleRLS || !canCreatePolicies
|
|
? 'You need additional permissions to create RLS policies'
|
|
: undefined
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Create policy
|
|
</ButtonTooltip>
|
|
|
|
<ButtonTooltip
|
|
type="default"
|
|
className="px-1"
|
|
onClick={() => {
|
|
if (enableAssistantV2) {
|
|
setAiAssistantPanel({
|
|
open: true,
|
|
initialInput: `Create a new policy for the ${table.schema} schema on the ${table.name} table that ...`,
|
|
})
|
|
} else {
|
|
onSelectCreatePolicy()
|
|
setEditView('conversation')
|
|
}
|
|
}}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text:
|
|
!canToggleRLS || !canCreatePolicies
|
|
? 'You need additional permissions to create RLS policies'
|
|
: 'Create with Supabase Assistant',
|
|
},
|
|
}}
|
|
>
|
|
<AiIconAnimation className="scale-75 [&>div>div]:border-black dark:[&>div>div]:border-white" />
|
|
</ButtonTooltip>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default PolicyTableRowHeader
|